diff options
Diffstat (limited to 'rpc')
58 files changed, 1674 insertions, 7935 deletions
diff --git a/rpc/rpc-lib/src/Makefile.am b/rpc/rpc-lib/src/Makefile.am index 81a96476883..35c9db07e7f 100644 --- a/rpc/rpc-lib/src/Makefile.am +++ b/rpc/rpc-lib/src/Makefile.am @@ -2,7 +2,7 @@ lib_LTLIBRARIES = libgfrpc.la libgfrpc_la_SOURCES = auth-unix.c rpcsvc-auth.c rpcsvc.c auth-null.c \ rpc-transport.c xdr-rpc.c xdr-rpcclnt.c rpc-clnt.c auth-glusterfs.c \ - rpc-drc.c $(CONTRIBDIR)/sunrpc/xdr_sizeof.c rpc-clnt-ping.c \ + rpc-drc.c rpc-clnt-ping.c \ autoscale-threads.c mgmt-pmap.c EXTRA_DIST = libgfrpc.sym diff --git a/rpc/rpc-lib/src/auth-glusterfs.c b/rpc/rpc-lib/src/auth-glusterfs.c index d569a0403f8..69a96f7512f 100644 --- a/rpc/rpc-lib/src/auth-glusterfs.c +++ b/rpc/rpc-lib/src/auth-glusterfs.c @@ -9,8 +9,7 @@ */ #include "rpcsvc.h" -#include "list.h" -#include "dict.h" +#include <glusterfs/dict.h> #include "xdr-rpc.h" #include "xdr-common.h" #include "rpc-common-xdr.h" diff --git a/rpc/rpc-lib/src/auth-null.c b/rpc/rpc-lib/src/auth-null.c index 46046e8e440..6d059b9da50 100644 --- a/rpc/rpc-lib/src/auth-null.c +++ b/rpc/rpc-lib/src/auth-null.c @@ -9,8 +9,7 @@ */ #include "rpcsvc.h" -#include "list.h" -#include "dict.h" +#include <glusterfs/dict.h> int auth_null_request_init(rpcsvc_request_t *req, void *priv) diff --git a/rpc/rpc-lib/src/auth-unix.c b/rpc/rpc-lib/src/auth-unix.c index c53870fcf94..61d475a5e84 100644 --- a/rpc/rpc-lib/src/auth-unix.c +++ b/rpc/rpc-lib/src/auth-unix.c @@ -9,8 +9,7 @@ */ #include "rpcsvc.h" -#include "list.h" -#include "dict.h" +#include <glusterfs/dict.h> #include "xdr-rpc.h" int diff --git a/rpc/rpc-lib/src/autoscale-threads.c b/rpc/rpc-lib/src/autoscale-threads.c index 337f002df10..a954ae7a27a 100644 --- a/rpc/rpc-lib/src/autoscale-threads.c +++ b/rpc/rpc-lib/src/autoscale-threads.c @@ -8,7 +8,7 @@ cases as published by the Free Software Foundation. */ -#include "gf-event.h" +#include <glusterfs/gf-event.h> #include "rpcsvc.h" void @@ -18,6 +18,5 @@ rpcsvc_autoscale_threads(glusterfs_ctx_t *ctx, rpcsvc_t *rpc, int incr) int thread_count = pool->eventthreadcount; pool->auto_thread_count += incr; - (void)event_reconfigure_threads(pool, thread_count + incr); - rpcsvc_ownthread_reconf(rpc, pool->eventthreadcount); + (void)gf_event_reconfigure_threads(pool, thread_count + incr); } diff --git a/rpc/rpc-lib/src/libgfrpc.sym b/rpc/rpc-lib/src/libgfrpc.sym index a7cb5f6b5cb..e026d80259b 100644 --- a/rpc/rpc-lib/src/libgfrpc.sym +++ b/rpc/rpc-lib/src/libgfrpc.sym @@ -3,7 +3,6 @@ rpcclnt_cbk_program_register rpc_clnt_cleanup_and_start rpc_clnt_connection_cleanup rpc_clnt_disable -rpc_clnt_disconnect rpc_clnt_new rpc_clnt_reconfig rpc_clnt_reconnect @@ -26,6 +25,7 @@ rpcsvc_drc_priv rpcsvc_drc_reconfigure rpcsvc_get_program_vector_sizer rpcsvc_init +rpcsvc_destroy rpcsvc_init_options rpcsvc_listener_destroy rpcsvc_program_register @@ -51,7 +51,6 @@ rpcsvc_transport_connect rpcsvc_transport_getpeeraddr rpcsvc_unregister_notify rpcsvc_volume_allowed -rpcsvc_ownthread_reconf rpc_transport_count rpc_transport_connect rpc_transport_disconnect @@ -66,3 +65,4 @@ rpc_transport_unix_options_build rpc_transport_unref rpc_clnt_mgmt_pmap_signout rpcsvc_autoscale_threads +rpcsvc_statedump diff --git a/rpc/rpc-lib/src/mgmt-pmap.c b/rpc/rpc-lib/src/mgmt-pmap.c index 344ec56bbf7..25a7148e5a3 100644 --- a/rpc/rpc-lib/src/mgmt-pmap.c +++ b/rpc/rpc-lib/src/mgmt-pmap.c @@ -12,7 +12,6 @@ #include "protocol-common.h" #include "rpc-clnt.h" #include "xdr-generic.h" -#include "xlator.h" /* Defining a minimal RPC client program for portmap signout */ @@ -35,7 +34,9 @@ mgmt_pmap_signout_cbk(struct rpc_req *req, struct iovec *iov, int count, 0, }; int ret = 0; + call_frame_t *frame = NULL; + frame = myframe; if (-1 == req->rpc_status) { rsp.op_ret = -1; rsp.op_errno = EINVAL; @@ -56,6 +57,10 @@ mgmt_pmap_signout_cbk(struct rpc_req *req, struct iovec *iov, int count, goto out; } out: + if (frame) { + STACK_DESTROY(frame->root); + } + return 0; } diff --git a/rpc/rpc-lib/src/protocol-common.h b/rpc/rpc-lib/src/protocol-common.h index 4950857ae9e..0cb5862e9a9 100644 --- a/rpc/rpc-lib/src/protocol-common.h +++ b/rpc/rpc-lib/src/protocol-common.h @@ -68,6 +68,7 @@ enum gf_fop_procnum { GFS3_OP_ICREATE, GFS3_OP_NAMELINK, GFS3_OP_PUT, + GFS3_OP_COPY_FILE_RANGE, GFS3_OP_MAXVALUE, }; @@ -244,6 +245,8 @@ enum glusterd_brick_procnum { GLUSTERD_NODE_BITROT, GLUSTERD_BRICK_ATTACH, GLUSTERD_DUMP_METRICS, + GLUSTERD_SVC_ATTACH, + GLUSTERD_SVC_DETACH, GLUSTERD_BRICK_MAXVALUE, }; @@ -306,6 +309,7 @@ enum glusterd_mgmt_v3_procnum { GLUSTERD_MGMT_V3_PRE_VALIDATE, GLUSTERD_MGMT_V3_BRICK_OP, GLUSTERD_MGMT_V3_COMMIT, + GLUSTERD_MGMT_V3_POST_COMMIT, GLUSTERD_MGMT_V3_POST_VALIDATE, GLUSTERD_MGMT_V3_UNLOCK, GLUSTERD_MGMT_V3_MAXVALUE, diff --git a/rpc/rpc-lib/src/rpc-clnt-ping.c b/rpc/rpc-lib/src/rpc-clnt-ping.c index a98a83dd8c8..31f17841bea 100644 --- a/rpc/rpc-lib/src/rpc-clnt-ping.c +++ b/rpc/rpc-lib/src/rpc-clnt-ping.c @@ -10,14 +10,14 @@ #include "rpc-clnt.h" #include "rpc-clnt-ping.h" -#include "byte-order.h" +#include <glusterfs/byte-order.h> #include "xdr-rpcclnt.h" #include "rpc-transport.h" #include "protocol-common.h" -#include "mem-pool.h" +#include <glusterfs/mem-pool.h> #include "xdr-rpc.h" #include "rpc-common-xdr.h" -#include "timespec.h" +#include <glusterfs/timespec.h> char *clnt_ping_procs[GF_DUMP_MAXVALUE] = { [GF_DUMP_PING] = "NULL", @@ -108,7 +108,6 @@ rpc_clnt_ping_timer_expired(void *rpc_ptr) rpc_transport_t *trans = NULL; rpc_clnt_connection_t *conn = NULL; int disconnect = 0; - int transport_activity = 0; struct timespec current = { 0, }; @@ -123,28 +122,22 @@ rpc_clnt_ping_timer_expired(void *rpc_ptr) goto out; } + timespec_now_realtime(¤t); pthread_mutex_lock(&conn->lock); { unref = rpc_clnt_remove_ping_timer_locked(rpc); - clock_gettime(CLOCK_REALTIME, ¤t); if (((current.tv_sec - conn->last_received.tv_sec) < conn->ping_timeout) || ((current.tv_sec - conn->last_sent.tv_sec) < conn->ping_timeout)) { - transport_activity = 1; - } - - if (transport_activity) { gf_log(trans->name, GF_LOG_TRACE, "ping timer expired but transport activity " "detected - not bailing transport"); - if (__rpc_clnt_rearm_ping_timer(rpc, rpc_clnt_ping_timer_expired) == -1) { gf_log(trans->name, GF_LOG_WARNING, "unable to setup ping timer"); } - } else { conn->ping_started = 0; disconnect = 1; @@ -198,14 +191,16 @@ rpc_clnt_ping_cbk(struct rpc_req *req, struct iovec *iov, int count, timespec_sub(&local->submit_time, &now, &delta); latency_msec = delta.tv_sec * 1000 + delta.tv_nsec / 1000000; + gf_log(THIS->name, GF_LOG_DEBUG, "Ping latency is %" PRIu64 "ms", + latency_msec); + call_notify = _gf_true; + pthread_mutex_lock(&conn->lock); { - gf_log(THIS->name, GF_LOG_DEBUG, "Ping latency is %" PRIu64 "ms", - latency_msec); - - call_notify = _gf_true; + unref = rpc_clnt_remove_ping_timer_locked(local->rpc); if (req->rpc_status == -1) { - unref = rpc_clnt_remove_ping_timer_locked(local->rpc); + conn->ping_started = 0; + pthread_mutex_unlock(&conn->lock); if (unref) { gf_log(this->name, GF_LOG_WARNING, "socket or ib related error"); @@ -214,19 +209,20 @@ rpc_clnt_ping_cbk(struct rpc_req *req, struct iovec *iov, int count, /* timer expired and transport bailed out */ gf_log(this->name, GF_LOG_WARNING, "socket disconnected"); } - conn->ping_started = 0; - goto unlock; + goto after_unlock; } - unref = rpc_clnt_remove_ping_timer_locked(local->rpc); if (__rpc_clnt_rearm_ping_timer(local->rpc, rpc_clnt_start_ping) == -1) { + /* unlock before logging error */ + pthread_mutex_unlock(&conn->lock); gf_log(this->name, GF_LOG_WARNING, "failed to set the ping timer"); + } else { + /* just unlock the mutex */ + pthread_mutex_unlock(&conn->lock); } } -unlock: - pthread_mutex_unlock(&conn->lock); - +after_unlock: if (call_notify) { ret = local->rpc->notifyfn(local->rpc, this, RPC_CLNT_PING, (void *)(uintptr_t)latency_msec); diff --git a/rpc/rpc-lib/src/rpc-clnt-ping.h b/rpc/rpc-lib/src/rpc-clnt-ping.h index fcbac6f9e21..e5466a828c2 100644 --- a/rpc/rpc-lib/src/rpc-clnt-ping.h +++ b/rpc/rpc-lib/src/rpc-clnt-ping.h @@ -8,6 +8,7 @@ cases as published by the Free Software Foundation. */ +struct rpc_clnt; #define RPC_DEFAULT_PING_TIMEOUT 30 void rpc_clnt_check_and_start_ping(struct rpc_clnt *rpc_ptr); diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c index 9b8e79070ec..517037c4a5d 100644 --- a/rpc/rpc-lib/src/rpc-clnt.c +++ b/rpc/rpc-lib/src/rpc-clnt.c @@ -12,11 +12,11 @@ #include "rpc-clnt.h" #include "rpc-clnt-ping.h" -#include "byte-order.h" +#include <glusterfs/byte-order.h> #include "xdr-rpcclnt.h" #include "rpc-transport.h" #include "protocol-common.h" -#include "mem-pool.h" +#include <glusterfs/mem-pool.h> #include "xdr-rpc.h" #include "rpc-common-xdr.h" @@ -55,25 +55,25 @@ _is_lock_fop(struct saved_frame *sframe) (fop == GFS3_OP_FENTRYLK)); } -struct saved_frame * +static struct saved_frame * __saved_frames_put(struct saved_frames *frames, void *frame, struct rpc_req *rpcreq) { - struct saved_frame *saved_frame = NULL; + struct saved_frame *saved_frame = mem_get( + rpcreq->conn->rpc_clnt->saved_frames_pool); - saved_frame = mem_get(rpcreq->conn->rpc_clnt->saved_frames_pool); if (!saved_frame) { goto out; } /* THIS should be saved and set back */ - memset(saved_frame, 0, sizeof(*saved_frame)); INIT_LIST_HEAD(&saved_frame->list); saved_frame->capital_this = THIS; saved_frame->frame = frame; saved_frame->rpcreq = rpcreq; gettimeofday(&saved_frame->saved_at, NULL); + memset(&saved_frame->rsp, 0, sizeof(rpc_transport_rsp_t)); if (_is_lock_fop(saved_frame)) list_add_tail(&saved_frame->list, &frames->lk_sf.list); @@ -97,7 +97,7 @@ call_bail(void *data) struct saved_frame *saved_frame = NULL; struct saved_frame *trav = NULL; struct saved_frame *tmp = NULL; - char frame_sent[256] = { + char frame_sent[GF_TIMESTR_SIZE] = { 0, }; struct timespec timeout = { @@ -105,7 +105,6 @@ call_bail(void *data) }; char peerid[UNIX_PATH_MAX] = {0}; gf_boolean_t need_unref = _gf_false; - int len; GF_VALIDATE_OR_GOTO("client", data, out); @@ -116,8 +115,8 @@ call_bail(void *data) { trans = conn->trans; if (trans) { - strncpy(peerid, conn->trans->peerinfo.identifier, - sizeof(peerid) - 1); + (void)snprintf(peerid, sizeof(peerid), "%s", + conn->trans->peerinfo.identifier); } } pthread_mutex_unlock(&conn->lock); @@ -165,11 +164,8 @@ call_bail(void *data) list_for_each_entry_safe(trav, tmp, &list, list) { - gf_time_fmt(frame_sent, sizeof frame_sent, trav->saved_at.tv_sec, - gf_timefmt_FT); - len = strlen(frame_sent); - snprintf(frame_sent + len, sizeof(frame_sent) - len, - ".%" GF_PRI_SUSECONDS, trav->saved_at.tv_usec); + gf_time_fmt_tv(frame_sent, sizeof frame_sent, &trav->saved_at, + gf_timefmt_FT); gf_log(conn->name, GF_LOG_ERROR, "bailing out frame type(%s), op(%s(%d)), xid = 0x%x, " @@ -199,19 +195,16 @@ out: } /* to be called with conn->lock held */ -struct saved_frame * +static struct saved_frame * __save_frame(struct rpc_clnt *rpc_clnt, call_frame_t *frame, struct rpc_req *rpcreq) { - rpc_clnt_connection_t *conn = NULL; + rpc_clnt_connection_t *conn = &rpc_clnt->conn; struct timespec timeout = { 0, }; - struct saved_frame *saved_frame = NULL; - - conn = &rpc_clnt->conn; - - saved_frame = __saved_frames_put(conn->saved_frames, frame, rpcreq); + struct saved_frame *saved_frame = __saved_frames_put(conn->saved_frames, + frame, rpcreq); if (saved_frame == NULL) { goto out; @@ -320,20 +313,15 @@ saved_frames_unwind(struct saved_frames *saved_frames) { struct saved_frame *trav = NULL; struct saved_frame *tmp = NULL; - char timestr[1024] = { + char timestr[GF_TIMESTR_SIZE] = { 0, }; - int len; list_splice_init(&saved_frames->lk_sf.list, &saved_frames->sf.list); list_for_each_entry_safe(trav, tmp, &saved_frames->sf.list, list) { - gf_time_fmt(timestr, sizeof timestr, trav->saved_at.tv_sec, - gf_timefmt_FT); - len = strlen(timestr); - snprintf(timestr + len, sizeof(timestr) - len, ".%" GF_PRI_SUSECONDS, - trav->saved_at.tv_usec); + gf_time_fmt_tv(timestr, sizeof timestr, &trav->saved_at, gf_timefmt_FT); if (!trav->rpcreq || !trav->rpcreq->prog) continue; @@ -379,19 +367,20 @@ rpc_clnt_reconnect(void *conn_ptr) struct timespec ts = {0, 0}; struct rpc_clnt *clnt = NULL; gf_boolean_t need_unref = _gf_false; + gf_boolean_t canceled_unref = _gf_false; conn = conn_ptr; clnt = conn->rpc_clnt; - pthread_mutex_lock(&conn->lock); { trans = conn->trans; - if (!trans) { - pthread_mutex_unlock(&conn->lock); - return; + if (!trans) + goto out_unlock; + + if (conn->reconnect) { + if (!gf_timer_call_cancel(clnt->ctx, conn->reconnect)) + canceled_unref = _gf_true; } - if (conn->reconnect) - gf_timer_call_cancel(clnt->ctx, conn->reconnect); conn->reconnect = 0; if ((conn->connected == 0) && !clnt->disabled) { @@ -412,11 +401,14 @@ rpc_clnt_reconnect(void *conn_ptr) gf_log(conn->name, GF_LOG_TRACE, "breaking reconnect chain"); } } +out_unlock: pthread_mutex_unlock(&conn->lock); rpc_clnt_unref(clnt); if (need_unref) rpc_clnt_unref(clnt); + if (canceled_unref) + rpc_clnt_unref(clnt); return; } @@ -498,6 +490,7 @@ rpc_clnt_connection_cleanup(rpc_clnt_connection_t *conn) int unref = 0; int ret = 0; gf_boolean_t timer_unref = _gf_false; + gf_boolean_t reconnect_unref = _gf_false; if (!conn) { goto out; @@ -517,6 +510,12 @@ rpc_clnt_connection_cleanup(rpc_clnt_connection_t *conn) timer_unref = _gf_true; conn->timer = NULL; } + if (conn->reconnect) { + ret = gf_timer_call_cancel(clnt->ctx, conn->reconnect); + if (!ret) + reconnect_unref = _gf_true; + conn->reconnect = NULL; + } conn->connected = 0; conn->disconnected = 1; @@ -536,6 +535,8 @@ rpc_clnt_connection_cleanup(rpc_clnt_connection_t *conn) if (timer_unref) rpc_clnt_unref(clnt); + if (reconnect_unref) + rpc_clnt_unref(clnt); out: return 0; } @@ -780,8 +781,7 @@ is_rpc_clnt_disconnected(rpc_clnt_connection_t *conn) pthread_mutex_lock(&conn->lock); { - if (conn->disconnected == _gf_false) - disconnected = _gf_false; + disconnected = conn->disconnected; } pthread_mutex_unlock(&conn->lock); @@ -834,7 +834,7 @@ rpc_clnt_handle_disconnect(struct rpc_clnt *clnt, rpc_clnt_connection_t *conn) pthread_mutex_lock(&conn->lock); { if (!conn->rpc_clnt->disabled && (conn->reconnect == NULL)) { - ts.tv_sec = 10; + ts.tv_sec = 3; ts.tv_nsec = 0; rpc_clnt_ref(clnt); @@ -919,7 +919,7 @@ rpc_clnt_notify(rpc_transport_t *trans, void *mydata, } case RPC_TRANSPORT_MSG_RECEIVED: { - clock_gettime(CLOCK_REALTIME, &conn->last_received); + timespec_now_realtime(&conn->last_received); pollin = data; if (pollin->is_reply) @@ -933,8 +933,7 @@ rpc_clnt_notify(rpc_transport_t *trans, void *mydata, } case RPC_TRANSPORT_MSG_SENT: { - clock_gettime(CLOCK_REALTIME, &conn->last_sent); - + timespec_now_realtime(&conn->last_sent); ret = 0; break; } @@ -951,6 +950,7 @@ rpc_clnt_notify(rpc_transport_t *trans, void *mydata, conn->config.remote_port = 0; conn->connected = 1; conn->disconnected = 0; + pthread_cond_broadcast(&conn->cond); } pthread_mutex_unlock(&conn->lock); @@ -973,6 +973,12 @@ rpc_clnt_notify(rpc_transport_t *trans, void *mydata, */ ret = 0; break; + + case RPC_TRANSPORT_EVENT_THREAD_DIED: + /* only meaningful on a server, no need of handling this event on a + * client */ + ret = 0; + break; } out: @@ -990,6 +996,7 @@ rpc_clnt_connection_init(struct rpc_clnt *clnt, glusterfs_ctx_t *ctx, conn = &clnt->conn; pthread_mutex_init(&clnt->conn.lock, NULL); + pthread_cond_init(&clnt->conn.cond, NULL); conn->name = gf_strdup(name); if (!conn->name) { @@ -1114,8 +1121,6 @@ rpc_clnt_new(dict_t *options, xlator_t *owner, char *name, mem_pool_destroy(rpc->saved_frames_pool); GF_FREE(rpc); rpc = NULL; - if (options) - dict_unref(options); goto out; } @@ -1679,18 +1684,19 @@ rpc_clnt_submit(struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, int procnum, { if (conn->connected == 0) { if (rpc->disabled) - goto nosubmit; + goto unlock; ret = rpc_transport_connect(conn->trans, conn->config.remote_port); if (ret < 0) { - gf_log(conn->name, GF_LOG_WARNING, + gf_log(conn->name, + (errno == EINPROGRESS) ? GF_LOG_DEBUG : GF_LOG_WARNING, "error returned while attempting to " "connect to host:%s, port:%d", conn->config.remote_host, conn->config.remote_port); + goto unlock; } } ret = rpc_transport_submit_request(conn->trans, &req); - nosubmit: if (ret == -1) { gf_log(conn->name, GF_LOG_WARNING, "failed to submit rpc-request " @@ -1699,9 +1705,7 @@ rpc_clnt_submit(struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, int procnum, "ProgVers: %d, Proc: %d) to rpc-transport (%s)", cframe->root->unique, rpcreq->xid, rpcreq->prog->progname, rpcreq->prog->progver, rpcreq->procnum, conn->name); - } - - if ((ret >= 0) && frame) { + } else if ((ret >= 0) && frame) { /* Save the frame in queue */ __save_frame(rpc, frame, rpcreq); @@ -1723,6 +1727,7 @@ rpc_clnt_submit(struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, int procnum, rpcreq->prog->progver, rpcreq->procnum, conn->name); } } +unlock: pthread_mutex_unlock(&conn->lock); if (need_unref) @@ -1777,7 +1782,7 @@ rpc_clnt_trigger_destroy(struct rpc_clnt *rpc) * ref*/ conn = &rpc->conn; trans = conn->trans; - rpc_clnt_disconnect(rpc); + rpc_clnt_disable(rpc); /* This is to account for rpc_clnt_disable that might have been called * before rpc_clnt_unref */ @@ -1817,6 +1822,7 @@ rpc_clnt_destroy(struct rpc_clnt *rpc) saved_frames_destroy(saved_frames); pthread_mutex_destroy(&rpc->lock); pthread_mutex_destroy(&rpc->conn.lock); + pthread_cond_destroy(&rpc->conn.cond); /* mem-pool should be destroyed, otherwise, it will cause huge memory leaks */ @@ -1849,29 +1855,7 @@ rpc_clnt_unref(struct rpc_clnt *rpc) return rpc; } -char -rpc_clnt_is_disabled(struct rpc_clnt *rpc) -{ - rpc_clnt_connection_t *conn = NULL; - char disabled = 0; - - if (!rpc) { - goto out; - } - - conn = &rpc->conn; - - pthread_mutex_lock(&conn->lock); - { - disabled = rpc->disabled; - } - pthread_mutex_unlock(&conn->lock); - -out: - return disabled; -} - -void +int rpc_clnt_disable(struct rpc_clnt *rpc) { rpc_clnt_connection_t *conn = NULL; @@ -1915,81 +1899,9 @@ rpc_clnt_disable(struct rpc_clnt *rpc) } pthread_mutex_unlock(&conn->lock); + ret = -1; if (trans) { - rpc_transport_disconnect(trans, _gf_true); - /* The auth_value was being reset to AUTH_GLUSTERFS_v2. - * if (clnt->auth_value) - * clnt->auth_value = AUTH_GLUSTERFS_v2; - * It should not be reset here. The disconnect during - * portmap request can race with handshake. If handshake - * happens first and disconnect later, auth_value would set - * to default value and it never sets back to actual auth_value - * supported by server. But it's important to set to lower - * version supported in the case where the server downgrades. - * So moving this code to RPC_TRANSPORT_CONNECT. Note that - * CONNECT cannot race with handshake as by nature it is - * serialized with handhake. An handshake can happen only - * on a connected transport and hence its strictly serialized. - */ - } - - if (unref) - rpc_clnt_unref(rpc); - - if (timer_unref) - rpc_clnt_unref(rpc); - - if (reconnect_unref) - rpc_clnt_unref(rpc); - -out: - return; -} - -void -rpc_clnt_disconnect(struct rpc_clnt *rpc) -{ - rpc_clnt_connection_t *conn = NULL; - rpc_transport_t *trans = NULL; - int unref = 0; - int ret = 0; - gf_boolean_t timer_unref = _gf_false; - gf_boolean_t reconnect_unref = _gf_false; - - if (!rpc) - goto out; - - conn = &rpc->conn; - - pthread_mutex_lock(&conn->lock); - { - rpc->disabled = 1; - if (conn->timer) { - ret = gf_timer_call_cancel(rpc->ctx, conn->timer); - /* If the event is not fired and it actually cancelled - * the timer, do the unref else registered call back - * function will take care of unref. - */ - if (!ret) - timer_unref = _gf_true; - conn->timer = NULL; - } - - if (conn->reconnect) { - ret = gf_timer_call_cancel(rpc->ctx, conn->reconnect); - if (!ret) - reconnect_unref = _gf_true; - conn->reconnect = NULL; - } - conn->connected = 0; - - unref = rpc_clnt_remove_ping_timer_locked(rpc); - trans = conn->trans; - } - pthread_mutex_unlock(&conn->lock); - - if (trans) { - rpc_transport_disconnect(trans, _gf_true); + ret = rpc_transport_disconnect(trans, _gf_true); /* The auth_value was being reset to AUTH_GLUSTERFS_v2. * if (clnt->auth_value) * clnt->auth_value = AUTH_GLUSTERFS_v2; @@ -2015,7 +1927,7 @@ rpc_clnt_disconnect(struct rpc_clnt *rpc) rpc_clnt_unref(rpc); out: - return; + return ret; } void diff --git a/rpc/rpc-lib/src/rpc-clnt.h b/rpc/rpc-lib/src/rpc-clnt.h index 28b6f0e7f4d..2945265200b 100644 --- a/rpc/rpc-lib/src/rpc-clnt.h +++ b/rpc/rpc-lib/src/rpc-clnt.h @@ -11,9 +11,9 @@ #ifndef __RPC_CLNT_H #define __RPC_CLNT_H -#include "stack.h" +#include <glusterfs/stack.h> #include "rpc-transport.h" -#include "timer.h" +#include <glusterfs/timer.h> #include "xdr-common.h" #include "glusterfs3.h" @@ -52,8 +52,8 @@ struct saved_frame { }; void *capital_this; void *frame; - struct timeval saved_at; struct rpc_req *rpcreq; + struct timeval saved_at; rpc_transport_rsp_t rsp; }; @@ -85,8 +85,8 @@ typedef int (*rpcclnt_cb_fn)(struct rpc_clnt *rpc, void *mydata, void *data); */ typedef struct rpcclnt_actor_desc { char procname[32]; - int procnum; rpcclnt_cb_fn actor; + int procnum; } rpcclnt_cb_actor_t; /* Describes a program and its version along with the function pointers @@ -98,8 +98,6 @@ typedef struct rpcclnt_cb_program { int prognum; int progver; rpcclnt_cb_actor_t *actors; /* All procedure handlers */ - int numactors; /* Num actors in actor array */ - /* Program specific state handed to actors */ void *private; @@ -108,6 +106,8 @@ typedef struct rpcclnt_cb_program { /* Needed for passing back in cb_actor */ void *mydata; + int numactors; /* Num actors in actor array */ + } rpcclnt_cb_program_t; typedef struct rpc_auth_data { @@ -127,42 +127,43 @@ struct rpc_clnt_config { struct rpc_clnt_connection { pthread_mutex_t lock; + pthread_cond_t cond; rpc_transport_t *trans; struct rpc_clnt_config config; gf_timer_t *reconnect; gf_timer_t *timer; gf_timer_t *ping_timer; struct rpc_clnt *rpc_clnt; - char connected; - gf_boolean_t disconnected; struct saved_frames *saved_frames; - int32_t frame_timeout; struct timespec last_sent; struct timespec last_received; - int32_t ping_started; - char *name; - int32_t ping_timeout; uint64_t pingcnt; uint64_t msgcnt; uint64_t cleanup_gen; + char *name; + int32_t ping_started; + int32_t frame_timeout; + int32_t ping_timeout; + gf_boolean_t disconnected; + char connected; }; typedef struct rpc_clnt_connection rpc_clnt_connection_t; struct rpc_req { rpc_clnt_connection_t *conn; - uint32_t xid; struct iovec req[2]; - int reqcnt; struct iobref *req_iobref; struct iovec rsp[2]; int rspcnt; + int reqcnt; struct iobref *rsp_iobref; - int rpc_status; - rpc_auth_data_t verf; rpc_clnt_prog_t *prog; - int procnum; + rpc_auth_data_t verf; fop_cbk_fn_t cbkfn; void *conn_private; + int procnum; + int rpc_status; + uint32_t xid; }; typedef struct rpc_clnt { @@ -182,9 +183,9 @@ typedef struct rpc_clnt { glusterfs_ctx_t *ctx; gf_atomic_t refcount; + xlator_t *owner; int auth_value; char disabled; - xlator_t *owner; } rpc_clnt_t; struct rpc_clnt * @@ -250,15 +251,9 @@ int rpcclnt_cbk_program_register(struct rpc_clnt *svc, rpcclnt_cb_program_t *program, void *mydata); -void +int rpc_clnt_disable(struct rpc_clnt *rpc); -void -rpc_clnt_disconnect(struct rpc_clnt *rpc); - -char -rpc_clnt_is_disabled(struct rpc_clnt *rpc); - int rpc_clnt_mgmt_pmap_signout(glusterfs_ctx_t *ctx, char *brick_name); diff --git a/rpc/rpc-lib/src/rpc-drc.c b/rpc/rpc-lib/src/rpc-drc.c index 50013776c86..de8dc630626 100644 --- a/rpc/rpc-lib/src/rpc-drc.c +++ b/rpc/rpc-lib/src/rpc-drc.c @@ -12,11 +12,9 @@ #ifndef RPC_DRC_H #include "rpc-drc.h" #endif -#include "locking.h" -#include "hashfn.h" -#include "common-utils.h" -#include "statedump.h" -#include "mem-pool.h" +#include <glusterfs/locking.h> +#include <glusterfs/statedump.h> +#include <glusterfs/mem-pool.h> #include <netinet/in.h> #include <unistd.h> @@ -192,7 +190,7 @@ rpcsvc_get_drc_client(rpcsvc_drc_globals_t *drc, if (!client) goto out; - client->ref = 0; + GF_ATOMIC_INIT(client->ref, 0); client->sock_union = (union gf_sock_union) * sockaddr; client->op_count = 0; INIT_LIST_HEAD(&client->client_list); @@ -248,7 +246,7 @@ static drc_client_t * rpcsvc_drc_client_ref(drc_client_t *client) { GF_ASSERT(client); - client->ref++; + GF_ATOMIC_INC(client->ref); return client; } @@ -263,11 +261,12 @@ rpcsvc_drc_client_ref(drc_client_t *client) static drc_client_t * rpcsvc_drc_client_unref(rpcsvc_drc_globals_t *drc, drc_client_t *client) { + uint32_t refcount; + GF_ASSERT(drc); - GF_ASSERT(client->ref); - client->ref--; - if (!client->ref) { + refcount = GF_ATOMIC_DEC(client->ref); + if (!refcount) { drc->client_count--; rpcsvc_remove_drc_client(client); client = NULL; @@ -591,7 +590,7 @@ rpcsvc_drc_priv(rpcsvc_drc_globals_t *drc) } gf_proc_dump_build_key(key, "client", "%d.ref_count", i); - gf_proc_dump_write(key, "%d", client->ref); + gf_proc_dump_write(key, "%" PRIu32, GF_ATOMIC_GET(client->ref)); gf_proc_dump_build_key(key, "client", "%d.op_count", i); gf_proc_dump_write(key, "%d", client->op_count); i++; @@ -699,47 +698,42 @@ rpcsvc_drc_init(rpcsvc_t *svc, dict_t *options) LOCK_INIT(&drc->lock); svc->drc = drc; - LOCK(&drc->lock); - /* Specify type of DRC to be used */ ret = dict_get_uint32(options, "nfs.drc-type", &drc_type); if (ret) { gf_log(GF_RPCSVC, GF_LOG_DEBUG, - "drc type not set." - " Continuing with default"); + "drc type not set. Continuing with default"); drc_type = DRC_DEFAULT_TYPE; } - drc->type = drc_type; - /* Set the global cache size (no. of ops to cache) */ ret = dict_get_uint32(options, "nfs.drc-size", &drc_size); if (ret) { gf_log(GF_RPCSVC, GF_LOG_DEBUG, - "drc size not set." - " Continuing with default size"); + "drc size not set. Continuing with default size"); drc_size = DRC_DEFAULT_CACHE_SIZE; } + LOCK(&drc->lock); + + drc->type = drc_type; drc->global_cache_size = drc_size; /* Mempool for cached ops */ drc->mempool = mem_pool_new(drc_cached_op_t, drc->global_cache_size); if (!drc->mempool) { + UNLOCK(&drc->lock); gf_log(GF_RPCSVC, GF_LOG_ERROR, - "Failed to get mempool for" - " DRC, drc-size: %d", - drc->global_cache_size); + "Failed to get mempool for DRC, drc-size: %d", drc_size); ret = -1; - goto out; + goto post_unlock; } /* What percent of cache to be evicted whenever it fills up */ ret = dict_get_uint32(options, "nfs.drc-lru-factor", &drc_factor); if (ret) { gf_log(GF_RPCSVC, GF_LOG_DEBUG, - "drc lru factor not set." - " Continuing with policy default"); + "drc lru factor not set. Continuing with policy default"); drc_factor = DRC_DEFAULT_LRU_FACTOR; } @@ -750,15 +744,16 @@ rpcsvc_drc_init(rpcsvc_t *svc, dict_t *options) ret = rpcsvc_register_notify(svc, rpcsvc_drc_notify, THIS); if (ret) { + UNLOCK(&drc->lock); gf_log(GF_RPCSVC, GF_LOG_ERROR, "registration of drc_notify function failed"); - goto out; + goto post_unlock; } - gf_log(GF_RPCSVC, GF_LOG_DEBUG, "drc init successful"); drc->status = DRC_INITIATED; -out: UNLOCK(&drc->lock); + gf_log(GF_RPCSVC, GF_LOG_DEBUG, "drc init successful"); +post_unlock: if (ret == -1) { if (drc->mempool) { mem_pool_destroy(drc->mempool); diff --git a/rpc/rpc-lib/src/rpc-drc.h b/rpc/rpc-lib/src/rpc-drc.h index 1fd1e5e24ef..ce66430809b 100644 --- a/rpc/rpc-lib/src/rpc-drc.h +++ b/rpc/rpc-lib/src/rpc-drc.h @@ -13,24 +13,23 @@ #include "rpcsvc-common.h" #include "rpcsvc.h" -#include "locking.h" -#include "dict.h" +#include <glusterfs/locking.h> +#include <glusterfs/dict.h> #include "rb.h" /* per-client cache structure */ struct drc_client { - uint32_t ref; union gf_sock_union sock_union; /* pointers to the cache */ struct rb_table *rbtree; /* no. of ops currently cached */ uint32_t op_count; + gf_atomic_uint32_t ref; struct list_head client_list; }; struct drc_cached_op { drc_op_state_t state; - uint32_t xid; int prognum; int progversion; int procnum; @@ -39,6 +38,7 @@ struct drc_cached_op { struct list_head client_list; struct list_head global_list; int32_t ref; + uint32_t xid; }; /* global drc definitions */ @@ -50,19 +50,19 @@ struct drc_globals { * it is used so in gf_libavl_allocator */ struct libavl_allocator allocator; - drc_type_t type; /* configurable size parameter */ - uint32_t global_cache_size; - drc_lru_factor_t lru_factor; gf_lock_t lock; - drc_status_t status; - uint32_t op_count; uint64_t cache_hits; uint64_t intransit_hits; struct mem_pool *mempool; struct list_head cache_head; - uint32_t client_count; struct list_head clients_head; + uint32_t op_count; + uint32_t client_count; + uint32_t global_cache_size; + drc_type_t type; + drc_lru_factor_t lru_factor; + drc_status_t status; }; int diff --git a/rpc/rpc-lib/src/rpc-lib-messages.h b/rpc/rpc-lib/src/rpc-lib-messages.h index 9251578a121..2c0b820dbf9 100644 --- a/rpc/rpc-lib/src/rpc-lib-messages.h +++ b/rpc/rpc-lib/src/rpc-lib-messages.h @@ -11,7 +11,7 @@ #ifndef _RPC_LIB_MESSAGES_H_ #define _RPC_LIB_MESSAGES_H_ -#include "glfs-message-id.h" +#include <glusterfs/glfs-message-id.h> /* To add new message IDs, append new identifiers at the end of the list. * diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c index d70334476c7..a6e201a9b36 100644 --- a/rpc/rpc-lib/src/rpc-transport.c +++ b/rpc/rpc-lib/src/rpc-transport.c @@ -12,17 +12,9 @@ #include <stdlib.h> #include <stdio.h> #include <sys/poll.h> -#include <fnmatch.h> #include <stdint.h> -#include "logging.h" #include "rpc-transport.h" -#include "glusterfs.h" -/* FIXME: xlator.h is needed for volume_option_t, need to define the datatype - * in some other header - */ -#include "xlator.h" -#include "list.h" #ifndef GF_OPTION_LIST_EMPTY #define GF_OPTION_LIST_EMPTY(_opt) (_opt->value[0] == NULL) @@ -68,17 +60,6 @@ out: } int32_t -rpc_transport_get_myname(rpc_transport_t *this, char *hostname, int hostlen) -{ - int32_t ret = -1; - GF_VALIDATE_OR_GOTO("rpc", this, out); - - ret = this->ops->get_myname(this, hostname, hostlen); -out: - return ret; -} - -int32_t rpc_transport_get_peername(rpc_transport_t *this, char *hostname, int hostlen) { int32_t ret = -1; @@ -92,14 +73,10 @@ out: int rpc_transport_throttle(rpc_transport_t *this, gf_boolean_t onoff) { - int ret = 0; - if (!this->ops->throttle) return -ENOSYS; - ret = this->ops->throttle(this, onoff); - - return ret; + return this->ops->throttle(this, onoff); } int32_t @@ -144,6 +121,8 @@ rpc_transport_pollin_alloc(rpc_transport_t *this, struct iovec *vector, goto out; } + msg->trans = this; + if (count > 1) { msg->vectored = 1; } @@ -159,6 +138,31 @@ out: return msg; } +void +rpc_transport_cleanup(rpc_transport_t *trans) +{ + if (!trans) + return; + + if (trans->fini) + trans->fini(trans); + + if (trans->options) { + dict_unref(trans->options); + trans->options = NULL; + } + + GF_FREE(trans->name); + + if (trans->xl) + pthread_mutex_destroy(&trans->lock); + + if (trans->dl_handle) + dlclose(trans->dl_handle); + + GF_FREE(trans); +} + rpc_transport_t * rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) { @@ -166,7 +170,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) char *name = NULL; void *handle = NULL; char *type = NULL; - char str[] = "ERROR"; + static char str[] = "ERROR"; int32_t ret = -1; int is_tcp = 0, is_unix = 0, is_ibsdp = 0; volume_opt_list_t *vol_opt = NULL; @@ -191,9 +195,9 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) type = str; /* Backward compatibility */ - ret = dict_get_str(options, "transport-type", &type); + ret = dict_get_str_sizen(options, "transport-type", &type); if (ret < 0) { - ret = dict_set_str(options, "transport-type", "socket"); + ret = dict_set_str_sizen(options, "transport-type", "socket"); if (ret < 0) gf_log("dict", GF_LOG_DEBUG, "setting transport-type failed"); else @@ -215,15 +219,16 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) is_ibsdp = strcmp(type, "ib-sdp"); if ((is_tcp == 0) || (is_unix == 0) || (is_ibsdp == 0)) { if (is_unix == 0) - ret = dict_set_str(options, "transport.address-family", "unix"); + ret = dict_set_str_sizen(options, "transport.address-family", + "unix"); if (is_ibsdp == 0) - ret = dict_set_str(options, "transport.address-family", - "inet-sdp"); + ret = dict_set_str_sizen(options, "transport.address-family", + "inet-sdp"); if (ret < 0) gf_log("dict", GF_LOG_DEBUG, "setting address-family failed"); - ret = dict_set_str(options, "transport-type", "socket"); + ret = dict_set_str_sizen(options, "transport-type", "socket"); if (ret < 0) gf_log("dict", GF_LOG_DEBUG, "setting transport-type failed"); } @@ -232,9 +237,9 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) /* client-bind-insecure is for clients protocol, and * bind-insecure for glusterd. Both mutually exclusive */ - ret = dict_get_str(options, "client-bind-insecure", &type); + ret = dict_get_str_sizen(options, "client-bind-insecure", &type); if (ret) - ret = dict_get_str(options, "bind-insecure", &type); + ret = dict_get_str_sizen(options, "bind-insecure", &type); if (ret == 0) { ret = gf_string2boolean(type, &bind_insecure); if (ret < 0) { @@ -253,7 +258,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) trans->bind_insecure = 1; } - ret = dict_get_str(options, "transport-type", &type); + ret = dict_get_str_sizen(options, "transport-type", &type); if (ret < 0) { gf_log("rpc-transport", GF_LOG_ERROR, "'option transport-type <xx>' missing in volume '%s'", @@ -266,6 +271,10 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) goto fail; } + if (dict_get_sizen(options, "notify-poller-death")) { + trans->notify_poller_death = 1; + } + gf_log("rpc-transport", GF_LOG_DEBUG, "attempt to load file %s", name); handle = dlopen(name, RTLD_NOW); @@ -328,7 +337,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) } } - trans->options = options; + trans->options = dict_ref(options); pthread_mutex_init(&trans->lock, NULL); trans->xl = this; @@ -341,6 +350,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) } INIT_LIST_HEAD(&trans->list); + GF_ATOMIC_INIT(trans->disconnect_progress, 0); return_trans = trans; @@ -350,15 +360,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) fail: if (!success) { - if (trans) { - GF_FREE(trans->name); - - if (trans->dl_handle) - dlclose(trans->dl_handle); - - GF_FREE(trans); - } - + rpc_transport_cleanup(trans); GF_FREE(name); return_trans = NULL; @@ -437,13 +439,10 @@ fail: return ret; } -int32_t +static void rpc_transport_destroy(rpc_transport_t *this) { struct dnscache6 *cache = NULL; - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); if (this->clnt_options) dict_unref(this->clnt_options); @@ -471,10 +470,6 @@ rpc_transport_destroy(rpc_transport_t *this) } GF_FREE(this); - - ret = 0; -fail: - return ret; } rpc_transport_t * @@ -557,16 +552,17 @@ rpc_transport_keepalive_options_set(dict_t *options, int32_t interval, GF_ASSERT(options); GF_ASSERT((interval > 0) || (time > 0)); - ret = dict_set_int32(options, "transport.socket.keepalive-interval", - interval); + ret = dict_set_int32_sizen(options, "transport.socket.keepalive-interval", + interval); if (ret) goto out; - ret = dict_set_int32(options, "transport.socket.keepalive-time", time); + ret = dict_set_int32_sizen(options, "transport.socket.keepalive-time", + time); if (ret) goto out; - ret = dict_set_int32(options, "transport.tcp-user-timeout", timeout); + ret = dict_set_int32_sizen(options, "transport.tcp-user-timeout", timeout); if (ret) goto out; out: @@ -574,19 +570,14 @@ out: } int -rpc_transport_unix_options_build(dict_t **options, char *filepath, +rpc_transport_unix_options_build(dict_t *dict, char *filepath, int frame_timeout) { - dict_t *dict = NULL; char *fpath = NULL; int ret = -1; GF_ASSERT(filepath); - GF_ASSERT(options); - - dict = dict_new(); - if (!dict) - goto out; + GF_VALIDATE_OR_GOTO("rpc-transport", dict, out); fpath = gf_strdup(filepath); if (!fpath) { @@ -594,62 +585,52 @@ rpc_transport_unix_options_build(dict_t **options, char *filepath, goto out; } - ret = dict_set_dynstr(dict, "transport.socket.connect-path", fpath); + ret = dict_set_dynstr_sizen(dict, "transport.socket.connect-path", fpath); if (ret) { GF_FREE(fpath); goto out; } - ret = dict_set_str(dict, "transport.address-family", "unix"); + ret = dict_set_str_sizen(dict, "transport.address-family", "unix"); if (ret) goto out; - ret = dict_set_str(dict, "transport.socket.nodelay", "off"); + ret = dict_set_str_sizen(dict, "transport.socket.nodelay", "off"); if (ret) goto out; - ret = dict_set_str(dict, "transport-type", "socket"); + ret = dict_set_str_sizen(dict, "transport-type", "socket"); if (ret) goto out; - ret = dict_set_str(dict, "transport.socket.keepalive", "off"); + ret = dict_set_str_sizen(dict, "transport.socket.keepalive", "off"); if (ret) goto out; if (frame_timeout > 0) { - ret = dict_set_int32(dict, "frame-timeout", frame_timeout); + ret = dict_set_int32_sizen(dict, "frame-timeout", frame_timeout); if (ret) goto out; } - - *options = dict; out: - if (ret && dict) { - dict_unref(dict); - } return ret; } int -rpc_transport_inet_options_build(dict_t **options, const char *hostname, - int port) +rpc_transport_inet_options_build(dict_t *dict, const char *hostname, int port, + char *af) { - dict_t *dict = NULL; char *host = NULL; int ret = -1; #ifdef IPV6_DEFAULT - char *addr_family = "inet6"; + static char *addr_family = "inet6"; #else - char *addr_family = "inet"; + static char *addr_family = "inet"; #endif - GF_ASSERT(options); GF_ASSERT(hostname); GF_ASSERT(port >= 1024); - - dict = dict_new(); - if (!dict) - goto out; + GF_VALIDATE_OR_GOTO("rpc-transport", dict, out); host = gf_strdup((char *)hostname); if (!host) { @@ -657,7 +638,7 @@ rpc_transport_inet_options_build(dict_t **options, const char *hostname, goto out; } - ret = dict_set_dynstr(dict, "remote-host", host); + ret = dict_set_dynstr_sizen(dict, "remote-host", host); if (ret) { gf_log(THIS->name, GF_LOG_WARNING, "failed to set remote-host with %s", host); @@ -665,32 +646,27 @@ rpc_transport_inet_options_build(dict_t **options, const char *hostname, goto out; } - ret = dict_set_int32(dict, "remote-port", port); + ret = dict_set_int32_sizen(dict, "remote-port", port); if (ret) { gf_log(THIS->name, GF_LOG_WARNING, "failed to set remote-port with %d", port); goto out; } - ret = dict_set_str(dict, "address-family", addr_family); + ret = dict_set_str_sizen(dict, "address-family", + (af != NULL ? af : addr_family)); if (ret) { gf_log(THIS->name, GF_LOG_WARNING, "failed to set address-family to %s", addr_family); goto out; } - ret = dict_set_str(dict, "transport-type", "socket"); + ret = dict_set_str_sizen(dict, "transport-type", "socket"); if (ret) { gf_log(THIS->name, GF_LOG_WARNING, "failed to set trans-type with socket"); goto out; } - - *options = dict; out: - if (ret && dict) { - dict_unref(dict); - } - return ret; } diff --git a/rpc/rpc-lib/src/rpc-transport.h b/rpc/rpc-lib/src/rpc-transport.h index c238501b5c7..c499f0bb955 100644 --- a/rpc/rpc-lib/src/rpc-transport.h +++ b/rpc/rpc-lib/src/rpc-transport.h @@ -56,17 +56,18 @@ struct rpc_transport_ops; typedef struct rpc_transport rpc_transport_t; -#include "dict.h" -#include "compat.h" +#include <glusterfs/dict.h> +#include <glusterfs/compat.h> +#include <glusterfs/async.h> #include "rpcsvc-common.h" struct peer_info { - struct sockaddr_storage sockaddr; - socklen_t sockaddr_len; - char identifier[UNIX_PATH_MAX]; // OP-VERSION of clients uint32_t max_op_version; uint32_t min_op_version; + struct sockaddr_storage sockaddr; + socklen_t sockaddr_len; + char identifier[UNIX_PATH_MAX]; // Volume mounted by client char volname[NAME_MAX]; }; @@ -97,47 +98,48 @@ typedef enum { RPC_TRANSPORT_MSG_RECEIVED, /* Complete rpc msg has been read */ RPC_TRANSPORT_CONNECT, /* client is connected to server */ RPC_TRANSPORT_MSG_SENT, + RPC_TRANSPORT_EVENT_THREAD_DIED /* event-thread has died */ } rpc_transport_event_t; struct rpc_transport_msg { struct iovec *rpchdr; - int rpchdrcount; struct iovec *proghdr; + int rpchdrcount; int proghdrcount; struct iovec *progpayload; - int progpayloadcount; struct iobref *iobref; + int progpayloadcount; }; typedef struct rpc_transport_msg rpc_transport_msg_t; struct rpc_transport_rsp { struct iovec *rsphdr; - int rsphdr_count; struct iovec *rsp_payload; + int rsphdr_count; int rsp_payload_count; struct iobref *rsp_iobref; }; typedef struct rpc_transport_rsp rpc_transport_rsp_t; struct rpc_transport_req { + struct rpc_req *rpc_req; rpc_transport_msg_t msg; rpc_transport_rsp_t rsp; - struct rpc_req *rpc_req; }; typedef struct rpc_transport_req rpc_transport_req_t; struct rpc_transport_reply { - rpc_transport_msg_t msg; void *private; + rpc_transport_msg_t msg; }; typedef struct rpc_transport_reply rpc_transport_reply_t; struct rpc_transport_data { - char is_request; union { rpc_transport_req_t req; rpc_transport_reply_t reply; } data; + char is_request; }; typedef struct rpc_transport_data rpc_transport_data_t; @@ -145,25 +147,15 @@ typedef struct rpc_transport_data rpc_transport_data_t; * rpc_request, hence these should be removed from request_info */ struct rpc_request_info { - uint32_t xid; int prognum; int progver; - int procnum; void *rpc_req; /* struct rpc_req */ rpc_transport_rsp_t rsp; + int procnum; + uint32_t xid; }; typedef struct rpc_request_info rpc_request_info_t; -struct rpc_transport_pollin { - struct iovec vector[MAX_IOVEC]; - int count; - char vectored; - void *private; - struct iobref *iobref; - char is_reply; -}; -typedef struct rpc_transport_pollin rpc_transport_pollin_t; - typedef int (*rpc_transport_notify_t)(rpc_transport_t *, void *mydata, rpc_transport_event_t, void *data, ...); @@ -181,9 +173,6 @@ struct rpc_transport { void *mydata; pthread_mutex_t lock; gf_atomic_t refcount; - - int32_t outstanding_rpc_count; - glusterfs_ctx_t *ctx; dict_t *options; char *name; @@ -201,20 +190,36 @@ struct rpc_transport { uint64_t total_bytes_read; uint64_t total_bytes_write; uint32_t xid; /* RPC/XID used for callbacks */ + int32_t outstanding_rpc_count; struct list_head list; - int bind_insecure; void *dl_handle; /* handle of dlopen() */ char *ssl_name; dict_t *clnt_options; /* store options received from * client */ + gf_atomic_t disconnect_progress; + int bind_insecure; /* connect_failed: saves the connect() syscall status as socket_t * member holding connect() status can't be accessed by higher gfapi * layer or in client management notification handler functions */ gf_boolean_t connect_failed; + char notify_poller_death; + char poller_death_accept; }; +struct rpc_transport_pollin { + struct rpc_transport *trans; + void *private; + struct iobref *iobref; + struct iovec vector[MAX_IOVEC]; + gf_async_t async; + int count; + char is_reply; + char vectored; +}; +typedef struct rpc_transport_pollin rpc_transport_pollin_t; + struct rpc_transport_ops { /* no need of receive op, msg will be delivered through an event * notification @@ -247,9 +252,6 @@ int32_t rpc_transport_disconnect(rpc_transport_t *this, gf_boolean_t wait); int32_t -rpc_transport_destroy(rpc_transport_t *this); - -int32_t rpc_transport_notify(rpc_transport_t *this, rpc_transport_event_t event, void *data, ...); @@ -280,9 +282,6 @@ rpc_transport_get_peeraddr(rpc_transport_t *this, char *peeraddr, int addrlen, struct sockaddr_storage *sa, size_t salen); int32_t -rpc_transport_get_myname(rpc_transport_t *this, char *hostname, int hostlen); - -int32_t rpc_transport_get_myaddr(rpc_transport_t *this, char *peeraddr, int addrlen, struct sockaddr_storage *sa, size_t salen); @@ -301,10 +300,13 @@ rpc_transport_keepalive_options_set(dict_t *options, int32_t interval, int32_t time, int32_t timeout); int -rpc_transport_unix_options_build(dict_t **options, char *filepath, +rpc_transport_unix_options_build(dict_t *options, char *filepath, int frame_timeout); int -rpc_transport_inet_options_build(dict_t **options, const char *hostname, - int port); +rpc_transport_inet_options_build(dict_t *options, const char *hostname, + int port, char *af); + +void +rpc_transport_cleanup(rpc_transport_t *); #endif /* __RPC_TRANSPORT_H__ */ diff --git a/rpc/rpc-lib/src/rpcsvc-auth.c b/rpc/rpc-lib/src/rpcsvc-auth.c index da260ade0c0..8e76b4188bb 100644 --- a/rpc/rpc-lib/src/rpcsvc-auth.c +++ b/rpc/rpc-lib/src/rpcsvc-auth.c @@ -9,8 +9,7 @@ */ #include "rpcsvc.h" -#include "logging.h" -#include "dict.h" +#include <glusterfs/dict.h> extern rpcsvc_auth_t * rpcsvc_auth_null_init(rpcsvc_t *svc, dict_t *options); @@ -274,6 +273,44 @@ rpcsvc_set_root_squash(rpcsvc_t *svc, dict_t *options) } int +rpcsvc_set_all_squash(rpcsvc_t *svc, dict_t *options) +{ + int ret = -1; + + uid_t anonuid = -1; + gid_t anongid = -1; + + GF_ASSERT(svc); + GF_ASSERT(options); + + ret = dict_get_str_boolean(options, "all-squash", 0); + if (ret != -1) + svc->all_squash = ret; + else + svc->all_squash = _gf_false; + + ret = dict_get_uint32(options, "anonuid", &anonuid); + if (!ret) + svc->anonuid = anonuid; + else + svc->anonuid = RPC_NOBODY_UID; + + ret = dict_get_uint32(options, "anongid", &anongid); + if (!ret) + svc->anongid = anongid; + else + svc->anongid = RPC_NOBODY_GID; + + if (svc->all_squash) + gf_log(GF_RPCSVC, GF_LOG_DEBUG, + "all squashing enabled " + "(uid=%d, gid=%d)", + svc->anonuid, svc->anongid); + + return 0; +} + +int rpcsvc_auth_init(rpcsvc_t *svc, dict_t *options) { int ret = -1; @@ -283,6 +320,7 @@ rpcsvc_auth_init(rpcsvc_t *svc, dict_t *options) (void)rpcsvc_set_allow_insecure(svc, options); (void)rpcsvc_set_root_squash(svc, options); + (void)rpcsvc_set_all_squash(svc, options); (void)rpcsvc_set_addr_namelookup(svc, options); ret = rpcsvc_auth_add_initers(svc); if (ret == -1) { @@ -316,6 +354,10 @@ rpcsvc_auth_reconf(rpcsvc_t *svc, dict_t *options) if (ret) return (-1); + ret = rpcsvc_set_all_squash(svc, options); + if (ret) + return (-1); + return rpcsvc_set_addr_namelookup(svc, options); } diff --git a/rpc/rpc-lib/src/rpcsvc-common.h b/rpc/rpc-lib/src/rpcsvc-common.h index 6a36b1f1b9b..6c4ec49a6ef 100644 --- a/rpc/rpc-lib/src/rpcsvc-common.h +++ b/rpc/rpc-lib/src/rpcsvc-common.h @@ -12,11 +12,8 @@ #define _RPCSVC_COMMON_H #include <pthread.h> -#include "list.h" -#include "compat.h" -#include "glusterfs.h" -#include "dict.h" -#include "xlator.h" +#include <glusterfs/compat.h> +#include <glusterfs/dict.h> typedef enum { RPCSVC_EVENT_ACCEPT, @@ -42,18 +39,12 @@ typedef struct rpcsvc_state { pthread_rwlock_t rpclock; - unsigned int memfactor; - /* List of the authentication schemes available. */ struct list_head authschemes; /* Reference to the options */ dict_t *options; - /* Allow insecure ports. */ - gf_boolean_t allow_insecure; - gf_boolean_t register_portmap; - gf_boolean_t root_squash; uid_t anonuid; gid_t anongid; glusterfs_ctx_t *ctx; @@ -68,6 +59,8 @@ typedef struct rpcsvc_state { struct list_head notify; int notify_count; + unsigned int memfactor; + xlator_t *xl; /* xlator */ void *mydata; rpcsvc_notify_t notifyfn; @@ -79,6 +72,11 @@ typedef struct rpcsvc_state { gf_boolean_t addr_namelookup; /* determine whether throttling is needed, by default OFF */ gf_boolean_t throttle; + /* Allow insecure ports. */ + gf_boolean_t allow_insecure; + gf_boolean_t register_portmap; + gf_boolean_t root_squash; + gf_boolean_t all_squash; } rpcsvc_t; /* DRC START */ diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c index c6545193a11..39910d481bf 100644 --- a/rpc/rpc-lib/src/rpcsvc.c +++ b/rpc/rpc-lib/src/rpcsvc.c @@ -10,19 +10,16 @@ #include "rpcsvc.h" #include "rpc-transport.h" -#include "dict.h" -#include "logging.h" -#include "byte-order.h" -#include "common-utils.h" -#include "compat-errno.h" -#include "list.h" +#include <glusterfs/dict.h> +#include <glusterfs/byte-order.h> +#include <glusterfs/compat-errno.h> +#include <glusterfs/statedump.h> #include "xdr-rpc.h" -#include "iobuf.h" -#include "globals.h" +#include <glusterfs/iobuf.h> #include "xdr-common.h" #include "xdr-generic.h" #include "rpc-common-xdr.h" -#include "syncop.h" +#include <glusterfs/syncop.h> #include "rpc-drc.h" #include "protocol-common.h" @@ -36,15 +33,20 @@ #include <fnmatch.h> #include <stdarg.h> #include <stdio.h> +#include <dlfcn.h> #ifdef IPV6_DEFAULT #include <netconfig.h> #endif #include "xdr-rpcclnt.h" -#include "glusterfs-acl.h" +#include <glusterfs/glusterfs-acl.h> -struct rpcsvc_program gluster_dump_prog; +#ifndef PTHREAD_MUTEX_ADAPTIVE_NP +#define PTHREAD_MUTEX_ADAPTIVE_NP PTHREAD_MUTEX_DEFAULT +#endif + +static struct rpcsvc_program gluster_dump_prog; #define rpcsvc_alloc_request(svc, request) \ do { \ @@ -63,10 +65,41 @@ rpcsvc_get_listener(rpcsvc_t *svc, uint16_t port, rpc_transport_t *trans); int rpcsvc_notify(rpc_transport_t *trans, void *mydata, rpc_transport_event_t event, void *data, ...); +void * +rpcsvc_request_handler(void *arg); static int rpcsvc_match_subnet_v4(const char *addrtok, const char *ipaddr); +static void +rpcsvc_toggle_queue_status(rpcsvc_program_t *prog, + rpcsvc_request_queue_t *queue, + unsigned long status[]) +{ + unsigned queue_index = queue - prog->request_queue; + + status[queue_index / __BITS_PER_LONG] ^= (1UL << (queue_index % + __BITS_PER_LONG)); +} + +int +rpcsvc_get_free_queue_index(rpcsvc_program_t *prog) +{ + unsigned i, j = 0; + + for (i = 0; i < EVENT_MAX_THREADS / __BITS_PER_LONG; i++) + if (prog->request_queue_status[i] != ULONG_MAX) { + j = __builtin_ctzl(~prog->request_queue_status[i]); + break; + } + + if (i == EVENT_MAX_THREADS / __BITS_PER_LONG) + return -1; + + prog->request_queue_status[i] |= (1UL << j); + return i * __BITS_PER_LONG + j; +} + rpcsvc_notify_wrapper_t * rpcsvc_notify_wrapper_alloc(void) { @@ -309,6 +342,10 @@ rpcsvc_program_actor(rpcsvc_request_t *req) goto err; } + if (svc->xl->ctx->measure_latency) { + timespec_now(&req->begin); + } + req->ownthread = program->ownthread; req->synctask = program->synctask; @@ -575,6 +612,73 @@ rpcsvc_check_and_reply_error(int ret, call_frame_t *frame, void *opaque) return 0; } +void +rpcsvc_queue_event_thread_death(rpcsvc_t *svc, rpcsvc_program_t *prog, int gen) +{ + rpcsvc_request_queue_t *queue = NULL; + int num = 0; + void *value = NULL; + rpcsvc_request_t *req = NULL; + char empty = 0; + + value = pthread_getspecific(prog->req_queue_key); + if (value == NULL) { + return; + } + + num = ((unsigned long)value) - 1; + + queue = &prog->request_queue[num]; + + if (queue->gen == gen) { + /* duplicate event */ + gf_log(GF_RPCSVC, GF_LOG_INFO, + "not queuing duplicate event thread death. " + "queue %d program %s", + num, prog->progname); + return; + } + + rpcsvc_alloc_request(svc, req); + req->prognum = RPCSVC_INFRA_PROGRAM; + req->procnum = RPCSVC_PROC_EVENT_THREAD_DEATH; + gf_log(GF_RPCSVC, GF_LOG_INFO, + "queuing event thread death request to queue %d of program %s", num, + prog->progname); + + pthread_mutex_lock(&queue->queue_lock); + { + empty = list_empty(&queue->request_queue); + + list_add_tail(&req->request_list, &queue->request_queue); + queue->gen = gen; + + if (empty && queue->waiting) + pthread_cond_signal(&queue->queue_cond); + } + pthread_mutex_unlock(&queue->queue_lock); + + return; +} + +int +rpcsvc_handle_event_thread_death(rpcsvc_t *svc, rpc_transport_t *trans, int gen) +{ + rpcsvc_program_t *prog = NULL; + + pthread_rwlock_rdlock(&svc->rpclock); + { + list_for_each_entry(prog, &svc->programs, program) + { + if (prog->ownthread) + rpcsvc_queue_event_thread_death(svc, prog, gen); + } + } + pthread_rwlock_unlock(&svc->rpclock); + + return 0; +} + int rpcsvc_handle_rpc_call(rpcsvc_t *svc, rpc_transport_t *trans, rpc_transport_pollin_t *msg) @@ -585,9 +689,12 @@ rpcsvc_handle_rpc_call(rpcsvc_t *svc, rpc_transport_t *trans, int ret = -1; uint16_t port = 0; gf_boolean_t is_unix = _gf_false, empty = _gf_false; - gf_boolean_t unprivileged = _gf_false; + gf_boolean_t unprivileged = _gf_false, spawn_request_handler = 0; drc_cached_op_t *reply = NULL; rpcsvc_drc_globals_t *drc = NULL; + rpcsvc_request_queue_t *queue = NULL; + long num = 0; + void *value = NULL; if (!trans || !svc) return -1; @@ -700,19 +807,81 @@ rpcsvc_handle_rpc_call(rpcsvc_t *svc, rpc_transport_t *trans, ret = synctask_new(THIS->ctx->env, (synctask_fn_t)actor_fn, rpcsvc_check_and_reply_error, NULL, req); } else if (req->ownthread) { - pthread_mutex_lock(&req->prog->queue_lock); + value = pthread_getspecific(req->prog->req_queue_key); + if (value == NULL) { + pthread_mutex_lock(&req->prog->thr_lock); + { + num = rpcsvc_get_free_queue_index(req->prog); + if (num != -1) { + num++; + value = (void *)num; + ret = pthread_setspecific(req->prog->req_queue_key, + value); + if (ret < 0) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, + "setting request queue in TLS failed"); + rpcsvc_toggle_queue_status( + req->prog, &req->prog->request_queue[num - 1], + req->prog->request_queue_status); + num = -1; + } else { + spawn_request_handler = 1; + } + } + } + pthread_mutex_unlock(&req->prog->thr_lock); + } + + if (num == -1) + goto noqueue; + + num = ((unsigned long)value) - 1; + + queue = &req->prog->request_queue[num]; + + if (spawn_request_handler) { + ret = gf_thread_create(&queue->thread, NULL, + rpcsvc_request_handler, queue, + "rpcrqhnd"); + if (!ret) { + gf_log(GF_RPCSVC, GF_LOG_INFO, + "spawned a request handler thread for queue %d", + (int)num); + + req->prog->threadcount++; + } else { + gf_log( + GF_RPCSVC, GF_LOG_INFO, + "spawning a request handler thread for queue %d failed", + (int)num); + ret = pthread_setspecific(req->prog->req_queue_key, 0); + if (ret < 0) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, + "resetting request queue in TLS failed"); + } + + rpcsvc_toggle_queue_status( + req->prog, &req->prog->request_queue[num - 1], + req->prog->request_queue_status); + + goto noqueue; + } + } + + pthread_mutex_lock(&queue->queue_lock); { - empty = list_empty(&req->prog->request_queue); + empty = list_empty(&queue->request_queue); - list_add_tail(&req->request_list, &req->prog->request_queue); + list_add_tail(&req->request_list, &queue->request_queue); - if (empty) - pthread_cond_signal(&req->prog->queue_cond); + if (empty && queue->waiting) + pthread_cond_signal(&queue->queue_cond); } - pthread_mutex_unlock(&req->prog->queue_lock); + pthread_mutex_unlock(&queue->queue_lock); ret = 0; } else { + noqueue: ret = actor_fn(req); } } @@ -839,6 +1008,12 @@ rpcsvc_notify(rpc_transport_t *trans, void *mydata, rpc_transport_event_t event, "got MAP_XID event, which should have not come"); ret = 0; break; + + case RPC_TRANSPORT_EVENT_THREAD_DIED: + rpcsvc_handle_event_thread_death(svc, trans, + (int)(unsigned long)data); + ret = 0; + break; } out: @@ -1164,9 +1339,9 @@ rpcsvc_transport_submit(rpc_transport_t *trans, struct iovec *rpchdr, int progpayloadcount, struct iobref *iobref, void *priv) { int ret = -1; - rpc_transport_reply_t reply = {{ + rpc_transport_reply_t reply = { 0, - }}; + }; if ((!trans) || (!rpchdr) || (!rpchdr->iov_base)) { goto out; @@ -1320,10 +1495,18 @@ rpcsvc_submit_generic(rpcsvc_request_t *req, struct iovec *proghdr, size_t hdrlen = 0; char new_iobref = 0; rpcsvc_drc_globals_t *drc = NULL; + gf_latency_t *lat = NULL; if ((!req) || (!req->trans)) return -1; + if (req->prog && req->begin.tv_sec) { + if ((req->procnum >= 0) && (req->procnum < req->prog->numactors)) { + timespec_now(&req->end); + lat = &req->prog->latencies[req->procnum]; + gf_latency_update(lat, &req->begin, &req->end); + } + } trans = req->trans; for (i = 0; i < hdrcount; i++) { @@ -1654,6 +1837,15 @@ rpcsvc_submit_message(rpcsvc_request_t *req, struct iovec *proghdr, iobref); } +void +rpcsvc_program_destroy(rpcsvc_program_t *program) +{ + if (program) { + GF_FREE(program->latencies); + GF_FREE(program); + } +} + int rpcsvc_program_unregister(rpcsvc_t *svc, rpcsvc_program_t *program) { @@ -1663,6 +1855,18 @@ rpcsvc_program_unregister(rpcsvc_t *svc, rpcsvc_program_t *program) goto out; } + pthread_rwlock_rdlock(&svc->rpclock); + { + list_for_each_entry(prog, &svc->programs, program) + { + if ((prog->prognum == program->prognum) && + (prog->progver == program->progver)) { + break; + } + } + } + pthread_rwlock_unlock(&svc->rpclock); + ret = rpcsvc_program_unregister_portmap(program); if (ret == -1) { gf_log(GF_RPCSVC, GF_LOG_ERROR, @@ -1679,17 +1883,6 @@ rpcsvc_program_unregister(rpcsvc_t *svc, rpcsvc_program_t *program) goto out; } #endif - pthread_rwlock_rdlock(&svc->rpclock); - { - list_for_each_entry(prog, &svc->programs, program) - { - if ((prog->prognum == program->prognum) && - (prog->progver == program->progver)) { - break; - } - } - } - pthread_rwlock_unlock(&svc->rpclock); gf_log(GF_RPCSVC, GF_LOG_DEBUG, "Program unregistered: %s, Num: %d," @@ -1710,6 +1903,8 @@ rpcsvc_program_unregister(rpcsvc_t *svc, rpcsvc_program_t *program) ret = 0; out: + rpcsvc_program_destroy(prog); + if (ret == -1) { if (program) { gf_log(GF_RPCSVC, GF_LOG_ERROR, @@ -1804,6 +1999,7 @@ rpcsvc_create_listener(rpcsvc_t *svc, dict_t *options, char *name) listener = rpcsvc_listener_alloc(svc, trans); if (listener == NULL) { + ret = -1; goto out; } @@ -1811,6 +2007,7 @@ rpcsvc_create_listener(rpcsvc_t *svc, dict_t *options, char *name) out: if (!listener && trans) { rpc_transport_disconnect(trans, _gf_true); + rpc_transport_cleanup(trans); } return ret; @@ -1877,6 +2074,7 @@ rpcsvc_create_listeners(rpcsvc_t *svc, dict_t *options, char *name) goto out; } + dict_del(options, "notify-poller-death"); GF_FREE(transport_name); transport_name = NULL; count++; @@ -1961,55 +2159,84 @@ out: void * rpcsvc_request_handler(void *arg) { - rpcsvc_program_t *program = arg; - rpcsvc_request_t *req = NULL; + rpcsvc_request_queue_t *queue = NULL; + rpcsvc_program_t *program = NULL; + rpcsvc_request_t *req = NULL, *tmp_req = NULL; rpcsvc_actor_t *actor = NULL; gf_boolean_t done = _gf_false; int ret = 0; + struct list_head tmp_list; + + queue = arg; + program = queue->program; + + INIT_LIST_HEAD(&tmp_list); if (!program) return NULL; while (1) { - pthread_mutex_lock(&program->queue_lock); + pthread_mutex_lock(&queue->queue_lock); { - if (!program->alive && list_empty(&program->request_queue)) { + if (!program->alive && list_empty(&queue->request_queue)) { done = 1; goto unlock; } - while (list_empty(&program->request_queue) && - (program->threadcount <= program->eventthreadcount)) { - pthread_cond_wait(&program->queue_cond, &program->queue_lock); + while (list_empty(&queue->request_queue)) { + queue->waiting = _gf_true; + pthread_cond_wait(&queue->queue_cond, &queue->queue_lock); } - if (program->threadcount > program->eventthreadcount) { - done = 1; - program->threadcount--; - - gf_log(GF_RPCSVC, GF_LOG_INFO, - "program '%s' thread terminated; " - "total count:%d", - program->progname, program->threadcount); - } else if (!list_empty(&program->request_queue)) { - req = list_entry(program->request_queue.next, typeof(*req), - request_list); + queue->waiting = _gf_false; - list_del_init(&req->request_list); + if (!list_empty(&queue->request_queue)) { + INIT_LIST_HEAD(&tmp_list); + list_splice_init(&queue->request_queue, &tmp_list); } } unlock: - pthread_mutex_unlock(&program->queue_lock); + pthread_mutex_unlock(&queue->queue_lock); - if (req) { - THIS = req->svc->xl; - actor = rpcsvc_program_actor(req); - ret = actor->actor(req); + list_for_each_entry_safe(req, tmp_req, &tmp_list, request_list) + { + if (req) { + list_del_init(&req->request_list); - if (ret != 0) { - rpcsvc_check_and_reply_error(ret, NULL, req); + if (req->prognum == RPCSVC_INFRA_PROGRAM) { + switch (req->procnum) { + case RPCSVC_PROC_EVENT_THREAD_DEATH: + gf_log(GF_RPCSVC, GF_LOG_INFO, + "event thread died, exiting request handler " + "thread for queue %d of program %s", + (int)(queue - &program->request_queue[0]), + program->progname); + done = 1; + pthread_mutex_lock(&program->thr_lock); + { + rpcsvc_toggle_queue_status( + program, queue, + program->request_queue_status); + program->threadcount--; + } + pthread_mutex_unlock(&program->thr_lock); + rpcsvc_request_destroy(req); + break; + + default: + break; + } + } else { + THIS = req->svc->xl; + actor = rpcsvc_program_actor(req); + ret = actor->actor(req); + + if (ret != 0) { + rpcsvc_check_and_reply_error(ret, NULL, req); + } + req = NULL; + } } - req = NULL; } if (done) @@ -2020,61 +2247,14 @@ rpcsvc_request_handler(void *arg) } int -rpcsvc_spawn_threads(rpcsvc_t *svc, rpcsvc_program_t *program) -{ - int ret = 0, delta = 0, creates = 0; - - if (!program || !svc) - goto out; - - pthread_mutex_lock(&program->queue_lock); - { - delta = program->eventthreadcount - program->threadcount; - - if (delta >= 0) { - while (delta--) { - ret = gf_thread_create(&program->thread, NULL, - rpcsvc_request_handler, program, - "rpcrqhnd"); - if (!ret) { - program->threadcount++; - creates++; - } - } - - if (creates) { - gf_log(GF_RPCSVC, GF_LOG_INFO, - "spawned %d threads for program '%s'; " - "total count:%d", - creates, program->progname, program->threadcount); - } - } else { - gf_log(GF_RPCSVC, GF_LOG_INFO, - "terminating %d threads for program '%s'", -delta, - program->progname); - - /* this signal is to just wake up the threads so they - * test for the change in eventthreadcount and kill - * themselves until the program thread count becomes - * equal to the event thread count - */ - pthread_cond_broadcast(&program->queue_cond); - } - } - pthread_mutex_unlock(&program->queue_lock); - -out: - return creates; -} - -int rpcsvc_program_register(rpcsvc_t *svc, rpcsvc_program_t *program, gf_boolean_t add_to_head) { - int ret = -1; - int creates = -1; + int ret = -1, i = 0; rpcsvc_program_t *newprog = NULL; char already_registered = 0; + pthread_mutexattr_t attr[EVENT_MAX_THREADS]; + pthread_mutexattr_t thr_attr; if (!svc) { goto out; @@ -2108,25 +2288,45 @@ rpcsvc_program_register(rpcsvc_t *svc, rpcsvc_program_t *program, } memcpy(newprog, program, sizeof(*program)); + newprog->latencies = gf_latency_new(program->numactors); + if (!newprog->latencies) { + rpcsvc_program_destroy(newprog); + goto out; + } INIT_LIST_HEAD(&newprog->program); - INIT_LIST_HEAD(&newprog->request_queue); - pthread_mutex_init(&newprog->queue_lock, NULL); - pthread_cond_init(&newprog->queue_cond, NULL); + pthread_mutexattr_init(&thr_attr); + pthread_mutexattr_settype(&thr_attr, PTHREAD_MUTEX_ADAPTIVE_NP); + + for (i = 0; i < EVENT_MAX_THREADS; i++) { + pthread_mutexattr_init(&attr[i]); + pthread_mutexattr_settype(&attr[i], PTHREAD_MUTEX_ADAPTIVE_NP); + INIT_LIST_HEAD(&newprog->request_queue[i].request_queue); + pthread_mutex_init(&newprog->request_queue[i].queue_lock, &attr[i]); + pthread_cond_init(&newprog->request_queue[i].queue_cond, NULL); + newprog->request_queue[i].program = newprog; + } + + pthread_mutex_init(&newprog->thr_lock, &thr_attr); + pthread_cond_init(&newprog->thr_cond, NULL); newprog->alive = _gf_true; + if (gf_async_ctrl.enabled) { + newprog->ownthread = _gf_false; + newprog->synctask = _gf_false; + } + /* make sure synctask gets priority over ownthread */ if (newprog->synctask) newprog->ownthread = _gf_false; if (newprog->ownthread) { - newprog->eventthreadcount = 1; - creates = rpcsvc_spawn_threads(svc, newprog); + struct event_pool *ep = svc->ctx->event_pool; + newprog->eventthreadcount = ep->eventthreadcount; - if (creates < 1) { - goto out; - } + pthread_key_create(&newprog->req_queue_key, NULL); + newprog->thr_queue = 1; } pthread_rwlock_wrlock(&svc->rpclock); @@ -2366,7 +2566,7 @@ rpcsvc_reconfigure_options(rpcsvc_t *svc, dict_t *options) */ dict_del(svc->options, srchkey); if (!dict_get_str(options, srchkey, &keyval)) { - ret = dict_set_str(svc->options, srchkey, keyval); + ret = dict_set_dynstr_with_alloc(svc->options, srchkey, keyval); if (ret < 0) { gf_log(GF_RPCSVC, GF_LOG_ERROR, "dict_set_str error"); GF_FREE(srchkey); @@ -2398,7 +2598,7 @@ rpcsvc_reconfigure_options(rpcsvc_t *svc, dict_t *options) */ dict_del(svc->options, srchkey); if (!dict_get_str(options, srchkey, &keyval)) { - ret = dict_set_str(svc->options, srchkey, keyval); + ret = dict_set_dynstr_with_alloc(svc->options, srchkey, keyval); if (ret < 0) { gf_log(GF_RPCSVC, GF_LOG_ERROR, "dict_set_str error"); GF_FREE(srchkey); @@ -2418,18 +2618,13 @@ rpcsvc_reconfigure_options(rpcsvc_t *svc, dict_t *options) } int -rpcsvc_transport_unix_options_build(dict_t **options, char *filepath) +rpcsvc_transport_unix_options_build(dict_t *dict, char *filepath) { - dict_t *dict = NULL; char *fpath = NULL; int ret = -1; GF_ASSERT(filepath); - GF_ASSERT(options); - - dict = dict_new(); - if (!dict) - goto out; + GF_VALIDATE_OR_GOTO("rpcsvc", dict, out); fpath = gf_strdup(filepath); if (!fpath) { @@ -2452,13 +2647,9 @@ rpcsvc_transport_unix_options_build(dict_t **options, char *filepath) ret = dict_set_str(dict, "transport-type", "socket"); if (ret) goto out; - - *options = dict; out: if (ret) { GF_FREE(fpath); - if (dict) - dict_unref(dict); } return ret; } @@ -2553,6 +2744,43 @@ rpcsvc_get_throttle(rpcsvc_t *svc) return svc->throttle; } +/* Function call to cleanup resources for svc + */ +int +rpcsvc_destroy(rpcsvc_t *svc) +{ + struct rpcsvc_auth_list *auth = NULL; + struct rpcsvc_auth_list *tmp = NULL; + rpcsvc_listener_t *listener = NULL; + rpcsvc_listener_t *next = NULL; + int ret = 0; + + if (!svc) + return ret; + + list_for_each_entry_safe(listener, next, &svc->listeners, list) + { + rpcsvc_listener_destroy(listener); + } + + list_for_each_entry_safe(auth, tmp, &svc->authschemes, authlist) + { + list_del_init(&auth->authlist); + GF_FREE(auth); + } + + rpcsvc_program_unregister(svc, &gluster_dump_prog); + if (svc->rxpool) { + mem_pool_destroy(svc->rxpool); + svc->rxpool = NULL; + } + + pthread_rwlock_destroy(&svc->rpclock); + GF_FREE(svc); + + return ret; +} + /* The global RPC service initializer. */ rpcsvc_t * @@ -2649,6 +2877,10 @@ rpcsvc_transport_peer_check_search(dict_t *options, char *pattern, char *ip, } dup_addrstr = gf_strdup(addrstr); + if (dup_addrstr == NULL) { + ret = -1; + goto err; + } addrtok = strtok_r(dup_addrstr, ",", &svptr); while (addrtok) { /* CASEFOLD not present on Solaris */ @@ -2972,10 +3204,6 @@ rpcsvc_match_subnet_v4(const char *addrtok, const char *ipaddr) if (inet_pton(AF_INET, ipaddr, &sin1.sin_addr) == 0) goto out; - /* Find the network socket addr of subnet pattern */ - if (inet_pton(AF_INET, netaddr, &sin2.sin_addr) == 0) - goto out; - slash = strchr(netaddr, '/'); if (slash) { *slash = '\0'; @@ -2988,9 +3216,16 @@ rpcsvc_match_subnet_v4(const char *addrtok, const char *ipaddr) if (prefixlen > 31) goto out; } else { + /* if there is no '/', then this function wouldn't be called */ goto out; } + /* Need to do this after removing '/', as inet_pton() take IP address as + * second argument. Once we get sin2, then comparison is oranges to orange + */ + if (inet_pton(AF_INET, netaddr, &sin2.sin_addr) == 0) + goto out; + shift = IPv4_ADDR_SIZE - prefixlen; mask.sin_addr.s_addr = htonl((uint32_t)~0 << shift); @@ -3003,45 +3238,55 @@ out: return ret; } -/* During reconfigure, Make sure to call this function after event-threads are - * reconfigured as programs' threadcount will be made equal to event threads. - */ - -int -rpcsvc_ownthread_reconf(rpcsvc_t *svc, int new_eventthreadcount) +void +rpcsvc_program_dump(rpcsvc_program_t *prog) { - int ret = -1; - rpcsvc_program_t *program = NULL; + char key_prefix[GF_DUMP_MAX_BUF_LEN]; + char key[GF_DUMP_MAX_BUF_LEN]; + int i; - if (!svc) { - ret = 0; - goto out; + snprintf(key_prefix, GF_DUMP_MAX_BUF_LEN, "%s", prog->progname); + gf_proc_dump_add_section("%s", key_prefix); + + gf_proc_dump_build_key(key, key_prefix, "program-number"); + gf_proc_dump_write(key, "%d", prog->prognum); + + gf_proc_dump_build_key(key, key_prefix, "program-version"); + gf_proc_dump_write(key, "%d", prog->progver); + + strncat(key_prefix, ".latency", + sizeof(key_prefix) - strlen(key_prefix) - 1); + + for (i = 0; i < prog->numactors; i++) { + gf_proc_dump_build_key(key, key_prefix, "%s", prog->actors[i].procname); + gf_latency_statedump_and_reset(key, &prog->latencies[i]); } +} - pthread_rwlock_wrlock(&svc->rpclock); +void +rpcsvc_statedump(rpcsvc_t *svc) +{ + rpcsvc_program_t *prog = NULL; + int ret = 0; + ret = pthread_rwlock_tryrdlock(&svc->rpclock); + if (ret) + return; { - list_for_each_entry(program, &svc->programs, program) + list_for_each_entry(prog, &svc->programs, program) { - if (program->ownthread) { - program->eventthreadcount = new_eventthreadcount; - rpcsvc_spawn_threads(svc, program); - } + rpcsvc_program_dump(prog); } } pthread_rwlock_unlock(&svc->rpclock); - - ret = 0; -out: - return ret; } -rpcsvc_actor_t gluster_dump_actors[GF_DUMP_MAXVALUE] = { - [GF_DUMP_NULL] = {"NULL", GF_DUMP_NULL, NULL, NULL, 0, DRC_NA}, - [GF_DUMP_DUMP] = {"DUMP", GF_DUMP_DUMP, rpcsvc_dump, NULL, 0, DRC_NA}, - [GF_DUMP_PING] = {"PING", GF_DUMP_PING, rpcsvc_ping, NULL, 0, DRC_NA}, +static rpcsvc_actor_t gluster_dump_actors[GF_DUMP_MAXVALUE] = { + [GF_DUMP_NULL] = {"NULL", NULL, NULL, GF_DUMP_NULL, DRC_NA, 0}, + [GF_DUMP_DUMP] = {"DUMP", rpcsvc_dump, NULL, GF_DUMP_DUMP, DRC_NA, 0}, + [GF_DUMP_PING] = {"PING", rpcsvc_ping, NULL, GF_DUMP_PING, DRC_NA, 0}, }; -struct rpcsvc_program gluster_dump_prog = { +static struct rpcsvc_program gluster_dump_prog = { .progname = "GF-DUMP", .prognum = GLUSTER_DUMP_PROGRAM, .progver = GLUSTER_DUMP_VERSION, diff --git a/rpc/rpc-lib/src/rpcsvc.h b/rpc/rpc-lib/src/rpcsvc.h index ebb836fba3f..7b3030926c8 100644 --- a/rpc/rpc-lib/src/rpcsvc.h +++ b/rpc/rpc-lib/src/rpcsvc.h @@ -11,28 +11,33 @@ #ifndef _RPCSVC_H #define _RPCSVC_H -#include "gf-event.h" +#include <glusterfs/gf-event.h> #include "rpc-transport.h" -#include "logging.h" -#include "dict.h" -#include "mem-pool.h" -#include "list.h" -#include "iobuf.h" +#include <glusterfs/dict.h> #include "xdr-rpc.h" -#include "glusterfs.h" -#include "xlator.h" #include "rpcsvc-common.h" #include <pthread.h> #include <sys/uio.h> #include <inttypes.h> #include <rpc/rpc_msg.h> -#include "compat.h" +#include <glusterfs/compat.h> +#include <glusterfs/client_t.h> #ifndef MAX_IOVEC #define MAX_IOVEC 16 #endif +/* TODO: we should store prognums at a centralized location to avoid conflict + or use a robust random number generator to avoid conflicts +*/ + +#define RPCSVC_INFRA_PROGRAM 7712846 /* random number */ + +typedef enum { + RPCSVC_PROC_EVENT_THREAD_DEATH = 0, +} rpcsvc_infra_procnum_t; + #define RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT \ 64 /* Default for protocol/server */ #define RPCSVC_DEF_NFS_OUTSTANDING_RPC_LIMIT 16 /* Default for nfs/server */ @@ -138,12 +143,6 @@ struct rpcsvc_config { int max_block_size; }; -typedef struct rpcsvc_auth_data { - int flavour; - int datalen; - char authdata[GF_MAX_AUTH_BYTES]; -} rpcsvc_auth_data_t; - #define rpcsvc_auth_flavour(au) ((au).flavour) typedef struct drc_client drc_client_t; @@ -161,11 +160,6 @@ struct rpcsvc_request { rpcsvc_program_t *prog; - /* The identifier for the call from client. - * Needed to pair the reply with the call. - */ - uint32_t xid; - int prognum; int progver; @@ -196,24 +190,11 @@ struct rpcsvc_request { * by the program actors. This is the buffer that will need to * be de-xdred by the actor. */ - struct iovec msg[MAX_IOVEC]; int count; + struct iovec msg[MAX_IOVEC]; struct iobref *iobref; - /* Status of the RPC call, whether it was accepted or denied. */ - int rpc_status; - - /* In case, the call was denied, the RPC error is stored here - * till the reply is sent. - */ - int rpc_err; - - /* In case the failure happened because of an authentication problem - * , this value needs to be assigned the correct auth error number. - */ - int auth_err; - /* There can be cases of RPC requests where the reply needs to * be built from multiple sources. E.g. where even the NFS reply * can contain a payload, as in the NFSv3 read reply. Here the RPC header @@ -229,19 +210,14 @@ struct rpcsvc_request { size_t payloadsize; /* The credentials extracted from the rpc request */ - rpcsvc_auth_data_t cred; + client_auth_data_t cred; /* The verified extracted from the rpc request. In request side * processing this contains the verifier sent by the client, on reply * side processing, it is filled with the verified that will be * sent to the client. */ - rpcsvc_auth_data_t verf; - - /* Execute this request's actor function in ownthread of program?*/ - gf_boolean_t ownthread; - - gf_boolean_t synctask; + client_auth_data_t verf; /* Container for a RPC program wanting to store a temp * request-specific item. */ @@ -256,6 +232,19 @@ struct rpcsvc_request { /* request queue in rpcsvc */ struct list_head request_list; + /* Status of the RPC call, whether it was accepted or denied. */ + int rpc_status; + + /* In case, the call was denied, the RPC error is stored here + * till the reply is sent. + */ + int rpc_err; + + /* In case the failure happened because of an authentication problem + * , this value needs to be assigned the correct auth error number. + */ + int auth_err; + /* Things passed to rpc layer from client */ /* @flags: Can be used for binary data passed in xdata to be @@ -265,6 +254,18 @@ struct rpcsvc_request { /* ctime: origin of time on the client side, ideally this is the one we should consider for time */ struct timespec ctime; + + /* The identifier for the call from client. + * Needed to pair the reply with the call. + */ + uint32_t xid; + + /* Execute this request's actor function in ownthread of program?*/ + gf_boolean_t ownthread; + + gf_boolean_t synctask; + struct timespec begin; /*req handling start time*/ + struct timespec end; /*req handling end time*/ }; #define rpcsvc_request_program(req) ((rpcsvc_program_t *)((req)->prog)) @@ -306,6 +307,20 @@ struct rpcsvc_request { } \ } while (0); +#define RPC_AUTH_ALL_SQUASH(req) \ + do { \ + int gidcount = 0; \ + if (req->svc->all_squash) { \ + req->uid = req->svc->anonuid; \ + req->gid = req->svc->anongid; \ + \ + for (gidcount = 0; gidcount < req->auxgidcount; ++gidcount) { \ + if (!req->auxgids[gidcount]) \ + req->auxgids[gidcount] = req->svc->anongid; \ + } \ + } \ + } while (0); + #define RPCSVC_ACTOR_SUCCESS 0 #define RPCSVC_ACTOR_ERROR (-1) #define RPCSVC_ACTOR_IGNORE (-2) @@ -344,7 +359,6 @@ typedef void (*rpcsvc_deallocate_reply)(void *msg); */ typedef struct rpcsvc_actor_desc { char procname[RPCSVC_NAME_MAX]; - int procnum; rpcsvc_actor actor; /* Handler for cases where the RPC requests fragments are large enough @@ -357,11 +371,23 @@ typedef struct rpcsvc_actor_desc { */ rpcsvc_vector_sizer vector_sizer; + int procnum; + /* Can actor be ran on behalf an unprivileged requestor? */ - gf_boolean_t unprivileged; drc_op_type_t op_type; + gf_boolean_t unprivileged; } rpcsvc_actor_t; +typedef struct rpcsvc_request_queue { + struct list_head request_queue; + pthread_mutex_t queue_lock; + pthread_cond_t queue_cond; + pthread_t thread; + struct rpcsvc_program *program; + int gen; + gf_boolean_t waiting; +} rpcsvc_request_queue_t; + /* Describes a program and its version along with the function pointers * required to handle the procedures/actors of each program/version. * Never changed ever by any thread so no need for a lock. @@ -371,21 +397,20 @@ struct rpcsvc_program { int prognum; int progver; /* FIXME */ - dict_t *options; /* An opaque dictionary - * populated by the program - * (probably from xl->options) - * which contain enough - * information for transport to - * initialize. As a part of - * cleanup, the members of - * options which are of interest - * to transport should be put - * into a structure for better - * readability and structure - * should replace options member - * here. - */ - uint16_t progport; /* Registered with portmap */ + dict_t *options; /* An opaque dictionary + * populated by the program + * (probably from xl->options) + * which contain enough + * information for transport to + * initialize. As a part of + * cleanup, the members of + * options which are of interest + * to transport should be put + * into a structure for better + * readability and structure + * should replace options member + * here. + */ #if 0 int progaddrfamily; /* AF_INET or AF_INET6 */ char *proghost; /* Bind host, can be NULL */ @@ -394,10 +419,9 @@ struct rpcsvc_program { int numactors; /* Num actors in actor array */ int proghighvers; /* Highest ver for program supported by the system. */ - int proglowvers; /* Lowest ver */ - /* Program specific state handed to actors */ void *private; + gf_latency_t *latencies; /*Tracks latency statistics for the rpc call*/ /* This upcall is provided by the program during registration. * It is used to notify the program about events like connection being @@ -407,30 +431,36 @@ struct rpcsvc_program { */ rpcsvc_notify_t notify; + int proglowvers; /* Lowest ver */ + /* An integer that identifies the min auth strength that is required * by this protocol, for eg. MOUNT3 needs AUTH_UNIX at least. * See RFC 1813, Section 5.2.1. */ int min_auth; - /* Execute actor function in program's own thread? This will reduce */ - /* the workload on poller threads */ - gf_boolean_t ownthread; - gf_boolean_t alive; - - gf_boolean_t synctask; /* list member to link to list of registered services with rpcsvc */ struct list_head program; - struct list_head request_queue; - pthread_mutex_t queue_lock; - pthread_cond_t queue_cond; - pthread_t thread; + rpcsvc_request_queue_t request_queue[EVENT_MAX_THREADS]; + pthread_mutex_t thr_lock; + pthread_cond_t thr_cond; int threadcount; + int thr_queue; + pthread_key_t req_queue_key; + /* eventthreadcount is just a readonly copy of the actual value * owned by the event sub-system * It is used to control the scaling of rpcsvc_request_handler threads */ int eventthreadcount; + uint16_t progport; /* Registered with portmap */ + /* Execute actor function in program's own thread? This will reduce */ + /* the workload on poller threads */ + gf_boolean_t ownthread; + gf_boolean_t alive; + + gf_boolean_t synctask; + unsigned long request_queue_status[EVENT_MAX_THREADS / __BITS_PER_LONG]; }; typedef struct rpcsvc_cbk_program { @@ -562,9 +592,9 @@ typedef struct rpcsvc_auth_ops { typedef struct rpcsvc_auth_flavour_desc { char authname[RPCSVC_NAME_MAX]; - int authnum; rpcsvc_auth_ops_t *authops; void *authprivate; + int authnum; } rpcsvc_auth_t; typedef void *(*rpcsvc_auth_initer_t)(rpcsvc_t *svc, dict_t *options); @@ -628,7 +658,7 @@ rpcsvc_actor_t * rpcsvc_program_actor(rpcsvc_request_t *req); int -rpcsvc_transport_unix_options_build(dict_t **options, char *filepath); +rpcsvc_transport_unix_options_build(dict_t *options, char *filepath); int rpcsvc_set_allow_insecure(rpcsvc_t *svc, dict_t *options); int @@ -636,6 +666,8 @@ rpcsvc_set_addr_namelookup(rpcsvc_t *svc, dict_t *options); int rpcsvc_set_root_squash(rpcsvc_t *svc, dict_t *options); int +rpcsvc_set_all_squash(rpcsvc_t *svc, dict_t *options); +int rpcsvc_set_outstanding_rpc_limit(rpcsvc_t *svc, dict_t *options, int defvalue); int @@ -652,9 +684,11 @@ rpcsvc_auth_array(rpcsvc_t *svc, char *volname, int *autharr, int arrlen); rpcsvc_vector_sizer rpcsvc_get_program_vector_sizer(rpcsvc_t *svc, uint32_t prognum, uint32_t progver, int procnum); -extern int -rpcsvc_ownthread_reconf(rpcsvc_t *svc, int new_eventthreadcount); - void rpcsvc_autoscale_threads(glusterfs_ctx_t *ctx, rpcsvc_t *rpc, int incr); + +extern int +rpcsvc_destroy(rpcsvc_t *svc); +void +rpcsvc_statedump(rpcsvc_t *svc); #endif diff --git a/rpc/rpc-lib/src/xdr-common.h b/rpc/rpc-lib/src/xdr-common.h index 7b0bc36ec64..752736b3d4d 100644 --- a/rpc/rpc-lib/src/xdr-common.h +++ b/rpc/rpc-lib/src/xdr-common.h @@ -66,11 +66,9 @@ enum gf_dump_procnum { #ifdef GF_LINUX_HOST_OS #define xdr_u_int32_t xdr_uint32_t #define xdr_u_int64_t xdr_uint64_t -#ifdef IPV6_DEFAULT unsigned long xdr_sizeof(xdrproc_t func, void *data); #endif -#endif #ifdef GF_DARWIN_HOST_OS #define xdr_u_quad_t xdr_u_int64_t diff --git a/rpc/rpc-lib/src/xdr-rpc.c b/rpc/rpc-lib/src/xdr-rpc.c index 36fd9db1a97..4992dc5a7ce 100644 --- a/rpc/rpc-lib/src/xdr-rpc.c +++ b/rpc/rpc-lib/src/xdr-rpc.c @@ -9,17 +9,13 @@ */ #include <rpc/rpc.h> -#include <rpc/pmap_clnt.h> -#include <arpa/inet.h> #include <rpc/xdr.h> #include <sys/uio.h> #include <rpc/auth_unix.h> -#include "mem-pool.h" #include "xdr-rpc.h" #include "xdr-common.h" -#include "logging.h" -#include "common-utils.h" +#include <glusterfs/common-utils.h> /* Decodes the XDR format in msgbuf into rpc_msg. * The remaining payload is returned into payload. diff --git a/rpc/rpc-lib/src/xdr-rpc.h b/rpc/rpc-lib/src/xdr-rpc.h index a57cd9430be..7baed273846 100644 --- a/rpc/rpc-lib/src/xdr-rpc.h +++ b/rpc/rpc-lib/src/xdr-rpc.h @@ -20,7 +20,6 @@ #include <rpc/auth_sys.h> #endif -//#include <rpc/pmap_clnt.h> #include <arpa/inet.h> #include <rpc/xdr.h> #include <sys/uio.h> diff --git a/rpc/rpc-lib/src/xdr-rpcclnt.c b/rpc/rpc-lib/src/xdr-rpcclnt.c index 9e60d19e7a2..8dcdcfeda83 100644 --- a/rpc/rpc-lib/src/xdr-rpcclnt.c +++ b/rpc/rpc-lib/src/xdr-rpcclnt.c @@ -9,18 +9,14 @@ */ #include <rpc/rpc.h> -#include <rpc/pmap_clnt.h> -#include <arpa/inet.h> #include <rpc/xdr.h> #include <sys/uio.h> #include <rpc/auth_unix.h> #include <errno.h> -#include "mem-pool.h" #include "xdr-rpc.h" #include "xdr-common.h" -#include "logging.h" -#include "common-utils.h" +#include <glusterfs/common-utils.h> /* Decodes the XDR format in msgbuf into rpc_msg. * The remaining payload is returned into payload. diff --git a/rpc/rpc-lib/src/xdr-rpcclnt.h b/rpc/rpc-lib/src/xdr-rpcclnt.h index 4d6e38d429c..58eda4892a9 100644 --- a/rpc/rpc-lib/src/xdr-rpcclnt.h +++ b/rpc/rpc-lib/src/xdr-rpcclnt.h @@ -11,8 +11,6 @@ #ifndef _XDR_RPCCLNT_H #define _XDR_RPCCLNT_H -//#include <rpc/rpc.h> -//#include <rpc/pmap_clnt.h> #include <arpa/inet.h> #include <rpc/xdr.h> #include <sys/uio.h> diff --git a/rpc/rpc-transport/Makefile.am b/rpc/rpc-transport/Makefile.am index 221fd640514..7dd9f026cfc 100644 --- a/rpc/rpc-transport/Makefile.am +++ b/rpc/rpc-transport/Makefile.am @@ -1 +1 @@ -SUBDIRS = socket $(RDMA_SUBDIR) +SUBDIRS = socket diff --git a/rpc/rpc-transport/rdma/Makefile.am b/rpc/rpc-transport/rdma/Makefile.am deleted file mode 100644 index f963effea22..00000000000 --- a/rpc/rpc-transport/rdma/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = src
\ No newline at end of file diff --git a/rpc/rpc-transport/rdma/src/Makefile.am b/rpc/rpc-transport/rdma/src/Makefile.am deleted file mode 100644 index 40b5a19d3d1..00000000000 --- a/rpc/rpc-transport/rdma/src/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -# TODO : need to change transportdir - -transport_LTLIBRARIES = rdma.la -transportdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/rpc-transport - -rdma_la_LDFLAGS = -module -avoid-version -nostartfiles - -rdma_la_SOURCES = rdma.c name.c -rdma_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ - $(top_builddir)/rpc/xdr/src/libgfxdr.la \ - $(top_builddir)/rpc/rpc-lib/src/libgfrpc.la \ - -libverbs -lrdmacm - -noinst_HEADERS = rdma.h name.h rpc-trans-rdma-messages.h - -AM_CPPFLAGS = $(GF_CPPFLAGS) \ - -I$(top_srcdir)/libglusterfs/src \ - -I$(top_srcdir)/rpc/rpc-lib/src/ \ - -I$(top_srcdir)/rpc/xdr/src \ - -I$(top_builddir)/rpc/xdr/src - -AM_CFLAGS = -Wall $(GF_CFLAGS) - -CLEANFILES = *~ diff --git a/rpc/rpc-transport/rdma/src/name.c b/rpc/rpc-transport/rdma/src/name.c deleted file mode 100644 index e7d56fcc1a8..00000000000 --- a/rpc/rpc-transport/rdma/src/name.c +++ /dev/null @@ -1,709 +0,0 @@ -/* - Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> - This file is part of GlusterFS. - - This file is licensed to you under your choice of the GNU Lesser - General Public License, version 3 or any later version (LGPLv3 or - later), or the GNU General Public License, version 2 (GPLv2), in all - cases as published by the Free Software Foundation. -*/ - -#include <sys/types.h> -#include <sys/socket.h> -#include <errno.h> -#include <netdb.h> -#include <string.h> -#include <rdma/rdma_cma.h> - -#ifndef AF_INET_SDP -#define AF_INET_SDP 27 -#endif - -#include "rpc-transport.h" -#include "rdma.h" -#include "common-utils.h" -#include "rpc-lib-messages.h" -#include "rpc-trans-rdma-messages.h" - -int32_t -gf_resolve_ip6(const char *hostname, uint16_t port, int family, void **dnscache, - struct addrinfo **addr_info); - -static void -_assign_port(struct sockaddr *sockaddr, uint16_t port) -{ - switch (sockaddr->sa_family) { - case AF_INET6: - ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons(port); - break; - - case AF_INET_SDP: - case AF_INET: - ((struct sockaddr_in *)sockaddr)->sin_port = htons(port); - break; - } -} - -static int32_t -af_inet_bind_to_port_lt_ceiling(struct rdma_cm_id *cm_id, - struct sockaddr *sockaddr, - socklen_t sockaddr_len, uint32_t ceiling) -{ -#if GF_DISABLE_PRIVPORT_TRACKING - _assign_port(sockaddr, 0); - return rdma_bind_addr(cm_id, sockaddr); -#else - int32_t ret = -1; - uint16_t port = ceiling - 1; - unsigned char ports[GF_PORT_ARRAY_SIZE] = { - 0, - }; - int i = 0; - -loop: - ret = gf_process_reserved_ports(ports, ceiling); - - while (port) { - if (port == GF_CLIENT_PORT_CEILING) { - ret = -1; - break; - } - - /* ignore the reserved ports */ - if (BIT_VALUE(ports, port)) { - port--; - continue; - } - - _assign_port(sockaddr, port); - - ret = rdma_bind_addr(cm_id, sockaddr); - - if (ret == 0) - break; - - if (ret == -1 && errno == EACCES) - break; - - port--; - } - - /* In case if all the secure ports are exhausted, we are no more - * binding to secure ports, hence instead of getting a random - * port, lets define the range to restrict it from getting from - * ports reserved for bricks i.e from range of 49152 - 65535 - * which further may lead to port clash */ - if (!port) { - ceiling = port = GF_CLNT_INSECURE_PORT_CEILING; - for (i = 0; i <= ceiling; i++) - BIT_CLEAR(ports, i); - goto loop; - } - - return ret; -#endif /* GF_DISABLE_PRIVPORT_TRACKING */ -} - -#if 0 -static int32_t -af_unix_client_bind (rpc_transport_t *this, struct sockaddr *sockaddr, - socklen_t sockaddr_len, struct rdma_cm_id *cm_id) -{ - data_t *path_data = NULL; - struct sockaddr_un *addr = NULL; - int32_t ret = -1; - - path_data = dict_get (this->options, - "transport.rdma.bind-path"); - if (path_data) { - char *path = data_to_str (path_data); - if (!path || strlen (path) > UNIX_PATH_MAX) { - gf_msg_debug (this->name, 0, - "transport.rdma.bind-path not specified " - "for unix socket, letting connect to " - "assign default value"); - goto err; - } - - addr = (struct sockaddr_un *) sockaddr; - strcpy (addr->sun_path, path); - ret = bind (sock, (struct sockaddr *)addr, sockaddr_len); - if (ret == -1) { - gf_msg (this->name, GF_LOG_ERROR, errno, - TRANS_MSG_SOCKET_BIND_ERROR, - "cannot bind to unix-domain socket %d ", - sock); - goto err; - } - } - -err: - return ret; -} -#endif - -static int32_t -client_fill_address_family(rpc_transport_t *this, struct sockaddr *sockaddr) -{ - data_t *address_family_data = NULL; - - address_family_data = dict_get(this->options, "transport.address-family"); - if (!address_family_data) { - data_t *remote_host_data = NULL, *connect_path_data = NULL; - remote_host_data = dict_get(this->options, "remote-host"); - connect_path_data = dict_get(this->options, - "transport.rdma.connect-path"); - - if (!(remote_host_data || connect_path_data) || - (remote_host_data && connect_path_data)) { - gf_msg(this->name, GF_LOG_ERROR, 0, - TRANS_MSG_ADDR_FAMILY_NOT_SPECIFIED, - "address-family not specified and not able to " - "determine the same from other options " - "(remote-host:%s and connect-path:%s)", - data_to_str(remote_host_data), - data_to_str(connect_path_data)); - return -1; - } - - if (remote_host_data) { - gf_msg_debug(this->name, 0, - "address-family not " - "specified, guessing it to be " - "inet/inet6"); - sockaddr->sa_family = AF_UNSPEC; - } else { - gf_msg_debug(this->name, 0, - "address-family not " - "specified, guessing it to be unix"); - sockaddr->sa_family = AF_UNIX; - } - - } else { - char *address_family = data_to_str(address_family_data); - if (!strcasecmp(address_family, "unix")) { - sockaddr->sa_family = AF_UNIX; - } else if (!strcasecmp(address_family, "inet")) { - sockaddr->sa_family = AF_INET; - } else if (!strcasecmp(address_family, "inet6")) { - sockaddr->sa_family = AF_INET6; - } else if (!strcasecmp(address_family, "inet-sdp")) { - sockaddr->sa_family = AF_INET_SDP; - } else { - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_UNKNOWN_ADDR_FAMILY, - "unknown address-family (%s) specified", address_family); - sockaddr->sa_family = AF_UNSPEC; - return -1; - } - } - - return 0; -} - -static int32_t -af_inet_client_get_remote_sockaddr(rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, int16_t remote_port) -{ - dict_t *options = this->options; - data_t *remote_host_data = NULL; - data_t *remote_port_data = NULL; - char *remote_host = NULL; - struct addrinfo *addr_info = NULL; - int32_t ret = 0; - - remote_host_data = dict_get(options, "remote-host"); - if (remote_host_data == NULL) { - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_REMOTE_HOST_ERROR, - "option remote-host " - "missing in volume %s", - this->name); - ret = -1; - goto err; - } - - remote_host = data_to_str(remote_host_data); - if (remote_host == NULL) { - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_REMOTE_HOST_ERROR, - "option remote-host " - "has data NULL in volume %s", - this->name); - ret = -1; - goto err; - } - - if (remote_port == 0) { - remote_port_data = dict_get(options, "remote-port"); - if (remote_port_data == NULL) { - gf_msg_debug(this->name, 0, - "option remote-port " - "missing in volume %s. Defaulting to %d", - this->name, GF_DEFAULT_RDMA_LISTEN_PORT); - - remote_port = GF_DEFAULT_RDMA_LISTEN_PORT; - } else { - remote_port = data_to_uint16(remote_port_data); - } - } - - if (remote_port == -1) { - gf_msg(this->name, GF_LOG_ERROR, EINVAL, RDMA_MSG_INVALID_ENTRY, - "option remote-port has " - "invalid port in volume %s", - this->name); - ret = -1; - goto err; - } - - /* TODO: gf_resolve is a blocking call. kick in some - non blocking dns techniques */ - ret = gf_resolve_ip6(remote_host, remote_port, sockaddr->sa_family, - &this->dnscache, &addr_info); - if (ret == -1) { - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_DNS_RESOL_FAILED, - "DNS resolution failed on host %s", remote_host); - goto err; - } - - memcpy(sockaddr, addr_info->ai_addr, addr_info->ai_addrlen); - *sockaddr_len = addr_info->ai_addrlen; - -err: - return ret; -} - -static int32_t -af_unix_client_get_remote_sockaddr(rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len) -{ - struct sockaddr_un *sockaddr_un = NULL; - char *connect_path = NULL; - data_t *connect_path_data = NULL; - int32_t ret = 0; - - connect_path_data = dict_get(this->options, "transport.rdma.connect-path"); - if (!connect_path_data) { - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_CONNECT_PATH_ERROR, - "option " - "transport.rdma.connect-path not specified for " - "address-family unix"); - ret = -1; - goto err; - } - - connect_path = data_to_str(connect_path_data); - if (!connect_path) { - gf_msg(this->name, GF_LOG_ERROR, EINVAL, RDMA_MSG_INVALID_ENTRY, - "connect-path is null-string"); - ret = -1; - goto err; - } - - if (strlen(connect_path) > UNIX_PATH_MAX) { - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_CONNECT_PATH_ERROR, - "connect-path value length %" GF_PRI_SIZET - " > " - "%d octets", - strlen(connect_path), UNIX_PATH_MAX); - ret = -1; - goto err; - } - - gf_msg_debug(this->name, 0, "using connect-path %s", connect_path); - sockaddr_un = (struct sockaddr_un *)sockaddr; - strcpy(sockaddr_un->sun_path, connect_path); - *sockaddr_len = sizeof(struct sockaddr_un); - -err: - return ret; -} - -static int32_t -af_unix_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, - socklen_t *addr_len) -{ - data_t *listen_path_data = NULL; - char *listen_path = NULL; - int32_t ret = 0; - struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr; - - listen_path_data = dict_get(this->options, "transport.rdma.listen-path"); - if (!listen_path_data) { - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_LISTEN_PATH_ERROR, - "missing option listen-path"); - ret = -1; - goto err; - } - - listen_path = data_to_str(listen_path_data); - -#ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX 108 -#endif - - if (strlen(listen_path) > UNIX_PATH_MAX) { - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_LISTEN_PATH_ERROR, - "option listen-path has " - "value length %" GF_PRI_SIZET " > %d", - strlen(listen_path), UNIX_PATH_MAX); - ret = -1; - goto err; - } - - sunaddr->sun_family = AF_UNIX; - strcpy(sunaddr->sun_path, listen_path); - *addr_len = sizeof(struct sockaddr_un); - -err: - return ret; -} - -static int32_t -af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, - socklen_t *addr_len) -{ - struct addrinfo hints, *res = 0; - data_t *listen_port_data = NULL, *listen_host_data = NULL; - uint16_t listen_port = 0; - char service[NI_MAXSERV], *listen_host = NULL; - dict_t *options = NULL; - int32_t ret = 0; - - options = this->options; - - listen_port_data = dict_get(options, "transport.rdma.listen-port"); - if (listen_port_data) { - listen_port = data_to_uint16(listen_port_data); - } - - listen_host_data = dict_get(options, "transport.rdma.bind-address"); - if (listen_host_data) { - listen_host = data_to_str(listen_host_data); - } else { - if (addr->sa_family == AF_INET6) { - struct sockaddr_in6 *in = (struct sockaddr_in6 *)addr; - in->sin6_addr = in6addr_any; - in->sin6_port = htons(listen_port); - *addr_len = sizeof(struct sockaddr_in6); - goto out; - } else if (addr->sa_family == AF_INET) { - struct sockaddr_in *in = (struct sockaddr_in *)addr; - in->sin_addr.s_addr = htonl(INADDR_ANY); - in->sin_port = htons(listen_port); - *addr_len = sizeof(struct sockaddr_in); - goto out; - } - } - - sprintf(service, "%d", listen_port); - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = addr->sa_family; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE; - - ret = getaddrinfo(listen_host, service, &hints, &res); - if (ret != 0) { - gf_msg(this->name, GF_LOG_ERROR, ret, TRANS_MSG_GET_ADDR_INFO_FAILED, - "getaddrinfo failed for host %s, service %s", listen_host, - service); - ret = -1; - goto out; - } - - memcpy(addr, res->ai_addr, res->ai_addrlen); - *addr_len = res->ai_addrlen; - - freeaddrinfo(res); - -out: - return ret; -} - -int32_t -gf_rdma_client_bind(rpc_transport_t *this, struct sockaddr *sockaddr, - socklen_t *sockaddr_len, struct rdma_cm_id *cm_id) -{ - int ret = 0; - - *sockaddr_len = sizeof(struct sockaddr_in6); - switch (sockaddr->sa_family) { - case AF_INET_SDP: - case AF_INET: - *sockaddr_len = sizeof(struct sockaddr_in); - /* Fall through */ - case AF_INET6: - if (!this->bind_insecure) { - ret = af_inet_bind_to_port_lt_ceiling( - cm_id, sockaddr, *sockaddr_len, GF_CLIENT_PORT_CEILING); - if (ret == -1) { - gf_msg(this->name, GF_LOG_WARNING, errno, - RDMA_MSG_PORT_BIND_FAILED, - "cannot bind rdma_cm_id to port " - "less than %d", - GF_CLIENT_PORT_CEILING); - } - } else { - ret = af_inet_bind_to_port_lt_ceiling( - cm_id, sockaddr, *sockaddr_len, GF_IANA_PRIV_PORTS_START); - if (ret == -1) { - gf_msg(this->name, GF_LOG_WARNING, errno, - RDMA_MSG_PORT_BIND_FAILED, - "cannot bind rdma_cm_id to port " - "less than %d", - GF_IANA_PRIV_PORTS_START); - } - } - break; - - case AF_UNIX: - *sockaddr_len = sizeof(struct sockaddr_un); -#if 0 - ret = af_unix_client_bind (this, (struct sockaddr *)sockaddr, - *sockaddr_len, sock); -#endif - break; - - default: - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_UNKNOWN_ADDR_FAMILY, - "unknown address family %d", sockaddr->sa_family); - ret = -1; - break; - } - - return ret; -} - -int32_t -gf_rdma_client_get_remote_sockaddr(rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, int16_t remote_port) -{ - int32_t ret = 0; - char is_inet_sdp = 0; - - ret = client_fill_address_family(this, sockaddr); - if (ret) { - ret = -1; - goto err; - } - - switch (sockaddr->sa_family) { - case AF_INET_SDP: - sockaddr->sa_family = AF_INET; - is_inet_sdp = 1; - /* Fall through */ - case AF_INET: - case AF_INET6: - case AF_UNSPEC: - ret = af_inet_client_get_remote_sockaddr(this, sockaddr, - sockaddr_len, remote_port); - - if (is_inet_sdp) { - sockaddr->sa_family = AF_INET_SDP; - } - - break; - - case AF_UNIX: - ret = af_unix_client_get_remote_sockaddr(this, sockaddr, - sockaddr_len); - break; - - default: - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_UNKNOWN_ADDR_FAMILY, - "unknown address-family %d", sockaddr->sa_family); - ret = -1; - } - -err: - return ret; -} - -int32_t -gf_rdma_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, - socklen_t *addr_len) -{ - data_t *address_family_data = NULL; - int32_t ret = 0; - char is_inet_sdp = 0; - - address_family_data = dict_get(this->options, "transport.address-family"); - if (address_family_data) { - char *address_family = NULL; - address_family = data_to_str(address_family_data); - - if (!strcasecmp(address_family, "inet")) { - addr->sa_family = AF_INET; - } else if (!strcasecmp(address_family, "inet6")) { - addr->sa_family = AF_INET6; - } else if (!strcasecmp(address_family, "inet-sdp")) { - addr->sa_family = AF_INET_SDP; - } else if (!strcasecmp(address_family, "unix")) { - addr->sa_family = AF_UNIX; - } else { - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_UNKNOWN_ADDR_FAMILY, - "unknown address" - " family (%s) specified", - address_family); - addr->sa_family = AF_UNSPEC; - ret = -1; - goto err; - } - } else { - gf_msg_debug(this->name, 0, - "option address-family not " - "specified, defaulting to inet"); - addr->sa_family = AF_INET; - } - - switch (addr->sa_family) { - case AF_INET_SDP: - is_inet_sdp = 1; - addr->sa_family = AF_INET; - /* Fall through */ - case AF_INET: - case AF_INET6: - case AF_UNSPEC: - ret = af_inet_server_get_local_sockaddr(this, addr, addr_len); - if (is_inet_sdp && !ret) { - addr->sa_family = AF_INET_SDP; - } - break; - - case AF_UNIX: - ret = af_unix_server_get_local_sockaddr(this, addr, addr_len); - break; - } - -err: - return ret; -} - -int32_t -fill_inet6_inet_identifiers(rpc_transport_t *this, - struct sockaddr_storage *addr, int32_t addr_len, - char *identifier) -{ - int32_t ret = 0, tmpaddr_len = 0; - char service[NI_MAXSERV], host[NI_MAXHOST]; - union gf_sock_union sock_union; - - memset(&sock_union, 0, sizeof(sock_union)); - sock_union.storage = *addr; - tmpaddr_len = addr_len; - - if (sock_union.sa.sa_family == AF_INET6) { - int32_t one_to_four, four_to_eight, twelve_to_sixteen; - int16_t eight_to_ten, ten_to_twelve; - - one_to_four = four_to_eight = twelve_to_sixteen = 0; - eight_to_ten = ten_to_twelve = 0; - - one_to_four = sock_union.sin6.sin6_addr.s6_addr32[0]; - four_to_eight = sock_union.sin6.sin6_addr.s6_addr32[1]; -#ifdef GF_SOLARIS_HOST_OS - eight_to_ten = S6_ADDR16(sock_union.sin6.sin6_addr)[4]; -#else - eight_to_ten = sock_union.sin6.sin6_addr.s6_addr16[4]; -#endif - -#ifdef GF_SOLARIS_HOST_OS - ten_to_twelve = S6_ADDR16(sock_union.sin6.sin6_addr)[5]; -#else - ten_to_twelve = sock_union.sin6.sin6_addr.s6_addr16[5]; -#endif - twelve_to_sixteen = sock_union.sin6.sin6_addr.s6_addr32[3]; - - /* ipv4 mapped ipv6 address has - bits 0-80: 0 - bits 80-96: 0xffff - bits 96-128: ipv4 address - */ - - if (one_to_four == 0 && four_to_eight == 0 && eight_to_ten == 0 && - ten_to_twelve == -1) { - struct sockaddr_in *in_ptr = &sock_union.sin; - memset(&sock_union, 0, sizeof(sock_union)); - - in_ptr->sin_family = AF_INET; - in_ptr->sin_port = ((struct sockaddr_in6 *)addr)->sin6_port; - in_ptr->sin_addr.s_addr = twelve_to_sixteen; - tmpaddr_len = sizeof(*in_ptr); - } - } - - ret = getnameinfo(&sock_union.sa, tmpaddr_len, host, sizeof(host), service, - sizeof(service), NI_NUMERICHOST | NI_NUMERICSERV); - if (ret != 0) { - gf_msg(this->name, GF_LOG_ERROR, ret, TRANS_MSG_GET_NAME_INFO_FAILED, - "getnameinfo failed"); - } - - sprintf(identifier, "%s:%s", host, service); - - return ret; -} - -int32_t -gf_rdma_get_transport_identifiers(rpc_transport_t *this) -{ - int32_t ret = 0; - char is_inet_sdp = 0; - - switch (((struct sockaddr *)&this->myinfo.sockaddr)->sa_family) { - case AF_INET_SDP: - is_inet_sdp = 1; - ((struct sockaddr *)&this->peerinfo.sockaddr) - ->sa_family = ((struct sockaddr *)&this->myinfo.sockaddr) - ->sa_family = AF_INET; - /* Fall through */ - case AF_INET: - case AF_INET6: { - ret = fill_inet6_inet_identifiers(this, &this->myinfo.sockaddr, - this->myinfo.sockaddr_len, - this->myinfo.identifier); - if (ret == -1) { - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_INET_ERROR, - "can't fill inet/inet6 identifier for server"); - goto err; - } - - ret = fill_inet6_inet_identifiers(this, &this->peerinfo.sockaddr, - this->peerinfo.sockaddr_len, - this->peerinfo.identifier); - if (ret == -1) { - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_INET_ERROR, - "can't fill inet/inet6 identifier for client"); - goto err; - } - - if (is_inet_sdp) { - ((struct sockaddr *)&this->peerinfo.sockaddr) - ->sa_family = ((struct sockaddr *)&this->myinfo.sockaddr) - ->sa_family = AF_INET_SDP; - } - } break; - - case AF_UNIX: { - struct sockaddr_un *sunaddr = NULL; - - sunaddr = (struct sockaddr_un *)&this->myinfo.sockaddr; - strcpy(this->myinfo.identifier, sunaddr->sun_path); - - sunaddr = (struct sockaddr_un *)&this->peerinfo.sockaddr; - strcpy(this->peerinfo.identifier, sunaddr->sun_path); - } break; - - default: - gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_UNKNOWN_ADDR_FAMILY, - "unknown address family (%d)", - ((struct sockaddr *)&this->myinfo.sockaddr)->sa_family); - ret = -1; - break; - } - -err: - return ret; -} diff --git a/rpc/rpc-transport/rdma/src/name.h b/rpc/rpc-transport/rdma/src/name.h deleted file mode 100644 index 6c782b52db5..00000000000 --- a/rpc/rpc-transport/rdma/src/name.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> - This file is part of GlusterFS. - - This file is licensed to you under your choice of the GNU Lesser - General Public License, version 3 or any later version (LGPLv3 or - later), or the GNU General Public License, version 2 (GPLv2), in all - cases as published by the Free Software Foundation. -*/ - -#ifndef _IB_VERBS_NAME_H -#define _IB_VERBS_NAME_H - -#include <rdma/rdma_cma.h> - -#include "compat.h" - -int32_t -gf_rdma_client_bind(rpc_transport_t *this, struct sockaddr *sockaddr, - socklen_t *sockaddr_len, struct rdma_cm_id *cm_id); - -int32_t -gf_rdma_client_get_remote_sockaddr(rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - int16_t remote_port); - -int32_t -gf_rdma_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, - socklen_t *addr_len); - -int32_t -gf_rdma_get_transport_identifiers(rpc_transport_t *this); - -#endif /* _IB_VERBS_NAME_H */ diff --git a/rpc/rpc-transport/rdma/src/rdma.c b/rpc/rpc-transport/rdma/src/rdma.c deleted file mode 100644 index 26cf201a8a3..00000000000 --- a/rpc/rpc-transport/rdma/src/rdma.c +++ /dev/null @@ -1,4911 +0,0 @@ -/* - Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> - This file is part of GlusterFS. - - This file is licensed to you under your choice of the GNU Lesser - General Public License, version 3 or any later version (LGPLv3 or - later), or the GNU General Public License, version 2 (GPLv2), in all - cases as published by the Free Software Foundation. -*/ - -#include "dict.h" -#include "glusterfs.h" -#include "iobuf.h" -#include "logging.h" -#include "rdma.h" -#include "name.h" -#include "byte-order.h" -#include "xlator.h" -#include "xdr-rpc.h" -#include "rpc-lib-messages.h" -#include "rpc-trans-rdma-messages.h" -#include <signal.h> - -#define GF_RDMA_LOG_NAME "rpc-transport/rdma" - -static int32_t -__gf_rdma_ioq_churn(gf_rdma_peer_t *peer); - -gf_rdma_post_t * -gf_rdma_post_ref(gf_rdma_post_t *post); - -int -gf_rdma_post_unref(gf_rdma_post_t *post); - -static void * -gf_rdma_send_completion_proc(void *data); - -static void * -gf_rdma_recv_completion_proc(void *data); - -void * -gf_rdma_async_event_thread(void *context); - -static int32_t -gf_rdma_create_qp(rpc_transport_t *this); - -static int32_t -__gf_rdma_teardown(rpc_transport_t *this); - -static int32_t -gf_rdma_teardown(rpc_transport_t *this); - -static int32_t -gf_rdma_disconnect(rpc_transport_t *this, gf_boolean_t wait); - -static void -gf_rdma_cm_handle_disconnect(rpc_transport_t *this); - -static int -gf_rdma_cm_handle_connect_init(struct rdma_cm_event *event); - -static void -gf_rdma_put_post(gf_rdma_queue_t *queue, gf_rdma_post_t *post) -{ - post->ctx.is_request = 0; - - pthread_mutex_lock(&queue->lock); - { - if (post->prev) { - queue->active_count--; - post->prev->next = post->next; - } - - if (post->next) { - post->next->prev = post->prev; - } - - post->prev = &queue->passive_posts; - post->next = post->prev->next; - post->prev->next = post; - post->next->prev = post; - queue->passive_count++; - } - pthread_mutex_unlock(&queue->lock); -} - -static gf_rdma_post_t * -gf_rdma_new_post(rpc_transport_t *this, gf_rdma_device_t *device, int32_t len, - gf_rdma_post_type_t type) -{ - gf_rdma_post_t *post = NULL; - int ret = -1; - - post = (gf_rdma_post_t *)GF_CALLOC(1, sizeof(*post), - gf_common_mt_rdma_post_t); - if (post == NULL) { - goto out; - } - - pthread_mutex_init(&post->lock, NULL); - - post->buf_size = len; - - post->buf = valloc(len); - if (!post->buf) { - gf_msg_nomem(GF_RDMA_LOG_NAME, GF_LOG_ERROR, len); - goto out; - } - - post->mr = ibv_reg_mr(device->pd, post->buf, post->buf_size, - IBV_ACCESS_LOCAL_WRITE); - if (!post->mr) { - gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_MR_ALOC_FAILED, - "memory registration failed"); - goto out; - } - - post->device = device; - post->type = type; - - ret = 0; -out: - if (ret != 0 && post) { - free(post->buf); - - GF_FREE(post); - post = NULL; - } - - return post; -} - -static gf_rdma_post_t * -gf_rdma_get_post(gf_rdma_queue_t *queue) -{ - gf_rdma_post_t *post = NULL; - - pthread_mutex_lock(&queue->lock); - { - post = queue->passive_posts.next; - if (post == &queue->passive_posts) - post = NULL; - - if (post) { - if (post->prev) - post->prev->next = post->next; - if (post->next) - post->next->prev = post->prev; - post->prev = &queue->active_posts; - post->next = post->prev->next; - post->prev->next = post; - post->next->prev = post; - post->reused++; - queue->active_count++; - } - } - pthread_mutex_unlock(&queue->lock); - - return post; -} - -void -gf_rdma_destroy_post(gf_rdma_post_t *post) -{ - ibv_dereg_mr(post->mr); - free(post->buf); - GF_FREE(post); -} - -static int32_t -__gf_rdma_quota_get(gf_rdma_peer_t *peer) -{ - int32_t ret = -1; - gf_rdma_private_t *priv = NULL; - - priv = peer->trans->private; - - if (priv->connected && peer->quota > 0) { - ret = peer->quota--; - } - - return ret; -} - -static void -__gf_rdma_ioq_entry_free(gf_rdma_ioq_t *entry) -{ - list_del_init(&entry->list); - - if (entry->iobref) { - iobref_unref(entry->iobref); - entry->iobref = NULL; - } - - if (entry->msg.request.rsp_iobref) { - iobref_unref(entry->msg.request.rsp_iobref); - entry->msg.request.rsp_iobref = NULL; - } - - mem_put(entry); -} - -static void -__gf_rdma_ioq_flush(gf_rdma_peer_t *peer) -{ - gf_rdma_ioq_t *entry = NULL, *dummy = NULL; - - list_for_each_entry_safe(entry, dummy, &peer->ioq, list) - { - __gf_rdma_ioq_entry_free(entry); - } -} - -static int32_t -__gf_rdma_disconnect(rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - - priv = this->private; - - if (priv->connected) { - rdma_disconnect(priv->peer.cm_id); - } - - return 0; -} - -static void -gf_rdma_queue_init(gf_rdma_queue_t *queue) -{ - pthread_mutex_init(&queue->lock, NULL); - - queue->active_posts.next = &queue->active_posts; - queue->active_posts.prev = &queue->active_posts; - queue->passive_posts.next = &queue->passive_posts; - queue->passive_posts.prev = &queue->passive_posts; -} - -static void -__gf_rdma_destroy_queue(gf_rdma_post_t *post) -{ - gf_rdma_post_t *tmp = NULL; - - while (post->next != post) { - tmp = post->next; - - post->next = post->next->next; - post->next->prev = post; - - gf_rdma_destroy_post(tmp); - } -} - -static void -gf_rdma_destroy_queue(gf_rdma_queue_t *queue) -{ - if (queue == NULL) { - goto out; - } - - pthread_mutex_lock(&queue->lock); - { - if (queue->passive_count > 0) { - __gf_rdma_destroy_queue(&queue->passive_posts); - queue->passive_count = 0; - } - - if (queue->active_count > 0) { - __gf_rdma_destroy_queue(&queue->active_posts); - queue->active_count = 0; - } - } - pthread_mutex_unlock(&queue->lock); - -out: - return; -} - -static void -gf_rdma_destroy_posts(rpc_transport_t *this) -{ - gf_rdma_device_t *device = NULL; - gf_rdma_private_t *priv = NULL; - - if (this == NULL) { - goto out; - } - - priv = this->private; - device = priv->device; - - gf_rdma_destroy_queue(&device->sendq); - gf_rdma_destroy_queue(&device->recvq); - -out: - return; -} - -static int32_t -__gf_rdma_create_posts(rpc_transport_t *this, int32_t count, int32_t size, - gf_rdma_queue_t *q, gf_rdma_post_type_t type) -{ - int32_t i = 0; - int32_t ret = 0; - gf_rdma_private_t *priv = NULL; - gf_rdma_device_t *device = NULL; - - priv = this->private; - device = priv->device; - - for (i = 0; i < count; i++) { - gf_rdma_post_t *post = NULL; - - post = gf_rdma_new_post(this, device, size + 2048, type); - if (!post) { - gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_POST_CREATION_FAILED, - "post creation failed"); - ret = -1; - break; - } - - gf_rdma_put_post(q, post); - } - return ret; -} - -static int32_t -gf_rdma_post_recv(struct ibv_srq *srq, gf_rdma_post_t *post) -{ - struct ibv_sge list = {.addr = (unsigned long)post->buf, - .length = post->buf_size, - .lkey = post->mr->lkey}; - - struct ibv_recv_wr wr = - { - .wr_id = (unsigned long)post, - .sg_list = &list, - .num_sge = 1, - }, - *bad_wr; - - gf_rdma_post_ref(post); - - return ibv_post_srq_recv(srq, &wr, &bad_wr); -} - -static void -gf_rdma_deregister_iobuf_pool(gf_rdma_device_t *device) -{ - gf_rdma_arena_mr *arena_mr = NULL; - gf_rdma_arena_mr *tmp = NULL; - - while (device) { - pthread_mutex_lock(&device->all_mr_lock); - { - if (!list_empty(&device->all_mr)) { - list_for_each_entry_safe(arena_mr, tmp, &device->all_mr, list) - { - if (ibv_dereg_mr(arena_mr->mr)) { - gf_msg("rdma", GF_LOG_WARNING, 0, - RDMA_MSG_DEREGISTER_ARENA_FAILED, - "deallocation of memory region " - "failed"); - pthread_mutex_unlock(&device->all_mr_lock); - return; - } - list_del(&arena_mr->list); - GF_FREE(arena_mr); - } - } - } - pthread_mutex_unlock(&device->all_mr_lock); - - device = device->next; - } -} - -int -gf_rdma_deregister_arena(struct list_head **mr_list, - struct iobuf_arena *iobuf_arena) -{ - gf_rdma_arena_mr *tmp = NULL; - gf_rdma_arena_mr *dummy = NULL; - gf_rdma_device_t *device = NULL; - int count = 0, i = 0; - - count = iobuf_arena->iobuf_pool->rdma_device_count; - for (i = 0; i < count; i++) { - device = iobuf_arena->iobuf_pool->device[i]; - pthread_mutex_lock(&device->all_mr_lock); - { - list_for_each_entry_safe(tmp, dummy, mr_list[i], list) - { - if (tmp->iobuf_arena == iobuf_arena) { - if (ibv_dereg_mr(tmp->mr)) { - gf_msg("rdma", GF_LOG_WARNING, 0, - RDMA_MSG_DEREGISTER_ARENA_FAILED, - "deallocation of memory region " - "failed"); - pthread_mutex_unlock(&device->all_mr_lock); - return -1; - } - list_del(&tmp->list); - GF_FREE(tmp); - break; - } - } - } - pthread_mutex_unlock(&device->all_mr_lock); - } - - return 0; -} - -int -gf_rdma_register_arena(void **arg1, void *arg2) -{ - struct ibv_mr *mr = NULL; - gf_rdma_arena_mr *new = NULL; - struct iobuf_pool *iobuf_pool = NULL; - gf_rdma_device_t **device = (gf_rdma_device_t **)arg1; - struct iobuf_arena *iobuf_arena = arg2; - int count = 0, i = 0; - - iobuf_pool = iobuf_arena->iobuf_pool; - count = iobuf_pool->rdma_device_count; - for (i = 0; i < count; i++) { - new = GF_CALLOC(1, sizeof(gf_rdma_arena_mr), - gf_common_mt_rdma_arena_mr); - if (new == NULL) { - gf_msg("rdma", GF_LOG_INFO, ENOMEM, RDMA_MSG_MR_ALOC_FAILED, - "Out of " - "memory: registering pre allocated buffer " - "with rdma device failed."); - return -1; - } - INIT_LIST_HEAD(&new->list); - new->iobuf_arena = iobuf_arena; - - mr = ibv_reg_mr(device[i]->pd, iobuf_arena->mem_base, - iobuf_arena->arena_size, - IBV_ACCESS_REMOTE_READ | IBV_ACCESS_LOCAL_WRITE | - IBV_ACCESS_REMOTE_WRITE); - if (!mr) - gf_msg("rdma", GF_LOG_WARNING, 0, RDMA_MSG_MR_ALOC_FAILED, - "allocation of mr " - "failed"); - - new->mr = mr; - pthread_mutex_lock(&device[i]->all_mr_lock); - { - list_add(&new->list, &device[i]->all_mr); - } - pthread_mutex_unlock(&device[i]->all_mr_lock); - new = NULL; - } - - return 0; -} - -static void -gf_rdma_register_iobuf_pool(gf_rdma_device_t *device, - struct iobuf_pool *iobuf_pool) -{ - struct iobuf_arena *tmp = NULL; - struct iobuf_arena *dummy = NULL; - struct ibv_mr *mr = NULL; - gf_rdma_arena_mr *new = NULL; - - if (!list_empty(&iobuf_pool->all_arenas)) { - list_for_each_entry_safe(tmp, dummy, &iobuf_pool->all_arenas, all_list) - { - new = GF_CALLOC(1, sizeof(gf_rdma_arena_mr), - gf_common_mt_rdma_arena_mr); - if (new == NULL) { - gf_msg("rdma", GF_LOG_INFO, ENOMEM, RDMA_MSG_MR_ALOC_FAILED, - "Out of " - "memory: registering pre allocated " - "buffer with rdma device failed."); - return; - } - INIT_LIST_HEAD(&new->list); - new->iobuf_arena = tmp; - - mr = ibv_reg_mr(device->pd, tmp->mem_base, tmp->arena_size, - IBV_ACCESS_REMOTE_READ | IBV_ACCESS_LOCAL_WRITE | - IBV_ACCESS_REMOTE_WRITE); - if (!mr) { - gf_msg("rdma", GF_LOG_WARNING, 0, RDMA_MSG_MR_ALOC_FAILED, - "failed" - " to pre register buffers with rdma " - "devices."); - } - new->mr = mr; - pthread_mutex_lock(&device->all_mr_lock); - { - list_add(&new->list, &device->all_mr); - } - pthread_mutex_unlock(&device->all_mr_lock); - - new = NULL; - } - } - - return; -} - -static void -gf_rdma_register_iobuf_pool_with_device(gf_rdma_device_t *device, - struct iobuf_pool *iobuf_pool) -{ - while (device) { - gf_rdma_register_iobuf_pool(device, iobuf_pool); - device = device->next; - } -} - -static struct ibv_mr * -gf_rdma_get_pre_registred_mr(rpc_transport_t *this, void *ptr, int size) -{ - gf_rdma_arena_mr *tmp = NULL; - gf_rdma_arena_mr *dummy = NULL; - gf_rdma_private_t *priv = NULL; - gf_rdma_device_t *device = NULL; - - priv = this->private; - device = priv->device; - - pthread_mutex_lock(&device->all_mr_lock); - { - if (!list_empty(&device->all_mr)) { - list_for_each_entry_safe(tmp, dummy, &device->all_mr, list) - { - if (tmp->iobuf_arena->mem_base <= ptr && - ptr < tmp->iobuf_arena->mem_base + - tmp->iobuf_arena->arena_size) { - pthread_mutex_unlock(&device->all_mr_lock); - return tmp->mr; - } - } - } - } - pthread_mutex_unlock(&device->all_mr_lock); - - return NULL; -} - -static int32_t -gf_rdma_create_posts(rpc_transport_t *this) -{ - int32_t i = 0, ret = 0; - gf_rdma_post_t *post = NULL; - gf_rdma_private_t *priv = NULL; - gf_rdma_options_t *options = NULL; - gf_rdma_device_t *device = NULL; - - priv = this->private; - options = &priv->options; - device = priv->device; - - ret = __gf_rdma_create_posts(this, options->send_count, options->send_size, - &device->sendq, GF_RDMA_SEND_POST); - if (!ret) - ret = __gf_rdma_create_posts(this, options->recv_count, - options->recv_size, &device->recvq, - GF_RDMA_RECV_POST); - - if (!ret) { - for (i = 0; i < options->recv_count; i++) { - post = gf_rdma_get_post(&device->recvq); - if (gf_rdma_post_recv(device->srq, post) != 0) { - ret = -1; - break; - } - } - } - - if (ret) - gf_rdma_destroy_posts(this); - - return ret; -} - -static void -gf_rdma_destroy_cq(rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - gf_rdma_device_t *device = NULL; - - priv = this->private; - device = priv->device; - - if (device->recv_cq) - ibv_destroy_cq(device->recv_cq); - device->recv_cq = NULL; - - if (device->send_cq) - ibv_destroy_cq(device->send_cq); - device->send_cq = NULL; - - return; -} - -static int32_t -gf_rdma_create_cq(rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - gf_rdma_options_t *options = NULL; - gf_rdma_device_t *device = NULL; - uint64_t send_cqe = 0; - int32_t ret = 0; - struct ibv_device_attr device_attr = { - {0}, - }; - - priv = this->private; - options = &priv->options; - device = priv->device; - - device->recv_cq = ibv_create_cq(priv->device->context, - options->recv_count * 2, device, - device->recv_chan, 0); - if (!device->recv_cq) { - gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_CQ_CREATION_FAILED, - "creation of CQ for " - "device %s failed", - device->device_name); - ret = -1; - goto out; - } else if (ibv_req_notify_cq(device->recv_cq, 0)) { - gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_REQ_NOTIFY_CQ_REVQ_FAILED, - "ibv_req_notify_" - "cq on recv CQ of device %s failed", - device->device_name); - ret = -1; - goto out; - } - - do { - ret = ibv_query_device(priv->device->context, &device_attr); - if (ret != 0) { - gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_QUERY_DEVICE_FAILED, - "ibv_query_" - "device on %s returned %d (%s)", - priv->device->device_name, ret, - (ret > 0) ? strerror(ret) : ""); - ret = -1; - goto out; - } - - send_cqe = (uint64_t)options->send_count * 128; - send_cqe = (send_cqe > device_attr.max_cqe) ? device_attr.max_cqe - : send_cqe; - - /* TODO: make send_cq size dynamically adaptive */ - device->send_cq = ibv_create_cq(priv->device->context, send_cqe, device, - device->send_chan, 0); - if (!device->send_cq) { - gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_CQ_CREATION_FAILED, - "creation of send_cq " - "for device %s failed", - device->device_name); - ret = -1; - goto out; - } - - if (ibv_req_notify_cq(device->send_cq, 0)) { - gf_msg(this->name, GF_LOG_ERROR, 0, - RDMA_MSG_REQ_NOTIFY_CQ_SENDQ_FAILED, - "ibv_req_notify_cq on send_cq for device %s" - " failed", - device->device_name); - ret = -1; - goto out; - } - } while (0); - -out: - if (ret != 0) - gf_rdma_destroy_cq(this); - - return ret; -} - -static gf_rdma_device_t * -gf_rdma_get_device(rpc_transport_t *this, struct ibv_context *ibctx, - char *device_name) -{ - glusterfs_ctx_t *ctx = NULL; - gf_rdma_private_t *priv = NULL; - gf_rdma_options_t *options = NULL; - int32_t ret = 0; - int32_t i = 0; - gf_rdma_device_t *trav = NULL, *device = NULL; - gf_rdma_ctx_t *rdma_ctx = NULL; - struct iobuf_pool *iobuf_pool = NULL; - - priv = this->private; - options = &priv->options; - ctx = this->ctx; - rdma_ctx = ctx->ib; - iobuf_pool = ctx->iobuf_pool; - - trav = rdma_ctx->device; - - while (trav) { - if (!strcmp(trav->device_name, device_name)) - break; - trav = trav->next; - } - - if (!trav) { - trav = GF_CALLOC(1, sizeof(*trav), gf_common_mt_rdma_device_t); - if (trav == NULL) { - goto out; - } - priv->device = trav; - trav->context = ibctx; - - trav->next = rdma_ctx->device; - rdma_ctx->device = trav; - - iobuf_pool->device[iobuf_pool->rdma_device_count] = trav; - iobuf_pool->mr_list[iobuf_pool->rdma_device_count++] = &trav->all_mr; - trav->request_ctx_pool = mem_pool_new(gf_rdma_request_context_t, - GF_RDMA_POOL_SIZE); - if (trav->request_ctx_pool == NULL) { - goto out; - } - - trav->ioq_pool = mem_pool_new(gf_rdma_ioq_t, GF_RDMA_POOL_SIZE); - if (trav->ioq_pool == NULL) { - goto out; - } - - trav->reply_info_pool = mem_pool_new(gf_rdma_reply_info_t, - GF_RDMA_POOL_SIZE); - if (trav->reply_info_pool == NULL) { - goto out; - } - - trav->device_name = gf_strdup(device_name); - - trav->send_chan = ibv_create_comp_channel(trav->context); - if (!trav->send_chan) { - gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_SEND_COMP_CHAN_FAILED, - "could not " - "create send completion channel for " - "device (%s)", - device_name); - goto out; - } - - trav->recv_chan = ibv_create_comp_channel(trav->context); - if (!trav->recv_chan) { - gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_RECV_COMP_CHAN_FAILED, - "could not " - "create recv completion channel for " - "device (%s)", - device_name); - - /* TODO: cleanup current mess */ - goto out; - } - - if (gf_rdma_create_cq(this) < 0) { - gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_CQ_CREATION_FAILED, - "could not create CQ for device (%s)", device_name); - goto out; - } - - /* protection domain */ - trav->pd = ibv_alloc_pd(trav->context); - - if (!trav->pd) { - gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_ALOC_PROT_DOM_FAILED, - "could not " - "allocate protection domain for device (%s)", - device_name); - goto out; - } - - struct ibv_srq_init_attr attr = {.attr = {.max_wr = options->recv_count, - .max_sge = 1, - .srq_limit = 10}}; - trav->srq = ibv_create_srq(trav->pd, &attr); - - if (!trav->srq) { - gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_CRE_SRQ_FAILED, - "could not create SRQ" - " for device (%s)", - device_name); - goto out; - } - - /* queue init */ - gf_rdma_queue_init(&trav->sendq); - gf_rdma_queue_init(&trav->recvq); - - INIT_LIST_HEAD(&trav->all_mr); - pthread_mutex_init(&trav->all_mr_lock, NULL); - gf_rdma_register_iobuf_pool(trav, iobuf_pool); - - if (gf_rdma_create_posts(this) < 0) { - gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_ALOC_POST_FAILED, - "could not allocate" - "posts for device (%s)", - device_name); - goto out; - } - - /* completion threads */ - ret = gf_thread_create(&trav->send_thread, NULL, - gf_rdma_send_completion_proc, trav->send_chan, - "rdmascom"); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, - RDMA_MSG_SEND_COMP_THREAD_FAILED, - "could not create send completion thread for " - "device (%s)", - device_name); - goto out; - } - - ret = gf_thread_create(&trav->recv_thread, NULL, - gf_rdma_recv_completion_proc, trav->recv_chan, - "rdmarcom"); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, - RDMA_MSG_RECV_COMP_THREAD_FAILED, - "could not create recv completion thread " - "for device (%s)", - device_name); - return NULL; - } - - ret = gf_thread_create(&trav->async_event_thread, NULL, - gf_rdma_async_event_thread, ibctx, "rdmaAsyn"); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, - RDMA_MSG_ASYNC_EVENT_THEAD_FAILED, - "could not create async_event_thread"); - return NULL; - } - - /* qpreg */ - pthread_mutex_init(&trav->qpreg.lock, NULL); - for (i = 0; i < 42; i++) { - trav->qpreg.ents[i].next = &trav->qpreg.ents[i]; - trav->qpreg.ents[i].prev = &trav->qpreg.ents[i]; - } - } - - device = trav; - trav = NULL; -out: - - if (trav != NULL) { - rdma_ctx->device = trav->next; - gf_rdma_destroy_posts(this); - mem_pool_destroy(trav->ioq_pool); - mem_pool_destroy(trav->request_ctx_pool); - mem_pool_destroy(trav->reply_info_pool); - if (trav->pd != NULL) { - ibv_dealloc_pd(trav->pd); - } - gf_rdma_destroy_cq(this); - ibv_destroy_comp_channel(trav->recv_chan); - ibv_destroy_comp_channel(trav->send_chan); - GF_FREE((char *)trav->device_name); - GF_FREE(trav); - } - - return device; -} - -static rpc_transport_t * -gf_rdma_transport_new(rpc_transport_t *listener, struct rdma_cm_id *cm_id) -{ - gf_rdma_private_t *listener_priv = NULL, *priv = NULL; - rpc_transport_t *this = NULL, *new = NULL; - gf_rdma_options_t *options = NULL; - char *device_name = NULL; - - listener_priv = listener->private; - - this = GF_CALLOC(1, sizeof(rpc_transport_t), gf_common_mt_rpc_transport_t); - if (this == NULL) { - goto out; - } - - this->listener = listener; - - priv = GF_CALLOC(1, sizeof(gf_rdma_private_t), gf_common_mt_rdma_private_t); - if (priv == NULL) { - goto out; - } - - this->private = priv; - priv->options = listener_priv->options; - - priv->listener = listener; - priv->entity = GF_RDMA_SERVER; - - options = &priv->options; - - this->ops = listener->ops; - this->init = listener->init; - this->fini = listener->fini; - this->ctx = listener->ctx; - this->name = gf_strdup(listener->name); - this->notify = listener->notify; - this->mydata = listener->mydata; - this->xl = listener->xl; - - this->myinfo.sockaddr_len = sizeof(cm_id->route.addr.src_addr); - memcpy(&this->myinfo.sockaddr, &cm_id->route.addr.src_addr, - this->myinfo.sockaddr_len); - - this->peerinfo.sockaddr_len = sizeof(cm_id->route.addr.dst_addr); - memcpy(&this->peerinfo.sockaddr, &cm_id->route.addr.dst_addr, - this->peerinfo.sockaddr_len); - - priv->peer.trans = this; - gf_rdma_get_transport_identifiers(this); - - device_name = (char *)ibv_get_device_name(cm_id->verbs->device); - if (device_name == NULL) { - gf_msg(listener->name, GF_LOG_WARNING, 0, - RDMA_MSG_GET_DEVICE_NAME_FAILED, - "cannot get device " - "name (peer:%s me:%s)", - this->peerinfo.identifier, this->myinfo.identifier); - goto out; - } - - priv->device = gf_rdma_get_device(this, cm_id->verbs, device_name); - if (priv->device == NULL) { - gf_msg(listener->name, GF_LOG_WARNING, 0, RDMA_MSG_GET_IB_DEVICE_FAILED, - "cannot get infiniband" - " device %s (peer:%s me:%s)", - device_name, this->peerinfo.identifier, this->myinfo.identifier); - goto out; - } - - priv->peer.send_count = options->send_count; - priv->peer.recv_count = options->recv_count; - priv->peer.send_size = options->send_size; - priv->peer.recv_size = options->recv_size; - priv->peer.cm_id = cm_id; - INIT_LIST_HEAD(&priv->peer.ioq); - - pthread_mutex_init(&priv->write_mutex, NULL); - pthread_mutex_init(&priv->recv_mutex, NULL); - - cm_id->context = this; - - new = rpc_transport_ref(this); - this = NULL; -out: - if (this != NULL) { - if (this->private != NULL) { - GF_FREE(this->private); - } - - if (this->name != NULL) { - GF_FREE(this->name); - } - - GF_FREE(this); - } - - return new; -} - -static int -gf_rdma_cm_handle_connect_request(struct rdma_cm_event *event) -{ - int ret = -1; - rpc_transport_t *this = NULL, *listener = NULL; - struct rdma_cm_id *child_cm_id = NULL, *listener_cm_id = NULL; - struct rdma_conn_param conn_param = { - 0, - }; - gf_rdma_private_t *priv = NULL; - gf_rdma_options_t *options = NULL; - - child_cm_id = event->id; - listener_cm_id = event->listen_id; - - listener = listener_cm_id->context; - priv = listener->private; - options = &priv->options; - - this = gf_rdma_transport_new(listener, child_cm_id); - if (this == NULL) { - gf_msg(listener->name, GF_LOG_WARNING, 0, - RDMA_MSG_CREAT_INC_TRANS_FAILED, - "could not create " - "a transport for incoming connection" - " (me.name:%s me.identifier:%s)", - listener->name, listener->myinfo.identifier); - rdma_destroy_id(child_cm_id); - goto out; - } - - gf_msg_trace(listener->name, 0, - "got a connect request (me:%s peer:" - "%s)", - listener->myinfo.identifier, this->peerinfo.identifier); - - ret = gf_rdma_create_qp(this); - if (ret < 0) { - gf_msg(listener->name, GF_LOG_WARNING, 0, RDMA_MSG_CREAT_QP_FAILED, - "could not create QP " - "(peer:%s me:%s)", - this->peerinfo.identifier, this->myinfo.identifier); - gf_rdma_cm_handle_disconnect(this); - goto out; - } - - conn_param.responder_resources = 1; - conn_param.initiator_depth = 1; - conn_param.retry_count = options->attr_retry_cnt; - conn_param.rnr_retry_count = options->attr_rnr_retry; - - ret = rdma_accept(child_cm_id, &conn_param); - if (ret < 0) { - gf_msg(listener->name, GF_LOG_WARNING, errno, RDMA_MSG_ACCEPT_FAILED, - "rdma_accept failed peer:%s " - "me:%s", - this->peerinfo.identifier, this->myinfo.identifier); - gf_rdma_cm_handle_disconnect(this); - goto out; - } - gf_rdma_cm_handle_connect_init(event); - ret = 0; - -out: - return ret; -} - -static int -gf_rdma_cm_handle_route_resolved(struct rdma_cm_event *event) -{ - struct rdma_conn_param conn_param = { - 0, - }; - int ret = 0; - rpc_transport_t *this = NULL; - gf_rdma_private_t *priv = NULL; - gf_rdma_peer_t *peer = NULL; - gf_rdma_options_t *options = NULL; - - if (event == NULL) { - goto out; - } - - this = event->id->context; - - priv = this->private; - peer = &priv->peer; - options = &priv->options; - - ret = gf_rdma_create_qp(this); - if (ret != 0) { - gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_CREAT_QP_FAILED, - "could not create QP " - "(peer:%s me:%s)", - this->peerinfo.identifier, this->myinfo.identifier); - gf_rdma_cm_handle_disconnect(this); - goto out; - } - - memset(&conn_param, 0, sizeof conn_param); - conn_param.responder_resources = 1; - conn_param.initiator_depth = 1; - conn_param.retry_count = options->attr_retry_cnt; - conn_param.rnr_retry_count = options->attr_rnr_retry; - - ret = rdma_connect(peer->cm_id, &conn_param); - if (ret != 0) { - gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_CONNECT_FAILED, - "rdma_connect failed"); - gf_rdma_cm_handle_disconnect(this); - goto out; - } - - gf_msg_trace(this->name, 0, "route resolved (me:%s peer:%s)", - this->myinfo.identifier, this->peerinfo.identifier); - - ret = 0; -out: - return ret; -} - -static int -gf_rdma_cm_handle_addr_resolved(struct rdma_cm_event *event) -{ - rpc_transport_t *this = NULL; - gf_rdma_peer_t *peer = NULL; - gf_rdma_private_t *priv = NULL; - int ret = 0; - - this = event->id->context; - - priv = this->private; - peer = &priv->peer; - - GF_ASSERT(peer->cm_id == event->id); - - this->myinfo.sockaddr_len = sizeof(peer->cm_id->route.addr.src_addr); - memcpy(&this->myinfo.sockaddr, &peer->cm_id->route.addr.src_addr, - this->myinfo.sockaddr_len); - - this->peerinfo.sockaddr_len = sizeof(peer->cm_id->route.addr.dst_addr); - memcpy(&this->peerinfo.sockaddr, &peer->cm_id->route.addr.dst_addr, - this->peerinfo.sockaddr_len); - - gf_rdma_get_transport_identifiers(this); - - ret = rdma_resolve_route(peer->cm_id, 2000); - if (ret != 0) { - gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_ROUTE_RESOLVE_FAILED, - "rdma_resolve_route " - "failed (me:%s peer:%s)", - this->myinfo.identifier, this->peerinfo.identifier); - gf_rdma_cm_handle_disconnect(this); - return ret; - } - - gf_msg_trace(this->name, 0, "Address resolved (me:%s peer:%s)", - this->myinfo.identifier, this->peerinfo.identifier); - - return ret; -} - -static void -gf_rdma_cm_handle_disconnect(rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - char need_unref = 0; - - priv = this->private; - gf_msg_debug(this->name, 0, "peer disconnected, cleaning up"); - - pthread_mutex_lock(&priv->write_mutex); - { - if (priv->peer.cm_id != NULL) { - need_unref = 1; - priv->connected = 0; - } - - __gf_rdma_teardown(this); - } - pthread_mutex_unlock(&priv->write_mutex); - - rpc_transport_notify(this, RPC_TRANSPORT_DISCONNECT, this); - - if (need_unref) - rpc_transport_unref(this); -} - -static int -gf_rdma_cm_handle_connect_init(struct rdma_cm_event *event) -{ - rpc_transport_t *this = NULL; - gf_rdma_private_t *priv = NULL; - struct rdma_cm_id *cm_id = NULL; - int ret = 0; - - cm_id = event->id; - this = cm_id->context; - priv = this->private; - - if (priv->connected == 1) { - gf_msg_trace(this->name, 0, - "received event " - "RDMA_CM_EVENT_ESTABLISHED (me:%s peer:%s)", - this->myinfo.identifier, this->peerinfo.identifier); - return ret; - } - - priv->connected = 1; - - pthread_mutex_lock(&priv->write_mutex); - { - priv->peer.quota = 1; - priv->peer.quota_set = 0; - } - pthread_mutex_unlock(&priv->write_mutex); - - if (priv->entity == GF_RDMA_CLIENT) { - gf_msg_trace(this->name, 0, - "received event " - "RDMA_CM_EVENT_ESTABLISHED (me:%s peer:%s)", - this->myinfo.identifier, this->peerinfo.identifier); - ret = rpc_transport_notify(this, RPC_TRANSPORT_CONNECT, this); - - } else if (priv->entity == GF_RDMA_SERVER) { - ret = rpc_transport_notify(priv->listener, RPC_TRANSPORT_ACCEPT, this); - } - - if (ret < 0) { - gf_rdma_disconnect(this, _gf_false); - } - - return ret; -} - -static int -gf_rdma_cm_handle_event_error(rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - - priv = this->private; - - if (priv->entity != GF_RDMA_SERVER_LISTENER) { - gf_rdma_cm_handle_disconnect(this); - } - - return 0; -} - -static int -gf_rdma_cm_handle_device_removal(struct rdma_cm_event *event) -{ - return 0; -} - -static void * -gf_rdma_cm_event_handler(void *data) -{ - struct rdma_cm_event *event = NULL; - int ret = 0; - rpc_transport_t *this = NULL; - struct rdma_event_channel *event_channel = NULL; - - event_channel = data; - - while (1) { - ret = rdma_get_cm_event(event_channel, &event); - if (ret != 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno, - RDMA_MSG_CM_EVENT_FAILED, "rdma_cm_get_event failed"); - break; - } - - switch (event->event) { - case RDMA_CM_EVENT_ADDR_RESOLVED: - gf_rdma_cm_handle_addr_resolved(event); - break; - - case RDMA_CM_EVENT_ROUTE_RESOLVED: - gf_rdma_cm_handle_route_resolved(event); - break; - - case RDMA_CM_EVENT_CONNECT_REQUEST: - gf_rdma_cm_handle_connect_request(event); - break; - - case RDMA_CM_EVENT_ESTABLISHED: - gf_rdma_cm_handle_connect_init(event); - break; - - case RDMA_CM_EVENT_ADDR_ERROR: - case RDMA_CM_EVENT_ROUTE_ERROR: - case RDMA_CM_EVENT_CONNECT_ERROR: - case RDMA_CM_EVENT_UNREACHABLE: - case RDMA_CM_EVENT_REJECTED: - this = event->id->context; - - gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_CM_EVENT_FAILED, - "cma event %s, " - "error %d (me:%s peer:%s)\n", - rdma_event_str(event->event), event->status, - this->myinfo.identifier, this->peerinfo.identifier); - - rdma_ack_cm_event(event); - event = NULL; - - gf_rdma_cm_handle_event_error(this); - continue; - - case RDMA_CM_EVENT_DISCONNECTED: - this = event->id->context; - - gf_msg_debug(this->name, 0, - "received disconnect " - "(me:%s peer:%s)\n", - this->myinfo.identifier, - this->peerinfo.identifier); - - rdma_ack_cm_event(event); - event = NULL; - - gf_rdma_cm_handle_disconnect(this); - continue; - - case RDMA_CM_EVENT_DEVICE_REMOVAL: - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_CM_EVENT_FAILED, - "device " - "removed"); - gf_rdma_cm_handle_device_removal(event); - break; - - default: - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_CM_EVENT_FAILED, - "unhandled event: %s, ignoring", - rdma_event_str(event->event)); - break; - } - - rdma_ack_cm_event(event); - } - - return NULL; -} - -static int32_t -gf_rdma_post_send(struct ibv_qp *qp, gf_rdma_post_t *post, int32_t len) -{ - struct ibv_sge list = {.addr = (unsigned long)post->buf, - .length = len, - .lkey = post->mr->lkey}; - - struct ibv_send_wr wr = - { - .wr_id = (unsigned long)post, - .sg_list = &list, - .num_sge = 1, - .opcode = IBV_WR_SEND, - .send_flags = IBV_SEND_SIGNALED, - }, - *bad_wr; - - if (!qp) - return EINVAL; - - return ibv_post_send(qp, &wr, &bad_wr); -} - -int -__gf_rdma_encode_error(gf_rdma_peer_t *peer, gf_rdma_reply_info_t *reply_info, - struct iovec *rpchdr, gf_rdma_header_t *hdr, - gf_rdma_errcode_t err) -{ - struct rpc_msg *rpc_msg = NULL; - - if (reply_info != NULL) { - hdr->rm_xid = hton32(reply_info->rm_xid); - } else { - rpc_msg = rpchdr[0].iov_base; /* assume rpchdr contains - * only one vector. - * (which is true) - */ - hdr->rm_xid = rpc_msg->rm_xid; - } - - hdr->rm_vers = hton32(GF_RDMA_VERSION); - hdr->rm_credit = hton32(peer->send_count); - hdr->rm_type = hton32(GF_RDMA_ERROR); - hdr->rm_body.rm_error.rm_type = hton32(err); - if (err == ERR_VERS) { - hdr->rm_body.rm_error.rm_version.gf_rdma_vers_low = hton32( - GF_RDMA_VERSION); - hdr->rm_body.rm_error.rm_version.gf_rdma_vers_high = hton32( - GF_RDMA_VERSION); - } - - return sizeof(*hdr); -} - -int32_t -__gf_rdma_send_error(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry, - gf_rdma_post_t *post, gf_rdma_reply_info_t *reply_info, - gf_rdma_errcode_t err) -{ - int32_t ret = -1, len = 0; - - len = __gf_rdma_encode_error(peer, reply_info, entry->rpchdr, - (gf_rdma_header_t *)post->buf, err); - if (len == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, 0, RDMA_MSG_ENCODE_ERROR, - "encode error returned -1"); - goto out; - } - - gf_rdma_post_ref(post); - - ret = gf_rdma_post_send(peer->qp, post, len); - if (!ret) { - ret = len; - } else { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_POST_SEND_FAILED, - "gf_rdma_post_send (to %s) failed with ret = %d (%s)", - peer->trans->peerinfo.identifier, ret, - (ret > 0) ? strerror(ret) : ""); - gf_rdma_post_unref(post); - __gf_rdma_disconnect(peer->trans); - ret = -1; - } - -out: - return ret; -} - -int32_t -__gf_rdma_create_read_chunks_from_vector(gf_rdma_peer_t *peer, - gf_rdma_read_chunk_t **readch_ptr, - int32_t *pos, struct iovec *vector, - int count, - gf_rdma_request_context_t *request_ctx) -{ - int i = 0; - gf_rdma_private_t *priv = NULL; - gf_rdma_device_t *device = NULL; - struct ibv_mr *mr = NULL; - gf_rdma_read_chunk_t *readch = NULL; - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, readch_ptr, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, *readch_ptr, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, request_ctx, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, vector, out); - - priv = peer->trans->private; - device = priv->device; - readch = *readch_ptr; - - for (i = 0; i < count; i++) { - readch->rc_discrim = hton32(1); - readch->rc_position = hton32(*pos); - - mr = gf_rdma_get_pre_registred_mr( - peer->trans, (void *)vector[i].iov_base, vector[i].iov_len); - if (!mr) { - mr = ibv_reg_mr(device->pd, vector[i].iov_base, vector[i].iov_len, - IBV_ACCESS_REMOTE_READ); - } - if (!mr) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno, - RDMA_MSG_MR_ALOC_FAILED, - "memory registration failed (peer:%s)", - peer->trans->peerinfo.identifier); - goto out; - } - - request_ctx->mr[request_ctx->mr_count++] = mr; - - readch->rc_target.rs_handle = hton32(mr->rkey); - readch->rc_target.rs_length = hton32(vector[i].iov_len); - readch->rc_target.rs_offset = hton64( - (uint64_t)(unsigned long)vector[i].iov_base); - - *pos = *pos + vector[i].iov_len; - readch++; - } - - *readch_ptr = readch; - - ret = 0; -out: - return ret; -} - -int32_t -__gf_rdma_create_read_chunks(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry, - gf_rdma_chunktype_t type, uint32_t **ptr, - gf_rdma_request_context_t *request_ctx) -{ - int32_t ret = -1; - int pos = 0; - - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, entry, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, ptr, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, *ptr, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, request_ctx, out); - - request_ctx->iobref = iobref_ref(entry->iobref); - - if (type == gf_rdma_areadch) { - pos = 0; - ret = __gf_rdma_create_read_chunks_from_vector( - peer, (gf_rdma_read_chunk_t **)ptr, &pos, entry->rpchdr, - entry->rpchdr_count, request_ctx); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_READ_CHUNK_VECTOR_FAILED, - "cannot create read chunks from vector " - "entry->rpchdr"); - goto out; - } - - ret = __gf_rdma_create_read_chunks_from_vector( - peer, (gf_rdma_read_chunk_t **)ptr, &pos, entry->proghdr, - entry->proghdr_count, request_ctx); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_READ_CHUNK_VECTOR_FAILED, - "cannot create read chunks from vector " - "entry->proghdr"); - } - - if (entry->prog_payload_count != 0) { - ret = __gf_rdma_create_read_chunks_from_vector( - peer, (gf_rdma_read_chunk_t **)ptr, &pos, entry->prog_payload, - entry->prog_payload_count, request_ctx); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_READ_CHUNK_VECTOR_FAILED, - "cannot create read chunks from vector" - " entry->prog_payload"); - } - } - } else { - pos = iov_length(entry->rpchdr, entry->rpchdr_count); - ret = __gf_rdma_create_read_chunks_from_vector( - peer, (gf_rdma_read_chunk_t **)ptr, &pos, entry->prog_payload, - entry->prog_payload_count, request_ctx); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_READ_CHUNK_VECTOR_FAILED, - "cannot create read chunks from vector " - "entry->prog_payload"); - } - } - - /* terminate read-chunk list*/ - **ptr = 0; - *ptr = *ptr + 1; -out: - return ret; -} - -int32_t -__gf_rdma_create_write_chunks_from_vector( - gf_rdma_peer_t *peer, gf_rdma_write_chunk_t **writech_ptr, - struct iovec *vector, int count, gf_rdma_request_context_t *request_ctx) -{ - int i = 0; - gf_rdma_private_t *priv = NULL; - gf_rdma_device_t *device = NULL; - struct ibv_mr *mr = NULL; - gf_rdma_write_chunk_t *writech = NULL; - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, writech_ptr, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, *writech_ptr, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, request_ctx, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, vector, out); - - writech = *writech_ptr; - - priv = peer->trans->private; - device = priv->device; - - for (i = 0; i < count; i++) { - mr = gf_rdma_get_pre_registred_mr( - peer->trans, (void *)vector[i].iov_base, vector[i].iov_len); - if (!mr) { - mr = ibv_reg_mr(device->pd, vector[i].iov_base, vector[i].iov_len, - IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE); - } - - if (!mr) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno, - RDMA_MSG_MR_ALOC_FAILED, - "memory " - "registration failed (peer:%s)", - peer->trans->peerinfo.identifier); - goto out; - } - - request_ctx->mr[request_ctx->mr_count++] = mr; - - writech->wc_target.rs_handle = hton32(mr->rkey); - writech->wc_target.rs_length = hton32(vector[i].iov_len); - writech->wc_target.rs_offset = hton64( - ((uint64_t)(unsigned long)vector[i].iov_base)); - - writech++; - } - - *writech_ptr = writech; - - ret = 0; -out: - return ret; -} - -int32_t -__gf_rdma_create_write_chunks(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry, - gf_rdma_chunktype_t chunk_type, uint32_t **ptr, - gf_rdma_request_context_t *request_ctx) -{ - int32_t ret = -1; - gf_rdma_write_array_t *warray = NULL; - - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, ptr, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, *ptr, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, request_ctx, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, entry, out); - - if ((chunk_type == gf_rdma_replych) && - ((entry->msg.request.rsphdr_count != 1) || - (entry->msg.request.rsphdr_vec[0].iov_base == NULL))) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_BUFFER_ERROR, - (entry->msg.request.rsphdr_count == 1) - ? "chunktype specified as reply chunk but the vector " - "specifying the buffer to be used for holding reply" - " header is not correct" - : "chunktype specified as reply chunk, but more than one " - "buffer provided for holding reply"); - goto out; - } - - /* - if ((chunk_type == gf_rdma_writech) - && ((entry->msg.request.rsphdr_count == 0) - || (entry->msg.request.rsphdr_vec[0].iov_base == NULL))) { - gf_msg_debug (GF_RDMA_LOG_NAME, 0, - "vector specifying buffer to hold the program's reply " - "header should also be provided when buffers are " - "provided for holding the program's payload in reply"); - goto out; - } - */ - - if (chunk_type == gf_rdma_writech) { - warray = (gf_rdma_write_array_t *)*ptr; - warray->wc_discrim = hton32(1); - warray->wc_nchunks = hton32(entry->msg.request.rsp_payload_count); - - *ptr = (uint32_t *)&warray->wc_array[0]; - - ret = __gf_rdma_create_write_chunks_from_vector( - peer, (gf_rdma_write_chunk_t **)ptr, entry->msg.request.rsp_payload, - entry->msg.request.rsp_payload_count, request_ctx); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_WRITE_CHUNK_VECTOR_FAILED, - "cannot create write chunks from vector " - "entry->rpc_payload"); - goto out; - } - - /* terminate write chunklist */ - **ptr = 0; - *ptr = *ptr + 1; - - /* no reply chunklist */ - **ptr = 0; - *ptr = *ptr + 1; - } else { - /* no write chunklist */ - **ptr = 0; - *ptr = *ptr + 1; - - warray = (gf_rdma_write_array_t *)*ptr; - warray->wc_discrim = hton32(1); - warray->wc_nchunks = hton32(entry->msg.request.rsphdr_count); - - *ptr = (uint32_t *)&warray->wc_array[0]; - - ret = __gf_rdma_create_write_chunks_from_vector( - peer, (gf_rdma_write_chunk_t **)ptr, entry->msg.request.rsphdr_vec, - entry->msg.request.rsphdr_count, request_ctx); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_WRITE_CHUNK_VECTOR_FAILED, - "cannot create write chunks from vector " - "entry->rpchdr"); - goto out; - } - - /* terminate reply chunklist */ - **ptr = 0; - *ptr = *ptr + 1; - } - -out: - return ret; -} - -static void -__gf_rdma_deregister_mr(gf_rdma_device_t *device, struct ibv_mr **mr, int count) -{ - gf_rdma_arena_mr *tmp = NULL; - gf_rdma_arena_mr *dummy = NULL; - int i = 0; - int found = 0; - - if (mr == NULL) { - goto out; - } - - for (i = 0; i < count; i++) { - found = 0; - pthread_mutex_lock(&device->all_mr_lock); - { - if (!list_empty(&device->all_mr)) { - list_for_each_entry_safe(tmp, dummy, &device->all_mr, list) - { - if (tmp->mr == mr[i]) { - found = 1; - break; - } - } - } - } - pthread_mutex_unlock(&device->all_mr_lock); - if (!found) - ibv_dereg_mr(mr[i]); - } - -out: - return; -} - -static int32_t -__gf_rdma_quota_put(gf_rdma_peer_t *peer) -{ - int32_t ret = 0; - - peer->quota++; - ret = peer->quota; - - if (!list_empty(&peer->ioq)) { - ret = __gf_rdma_ioq_churn(peer); - } - - return ret; -} - -static int32_t -gf_rdma_quota_put(gf_rdma_peer_t *peer) -{ - int32_t ret = 0; - gf_rdma_private_t *priv = NULL; - - priv = peer->trans->private; - pthread_mutex_lock(&priv->write_mutex); - { - ret = __gf_rdma_quota_put(peer); - } - pthread_mutex_unlock(&priv->write_mutex); - - return ret; -} - -/* to be called with priv->mutex held */ -void -__gf_rdma_request_context_destroy(gf_rdma_request_context_t *context) -{ - gf_rdma_peer_t *peer = NULL; - gf_rdma_private_t *priv = NULL; - gf_rdma_device_t *device = NULL; - int32_t ret = 0; - - if (context == NULL) { - goto out; - } - - peer = context->peer; - - priv = peer->trans->private; - device = priv->device; - __gf_rdma_deregister_mr(device, context->mr, context->mr_count); - - if (priv->connected) { - ret = __gf_rdma_quota_put(peer); - if (ret < 0) { - gf_msg_debug("rdma", 0, "failed to send message"); - mem_put(context); - __gf_rdma_disconnect(peer->trans); - goto out; - } - } - - if (context->iobref != NULL) { - iobref_unref(context->iobref); - context->iobref = NULL; - } - - if (context->rsp_iobref != NULL) { - iobref_unref(context->rsp_iobref); - context->rsp_iobref = NULL; - } - - mem_put(context); - -out: - return; -} - -void -gf_rdma_post_context_destroy(gf_rdma_device_t *device, - gf_rdma_post_context_t *ctx) -{ - if (ctx == NULL) { - goto out; - } - - __gf_rdma_deregister_mr(device, ctx->mr, ctx->mr_count); - - if (ctx->iobref != NULL) { - iobref_unref(ctx->iobref); - } - - if (ctx->hdr_iobuf != NULL) { - iobuf_unref(ctx->hdr_iobuf); - } - - memset(ctx, 0, sizeof(*ctx)); -out: - return; -} - -int -gf_rdma_post_unref(gf_rdma_post_t *post) -{ - int refcount = -1; - - if (post == NULL) { - goto out; - } - - pthread_mutex_lock(&post->lock); - { - refcount = --post->refcount; - } - pthread_mutex_unlock(&post->lock); - - if (refcount == 0) { - gf_rdma_post_context_destroy(post->device, &post->ctx); - if (post->type == GF_RDMA_SEND_POST) { - gf_rdma_put_post(&post->device->sendq, post); - } else { - gf_rdma_post_recv(post->device->srq, post); - } - } -out: - return refcount; -} - -int -gf_rdma_post_get_refcount(gf_rdma_post_t *post) -{ - int refcount = -1; - - if (post == NULL) { - goto out; - } - - pthread_mutex_lock(&post->lock); - { - refcount = post->refcount; - } - pthread_mutex_unlock(&post->lock); - -out: - return refcount; -} - -gf_rdma_post_t * -gf_rdma_post_ref(gf_rdma_post_t *post) -{ - if (post == NULL) { - goto out; - } - - pthread_mutex_lock(&post->lock); - { - post->refcount++; - } - pthread_mutex_unlock(&post->lock); - -out: - return post; -} - -int32_t -__gf_rdma_ioq_churn_request(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry, - gf_rdma_post_t *post) -{ - gf_rdma_chunktype_t rtype = gf_rdma_noch; - gf_rdma_chunktype_t wtype = gf_rdma_noch; - uint64_t send_size = 0; - gf_rdma_header_t *hdr = NULL; - struct rpc_msg *rpc_msg = NULL; - uint32_t *chunkptr = NULL; - char *buf = NULL; - int32_t ret = 0; - gf_rdma_private_t *priv = NULL; - gf_rdma_device_t *device = NULL; - int chunk_count = 0; - gf_rdma_request_context_t *request_ctx = NULL; - uint32_t prog_payload_length = 0, len = 0; - struct rpc_req *rpc_req = NULL; - - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, entry, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, post, out); - - if ((entry->msg.request.rsphdr_count != 0) && - (entry->msg.request.rsp_payload_count != 0)) { - ret = -1; - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_WRITE_REPLY_CHUNCK_CONFLICT, - "both write-chunklist and reply-chunk cannot be " - "present"); - goto out; - } - - post->ctx.is_request = 1; - priv = peer->trans->private; - device = priv->device; - - hdr = (gf_rdma_header_t *)post->buf; - - send_size = iov_length(entry->rpchdr, entry->rpchdr_count) + - iov_length(entry->proghdr, entry->proghdr_count) + - GLUSTERFS_RDMA_MAX_HEADER_SIZE; - - if (entry->prog_payload_count != 0) { - prog_payload_length = iov_length(entry->prog_payload, - entry->prog_payload_count); - } - - if (send_size > GLUSTERFS_RDMA_INLINE_THRESHOLD) { - rtype = gf_rdma_areadch; - } else if ((send_size + prog_payload_length) < - GLUSTERFS_RDMA_INLINE_THRESHOLD) { - rtype = gf_rdma_noch; - } else if (entry->prog_payload_count != 0) { - rtype = gf_rdma_readch; - } - - if (entry->msg.request.rsphdr_count != 0) { - wtype = gf_rdma_replych; - } else if (entry->msg.request.rsp_payload_count != 0) { - wtype = gf_rdma_writech; - } - - if (rtype == gf_rdma_readch) { - chunk_count += entry->prog_payload_count; - } else if (rtype == gf_rdma_areadch) { - chunk_count += entry->rpchdr_count; - chunk_count += entry->proghdr_count; - } - - if (wtype == gf_rdma_writech) { - chunk_count += entry->msg.request.rsp_payload_count; - } else if (wtype == gf_rdma_replych) { - chunk_count += entry->msg.request.rsphdr_count; - } - - if (chunk_count > GF_RDMA_MAX_SEGMENTS) { - ret = -1; - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_CHUNK_COUNT_GREAT_MAX_SEGMENTS, - "chunk count(%d) exceeding maximum allowed RDMA " - "segment count(%d)", - chunk_count, GF_RDMA_MAX_SEGMENTS); - goto out; - } - - if ((wtype != gf_rdma_noch) || (rtype != gf_rdma_noch)) { - request_ctx = mem_get(device->request_ctx_pool); - if (request_ctx == NULL) { - ret = -1; - goto out; - } - - memset(request_ctx, 0, sizeof(*request_ctx)); - - request_ctx->pool = device->request_ctx_pool; - request_ctx->peer = peer; - - entry->msg.request.rpc_req->conn_private = request_ctx; - - if (entry->msg.request.rsp_iobref != NULL) { - request_ctx->rsp_iobref = iobref_ref(entry->msg.request.rsp_iobref); - } - } - - rpc_msg = (struct rpc_msg *)entry->rpchdr[0].iov_base; - - hdr->rm_xid = rpc_msg->rm_xid; /* no need of hton32(rpc_msg->rm_xid), - * since rpc_msg->rm_xid is already - * hton32ed value of actual xid - */ - hdr->rm_vers = hton32(GF_RDMA_VERSION); - hdr->rm_credit = hton32(peer->send_count); - if (rtype == gf_rdma_areadch) { - hdr->rm_type = hton32(GF_RDMA_NOMSG); - } else { - hdr->rm_type = hton32(GF_RDMA_MSG); - } - - chunkptr = &hdr->rm_body.rm_chunks[0]; - if (rtype != gf_rdma_noch) { - ret = __gf_rdma_create_read_chunks(peer, entry, rtype, &chunkptr, - request_ctx); - if (ret != 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_CREATE_READ_CHUNK_FAILED, - "creation of read chunks failed"); - goto out; - } - } else { - *chunkptr++ = 0; /* no read chunks */ - } - - if (wtype != gf_rdma_noch) { - ret = __gf_rdma_create_write_chunks(peer, entry, wtype, &chunkptr, - request_ctx); - if (ret != 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_CREATE_WRITE_REPLAY_FAILED, - "creation of write/reply chunk failed"); - goto out; - } - } else { - *chunkptr++ = 0; /* no write chunks */ - *chunkptr++ = 0; /* no reply chunk */ - } - - buf = (char *)chunkptr; - - if (rtype != gf_rdma_areadch) { - iov_unload(buf, entry->rpchdr, entry->rpchdr_count); - buf += iov_length(entry->rpchdr, entry->rpchdr_count); - - iov_unload(buf, entry->proghdr, entry->proghdr_count); - buf += iov_length(entry->proghdr, entry->proghdr_count); - - if (rtype != gf_rdma_readch) { - iov_unload(buf, entry->prog_payload, entry->prog_payload_count); - buf += iov_length(entry->prog_payload, entry->prog_payload_count); - } - } - - len = buf - post->buf; - - gf_rdma_post_ref(post); - - ret = gf_rdma_post_send(peer->qp, post, len); - if (!ret) { - ret = len; - } else { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_POST_SEND_FAILED, - "gf_rdma_post_send (to %s) failed with ret = %d (%s)", - peer->trans->peerinfo.identifier, ret, - (ret > 0) ? strerror(ret) : ""); - gf_rdma_post_unref(post); - __gf_rdma_disconnect(peer->trans); - ret = -1; - } - -out: - if (ret == -1) { - rpc_req = entry->msg.request.rpc_req; - - if (request_ctx != NULL) { - __gf_rdma_request_context_destroy(rpc_req->conn_private); - } - - rpc_req->conn_private = NULL; - } - - return ret; -} - -static void -__gf_rdma_fill_reply_header(gf_rdma_header_t *header, struct iovec *rpchdr, - gf_rdma_reply_info_t *reply_info, int credits) -{ - struct rpc_msg *rpc_msg = NULL; - - if (reply_info != NULL) { - header->rm_xid = hton32(reply_info->rm_xid); - } else { - rpc_msg = rpchdr[0].iov_base; /* assume rpchdr contains - * only one vector. - * (which is true) - */ - header->rm_xid = rpc_msg->rm_xid; - } - - header->rm_type = hton32(GF_RDMA_MSG); - header->rm_vers = hton32(GF_RDMA_VERSION); - header->rm_credit = hton32(credits); - - header->rm_body.rm_chunks[0] = 0; /* no read chunks */ - header->rm_body.rm_chunks[1] = 0; /* no write chunks */ - header->rm_body.rm_chunks[2] = 0; /* no reply chunks */ - - return; -} - -int32_t -__gf_rdma_send_reply_inline(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry, - gf_rdma_post_t *post, - gf_rdma_reply_info_t *reply_info) -{ - gf_rdma_header_t *header = NULL; - int32_t send_size = 0, ret = 0; - char *buf = NULL; - - send_size = iov_length(entry->rpchdr, entry->rpchdr_count) + - iov_length(entry->proghdr, entry->proghdr_count) + - iov_length(entry->prog_payload, entry->prog_payload_count) + - sizeof(gf_rdma_header_t); /* - * remember, no chunklists in the - * reply - */ - - if (send_size > GLUSTERFS_RDMA_INLINE_THRESHOLD) { - ret = __gf_rdma_send_error(peer, entry, post, reply_info, ERR_CHUNK); - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_SEND_SIZE_GREAT_INLINE_THRESHOLD, - "msg size (%d) is greater than maximum size " - "of msg that can be sent inlined (%d)", - send_size, GLUSTERFS_RDMA_INLINE_THRESHOLD); - goto out; - } - - header = (gf_rdma_header_t *)post->buf; - - __gf_rdma_fill_reply_header(header, entry->rpchdr, reply_info, - peer->send_count); - - buf = (char *)&header->rm_body.rm_chunks[3]; - - if (entry->rpchdr_count != 0) { - iov_unload(buf, entry->rpchdr, entry->rpchdr_count); - buf += iov_length(entry->rpchdr, entry->rpchdr_count); - } - - if (entry->proghdr_count != 0) { - iov_unload(buf, entry->proghdr, entry->proghdr_count); - buf += iov_length(entry->proghdr, entry->proghdr_count); - } - - if (entry->prog_payload_count != 0) { - iov_unload(buf, entry->prog_payload, entry->prog_payload_count); - buf += iov_length(entry->prog_payload, entry->prog_payload_count); - } - - gf_rdma_post_ref(post); - - ret = gf_rdma_post_send(peer->qp, post, (buf - post->buf)); - if (!ret) { - ret = send_size; - } else { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_POST_SEND_FAILED, - "posting send (to %s) " - "failed with ret = %d (%s)", - peer->trans->peerinfo.identifier, ret, - (ret > 0) ? strerror(ret) : ""); - gf_rdma_post_unref(post); - __gf_rdma_disconnect(peer->trans); - ret = -1; - } - -out: - return ret; -} - -int32_t -__gf_rdma_reply_encode_write_chunks(gf_rdma_peer_t *peer, uint32_t payload_size, - gf_rdma_post_t *post, - gf_rdma_reply_info_t *reply_info, - uint32_t **ptr) -{ - uint32_t chunk_size = 0; - int32_t ret = -1; - gf_rdma_write_array_t *target_array = NULL; - int i = 0; - - target_array = (gf_rdma_write_array_t *)*ptr; - - for (i = 0; i < reply_info->wc_array->wc_nchunks; i++) { - chunk_size += reply_info->wc_array->wc_array[i].wc_target.rs_length; - } - - if (chunk_size < payload_size) { - gf_msg_debug(GF_RDMA_LOG_NAME, 0, - "length of payload (%d) is " - "exceeding the total write chunk length (%d)", - payload_size, chunk_size); - goto out; - } - - target_array->wc_discrim = hton32(1); - for (i = 0; (i < reply_info->wc_array->wc_nchunks) && (payload_size != 0); - i++) { - target_array->wc_array[i].wc_target.rs_offset = hton64( - reply_info->wc_array->wc_array[i].wc_target.rs_offset); - - target_array->wc_array[i].wc_target.rs_length = hton32( - min(payload_size, - reply_info->wc_array->wc_array[i].wc_target.rs_length)); - } - - target_array->wc_nchunks = hton32(i); - target_array->wc_array[i].wc_target.rs_handle = 0; /* terminate - chunklist */ - - ret = 0; - - *ptr = &target_array->wc_array[i].wc_target.rs_length; -out: - return ret; -} - -static int32_t -__gf_rdma_register_local_mr_for_rdma(gf_rdma_peer_t *peer, struct iovec *vector, - int count, gf_rdma_post_context_t *ctx) -{ - int i = 0; - int32_t ret = -1; - gf_rdma_private_t *priv = NULL; - gf_rdma_device_t *device = NULL; - - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, ctx, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, vector, out); - - priv = peer->trans->private; - device = priv->device; - - for (i = 0; i < count; i++) { - /* what if the memory is registered more than once? - * Assume that a single write buffer is passed to afr, which - * then passes it to its children. If more than one children - * happen to use rdma, then the buffer is registered more than - * once. - * Ib-verbs specification says that multiple registrations of - * same memory location is allowed. Refer to 10.6.3.8 of - * Infiniband Architecture Specification Volume 1 - * (Release 1.2.1) - */ - ctx->mr[ctx->mr_count] = gf_rdma_get_pre_registred_mr( - peer->trans, (void *)vector[i].iov_base, vector[i].iov_len); - - if (!ctx->mr[ctx->mr_count]) { - ctx->mr[ctx->mr_count] = ibv_reg_mr(device->pd, vector[i].iov_base, - vector[i].iov_len, - IBV_ACCESS_LOCAL_WRITE); - } - if (ctx->mr[ctx->mr_count] == NULL) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno, - RDMA_MSG_MR_ALOC_FAILED, - "registering memory for IBV_ACCESS_LOCAL_WRITE" - " failed"); - goto out; - } - - ctx->mr_count++; - } - - ret = 0; -out: - return ret; -} - -/* 1. assumes xfer_len of data is pointed by vector(s) starting from vec[*idx] - * 2. modifies vec - */ -int32_t -__gf_rdma_write(gf_rdma_peer_t *peer, gf_rdma_post_t *post, struct iovec *vec, - uint32_t xfer_len, int *idx, gf_rdma_write_chunk_t *writech) -{ - int size = 0, num_sge = 0, i = 0; - int32_t ret = -1; - struct ibv_sge *sg_list = NULL; - struct ibv_send_wr wr = - { - .opcode = IBV_WR_RDMA_WRITE, - .send_flags = IBV_SEND_SIGNALED, - }, - *bad_wr; - - if ((peer == NULL) || (writech == NULL) || (idx == NULL) || - (post == NULL) || (vec == NULL) || (xfer_len == 0)) { - goto out; - } - - for (i = *idx; size < xfer_len; i++) { - size += vec[i].iov_len; - } - - num_sge = i - *idx; - - sg_list = GF_CALLOC(num_sge, sizeof(struct ibv_sge), gf_common_mt_sge); - if (sg_list == NULL) { - ret = -1; - goto out; - } - - for ((i = *idx), (num_sge = 0); (xfer_len != 0); i++, num_sge++) { - size = min(xfer_len, vec[i].iov_len); - - sg_list[num_sge].addr = (unsigned long)vec[i].iov_base; - sg_list[num_sge].length = size; - sg_list[num_sge].lkey = post->ctx.mr[i]->lkey; - - xfer_len -= size; - } - - *idx = i; - - if (size < vec[i - 1].iov_len) { - vec[i - 1].iov_base += size; - vec[i - 1].iov_len -= size; - *idx = i - 1; - } - - wr.sg_list = sg_list; - wr.num_sge = num_sge; - wr.wr_id = (unsigned long)gf_rdma_post_ref(post); - wr.wr.rdma.rkey = writech->wc_target.rs_handle; - wr.wr.rdma.remote_addr = writech->wc_target.rs_offset; - - ret = ibv_post_send(peer->qp, &wr, &bad_wr); - if (ret) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_WRITE_CLIENT_ERROR, - "rdma write to " - "client (%s) failed with ret = %d (%s)", - peer->trans->peerinfo.identifier, ret, - (ret > 0) ? strerror(ret) : ""); - ret = -1; - } - - GF_FREE(sg_list); -out: - return ret; -} - -int32_t -__gf_rdma_do_gf_rdma_write(gf_rdma_peer_t *peer, gf_rdma_post_t *post, - struct iovec *vector, int count, - struct iobref *iobref, - gf_rdma_reply_info_t *reply_info) -{ - int i = 0, payload_idx = 0; - uint32_t payload_size = 0, xfer_len = 0; - int32_t ret = -1; - - if (count != 0) { - payload_size = iov_length(vector, count); - } - - if (payload_size == 0) { - ret = 0; - goto out; - } - - ret = __gf_rdma_register_local_mr_for_rdma(peer, vector, count, &post->ctx); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_MR_ALOC_FAILED, - "registering memory region for rdma failed"); - goto out; - } - - post->ctx.iobref = iobref_ref(iobref); - - for (i = 0; (i < reply_info->wc_array->wc_nchunks) && (payload_size != 0); - i++) { - xfer_len = min(payload_size, - reply_info->wc_array->wc_array[i].wc_target.rs_length); - - ret = __gf_rdma_write(peer, post, vector, xfer_len, &payload_idx, - &reply_info->wc_array->wc_array[i]); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_WRITE_CLIENT_ERROR, - "rdma write to " - "client (%s) failed", - peer->trans->peerinfo.identifier); - goto out; - } - - payload_size -= xfer_len; - } - - ret = 0; -out: - - return ret; -} - -int32_t -__gf_rdma_send_reply_type_nomsg(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry, - gf_rdma_post_t *post, - gf_rdma_reply_info_t *reply_info) -{ - gf_rdma_header_t *header = NULL; - char *buf = NULL; - uint32_t payload_size = 0; - int count = 0, i = 0; - int32_t ret = 0; - struct iovec vector[MAX_IOVEC]; - - header = (gf_rdma_header_t *)post->buf; - - __gf_rdma_fill_reply_header(header, entry->rpchdr, reply_info, - peer->send_count); - - header->rm_type = hton32(GF_RDMA_NOMSG); - - payload_size = iov_length(entry->rpchdr, entry->rpchdr_count) + - iov_length(entry->proghdr, entry->proghdr_count); - - /* encode reply chunklist */ - buf = (char *)&header->rm_body.rm_chunks[2]; - ret = __gf_rdma_reply_encode_write_chunks(peer, payload_size, post, - reply_info, (uint32_t **)&buf); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_ENCODE_ERROR, - "encoding write chunks failed"); - ret = __gf_rdma_send_error(peer, entry, post, reply_info, ERR_CHUNK); - goto out; - } - - gf_rdma_post_ref(post); - - for (i = 0; i < entry->rpchdr_count; i++) { - vector[count++] = entry->rpchdr[i]; - } - - for (i = 0; i < entry->proghdr_count; i++) { - vector[count++] = entry->proghdr[i]; - } - - ret = __gf_rdma_do_gf_rdma_write(peer, post, vector, count, entry->iobref, - reply_info); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_WRITE_PEER_FAILED, - "rdma write to peer " - "(%s) failed", - peer->trans->peerinfo.identifier); - gf_rdma_post_unref(post); - goto out; - } - - ret = gf_rdma_post_send(peer->qp, post, (buf - post->buf)); - if (ret) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_POST_SEND_FAILED, - "posting a send request " - "to client (%s) failed with ret = %d (%s)", - peer->trans->peerinfo.identifier, ret, - (ret > 0) ? strerror(ret) : ""); - ret = -1; - gf_rdma_post_unref(post); - } else { - ret = payload_size; - } - -out: - return ret; -} - -int32_t -__gf_rdma_send_reply_type_msg(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry, - gf_rdma_post_t *post, - gf_rdma_reply_info_t *reply_info) -{ - gf_rdma_header_t *header = NULL; - int32_t send_size = 0, ret = 0; - char *ptr = NULL; - uint32_t payload_size = 0; - - send_size = iov_length(entry->rpchdr, entry->rpchdr_count) + - iov_length(entry->proghdr, entry->proghdr_count) + - GLUSTERFS_RDMA_MAX_HEADER_SIZE; - - if (send_size > GLUSTERFS_RDMA_INLINE_THRESHOLD) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_SEND_SIZE_GREAT_INLINE_THRESHOLD, - "client has provided only write chunks, but the " - "combined size of rpc and program header (%d) is " - "exceeding the size of msg that can be sent using " - "RDMA send (%d)", - send_size, GLUSTERFS_RDMA_INLINE_THRESHOLD); - - ret = __gf_rdma_send_error(peer, entry, post, reply_info, ERR_CHUNK); - goto out; - } - - header = (gf_rdma_header_t *)post->buf; - - __gf_rdma_fill_reply_header(header, entry->rpchdr, reply_info, - peer->send_count); - - payload_size = iov_length(entry->prog_payload, entry->prog_payload_count); - ptr = (char *)&header->rm_body.rm_chunks[1]; - - ret = __gf_rdma_reply_encode_write_chunks(peer, payload_size, post, - reply_info, (uint32_t **)&ptr); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_ENCODE_ERROR, - "encoding write chunks failed"); - ret = __gf_rdma_send_error(peer, entry, post, reply_info, ERR_CHUNK); - goto out; - } - - *(uint32_t *)ptr = 0; /* terminate reply chunklist */ - ptr += sizeof(uint32_t); - - gf_rdma_post_ref(post); - - ret = __gf_rdma_do_gf_rdma_write(peer, post, entry->prog_payload, - entry->prog_payload_count, entry->iobref, - reply_info); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_WRITE_PEER_FAILED, - "rdma write to peer " - "(%s) failed", - peer->trans->peerinfo.identifier); - gf_rdma_post_unref(post); - goto out; - } - - iov_unload(ptr, entry->rpchdr, entry->rpchdr_count); - ptr += iov_length(entry->rpchdr, entry->rpchdr_count); - - iov_unload(ptr, entry->proghdr, entry->proghdr_count); - ptr += iov_length(entry->proghdr, entry->proghdr_count); - - ret = gf_rdma_post_send(peer->qp, post, (ptr - post->buf)); - if (ret) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_SEND_CLIENT_ERROR, - "rdma send to client (%s) failed with ret = %d (%s)", - peer->trans->peerinfo.identifier, ret, - (ret > 0) ? strerror(ret) : ""); - gf_rdma_post_unref(post); - ret = -1; - } else { - ret = send_size + payload_size; - } - -out: - return ret; -} - -void -gf_rdma_reply_info_destroy(gf_rdma_reply_info_t *reply_info) -{ - if (reply_info == NULL) { - goto out; - } - - if (reply_info->wc_array != NULL) { - GF_FREE(reply_info->wc_array); - reply_info->wc_array = NULL; - } - - mem_put(reply_info); -out: - return; -} - -gf_rdma_reply_info_t * -gf_rdma_reply_info_alloc(gf_rdma_peer_t *peer) -{ - gf_rdma_reply_info_t *reply_info = NULL; - gf_rdma_private_t *priv = NULL; - - priv = peer->trans->private; - - reply_info = mem_get(priv->device->reply_info_pool); - if (reply_info == NULL) { - goto out; - } - - memset(reply_info, 0, sizeof(*reply_info)); - reply_info->pool = priv->device->reply_info_pool; - -out: - return reply_info; -} - -int32_t -__gf_rdma_ioq_churn_reply(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry, - gf_rdma_post_t *post) -{ - gf_rdma_reply_info_t *reply_info = NULL; - int32_t ret = -1; - gf_rdma_chunktype_t type = gf_rdma_noch; - - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, entry, out); - GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, post, out); - - reply_info = entry->msg.reply_info; - if (reply_info != NULL) { - type = reply_info->type; - } - - switch (type) { - case gf_rdma_noch: - ret = __gf_rdma_send_reply_inline(peer, entry, post, reply_info); - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_SEND_REPLY_FAILED, - "failed to send reply to peer (%s) as an " - "inlined rdma msg", - peer->trans->peerinfo.identifier); - } - break; - - case gf_rdma_replych: - ret = __gf_rdma_send_reply_type_nomsg(peer, entry, post, - reply_info); - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_SEND_REPLY_FAILED, - "failed to send reply to peer (%s) as " - "RDMA_NOMSG", - peer->trans->peerinfo.identifier); - } - break; - - case gf_rdma_writech: - ret = __gf_rdma_send_reply_type_msg(peer, entry, post, reply_info); - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_SEND_REPLY_FAILED, - "failed to send reply with write chunks " - "to peer (%s)", - peer->trans->peerinfo.identifier); - } - break; - - default: - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_INVALID_CHUNK_TYPE, - "invalid chunktype (%d) specified for sending reply " - " (peer:%s)", - type, peer->trans->peerinfo.identifier); - break; - } - - if (reply_info != NULL) { - gf_rdma_reply_info_destroy(reply_info); - } -out: - return ret; -} - -int32_t -__gf_rdma_ioq_churn_entry(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry) -{ - int32_t ret = 0, quota = 0; - gf_rdma_private_t *priv = NULL; - gf_rdma_device_t *device = NULL; - gf_rdma_options_t *options = NULL; - gf_rdma_post_t *post = NULL; - - priv = peer->trans->private; - options = &priv->options; - device = priv->device; - - quota = __gf_rdma_quota_get(peer); - if (quota > 0) { - post = gf_rdma_get_post(&device->sendq); - if (post == NULL) { - post = gf_rdma_new_post(peer->trans, device, - (options->send_size + 2048), - GF_RDMA_SEND_POST); - } - - if (post == NULL) { - ret = -1; - gf_msg_callingfn(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_POST_SEND_FAILED, - "not able to get a post to send msg"); - goto out; - } - - if (entry->is_request) { - ret = __gf_rdma_ioq_churn_request(peer, entry, post); - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_PROC_IOQ_ENTRY_FAILED, - "failed to process request ioq entry " - "to peer(%s)", - peer->trans->peerinfo.identifier); - } - } else { - ret = __gf_rdma_ioq_churn_reply(peer, entry, post); - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_PROC_IOQ_ENTRY_FAILED, - "failed to process reply ioq entry " - "to peer (%s)", - peer->trans->peerinfo.identifier); - } - } - - if (ret != 0) { - __gf_rdma_ioq_entry_free(entry); - } - } else { - ret = 0; - } - -out: - return ret; -} - -static int32_t -__gf_rdma_ioq_churn(gf_rdma_peer_t *peer) -{ - gf_rdma_ioq_t *entry = NULL; - int32_t ret = 0; - - while (!list_empty(&peer->ioq)) { - /* pick next entry */ - entry = peer->ioq_next; - - ret = __gf_rdma_ioq_churn_entry(peer, entry); - - if (ret <= 0) - break; - } - - /* - list_for_each_entry_safe (entry, dummy, &peer->ioq, list) { - ret = __gf_rdma_ioq_churn_entry (peer, entry); - if (ret <= 0) { - break; - } - } - */ - - return ret; -} - -static int32_t -gf_rdma_writev(rpc_transport_t *this, gf_rdma_ioq_t *entry) -{ - int32_t ret = 0, need_append = 1; - gf_rdma_private_t *priv = NULL; - gf_rdma_peer_t *peer = NULL; - - priv = this->private; - pthread_mutex_lock(&priv->write_mutex); - { - if (!priv->connected) { - gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_PEER_DISCONNECTED, - "rdma is not connected to peer (%s)", - this->peerinfo.identifier); - ret = -1; - goto unlock; - } - - peer = &priv->peer; - if (list_empty(&peer->ioq)) { - ret = __gf_rdma_ioq_churn_entry(peer, entry); - if (ret != 0) { - need_append = 0; - - if (ret < 0) { - gf_msg(this->name, GF_LOG_WARNING, 0, - RDMA_MSG_PROC_IOQ_ENTRY_FAILED, - "processing ioq entry destined" - " to (%s) failed", - this->peerinfo.identifier); - } - } - } - - if (need_append) { - list_add_tail(&entry->list, &peer->ioq); - } - } -unlock: - pthread_mutex_unlock(&priv->write_mutex); - return ret; -} - -gf_rdma_ioq_t * -gf_rdma_ioq_new(rpc_transport_t *this, rpc_transport_data_t *data) -{ - gf_rdma_ioq_t *entry = NULL; - int count = 0, i = 0; - rpc_transport_msg_t *msg = NULL; - gf_rdma_private_t *priv = NULL; - - if ((data == NULL) || (this == NULL)) { - goto out; - } - - priv = this->private; - - entry = mem_get(priv->device->ioq_pool); - if (entry == NULL) { - goto out; - } - memset(entry, 0, sizeof(*entry)); - entry->pool = priv->device->ioq_pool; - - if (data->is_request) { - msg = &data->data.req.msg; - if (data->data.req.rsp.rsphdr_count != 0) { - for (i = 0; i < data->data.req.rsp.rsphdr_count; i++) { - entry->msg.request.rsphdr_vec[i] = data->data.req.rsp.rsphdr[i]; - } - - entry->msg.request.rsphdr_count = data->data.req.rsp.rsphdr_count; - } - - if (data->data.req.rsp.rsp_payload_count != 0) { - for (i = 0; i < data->data.req.rsp.rsp_payload_count; i++) { - entry->msg.request.rsp_payload[i] = data->data.req.rsp - .rsp_payload[i]; - } - - entry->msg.request.rsp_payload_count = data->data.req.rsp - .rsp_payload_count; - } - - entry->msg.request.rpc_req = data->data.req.rpc_req; - - if (data->data.req.rsp.rsp_iobref != NULL) { - entry->msg.request.rsp_iobref = iobref_ref( - data->data.req.rsp.rsp_iobref); - } - } else { - msg = &data->data.reply.msg; - entry->msg.reply_info = data->data.reply.private; - } - - entry->is_request = data->is_request; - - count = msg->rpchdrcount + msg->proghdrcount + msg->progpayloadcount; - - GF_ASSERT(count <= MAX_IOVEC); - - if (msg->rpchdr != NULL) { - memcpy(&entry->rpchdr[0], msg->rpchdr, - sizeof(struct iovec) * msg->rpchdrcount); - entry->rpchdr_count = msg->rpchdrcount; - } - - if (msg->proghdr != NULL) { - memcpy(&entry->proghdr[0], msg->proghdr, - sizeof(struct iovec) * msg->proghdrcount); - entry->proghdr_count = msg->proghdrcount; - } - - if (msg->progpayload != NULL) { - memcpy(&entry->prog_payload[0], msg->progpayload, - sizeof(struct iovec) * msg->progpayloadcount); - entry->prog_payload_count = msg->progpayloadcount; - } - - if (msg->iobref != NULL) { - entry->iobref = iobref_ref(msg->iobref); - } - - INIT_LIST_HEAD(&entry->list); - -out: - return entry; -} - -int32_t -gf_rdma_submit_request(rpc_transport_t *this, rpc_transport_req_t *req) -{ - int32_t ret = 0; - gf_rdma_ioq_t *entry = NULL; - rpc_transport_data_t data = { - 0, - }; - gf_rdma_private_t *priv = NULL; - gf_rdma_peer_t *peer = NULL; - - if (req == NULL) { - goto out; - } - - priv = this->private; - if (priv == NULL) { - ret = -1; - goto out; - } - - peer = &priv->peer; - data.is_request = 1; - data.data.req = *req; - /* - * when fist message is received on a transport, quota variable will - * initiaize and quota_set will set to one. In gluster code client - * process with respect to transport is the one who sends the first - * message. Before settng quota_set variable if a submit request is - * came on server, then the message should not send. - */ - - if (priv->entity == GF_RDMA_SERVER && peer->quota_set == 0) { - ret = 0; - goto out; - } - - entry = gf_rdma_ioq_new(this, &data); - if (entry == NULL) { - gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_NEW_IOQ_ENTRY_FAILED, - "getting a new ioq entry failed (peer:%s)", - this->peerinfo.identifier); - goto out; - } - - ret = gf_rdma_writev(this, entry); - - if (ret > 0) { - ret = 0; - } else if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_WRITE_PEER_FAILED, - "sending request to peer (%s) failed", - this->peerinfo.identifier); - rpc_transport_disconnect(this, _gf_false); - } - -out: - return ret; -} - -int32_t -gf_rdma_submit_reply(rpc_transport_t *this, rpc_transport_reply_t *reply) -{ - int32_t ret = 0; - gf_rdma_ioq_t *entry = NULL; - rpc_transport_data_t data = { - 0, - }; - - if (reply == NULL) { - goto out; - } - - data.data.reply = *reply; - - entry = gf_rdma_ioq_new(this, &data); - if (entry == NULL) { - gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_NEW_IOQ_ENTRY_FAILED, - "getting a new ioq entry failed (peer:%s)", - this->peerinfo.identifier); - goto out; - } - - ret = gf_rdma_writev(this, entry); - if (ret > 0) { - ret = 0; - } else if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_WRITE_PEER_FAILED, - "sending request to peer (%s) failed", - this->peerinfo.identifier); - rpc_transport_disconnect(this, _gf_false); - } - -out: - return ret; -} - -static int -gf_rdma_register_peer(gf_rdma_device_t *device, int32_t qp_num, - gf_rdma_peer_t *peer) -{ - struct _qpent *ent = NULL; - gf_rdma_qpreg_t *qpreg = NULL; - int32_t hash = 0; - int ret = -1; - - qpreg = &device->qpreg; - hash = qp_num % 42; - - pthread_mutex_lock(&qpreg->lock); - { - ent = qpreg->ents[hash].next; - while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num)) { - ent = ent->next; - } - - if (ent->qp_num == qp_num) { - ret = 0; - goto unlock; - } - - ent = (struct _qpent *)GF_CALLOC(1, sizeof(*ent), gf_common_mt_qpent); - if (ent == NULL) { - goto unlock; - } - - /* TODO: ref reg->peer */ - ent->peer = peer; - ent->next = &qpreg->ents[hash]; - ent->prev = ent->next->prev; - ent->next->prev = ent; - ent->prev->next = ent; - ent->qp_num = qp_num; - qpreg->count++; - ret = 0; - } -unlock: - pthread_mutex_unlock(&qpreg->lock); - - return ret; -} - -static void -gf_rdma_unregister_peer(gf_rdma_device_t *device, int32_t qp_num) -{ - struct _qpent *ent = NULL; - gf_rdma_qpreg_t *qpreg = NULL; - int32_t hash = 0; - - qpreg = &device->qpreg; - hash = qp_num % 42; - - pthread_mutex_lock(&qpreg->lock); - { - ent = qpreg->ents[hash].next; - while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num)) - ent = ent->next; - if ((ent->qp_num != qp_num) || (ent == &qpreg->ents[hash])) { - pthread_mutex_unlock(&qpreg->lock); - return; - } - ent->prev->next = ent->next; - ent->next->prev = ent->prev; - /* TODO: unref reg->peer */ - GF_FREE(ent); - qpreg->count--; - } - pthread_mutex_unlock(&qpreg->lock); -} - -static gf_rdma_peer_t * -__gf_rdma_lookup_peer(gf_rdma_device_t *device, int32_t qp_num) -{ - struct _qpent *ent = NULL; - gf_rdma_peer_t *peer = NULL; - gf_rdma_qpreg_t *qpreg = NULL; - int32_t hash = 0; - - qpreg = &device->qpreg; - hash = qp_num % 42; - ent = qpreg->ents[hash].next; - while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num)) - ent = ent->next; - - if (ent != &qpreg->ents[hash]) { - peer = ent->peer; - } - - return peer; -} - -static void -__gf_rdma_destroy_qp(rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - - priv = this->private; - if (priv->peer.qp) { - gf_rdma_unregister_peer(priv->device, priv->peer.qp->qp_num); - rdma_destroy_qp(priv->peer.cm_id); - } - priv->peer.qp = NULL; - - return; -} - -static int32_t -gf_rdma_create_qp(rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - gf_rdma_device_t *device = NULL; - int32_t ret = 0; - gf_rdma_peer_t *peer = NULL; - char *device_name = NULL; - - priv = this->private; - - peer = &priv->peer; - - device_name = (char *)ibv_get_device_name(peer->cm_id->verbs->device); - if (device_name == NULL) { - ret = -1; - gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_GET_DEVICE_NAME_FAILED, - "cannot get " - "device_name"); - goto out; - } - - device = gf_rdma_get_device(this, peer->cm_id->verbs, device_name); - if (device == NULL) { - ret = -1; - gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_GET_DEVICE_FAILED, - "cannot get device for " - "device %s", - device_name); - goto out; - } - - if (priv->device == NULL) { - priv->device = device; - } - - struct ibv_qp_init_attr init_attr = { - .send_cq = device->send_cq, - .recv_cq = device->recv_cq, - .srq = device->srq, - .cap = {.max_send_wr = peer->send_count, - .max_recv_wr = peer->recv_count, - .max_send_sge = 2, - .max_recv_sge = 1}, - .qp_type = IBV_QPT_RC}; - - ret = rdma_create_qp(peer->cm_id, device->pd, &init_attr); - if (ret != 0) { - gf_msg(peer->trans->name, GF_LOG_CRITICAL, errno, - RDMA_MSG_CREAT_QP_FAILED, "%s: could not create QP", this->name); - ret = -1; - goto out; - } - - peer->qp = peer->cm_id->qp; - - ret = gf_rdma_register_peer(device, peer->qp->qp_num, peer); - -out: - if (ret == -1) - __gf_rdma_destroy_qp(this); - - return ret; -} - -static int32_t -__gf_rdma_teardown(rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - gf_rdma_peer_t *peer = NULL; - - priv = this->private; - peer = &priv->peer; - - if (peer->cm_id && peer->cm_id->qp != NULL) { - __gf_rdma_destroy_qp(this); - } - - if (!list_empty(&priv->peer.ioq)) { - __gf_rdma_ioq_flush(peer); - } - - if (peer->cm_id != NULL) { - rdma_destroy_id(peer->cm_id); - peer->cm_id = NULL; - } - - /* TODO: decrement cq size */ - return 0; -} - -static int32_t -gf_rdma_teardown(rpc_transport_t *this) -{ - int32_t ret = 0; - gf_rdma_private_t *priv = NULL; - - if (this == NULL) { - goto out; - } - - priv = this->private; - - pthread_mutex_lock(&priv->write_mutex); - { - ret = __gf_rdma_teardown(this); - } - pthread_mutex_unlock(&priv->write_mutex); - -out: - return ret; -} - -/* - * allocates new memory to hold write-chunklist. New memory is needed since - * write-chunklist will be used while sending reply and the post holding initial - * write-chunklist sent from client will be put back to srq before a pollin - * event is sent to upper layers. - */ -int32_t -gf_rdma_get_write_chunklist(char **ptr, gf_rdma_write_array_t **write_ary) -{ - gf_rdma_write_array_t *from = NULL, *to = NULL; - int32_t ret = -1, size = 0, i = 0; - - from = (gf_rdma_write_array_t *)*ptr; - if (from->wc_discrim == 0) { - ret = 0; - goto out; - } - - from->wc_nchunks = ntoh32(from->wc_nchunks); - - size = sizeof(*from) + (sizeof(gf_rdma_write_chunk_t) * from->wc_nchunks); - - to = GF_CALLOC(1, size, gf_common_mt_char); - if (to == NULL) { - ret = -1; - goto out; - } - - to->wc_discrim = ntoh32(from->wc_discrim); - to->wc_nchunks = from->wc_nchunks; - - for (i = 0; i < to->wc_nchunks; i++) { - to->wc_array[i].wc_target.rs_handle = ntoh32( - from->wc_array[i].wc_target.rs_handle); - to->wc_array[i].wc_target.rs_length = ntoh32( - from->wc_array[i].wc_target.rs_length); - to->wc_array[i].wc_target.rs_offset = ntoh64( - from->wc_array[i].wc_target.rs_offset); - } - - *write_ary = to; - ret = 0; - *ptr = (char *)&from->wc_array[i].wc_target.rs_handle; -out: - return ret; -} - -/* - * does not allocate new memory to hold read-chunklist. New memory is not - * needed, since post is not put back to srq till we've completed all the - * rdma-reads and hence readchunk-list can point to memory held by post. - */ -int32_t -gf_rdma_get_read_chunklist(char **ptr, gf_rdma_read_chunk_t **readch) -{ - int32_t ret = -1; - gf_rdma_read_chunk_t *chunk = NULL; - int i = 0; - - chunk = (gf_rdma_read_chunk_t *)*ptr; - if (chunk[0].rc_discrim == 0) { - ret = 0; - goto out; - } - - for (i = 0; chunk[i].rc_discrim != 0; i++) { - chunk[i].rc_discrim = ntoh32(chunk[i].rc_discrim); - chunk[i].rc_position = ntoh32(chunk[i].rc_position); - chunk[i].rc_target.rs_handle = ntoh32(chunk[i].rc_target.rs_handle); - chunk[i].rc_target.rs_length = ntoh32(chunk[i].rc_target.rs_length); - chunk[i].rc_target.rs_offset = ntoh64(chunk[i].rc_target.rs_offset); - } - - *readch = &chunk[0]; - ret = 0; - *ptr = (char *)&chunk[i].rc_discrim; -out: - return ret; -} - -static int32_t -gf_rdma_decode_error_msg(gf_rdma_peer_t *peer, gf_rdma_post_t *post, - size_t bytes_in_post) -{ - gf_rdma_header_t *header = NULL; - struct iobuf *iobuf = NULL; - struct iobref *iobref = NULL; - int32_t ret = -1; - struct rpc_msg rpc_msg = { - 0, - }; - - header = (gf_rdma_header_t *)post->buf; - header->rm_body.rm_error.rm_type = ntoh32(header->rm_body.rm_error.rm_type); - if (header->rm_body.rm_error.rm_type == ERR_VERS) { - header->rm_body.rm_error.rm_version.gf_rdma_vers_low = ntoh32( - header->rm_body.rm_error.rm_version.gf_rdma_vers_low); - header->rm_body.rm_error.rm_version.gf_rdma_vers_high = ntoh32( - header->rm_body.rm_error.rm_version.gf_rdma_vers_high); - } - - rpc_msg.rm_xid = header->rm_xid; - rpc_msg.rm_direction = REPLY; - rpc_msg.rm_reply.rp_stat = MSG_DENIED; - - iobuf = iobuf_get2(peer->trans->ctx->iobuf_pool, bytes_in_post); - if (iobuf == NULL) { - ret = -1; - goto out; - } - - post->ctx.iobref = iobref = iobref_new(); - if (iobref == NULL) { - ret = -1; - goto out; - } - - ret = rpc_reply_to_xdr(&rpc_msg, iobuf_ptr(iobuf), iobuf_pagesize(iobuf), - &post->ctx.vector[0]); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_RPC_REPLY_CREATE_FAILED, - "Failed to create " - "RPC reply"); - goto out; - } - - iobref_add(iobref, iobuf); - iobuf_unref(iobuf); - - post->ctx.count = 1; - - iobuf = NULL; - iobref = NULL; - -out: - if (ret == -1) { - if (iobuf != NULL) { - iobuf_unref(iobuf); - } - - if (iobref != NULL) { - iobref_unref(iobref); - } - } - - return 0; -} - -int32_t -gf_rdma_decode_msg(gf_rdma_peer_t *peer, gf_rdma_post_t *post, - gf_rdma_read_chunk_t **readch, size_t bytes_in_post) -{ - int32_t ret = -1; - gf_rdma_header_t *header = NULL; - gf_rdma_reply_info_t *reply_info = NULL; - char *ptr = NULL; - gf_rdma_write_array_t *write_ary = NULL; - size_t header_len = 0; - - header = (gf_rdma_header_t *)post->buf; - - ptr = (char *)&header->rm_body.rm_chunks[0]; - - ret = gf_rdma_get_read_chunklist(&ptr, readch); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_GET_READ_CHUNK_FAILED, - "cannot get read " - "chunklist from msg"); - goto out; - } - - /* skip terminator of read-chunklist */ - ptr = ptr + sizeof(uint32_t); - - ret = gf_rdma_get_write_chunklist(&ptr, &write_ary); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_GET_WRITE_CHUNK_FAILED, - "cannot get write " - "chunklist from msg"); - goto out; - } - - /* skip terminator of write-chunklist */ - ptr = ptr + sizeof(uint32_t); - - if (write_ary != NULL) { - reply_info = gf_rdma_reply_info_alloc(peer); - if (reply_info == NULL) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_REPLY_INFO_ALLOC_FAILED, "reply_info_alloc failed"); - ret = -1; - goto out; - } - - reply_info->type = gf_rdma_writech; - reply_info->wc_array = write_ary; - reply_info->rm_xid = header->rm_xid; - } else { - ret = gf_rdma_get_write_chunklist(&ptr, &write_ary); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_CHUNKLIST_ERROR, - "cannot get reply " - "chunklist from msg"); - goto out; - } - - if (write_ary != NULL) { - reply_info = gf_rdma_reply_info_alloc(peer); - if (reply_info == NULL) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_REPLY_INFO_ALLOC_FAILED, - "reply_info_alloc_failed"); - ret = -1; - goto out; - } - - reply_info->type = gf_rdma_replych; - reply_info->wc_array = write_ary; - reply_info->rm_xid = header->rm_xid; - } - } - - /* skip terminator of reply chunk */ - ptr = ptr + sizeof(uint32_t); - if (header->rm_type != GF_RDMA_NOMSG) { - header_len = (long)ptr - (long)post->buf; - post->ctx.vector[0].iov_len = (bytes_in_post - header_len); - - post->ctx.hdr_iobuf = iobuf_get2(peer->trans->ctx->iobuf_pool, - (bytes_in_post - header_len)); - if (post->ctx.hdr_iobuf == NULL) { - ret = -1; - goto out; - } - - post->ctx.vector[0].iov_base = iobuf_ptr(post->ctx.hdr_iobuf); - memcpy(post->ctx.vector[0].iov_base, ptr, post->ctx.vector[0].iov_len); - post->ctx.count = 1; - } - - post->ctx.reply_info = reply_info; -out: - if (ret == -1) { - if (*readch != NULL) { - GF_FREE(*readch); - *readch = NULL; - } - if (reply_info) - GF_FREE(reply_info); - GF_FREE(write_ary); - } - - return ret; -} - -/* Assumes only one of either write-chunklist or a reply chunk is present */ -int32_t -gf_rdma_decode_header(gf_rdma_peer_t *peer, gf_rdma_post_t *post, - gf_rdma_read_chunk_t **readch, size_t bytes_in_post) -{ - int32_t ret = -1; - gf_rdma_header_t *header = NULL; - - header = (gf_rdma_header_t *)post->buf; - - header->rm_xid = ntoh32(header->rm_xid); - header->rm_vers = ntoh32(header->rm_vers); - header->rm_credit = ntoh32(header->rm_credit); - header->rm_type = ntoh32(header->rm_type); - - switch (header->rm_type) { - case GF_RDMA_MSG: - case GF_RDMA_NOMSG: - ret = gf_rdma_decode_msg(peer, post, readch, bytes_in_post); - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_ENCODE_ERROR, - "cannot decode msg of " - "type (%d)", - header->rm_type); - } - - break; - - case GF_RDMA_MSGP: - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_INVALID_ENTRY, - "rdma msg of msg-type " - "GF_RDMA_MSGP should not have been received"); - ret = -1; - break; - - case GF_RDMA_DONE: - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_INVALID_ENTRY, - "rdma msg of msg-type " - "GF_RDMA_DONE should not have been received"); - ret = -1; - break; - - case GF_RDMA_ERROR: - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_RDMA_ERROR_RECEIVED, - "received a msg of type" - " RDMA_ERROR"); - ret = gf_rdma_decode_error_msg(peer, post, bytes_in_post); - break; - - default: - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_INVALID_ENTRY, - "unknown rdma msg-type (%d)", header->rm_type); - } - - return ret; -} - -int32_t -gf_rdma_do_reads(gf_rdma_peer_t *peer, gf_rdma_post_t *post, - gf_rdma_read_chunk_t *readch) -{ - int32_t ret = -1, i = 0, count = 0; - size_t size = 0; - char *ptr = NULL; - struct iobuf *iobuf = NULL; - gf_rdma_private_t *priv = NULL; - struct ibv_sge *list = NULL; - struct ibv_send_wr *wr = NULL, *bad_wr = NULL; - int total_ref = 0; - priv = peer->trans->private; - - for (i = 0; readch[i].rc_discrim != 0; i++) { - size += readch[i].rc_target.rs_length; - } - - if (i == 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_INVALID_CHUNK_TYPE, - "message type specified " - "as rdma-read but there are no rdma read-chunks " - "present"); - goto out; - } - - post->ctx.gf_rdma_reads = i; - i = 0; - iobuf = iobuf_get2(peer->trans->ctx->iobuf_pool, size); - if (iobuf == NULL) { - goto out; - } - - if (post->ctx.iobref == NULL) { - post->ctx.iobref = iobref_new(); - if (post->ctx.iobref == NULL) { - iobuf_unref(iobuf); - iobuf = NULL; - goto out; - } - } - - ptr = iobuf_ptr(iobuf); - iobref_add(post->ctx.iobref, iobuf); - iobuf_unref(iobuf); - - iobuf = NULL; - - pthread_mutex_lock(&priv->write_mutex); - { - if (!priv->connected) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_PEER_DISCONNECTED, - "transport not " - "connected to peer (%s), not doing rdma reads", - peer->trans->peerinfo.identifier); - goto unlock; - } - - list = GF_CALLOC(post->ctx.gf_rdma_reads, sizeof(struct ibv_sge), - gf_common_mt_sge); - - if (list == NULL) { - errno = ENOMEM; - ret = -1; - goto unlock; - } - wr = GF_CALLOC(post->ctx.gf_rdma_reads, sizeof(struct ibv_send_wr), - gf_common_mt_wr); - if (wr == NULL) { - errno = ENOMEM; - ret = -1; - goto unlock; - } - for (i = 0; readch[i].rc_discrim != 0; i++) { - count = post->ctx.count++; - post->ctx.vector[count].iov_base = ptr; - post->ctx.vector[count].iov_len = readch[i].rc_target.rs_length; - - ret = __gf_rdma_register_local_mr_for_rdma( - peer, &post->ctx.vector[count], 1, &post->ctx); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_MR_ALOC_FAILED, - "registering local memory" - " for rdma read failed"); - goto unlock; - } - - list[i].addr = (unsigned long)post->ctx.vector[count].iov_base; - list[i].length = post->ctx.vector[count].iov_len; - list[i].lkey = post->ctx.mr[post->ctx.mr_count - 1]->lkey; - - wr[i].wr_id = (unsigned long)gf_rdma_post_ref(post); - wr[i].sg_list = &list[i]; - wr[i].next = &wr[i + 1]; - wr[i].num_sge = 1; - wr[i].opcode = IBV_WR_RDMA_READ; - wr[i].send_flags = IBV_SEND_SIGNALED; - wr[i].wr.rdma.remote_addr = readch[i].rc_target.rs_offset; - wr[i].wr.rdma.rkey = readch[i].rc_target.rs_handle; - - ptr += readch[i].rc_target.rs_length; - total_ref++; - } - wr[i - 1].next = NULL; - ret = ibv_post_send(peer->qp, wr, &bad_wr); - if (ret) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_READ_CLIENT_ERROR, - "rdma read from " - "client (%s) failed with ret = %d (%s)", - peer->trans->peerinfo.identifier, ret, - (ret > 0) ? strerror(ret) : ""); - - if (!bad_wr) { - ret = -1; - goto unlock; - } - - for (i = 0; i < post->ctx.gf_rdma_reads; i++) { - if (&wr[i] != bad_wr) - total_ref--; - else - break; - } - - ret = -1; - } - } -unlock: - pthread_mutex_unlock(&priv->write_mutex); -out: - if (list) - GF_FREE(list); - if (wr) - GF_FREE(wr); - - if (ret == -1) { - while (total_ref-- > 0) - gf_rdma_post_unref(post); - } - - return ret; -} - -int32_t -gf_rdma_pollin_notify(gf_rdma_peer_t *peer, gf_rdma_post_t *post) -{ - int32_t ret = -1; - enum msg_type msg_type = 0; - struct rpc_req *rpc_req = NULL; - gf_rdma_request_context_t *request_context = NULL; - rpc_request_info_t request_info = { - 0, - }; - gf_rdma_private_t *priv = NULL; - uint32_t *ptr = NULL; - rpc_transport_pollin_t *pollin = NULL; - - if ((peer == NULL) || (post == NULL)) { - goto out; - } - - if (post->ctx.iobref == NULL) { - post->ctx.iobref = iobref_new(); - if (post->ctx.iobref == NULL) { - goto out; - } - - /* handling the case where both hdr and payload of - * GF_FOP_READ_CBK were received in a single iobuf - * because of server sending entire msg as inline without - * doing rdma writes. - */ - if (post->ctx.hdr_iobuf) - iobref_add(post->ctx.iobref, post->ctx.hdr_iobuf); - } - - pollin = rpc_transport_pollin_alloc(peer->trans, post->ctx.vector, - post->ctx.count, post->ctx.hdr_iobuf, - post->ctx.iobref, post->ctx.reply_info); - if (pollin == NULL) { - goto out; - } - - ptr = (uint32_t *)pollin->vector[0].iov_base; - - request_info.xid = ntoh32(*ptr); - msg_type = ntoh32(*(ptr + 1)); - - if (msg_type == REPLY) { - ret = rpc_transport_notify(peer->trans, RPC_TRANSPORT_MAP_XID_REQUEST, - &request_info); - if (ret == -1) { - gf_msg_debug(GF_RDMA_LOG_NAME, 0, - "cannot get request" - "information from rpc layer"); - goto out; - } - - rpc_req = request_info.rpc_req; - if (rpc_req == NULL) { - gf_msg_debug(GF_RDMA_LOG_NAME, 0, - "rpc request " - "structure not found"); - ret = -1; - goto out; - } - - request_context = rpc_req->conn_private; - rpc_req->conn_private = NULL; - - priv = peer->trans->private; - if (request_context != NULL) { - pthread_mutex_lock(&priv->write_mutex); - { - __gf_rdma_request_context_destroy(request_context); - } - pthread_mutex_unlock(&priv->write_mutex); - } else { - gf_rdma_quota_put(peer); - } - - pollin->is_reply = 1; - } - - ret = rpc_transport_notify(peer->trans, RPC_TRANSPORT_MSG_RECEIVED, pollin); - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, TRANS_MSG_TRANSPORT_ERROR, - "transport_notify failed"); - } - -out: - if (pollin != NULL) { - pollin->private = NULL; - rpc_transport_pollin_destroy(pollin); - } - - return ret; -} - -int32_t -gf_rdma_recv_reply(gf_rdma_peer_t *peer, gf_rdma_post_t *post) -{ - int32_t ret = -1; - gf_rdma_header_t *header = NULL; - gf_rdma_reply_info_t *reply_info = NULL; - gf_rdma_write_array_t *wc_array = NULL; - int i = 0; - uint32_t *ptr = NULL; - gf_rdma_request_context_t *ctx = NULL; - rpc_request_info_t request_info = { - 0, - }; - struct rpc_req *rpc_req = NULL; - - header = (gf_rdma_header_t *)post->buf; - reply_info = post->ctx.reply_info; - - /* no write chunklist, just notify upper layers */ - if (reply_info == NULL) { - ret = 0; - goto out; - } - - wc_array = reply_info->wc_array; - - if (header->rm_type == GF_RDMA_NOMSG) { - post->ctx.vector[0].iov_base = (void *)(long)wc_array->wc_array[0] - .wc_target.rs_offset; - post->ctx.vector[0].iov_len = wc_array->wc_array[0].wc_target.rs_length; - - post->ctx.count = 1; - } else { - for (i = 0; i < wc_array->wc_nchunks; i++) { - post->ctx.vector[i + 1].iov_base = - (void *)(long)wc_array->wc_array[i].wc_target.rs_offset; - post->ctx.vector[i + 1].iov_len = wc_array->wc_array[i] - .wc_target.rs_length; - } - - post->ctx.count += wc_array->wc_nchunks; - } - - ptr = (uint32_t *)post->ctx.vector[0].iov_base; - request_info.xid = ntoh32(*ptr); - - ret = rpc_transport_notify(peer->trans, RPC_TRANSPORT_MAP_XID_REQUEST, - &request_info); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, TRANS_MSG_TRANSPORT_ERROR, - "cannot get request " - "information (peer:%s) from rpc layer", - peer->trans->peerinfo.identifier); - goto out; - } - - rpc_req = request_info.rpc_req; - if (rpc_req == NULL) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_RPC_ST_ERROR, - "rpc request structure not " - "found"); - ret = -1; - goto out; - } - - ctx = rpc_req->conn_private; - if ((post->ctx.iobref == NULL) && ctx->rsp_iobref) { - post->ctx.iobref = iobref_ref(ctx->rsp_iobref); - } - - ret = 0; - - gf_rdma_reply_info_destroy(reply_info); - -out: - if (ret == 0) { - ret = gf_rdma_pollin_notify(peer, post); - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_POLL_IN_NOTIFY_FAILED, "pollin notify failed"); - } - } - - return ret; -} - -static int32_t -gf_rdma_recv_request(gf_rdma_peer_t *peer, gf_rdma_post_t *post, - gf_rdma_read_chunk_t *readch) -{ - int32_t ret = -1; - - if (readch != NULL) { - ret = gf_rdma_do_reads(peer, post, readch); - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_PEER_READ_FAILED, "rdma read from peer (%s) failed", - peer->trans->peerinfo.identifier); - } - } else { - ret = gf_rdma_pollin_notify(peer, post); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_POLL_IN_NOTIFY_FAILED, - "pollin notification failed"); - } - } - - return ret; -} - -void -gf_rdma_process_recv(gf_rdma_peer_t *peer, struct ibv_wc *wc) -{ - gf_rdma_post_t *post = NULL; - gf_rdma_read_chunk_t *readch = NULL; - int ret = -1; - uint32_t *ptr = NULL; - enum msg_type msg_type = 0; - gf_rdma_header_t *header = NULL; - gf_rdma_private_t *priv = NULL; - - post = (gf_rdma_post_t *)(long)wc->wr_id; - if (post == NULL) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_POST_MISSING, - "no post found in successful " - "work completion element"); - goto out; - } - - ret = gf_rdma_decode_header(peer, post, &readch, wc->byte_len); - if (ret == -1) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_HEADER_DECODE_FAILED, - "decoding of header " - "failed"); - goto out; - } - - header = (gf_rdma_header_t *)post->buf; - - priv = peer->trans->private; - - pthread_mutex_lock(&priv->write_mutex); - { - if (!priv->peer.quota_set) { - priv->peer.quota_set = 1; - - /* Initially peer.quota is set to 1 as per RFC 5666. We - * have to account for the quota used while sending - * first msg (which may or may not be returned to pool - * at this point) while deriving peer.quota from - * header->rm_credit. Hence the arithmetic below, - * instead of directly setting it to header->rm_credit. - */ - priv->peer.quota = header->rm_credit - (1 - priv->peer.quota); - } - } - pthread_mutex_unlock(&priv->write_mutex); - - switch (header->rm_type) { - case GF_RDMA_MSG: - ptr = (uint32_t *)post->ctx.vector[0].iov_base; - msg_type = ntoh32(*(ptr + 1)); - break; - - case GF_RDMA_NOMSG: - if (readch != NULL) { - msg_type = CALL; - } else { - msg_type = REPLY; - } - break; - - case GF_RDMA_ERROR: - if (header->rm_body.rm_error.rm_type == ERR_CHUNK) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_RDMA_ERROR_RECEIVED, - "peer (%s), couldn't encode or decode the msg " - "properly or write chunks were not provided " - "for replies that were bigger than " - "RDMA_INLINE_THRESHOLD (%d)", - peer->trans->peerinfo.identifier, - GLUSTERFS_RDMA_INLINE_THRESHOLD); - ret = gf_rdma_pollin_notify(peer, post); - if (ret == -1) { - gf_msg_debug(GF_RDMA_LOG_NAME, 0, - "pollin " - "notification failed"); - } - goto out; - } else { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, 0, - TRANS_MSG_TRANSPORT_ERROR, - "an error has " - "happened while transmission of msg, " - "disconnecting the transport"); - ret = -1; - goto out; - } - - default: - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_INVALID_ENTRY, - "invalid rdma msg-type (%d)", header->rm_type); - goto out; - } - - if (msg_type == CALL) { - ret = gf_rdma_recv_request(peer, post, readch); - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_PEER_REQ_FAILED, - "receiving a request" - " from peer (%s) failed", - peer->trans->peerinfo.identifier); - } - } else { - ret = gf_rdma_recv_reply(peer, post); - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_PEER_REP_FAILED, - "receiving a reply " - "from peer (%s) failed", - peer->trans->peerinfo.identifier); - } - } - -out: - if (ret == -1) { - rpc_transport_disconnect(peer->trans, _gf_false); - } - - return; -} - -void * -gf_rdma_async_event_thread(void *context) -{ - struct ibv_async_event event; - int ret; - - while (1) { - do { - ret = ibv_get_async_event((struct ibv_context *)context, &event); - - if (ret && errno != EINTR) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno, - RDMA_MSG_EVENT_ERROR, - "Error getting " - "event"); - } - } while (ret && errno == EINTR); - - switch (event.event_type) { - case IBV_EVENT_SRQ_LIMIT_REACHED: - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_EVENT_SRQ_LIMIT_REACHED, - "received " - "srq_limit reached"); - break; - - default: - gf_msg_debug(GF_RDMA_LOG_NAME, 0, - "event (%d) " - "received", - event.event_type); - break; - } - - ibv_ack_async_event(&event); - } - - return 0; -} - -static void * -gf_rdma_recv_completion_proc(void *data) -{ - struct ibv_comp_channel *chan = NULL; - gf_rdma_device_t *device = NULL; - ; - gf_rdma_post_t *post = NULL; - gf_rdma_peer_t *peer = NULL; - struct ibv_cq *event_cq = NULL; - struct ibv_wc wc[10] = { - {0}, - }; - void *event_ctx = NULL; - int32_t ret = 0; - int32_t num_wr = 0, index = 0; - uint8_t failed = 0; - - chan = data; - - while (1) { - failed = 0; - ret = ibv_get_cq_event(chan, &event_cq, &event_ctx); - if (ret) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno, - RDMA_MSG_IBV_GET_CQ_FAILED, - "ibv_get_cq_event failed, terminating recv " - "thread %d (%d)", - ret, errno); - continue; - } - - device = event_ctx; - - ret = ibv_req_notify_cq(event_cq, 0); - if (ret) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno, - RDMA_MSG_IBV_REQ_NOTIFY_CQ_FAILED, - "ibv_req_notify_cq on %s failed, terminating " - "recv thread: %d (%d)", - device->device_name, ret, errno); - continue; - } - - device = (gf_rdma_device_t *)event_ctx; - - while (!failed && (num_wr = ibv_poll_cq(event_cq, 10, wc)) > 0) { - for (index = 0; index < num_wr && !failed; index++) { - post = (gf_rdma_post_t *)(long)wc[index].wr_id; - - pthread_mutex_lock(&device->qpreg.lock); - { - peer = __gf_rdma_lookup_peer(device, wc[index].qp_num); - - /* - * keep a refcount on transport so that it - * does not get freed because of some error - * indicated by wc.status till we are done - * with usage of peer and thereby that of - * trans. - */ - if (peer != NULL) { - rpc_transport_ref(peer->trans); - } - } - pthread_mutex_unlock(&device->qpreg.lock); - - if (wc[index].status != IBV_WC_SUCCESS) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, 0, - RDMA_MSG_RECV_ERROR, - "recv work " - "request on `%s' returned error (%d)", - device->device_name, wc[index].status); - failed = 1; - if (peer) { - ibv_ack_cq_events(event_cq, num_wr); - rpc_transport_disconnect(peer->trans, _gf_false); - rpc_transport_unref(peer->trans); - } - - if (post) { - gf_rdma_post_unref(post); - } - - continue; - } - - if (peer) { - gf_rdma_process_recv(peer, &wc[index]); - rpc_transport_unref(peer->trans); - } else { - gf_msg_debug(GF_RDMA_LOG_NAME, 0, - "could not lookup peer " - "for qp_num: %d", - wc[index].qp_num); - } - - gf_rdma_post_unref(post); - } - } - - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno, - RDMA_MSG_IBV_POLL_CQ_ERROR, - "ibv_poll_cq on `%s' returned error " - "(ret = %d, errno = %d)", - device->device_name, ret, errno); - continue; - } - if (!failed) - ibv_ack_cq_events(event_cq, num_wr); - } - - return NULL; -} - -void -gf_rdma_handle_failed_send_completion(gf_rdma_peer_t *peer, struct ibv_wc *wc) -{ - gf_rdma_post_t *post = NULL; - gf_rdma_device_t *device = NULL; - gf_rdma_private_t *priv = NULL; - - if (peer != NULL) { - priv = peer->trans->private; - if (priv != NULL) { - device = priv->device; - } - } - - post = (gf_rdma_post_t *)(long)wc->wr_id; - - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_RDMA_HANDLE_FAILED, - "send work request on `%s' returned error " - "wc.status = %d, wc.vendor_err = %d, post->buf = %p, " - "wc.byte_len = %d, post->reused = %d", - (device != NULL) ? device->device_name : NULL, wc->status, - wc->vendor_err, post->buf, wc->byte_len, post->reused); - - if (wc->status == IBV_WC_RETRY_EXC_ERR) { - gf_msg("rdma", GF_LOG_ERROR, 0, TRANS_MSG_TIMEOUT_EXCEEDED, - "connection between client and server not working. " - "check by running 'ibv_srq_pingpong'. also make sure " - "subnet manager is running (eg: 'opensm'), or check " - "if rdma port is valid (or active) by running " - "'ibv_devinfo'. contact Gluster Support Team if the " - "problem persists."); - } - - if (peer) { - rpc_transport_disconnect(peer->trans, _gf_false); - } - - return; -} - -void -gf_rdma_handle_successful_send_completion(gf_rdma_peer_t *peer, - struct ibv_wc *wc) -{ - gf_rdma_post_t *post = NULL; - int reads = 0, ret = 0; - gf_rdma_header_t *header = NULL; - - if (wc->opcode != IBV_WC_RDMA_READ) { - goto out; - } - - post = (gf_rdma_post_t *)(long)wc->wr_id; - - pthread_mutex_lock(&post->lock); - { - reads = --post->ctx.gf_rdma_reads; - } - pthread_mutex_unlock(&post->lock); - - if (reads != 0) { - /* if it is not the last rdma read, we've got nothing to do */ - goto out; - } - - header = (gf_rdma_header_t *)post->buf; - - if (header->rm_type == GF_RDMA_NOMSG) { - post->ctx.count = 1; - post->ctx.vector[0].iov_len += post->ctx.vector[1].iov_len; - } - /* - * if reads performed as vectored, then all the buffers are actually - * contiguous memory, so that we can use it as single vector, instead - * of multiple. - */ - while (post->ctx.count > 2) { - post->ctx.vector[1].iov_len += post->ctx.vector[post->ctx.count - 1] - .iov_len; - post->ctx.count--; - } - - ret = gf_rdma_pollin_notify(peer, post); - if ((ret == -1) && (peer != NULL)) { - rpc_transport_disconnect(peer->trans, _gf_false); - } - -out: - return; -} - -static void * -gf_rdma_send_completion_proc(void *data) -{ - struct ibv_comp_channel *chan = NULL; - gf_rdma_post_t *post = NULL; - gf_rdma_peer_t *peer = NULL; - struct ibv_cq *event_cq = NULL; - void *event_ctx = NULL; - gf_rdma_device_t *device = NULL; - struct ibv_wc wc[10] = { - {0}, - }; - char is_request = 0; - int32_t ret = 0, quota_ret = 0, num_wr = 0; - int32_t index = 0, failed = 0; - chan = data; - while (1) { - failed = 0; - ret = ibv_get_cq_event(chan, &event_cq, &event_ctx); - if (ret) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno, - RDMA_MSG_IBV_GET_CQ_FAILED, - "ibv_get_cq_event on failed, terminating " - "send thread: %d (%d)", - ret, errno); - continue; - } - - device = event_ctx; - - ret = ibv_req_notify_cq(event_cq, 0); - if (ret) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno, - RDMA_MSG_IBV_REQ_NOTIFY_CQ_FAILED, - "ibv_req_notify_cq on %s failed, terminating " - "send thread: %d (%d)", - device->device_name, ret, errno); - continue; - } - - while (!failed && (num_wr = ibv_poll_cq(event_cq, 10, wc)) > 0) { - for (index = 0; index < num_wr && !failed; index++) { - post = (gf_rdma_post_t *)(long)wc[index].wr_id; - - pthread_mutex_lock(&device->qpreg.lock); - { - peer = __gf_rdma_lookup_peer(device, wc[index].qp_num); - - /* - * keep a refcount on transport so that it - * does not get freed because of some error - * indicated by wc.status, till we are done - * with usage of peer and thereby that of trans. - */ - if (peer != NULL) { - rpc_transport_ref(peer->trans); - } - } - pthread_mutex_unlock(&device->qpreg.lock); - - if (wc[index].status != IBV_WC_SUCCESS) { - ibv_ack_cq_events(event_cq, num_wr); - failed = 1; - gf_rdma_handle_failed_send_completion(peer, &wc[index]); - } else { - gf_rdma_handle_successful_send_completion(peer, &wc[index]); - } - - if (post) { - is_request = post->ctx.is_request; - - ret = gf_rdma_post_unref(post); - if ((ret == 0) && (wc[index].status == IBV_WC_SUCCESS) && - !is_request && (post->type == GF_RDMA_SEND_POST) && - (peer != NULL)) { - /* An GF_RDMA_RECV_POST can end up in - * gf_rdma_send_completion_proc for - * rdma-reads, and we do not take - * quota for getting an GF_RDMA_RECV_POST. - */ - - /* - * if it is request, quota is returned - * after reply has come. - */ - quota_ret = gf_rdma_quota_put(peer); - if (quota_ret < 0) { - gf_msg_debug("rdma", 0, - "failed to send " - "message"); - } - } - } - - if (peer) { - rpc_transport_unref(peer->trans); - } else { - gf_msg_debug(GF_RDMA_LOG_NAME, 0, - "could not lookup peer for qp_num: %d", - wc[index].qp_num); - } - } - } - - if (ret < 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno, - RDMA_MSG_IBV_POLL_CQ_ERROR, - "ibv_poll_cq on `%s' returned error (ret = %d," - " errno = %d)", - device->device_name, ret, errno); - continue; - } - if (!failed) - ibv_ack_cq_events(event_cq, num_wr); - } - - return NULL; -} - -static void -gf_rdma_options_init(rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - gf_rdma_options_t *options = NULL; - int32_t mtu = 0; - data_t *temp = NULL; - - /* TODO: validate arguments from options below */ - - priv = this->private; - options = &priv->options; - options->send_size = - GLUSTERFS_RDMA_INLINE_THRESHOLD; /*this->ctx->page_size * 4; 512 KB*/ - options->recv_size = - GLUSTERFS_RDMA_INLINE_THRESHOLD; /*this->ctx->page_size * 4; 512 KB*/ - options->send_count = 4096; - options->recv_count = 4096; - options->attr_timeout = GF_RDMA_TIMEOUT; - options->attr_retry_cnt = GF_RDMA_RETRY_CNT; - options->attr_rnr_retry = GF_RDMA_RNR_RETRY; - - temp = dict_get(this->options, "transport.listen-backlog"); - if (temp) - options->backlog = data_to_uint32(temp); - else - options->backlog = GLUSTERFS_SOCKET_LISTEN_BACKLOG; - - temp = dict_get(this->options, "transport.rdma.work-request-send-count"); - if (temp) - options->send_count = data_to_int32(temp); - - temp = dict_get(this->options, "transport.rdma.work-request-recv-count"); - if (temp) - options->recv_count = data_to_int32(temp); - - temp = dict_get(this->options, "transport.rdma.attr-timeout"); - - if (temp) - options->attr_timeout = data_to_uint8(temp); - - temp = dict_get(this->options, "transport.rdma.attr-retry-cnt"); - - if (temp) - options->attr_retry_cnt = data_to_uint8(temp); - - temp = dict_get(this->options, "transport.rdma.attr-rnr-retry"); - - if (temp) - options->attr_rnr_retry = data_to_uint8(temp); - - options->port = 1; - temp = dict_get(this->options, "transport.rdma.port"); - if (temp) - options->port = data_to_uint64(temp); - - options->mtu = mtu = IBV_MTU_2048; - temp = dict_get(this->options, "transport.rdma.mtu"); - if (temp) - mtu = data_to_int32(temp); - switch (mtu) { - case 256: - options->mtu = IBV_MTU_256; - break; - - case 512: - options->mtu = IBV_MTU_512; - break; - - case 1024: - options->mtu = IBV_MTU_1024; - break; - - case 2048: - options->mtu = IBV_MTU_2048; - break; - - case 4096: - options->mtu = IBV_MTU_4096; - break; - default: - if (temp) - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, - RDMA_MSG_UNRECG_MTU_VALUE, - "%s: unrecognized " - "MTU value '%s', defaulting to '2048'", - this->name, data_to_str(temp)); - else - gf_msg_trace(GF_RDMA_LOG_NAME, 0, - "%s: defaulting " - "MTU to '2048'", - this->name); - options->mtu = IBV_MTU_2048; - break; - } - - temp = dict_get(this->options, "transport.rdma.device-name"); - if (temp) - options->device_name = gf_strdup(temp->data); - - return; -} - -gf_rdma_ctx_t * -__gf_rdma_ctx_create(void) -{ - gf_rdma_ctx_t *rdma_ctx = NULL; - int ret = -1; - - rdma_ctx = GF_CALLOC(1, sizeof(*rdma_ctx), gf_common_mt_char); - if (rdma_ctx == NULL) { - goto out; - } - pthread_mutex_init(&rdma_ctx->lock, NULL); - rdma_ctx->rdma_cm_event_channel = rdma_create_event_channel(); - if (rdma_ctx->rdma_cm_event_channel == NULL) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno, - RDMA_MSG_CM_EVENT_FAILED, - "rdma_cm event channel " - "creation failed"); - goto out; - } - - ret = gf_thread_create(&rdma_ctx->rdma_cm_thread, NULL, - gf_rdma_cm_event_handler, - rdma_ctx->rdma_cm_event_channel, "rdmaehan"); - if (ret != 0) { - gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, ret, RDMA_MSG_CM_EVENT_FAILED, - "creation of thread to " - "handle rdma-cm events failed"); - goto out; - } - -out: - if (ret < 0 && rdma_ctx) { - if (rdma_ctx->rdma_cm_event_channel != NULL) { - rdma_destroy_event_channel(rdma_ctx->rdma_cm_event_channel); - } - - GF_FREE(rdma_ctx); - rdma_ctx = NULL; - } - - return rdma_ctx; -} - -static int32_t -gf_rdma_init(rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - int32_t ret = 0; - glusterfs_ctx_t *ctx = NULL; - gf_rdma_options_t *options = NULL; - - ctx = this->ctx; - - priv = this->private; - - ibv_fork_init(); - gf_rdma_options_init(this); - - options = &priv->options; - priv->peer.send_count = options->send_count; - priv->peer.recv_count = options->recv_count; - priv->peer.send_size = options->send_size; - priv->peer.recv_size = options->recv_size; - priv->backlog = options->backlog; - - priv->peer.trans = this; - INIT_LIST_HEAD(&priv->peer.ioq); - - pthread_mutex_init(&priv->write_mutex, NULL); - pthread_mutex_init(&priv->recv_mutex, NULL); - pthread_cond_init(&priv->recv_cond, NULL); - - LOCK(&ctx->lock); - { - if (ctx->ib == NULL) { - ctx->ib = __gf_rdma_ctx_create(); - if (ctx->ib == NULL) { - ret = -1; - } - } - } - UNLOCK(&ctx->lock); - - return ret; -} - -static int32_t -gf_rdma_disconnect(rpc_transport_t *this, gf_boolean_t wait) -{ - gf_rdma_private_t *priv = NULL; - int32_t ret = 0; - - priv = this->private; - gf_msg_callingfn(this->name, GF_LOG_DEBUG, 0, RDMA_MSG_PEER_DISCONNECTED, - "disconnect called (peer:%s)", this->peerinfo.identifier); - - pthread_mutex_lock(&priv->write_mutex); - { - ret = __gf_rdma_disconnect(this); - } - pthread_mutex_unlock(&priv->write_mutex); - - return ret; -} - -static int32_t -gf_rdma_connect(struct rpc_transport *this, int port) -{ - gf_rdma_private_t *priv = NULL; - int32_t ret = 0; - union gf_sock_union sock_union = { - { - 0, - }, - }; - socklen_t sockaddr_len = 0; - gf_rdma_peer_t *peer = NULL; - gf_rdma_ctx_t *rdma_ctx = NULL; - gf_boolean_t connected = _gf_false; - - priv = this->private; - - peer = &priv->peer; - - rpc_transport_ref(this); - - ret = gf_rdma_client_get_remote_sockaddr(this, &sock_union.sa, - &sockaddr_len, port); - if (ret != 0) { - gf_msg_debug(this->name, 0, - "cannot get remote address to " - "connect"); - goto out; - } - - rdma_ctx = this->ctx->ib; - - pthread_mutex_lock(&priv->write_mutex); - { - if (peer->cm_id != NULL) { - ret = -1; - errno = EINPROGRESS; - connected = _gf_true; - goto unlock; - } - - priv->entity = GF_RDMA_CLIENT; - - ret = rdma_create_id(rdma_ctx->rdma_cm_event_channel, &peer->cm_id, - this, RDMA_PS_TCP); - if (ret != 0) { - gf_msg(this->name, GF_LOG_ERROR, errno, RDMA_MSG_CM_EVENT_FAILED, - "creation of " - "rdma_cm_id failed"); - ret = -errno; - goto unlock; - } - - memcpy(&this->peerinfo.sockaddr, &sock_union.storage, sockaddr_len); - this->peerinfo.sockaddr_len = sockaddr_len; - - if (port > 0) - sock_union.sin.sin_port = htons(port); - - ((struct sockaddr *)&this->myinfo.sockaddr)->sa_family = - ((struct sockaddr *)&this->peerinfo.sockaddr)->sa_family; - - ret = gf_rdma_client_bind(this, - (struct sockaddr *)&this->myinfo.sockaddr, - &this->myinfo.sockaddr_len, peer->cm_id); - if (ret != 0) { - gf_msg(this->name, GF_LOG_WARNING, errno, - RDMA_MSG_CLIENT_BIND_FAILED, "client bind failed"); - goto unlock; - } - - ret = rdma_resolve_addr(peer->cm_id, NULL, &sock_union.sa, 2000); - if (ret != 0) { - gf_msg(this->name, GF_LOG_WARNING, errno, - RDMA_MSG_RDMA_RESOLVE_ADDR_FAILED, - "rdma_resolve_addr failed"); - goto unlock; - } - - priv->connected = 0; - } -unlock: - pthread_mutex_unlock(&priv->write_mutex); - -out: - if (ret != 0) { - if (!connected) { - gf_rdma_teardown(this); - } - - rpc_transport_unref(this); - } - - return ret; -} - -static int32_t -gf_rdma_listen(rpc_transport_t *this) -{ - union gf_sock_union sock_union = { - { - 0, - }, - }; - socklen_t sockaddr_len = 0; - gf_rdma_private_t *priv = NULL; - gf_rdma_peer_t *peer = NULL; - int ret = 0; - gf_rdma_ctx_t *rdma_ctx = NULL; - cmd_args_t *cmd_args = NULL; - char service[NI_MAXSERV], host[NI_MAXHOST]; - int optval = 2; - - priv = this->private; - peer = &priv->peer; - - priv->entity = GF_RDMA_SERVER_LISTENER; - - rdma_ctx = this->ctx->ib; - - ret = gf_rdma_server_get_local_sockaddr(this, &sock_union.sa, - &sockaddr_len); - if (ret != 0) { - gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_NW_ADDR_UNKNOWN, - "cannot find network address of server to bind to"); - goto err; - } - - ret = rdma_create_id(rdma_ctx->rdma_cm_event_channel, &peer->cm_id, this, - RDMA_PS_TCP); - if (ret != 0) { - gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_CM_EVENT_FAILED, - "creation of rdma_cm_id " - "failed"); - goto err; - } - - memcpy(&this->myinfo.sockaddr, &sock_union.storage, sockaddr_len); - this->myinfo.sockaddr_len = sockaddr_len; - - ret = getnameinfo((struct sockaddr *)&this->myinfo.sockaddr, - this->myinfo.sockaddr_len, host, sizeof(host), service, - sizeof(service), NI_NUMERICHOST); - if (ret != 0) { - gf_msg(this->name, GF_LOG_ERROR, ret, TRANS_MSG_GET_NAME_INFO_FAILED, - "getnameinfo failed"); - goto err; - } - - sprintf(this->myinfo.identifier, "%s:%s", host, service); - - ret = rdma_set_option(peer->cm_id, RDMA_OPTION_ID, RDMA_OPTION_ID_REUSEADDR, - (void *)&optval, sizeof(optval)); - if (ret != 0) { - gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_OPTION_SET_FAILED, - "rdma option set failed"); - goto err; - } - - ret = rdma_bind_addr(peer->cm_id, &sock_union.sa); - if (ret != 0) { - gf_msg(this->name, GF_LOG_WARNING, errno, - RDMA_MSG_RDMA_BIND_ADDR_FAILED, "rdma_bind_addr failed"); - goto err; - } - ret = rdma_listen(peer->cm_id, priv->backlog); - if (ret != 0) { - gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_LISTEN_FAILED, - "rdma_listen failed"); - goto err; - } - - cmd_args = &(this->ctx->cmd_args); - if (!cmd_args->brick_port2) { - cmd_args->brick_port2 = rdma_get_src_port(peer->cm_id); - gf_log(this->name, GF_LOG_INFO, - "process started listening on port (%d)", cmd_args->brick_port2); - } - - rpc_transport_ref(this); - - ret = 0; -err: - if (ret < 0) { - if (peer->cm_id != NULL) { - rdma_destroy_id(peer->cm_id); - peer->cm_id = NULL; - } - } - - return ret; -} - -struct rpc_transport_ops tops = { - .submit_request = gf_rdma_submit_request, - .submit_reply = gf_rdma_submit_reply, - .connect = gf_rdma_connect, - .disconnect = gf_rdma_disconnect, - .listen = gf_rdma_listen, -}; - -int32_t -init(rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - gf_rdma_ctx_t *rdma_ctx = NULL; - struct iobuf_pool *iobuf_pool = NULL; - - priv = GF_CALLOC(1, sizeof(*priv), gf_common_mt_rdma_private_t); - if (!priv) - return -1; - - this->private = priv; - - if (gf_rdma_init(this)) { - gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_INIT_IB_DEVICE_FAILED, - "Failed to initialize IB Device"); - this->private = NULL; - GF_FREE(priv); - return -1; - } - rdma_ctx = this->ctx->ib; - if (!rdma_ctx) - return -1; - - pthread_mutex_lock(&rdma_ctx->lock); - { - if (this->dl_handle && (++(rdma_ctx->dlcount)) == 1) { - iobuf_pool = this->ctx->iobuf_pool; - iobuf_pool->rdma_registration = gf_rdma_register_arena; - iobuf_pool->rdma_deregistration = gf_rdma_deregister_arena; - gf_rdma_register_iobuf_pool_with_device(rdma_ctx->device, - iobuf_pool); - } - } - pthread_mutex_unlock(&rdma_ctx->lock); - - return 0; -} - -int -reconfigure(rpc_transport_t *this, dict_t *options) -{ - gf_rdma_private_t *priv = NULL; - uint32_t backlog = 0; - int ret = -1; - - GF_VALIDATE_OR_GOTO("rdma", this, out); - GF_VALIDATE_OR_GOTO("rdma", this->private, out); - - priv = this->private; - - if (dict_get_uint32(options, "transport.listen-backlog", &backlog) == 0) { - priv->backlog = backlog; - gf_log(this->name, GF_LOG_DEBUG, - "Reconfigued " - "transport.listen-backlog=%d", - priv->backlog); - } - ret = 0; -out: - return ret; -} -void -fini(struct rpc_transport *this) -{ - /* TODO: verify this function does graceful finish */ - gf_rdma_private_t *priv = NULL; - struct iobuf_pool *iobuf_pool = NULL; - gf_rdma_ctx_t *rdma_ctx = NULL; - - priv = this->private; - - this->private = NULL; - - if (priv) { - pthread_mutex_destroy(&priv->recv_mutex); - pthread_mutex_destroy(&priv->write_mutex); - - gf_msg_trace(this->name, 0, "called fini on transport: %p", this); - GF_FREE(priv); - } - - rdma_ctx = this->ctx->ib; - if (!rdma_ctx) - return; - - pthread_mutex_lock(&rdma_ctx->lock); - { - if (this->dl_handle && (--(rdma_ctx->dlcount)) == 0) { - iobuf_pool = this->ctx->iobuf_pool; - gf_rdma_deregister_iobuf_pool(rdma_ctx->device); - iobuf_pool->rdma_registration = NULL; - iobuf_pool->rdma_deregistration = NULL; - } - } - pthread_mutex_unlock(&rdma_ctx->lock); - - return; -} - -/* TODO: expand each option */ -struct volume_options options[] = { - {.key = {"transport.rdma.port", "rdma-port"}, - .type = GF_OPTION_TYPE_INT, - .min = 1, - .max = 4, - .description = "check the option by 'ibv_devinfo'"}, - { - .key = {"transport.rdma.mtu", "rdma-mtu"}, - .type = GF_OPTION_TYPE_INT, - }, - {.key = {"transport.rdma.device-name", "rdma-device-name"}, - .type = GF_OPTION_TYPE_ANY, - .description = "check by 'ibv_devinfo'"}, - { - .key = {"transport.rdma.work-request-send-count", - "rdma-work-request-send-count"}, - .type = GF_OPTION_TYPE_INT, - }, - { - .key = {"transport.rdma.work-request-recv-count", - "rdma-work-request-recv-count"}, - .type = GF_OPTION_TYPE_INT, - }, - {.key = {"remote-port", "transport.remote-port", - "transport.rdma.remote-port"}, - .type = GF_OPTION_TYPE_INT}, - {.key = {"transport.rdma.attr-timeout", "rdma-attr-timeout"}, - .type = GF_OPTION_TYPE_INT}, - {.key = {"transport.rdma.attr-retry-cnt", "rdma-attr-retry-cnt"}, - .type = GF_OPTION_TYPE_INT}, - {.key = {"transport.rdma.attr-rnr-retry", "rdma-attr-rnr-retry"}, - .type = GF_OPTION_TYPE_INT}, - {.key = {"transport.rdma.listen-port", "listen-port"}, - .type = GF_OPTION_TYPE_INT}, - {.key = {"transport.rdma.connect-path", "connect-path"}, - .type = GF_OPTION_TYPE_ANY}, - {.key = {"transport.rdma.bind-path", "bind-path"}, - .type = GF_OPTION_TYPE_ANY}, - {.key = {"transport.rdma.listen-path", "listen-path"}, - .type = GF_OPTION_TYPE_ANY}, - {.key = {"transport.address-family", "address-family"}, - .value = {"inet", "inet6", "inet/inet6", "inet6/inet", "unix", "inet-sdp"}, - .type = GF_OPTION_TYPE_STR}, - {.key = {"transport.socket.lowlat"}, .type = GF_OPTION_TYPE_BOOL}, - {.key = {NULL}}}; diff --git a/rpc/rpc-transport/rdma/src/rdma.h b/rpc/rpc-transport/rdma/src/rdma.h deleted file mode 100644 index 84c1397054b..00000000000 --- a/rpc/rpc-transport/rdma/src/rdma.h +++ /dev/null @@ -1,384 +0,0 @@ -/* - Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> - This file is part of GlusterFS. - - This file is licensed to you under your choice of the GNU Lesser - General Public License, version 3 or any later version (LGPLv3 or - later), or the GNU General Public License, version 2 (GPLv2), in all - cases as published by the Free Software Foundation. -*/ - -#ifndef _XPORT_RDMA_H -#define _XPORT_RDMA_H - -#ifndef MAX_IOVEC -#define MAX_IOVEC 16 -#endif /* MAX_IOVEC */ - -#include "rpc-clnt.h" -#include "rpc-transport.h" -#include "xlator.h" -#include "gf-event.h" -#include <stdio.h> -#include <list.h> -#include <arpa/inet.h> -#include <infiniband/verbs.h> -#include <rdma/rdma_cma.h> - -/* FIXME: give appropriate values to these macros */ -#define GF_DEFAULT_RDMA_LISTEN_PORT (GF_DEFAULT_BASE_PORT + 1) - -/* If you are changing GF_RDMA_MAX_SEGMENTS, please make sure to update - * GLUSTERFS_GF_RDMA_MAX_HEADER_SIZE defined in glusterfs.h . - */ -#define GF_RDMA_MAX_SEGMENTS 8 - -#define GF_RDMA_VERSION 1 -#define GF_RDMA_POOL_SIZE 512 - -/* Additional attributes */ -#define GF_RDMA_TIMEOUT 14 -#define GF_RDMA_RETRY_CNT 7 -#define GF_RDMA_RNR_RETRY 7 - -typedef enum gf_rdma_errcode { ERR_VERS = 1, ERR_CHUNK = 2 } gf_rdma_errcode_t; - -struct gf_rdma_err_vers { - uint32_t gf_rdma_vers_low; /* Version range supported by peer */ - uint32_t gf_rdma_vers_high; -} __attribute__((packed)); -typedef struct gf_rdma_err_vers gf_rdma_err_vers_t; - -typedef enum gf_rdma_proc { - GF_RDMA_MSG = 0, /* An RPC call or reply msg */ - GF_RDMA_NOMSG = 1, /* An RPC call or reply msg - separate body */ - GF_RDMA_MSGP = 2, /* An RPC call or reply msg with padding */ - GF_RDMA_DONE = 3, /* Client signals reply completion */ - GF_RDMA_ERROR = 4 /* An RPC RDMA encoding error */ -} gf_rdma_proc_t; - -typedef enum gf_rdma_chunktype { - gf_rdma_noch = 0, /* no chunk */ - gf_rdma_readch, /* some argument through rdma read */ - gf_rdma_areadch, /* entire request through rdma read */ - gf_rdma_writech, /* some result through rdma write */ - gf_rdma_replych /* entire reply through rdma write */ -} gf_rdma_chunktype_t; - -/* If you are modifying __gf_rdma_header, please make sure to change - * GLUSTERFS_GF_RDMA_MAX_HEADER_SIZE defined in glusterfs.h to reflect your - * changes - */ -struct __gf_rdma_header { - uint32_t rm_xid; /* Mirrors the RPC header xid */ - uint32_t rm_vers; /* Version of this protocol */ - uint32_t rm_credit; /* Buffers requested/granted */ - uint32_t rm_type; /* Type of message (enum gf_rdma_proc) */ - union { - struct { /* no chunks */ - uint32_t rm_empty[3]; /* 3 empty chunk lists */ - } __attribute__((packed)) rm_nochunks; - - struct { /* no chunks and padded */ - uint32_t rm_align; /* Padding alignment */ - uint32_t rm_thresh; /* Padding threshold */ - uint32_t rm_pempty[3]; /* 3 empty chunk lists */ - } __attribute__((packed)) rm_padded; - - struct { - uint32_t rm_type; - gf_rdma_err_vers_t rm_version; - } __attribute__((packed)) rm_error; - - uint32_t rm_chunks[0]; /* read, write and reply chunks */ - } __attribute__((packed)) rm_body; -} __attribute__((packed)); -typedef struct __gf_rdma_header gf_rdma_header_t; - -/* If you are modifying __gf_rdma_segment or __gf_rdma_read_chunk, please make - * sure to change GLUSTERFS_GF_RDMA_MAX_HEADER_SIZE defined in glusterfs.h to - * reflect your changes. - */ -struct __gf_rdma_segment { - uint32_t rs_handle; /* Registered memory handle */ - uint32_t rs_length; /* Length of the chunk in bytes */ - uint64_t rs_offset; /* Chunk virtual address or offset */ -} __attribute__((packed)); -typedef struct __gf_rdma_segment gf_rdma_segment_t; - -/* read chunk(s), encoded as a linked list. */ -struct __gf_rdma_read_chunk { - uint32_t rc_discrim; /* 1 indicates presence */ - uint32_t rc_position; /* Position in XDR stream */ - gf_rdma_segment_t rc_target; -} __attribute__((packed)); -typedef struct __gf_rdma_read_chunk gf_rdma_read_chunk_t; - -/* write chunk, and reply chunk. */ -struct __gf_rdma_write_chunk { - gf_rdma_segment_t wc_target; -} __attribute__((packed)); -typedef struct __gf_rdma_write_chunk gf_rdma_write_chunk_t; - -/* write chunk(s), encoded as a counted array. */ -struct __gf_rdma_write_array { - uint32_t wc_discrim; /* 1 indicates presence */ - uint32_t wc_nchunks; /* Array count */ - struct __gf_rdma_write_chunk wc_array[0]; -} __attribute__((packed)); -typedef struct __gf_rdma_write_array gf_rdma_write_array_t; - -/* options per transport end point */ -struct __gf_rdma_options { - int32_t port; - char *device_name; - enum ibv_mtu mtu; - int32_t send_count; - int32_t recv_count; - uint64_t recv_size; - uint64_t send_size; - uint8_t attr_timeout; - uint8_t attr_retry_cnt; - uint8_t attr_rnr_retry; - uint32_t backlog; -}; -typedef struct __gf_rdma_options gf_rdma_options_t; - -struct __gf_rdma_reply_info { - uint32_t rm_xid; /* xid in network endian */ - gf_rdma_chunktype_t type; /* - * can be either gf_rdma_replych - * or gf_rdma_writech. - */ - gf_rdma_write_array_t *wc_array; - struct mem_pool *pool; -}; -typedef struct __gf_rdma_reply_info gf_rdma_reply_info_t; - -struct __gf_rdma_ioq { - union { - struct list_head list; - struct { - struct __gf_rdma_ioq *next; - struct __gf_rdma_ioq *prev; - }; - }; - - char is_request; - struct iovec rpchdr[MAX_IOVEC]; - int rpchdr_count; - struct iovec proghdr[MAX_IOVEC]; - int proghdr_count; - struct iovec prog_payload[MAX_IOVEC]; - int prog_payload_count; - - struct iobref *iobref; - - union { - struct __gf_rdma_ioq_request { - /* used to build reply_chunk for GF_RDMA_NOMSG type msgs */ - struct iovec rsphdr_vec[MAX_IOVEC]; - int rsphdr_count; - - /* - * used to build write_array during operations like - * read. - */ - struct iovec rsp_payload[MAX_IOVEC]; - int rsp_payload_count; - - struct rpc_req *rpc_req; /* FIXME: hack! hack! should be - * cleaned up later - */ - struct iobref *rsp_iobref; - } request; - - gf_rdma_reply_info_t *reply_info; - } msg; - - struct mem_pool *pool; -}; -typedef struct __gf_rdma_ioq gf_rdma_ioq_t; - -typedef enum __gf_rdma_send_post_type { - GF_RDMA_SEND_POST_NO_CHUNKLIST, /* post which is sent using rdma-send - * and the msg carries no - * chunklists. - */ - GF_RDMA_SEND_POST_READ_CHUNKLIST, /* post which is sent using rdma-send - * and the msg carries only read - * chunklist. - */ - GF_RDMA_SEND_POST_WRITE_CHUNKLIST, /* post which is sent using - * rdma-send and the msg carries - * only write chunklist. - */ - GF_RDMA_SEND_POST_READ_WRITE_CHUNKLIST, /* post which is sent using - * rdma-send and the msg - * carries both read and - * write chunklists. - */ - GF_RDMA_SEND_POST_GF_RDMA_READ, /* RDMA read */ - GF_RDMA_SEND_POST_GF_RDMA_WRITE, /* RDMA write */ -} gf_rdma_send_post_type_t; - -/* represents one communication peer, two per transport_t */ -struct __gf_rdma_peer { - rpc_transport_t *trans; - struct rdma_cm_id *cm_id; - struct ibv_qp *qp; - pthread_t rdma_event_thread; - char quota_set; - - int32_t recv_count; - int32_t send_count; - int32_t recv_size; - int32_t send_size; - - int32_t quota; - union { - struct list_head ioq; - struct { - gf_rdma_ioq_t *ioq_next; - gf_rdma_ioq_t *ioq_prev; - }; - }; - - /* QP attributes, needed to connect with remote QP */ - int32_t local_lid; - int32_t local_psn; - int32_t local_qpn; - int32_t remote_lid; - int32_t remote_psn; - int32_t remote_qpn; -}; -typedef struct __gf_rdma_peer gf_rdma_peer_t; - -struct __gf_rdma_post_context { - struct ibv_mr *mr[GF_RDMA_MAX_SEGMENTS]; - int mr_count; - struct iovec vector[MAX_IOVEC]; - int count; - struct iobref *iobref; - struct iobuf *hdr_iobuf; - char is_request; - int gf_rdma_reads; - gf_rdma_reply_info_t *reply_info; -}; -typedef struct __gf_rdma_post_context gf_rdma_post_context_t; - -typedef enum { GF_RDMA_SEND_POST, GF_RDMA_RECV_POST } gf_rdma_post_type_t; - -struct __gf_rdma_post { - struct __gf_rdma_post *next, *prev; - struct ibv_mr *mr; - char *buf; - int32_t buf_size; - char aux; - int32_t reused; - struct __gf_rdma_device *device; - gf_rdma_post_type_t type; - gf_rdma_post_context_t ctx; - int refcount; - pthread_mutex_t lock; -}; -typedef struct __gf_rdma_post gf_rdma_post_t; - -struct __gf_rdma_queue { - gf_rdma_post_t active_posts, passive_posts; - int32_t active_count, passive_count; - pthread_mutex_t lock; -}; -typedef struct __gf_rdma_queue gf_rdma_queue_t; - -struct __gf_rdma_qpreg { - pthread_mutex_t lock; - int32_t count; - struct _qpent { - struct _qpent *next, *prev; - int32_t qp_num; - gf_rdma_peer_t *peer; - } ents[42]; -}; -typedef struct __gf_rdma_qpreg gf_rdma_qpreg_t; - -/* context per device, stored in global glusterfs_ctx_t->ib */ -struct __gf_rdma_device { - struct __gf_rdma_device *next; - const char *device_name; - struct ibv_context *context; - int32_t port; - struct ibv_pd *pd; - struct ibv_srq *srq; - gf_rdma_qpreg_t qpreg; - struct ibv_comp_channel *send_chan, *recv_chan; - struct ibv_cq *send_cq, *recv_cq; - gf_rdma_queue_t sendq, recvq; - pthread_t send_thread, recv_thread, async_event_thread; - struct mem_pool *request_ctx_pool; - struct mem_pool *ioq_pool; - struct mem_pool *reply_info_pool; - struct list_head all_mr; - pthread_mutex_t all_mr_lock; -}; -typedef struct __gf_rdma_device gf_rdma_device_t; - -struct __gf_rdma_arena_mr { - struct list_head list; - struct iobuf_arena *iobuf_arena; - struct ibv_mr *mr; -}; - -typedef struct __gf_rdma_arena_mr gf_rdma_arena_mr; -struct __gf_rdma_ctx { - gf_rdma_device_t *device; - struct rdma_event_channel *rdma_cm_event_channel; - pthread_t rdma_cm_thread; - pthread_mutex_t lock; - int32_t dlcount; -}; -typedef struct __gf_rdma_ctx gf_rdma_ctx_t; - -struct __gf_rdma_request_context { - struct ibv_mr *mr[GF_RDMA_MAX_SEGMENTS]; - int mr_count; - struct mem_pool *pool; - gf_rdma_peer_t *peer; - struct iobref *iobref; - struct iobref *rsp_iobref; -}; -typedef struct __gf_rdma_request_context gf_rdma_request_context_t; - -typedef enum { - GF_RDMA_SERVER_LISTENER, - GF_RDMA_SERVER, - GF_RDMA_CLIENT, -} gf_rdma_transport_entity_t; - -struct __gf_rdma_private { - int32_t idx; - unsigned char connected; - in_addr_t addr; - unsigned short port; - - /* IB Verbs Driver specific variables, pointers */ - gf_rdma_peer_t peer; - struct __gf_rdma_device *device; - gf_rdma_options_t options; - - /* Used by trans->op->receive */ - char *data_ptr; - int32_t data_offset; - int32_t data_len; - - /* Mutex */ - pthread_mutex_t write_mutex; - rpc_transport_t *listener; - pthread_mutex_t recv_mutex; - pthread_cond_t recv_cond; - gf_rdma_transport_entity_t entity; - uint32_t backlog; -}; -typedef struct __gf_rdma_private gf_rdma_private_t; - -#endif /* _XPORT_GF_RDMA_H */ diff --git a/rpc/rpc-transport/rdma/src/rpc-trans-rdma-messages.h b/rpc/rpc-transport/rdma/src/rpc-trans-rdma-messages.h deleted file mode 100644 index 6e9ea9a2925..00000000000 --- a/rpc/rpc-transport/rdma/src/rpc-trans-rdma-messages.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright (c) 2015 Red Hat, Inc. <http://www.redhat.com> - This file is part of GlusterFS. - - This file is licensed to you under your choice of the GNU Lesser - General Public License, version 3 or any later version (LGPLv3 or - later), or the GNU General Public License, version 2 (GPLv2), in all - cases as published by the Free Software Foundation. -*/ - -#ifndef _RPC_TRANS_RDMA_MESSAGES_H_ -#define _RPC_TRANS_RDMA_MESSAGES_H_ - -#include "glfs-message-id.h" - -/* To add new message IDs, append new identifiers at the end of the list. - * - * Never remove a message ID. If it's not used anymore, you can rename it or - * leave it as it is, but not delete it. This is to prevent reutilization of - * IDs by other messages. - * - * The component name must match one of the entries defined in - * glfs-message-id.h. - */ - -GLFS_MSGID( - RPC_TRANS_RDMA, RDMA_MSG_PORT_BIND_FAILED, RDMA_MSG_POST_CREATION_FAILED, - RDMA_MSG_DEREGISTER_ARENA_FAILED, RDMA_MSG_MR_ALOC_FAILED, - RDMA_MSG_PREREG_BUFFER_FAILED, RDMA_MSG_CQ_CREATION_FAILED, - RDMA_MSG_REQ_NOTIFY_CQ_REVQ_FAILED, RDMA_MSG_QUERY_DEVICE_FAILED, - RDMA_MSG_REQ_NOTIFY_CQ_SENDQ_FAILED, RDMA_MSG_SEND_COMP_CHAN_FAILED, - RDMA_MSG_RECV_COMP_CHAN_FAILED, RDMA_MSG_ALOC_PROT_DOM_FAILED, - RDMA_MSG_CRE_SRQ_FAILED, RDMA_MSG_ALOC_POST_FAILED, - RDMA_MSG_SEND_COMP_THREAD_FAILED, RDMA_MSG_RECV_COMP_THREAD_FAILED, - RDMA_MSG_ASYNC_EVENT_THEAD_FAILED, RDMA_MSG_GET_DEVICE_NAME_FAILED, - RDMA_MSG_GET_IB_DEVICE_FAILED, RDMA_MSG_CREAT_INC_TRANS_FAILED, - RDMA_MSG_CREAT_QP_FAILED, RDMA_MSG_ACCEPT_FAILED, RDMA_MSG_CONNECT_FAILED, - RDMA_MSG_ROUTE_RESOLVE_FAILED, RDMA_MSG_GET_DEVICE_FAILED, - RDMA_MSG_PEER_DISCONNECTED, RDMA_MSG_ENCODE_ERROR, - RDMA_MSG_POST_SEND_FAILED, RDMA_MSG_READ_CHUNK_VECTOR_FAILED, - RDMA_MSG_WRITE_CHUNK_VECTOR_FAILED, RDMA_MSG_WRITE_REPLY_CHUNCK_CONFLICT, - RDMA_MSG_CHUNK_COUNT_GREAT_MAX_SEGMENTS, RDMA_MSG_CREATE_READ_CHUNK_FAILED, - RDMA_MSG_CREATE_WRITE_REPLAY_FAILED, - RDMA_MSG_SEND_SIZE_GREAT_INLINE_THRESHOLD, - RDMA_MSG_REG_ACCESS_LOCAL_WRITE_FAILED, RDMA_MSG_WRITE_PEER_FAILED, - RDMA_MSG_SEND_REPLY_FAILED, RDMA_MSG_INVALID_CHUNK_TYPE, - RDMA_MSG_PROC_IOQ_ENTRY_FAILED, RDMA_MSG_NEW_IOQ_ENTRY_FAILED, - RDMA_MSG_RPC_REPLY_CREATE_FAILED, RDMA_MSG_GET_READ_CHUNK_FAILED, - RDMA_MSG_GET_WRITE_CHUNK_FAILED, RDMA_MSG_REPLY_INFO_ALLOC_FAILED, - RDMA_MSG_RDMA_ERROR_RECEIVED, RDMA_MSG_GET_REQ_INFO_RPC_FAILED, - RDMA_MSG_POLL_IN_NOTIFY_FAILED, RDMA_MSG_HEADER_DECODE_FAILED, - RDMA_MSG_EVENT_SRQ_LIMIT_REACHED, RDMA_MSG_UNRECG_MQ_VALUE, - RDMA_MSG_BUFFER_ERROR, RDMA_MSG_OPTION_SET_FAILED, RDMA_MSG_LISTEN_FAILED, - RDMA_MSG_INIT_IB_DEVICE_FAILED, RDMA_MSG_WRITE_CLIENT_ERROR, - RDMA_MSG_CHUNKLIST_ERROR, RDMA_MSG_INVALID_ENTRY, - RDMA_MSG_READ_CLIENT_ERROR, RDMA_MSG_RPC_ST_ERROR, - RDMA_MSG_PEER_READ_FAILED, RDMA_MSG_POST_MISSING, RDMA_MSG_PEER_REQ_FAILED, - RDMA_MSG_PEER_REP_FAILED, RDMA_MSG_EVENT_ERROR, RDMA_MSG_IBV_GET_CQ_FAILED, - RDMA_MSG_IBV_REQ_NOTIFY_CQ_FAILED, RDMA_MSG_RECV_ERROR, - RDMA_MSG_IBV_POLL_CQ_ERROR, RDMA_MSG_RDMA_HANDLE_FAILED, - RDMA_MSG_CM_EVENT_FAILED, RDMA_MSG_CLIENT_BIND_FAILED, - RDMA_MSG_RDMA_RESOLVE_ADDR_FAILED, RDMA_MSG_NW_ADDR_UNKNOWN, - RDMA_MSG_RDMA_BIND_ADDR_FAILED, RDMA_MSG_SEND_CLIENT_ERROR, - RDMA_MSG_UNRECG_MTU_VALUE); - -#endif /* !_RPC_TRANS_RDMA_MESSAGES_H_ */ diff --git a/rpc/rpc-transport/socket/src/name.c b/rpc/rpc-transport/socket/src/name.c index 3d3d108f135..9286bbb236d 100644 --- a/rpc/rpc-transport/socket/src/name.c +++ b/rpc/rpc-transport/socket/src/name.c @@ -21,7 +21,7 @@ #include "rpc-transport.h" #include "socket.h" -#include "common-utils.h" +#include <glusterfs/common-utils.h> static void _assign_port(struct sockaddr *sockaddr, uint16_t port) @@ -105,10 +105,10 @@ af_unix_client_bind(rpc_transport_t *this, struct sockaddr *sockaddr, struct sockaddr_un *addr = NULL; int32_t ret = 0; - path_data = dict_get(this->options, "transport.socket.bind-path"); + path_data = dict_get_sizen(this->options, "transport.socket.bind-path"); if (path_data) { char *path = data_to_str(path_data); - if (!path || strlen(path) > UNIX_PATH_MAX) { + if (!path || path_data->len > 108) { /* 108 = addr->sun_path length */ gf_log(this->name, GF_LOG_TRACE, "bind-path not specified for unix socket, " "letting connect to assign default value"); @@ -134,7 +134,7 @@ err: return ret; } -int32_t +static int32_t client_fill_address_family(rpc_transport_t *this, sa_family_t *sa_family) { data_t *address_family_data = NULL; @@ -145,12 +145,13 @@ client_fill_address_family(rpc_transport_t *this, sa_family_t *sa_family) goto out; } - address_family_data = dict_get(this->options, "transport.address-family"); + address_family_data = dict_get_sizen(this->options, + "transport.address-family"); if (!address_family_data) { data_t *remote_host_data = NULL, *connect_path_data = NULL; - remote_host_data = dict_get(this->options, "remote-host"); - connect_path_data = dict_get(this->options, - "transport.socket.connect-path"); + remote_host_data = dict_get_sizen(this->options, "remote-host"); + connect_path_data = dict_get_sizen(this->options, + "transport.socket.connect-path"); if (!(remote_host_data || connect_path_data) || (remote_host_data && connect_path_data)) { @@ -179,7 +180,7 @@ client_fill_address_family(rpc_transport_t *this, sa_family_t *sa_family) } } else { - char *address_family = data_to_str(address_family_data); + const char *address_family = data_to_str(address_family_data); if (!strcasecmp(address_family, "unix")) { *sa_family = AF_UNIX; } else if (!strcasecmp(address_family, "inet")) { @@ -211,11 +212,12 @@ af_inet_client_get_remote_sockaddr(rpc_transport_t *this, data_t *remote_host_data = NULL; data_t *remote_port_data = NULL; char *remote_host = NULL; - uint16_t remote_port = 0; + uint16_t remote_port = GF_DEFAULT_SOCKET_LISTEN_PORT; struct addrinfo *addr_info = NULL; int32_t ret = 0; + struct in6_addr serveraddr; - remote_host_data = dict_get(options, "remote-host"); + remote_host_data = dict_get_sizen(options, "remote-host"); if (remote_host_data == NULL) { gf_log(this->name, GF_LOG_ERROR, "option remote-host missing in volume %s", this->name); @@ -231,22 +233,27 @@ af_inet_client_get_remote_sockaddr(rpc_transport_t *this, goto err; } - remote_port_data = dict_get(options, "remote-port"); + remote_port_data = dict_get_sizen(options, "remote-port"); if (remote_port_data == NULL) { gf_log(this->name, GF_LOG_TRACE, "option remote-port missing in volume %s. Defaulting to %d", this->name, GF_DEFAULT_SOCKET_LISTEN_PORT); - - remote_port = GF_DEFAULT_SOCKET_LISTEN_PORT; } else { remote_port = data_to_uint16(remote_port_data); + if (remote_port == (uint16_t)-1) { + gf_log(this->name, GF_LOG_ERROR, + "option remote-port has invalid port in volume %s", + this->name); + ret = -1; + goto err; + } } - if (remote_port == (uint16_t)-1) { - gf_log(this->name, GF_LOG_ERROR, - "option remote-port has invalid port in volume %s", this->name); - ret = -1; - goto err; + /* Need to update transport-address family if address-family is not provided + to command-line arguments + */ + if (inet_pton(AF_INET6, remote_host, &serveraddr)) { + sockaddr->sa_family = AF_INET6; } /* TODO: gf_resolve is a blocking call. kick in some @@ -274,31 +281,29 @@ af_unix_client_get_remote_sockaddr(rpc_transport_t *this, struct sockaddr_un *sockaddr_un = NULL; char *connect_path = NULL; data_t *connect_path_data = NULL; - int32_t ret = 0; + int32_t ret = -1; - connect_path_data = dict_get(this->options, - "transport.socket.connect-path"); + connect_path_data = dict_get_sizen(this->options, + "transport.socket.connect-path"); if (!connect_path_data) { gf_log(this->name, GF_LOG_ERROR, "option transport.unix.connect-path not specified for " "address-family unix"); - ret = -1; goto err; } - connect_path = data_to_str(connect_path_data); - if (!connect_path) { + /* 108 = sockaddr_un->sun_path length */ + if ((connect_path_data->len + 1) > 108) { gf_log(this->name, GF_LOG_ERROR, - "transport.unix.connect-path is null-string"); - ret = -1; + "connect-path value length %d > %d octets", + connect_path_data->len + 1, UNIX_PATH_MAX); goto err; } - if ((strlen(connect_path) + 1) > UNIX_PATH_MAX) { + connect_path = data_to_str(connect_path_data); + if (!connect_path) { gf_log(this->name, GF_LOG_ERROR, - "connect-path value length %" GF_PRI_SIZET " > %d octets", - strlen(connect_path), UNIX_PATH_MAX); - ret = -1; + "transport.unix.connect-path is null-string"); goto err; } @@ -307,6 +312,7 @@ af_unix_client_get_remote_sockaddr(rpc_transport_t *this, strcpy(sockaddr_un->sun_path, connect_path); *sockaddr_len = sizeof(struct sockaddr_un); + ret = 0; err: return ret; } @@ -320,7 +326,8 @@ af_unix_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, int32_t ret = 0; struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr; - listen_path_data = dict_get(this->options, "transport.socket.listen-path"); + listen_path_data = dict_get_sizen(this->options, + "transport.socket.listen-path"); if (!listen_path_data) { gf_log(this->name, GF_LOG_ERROR, "missing option transport.socket.listen-path"); @@ -334,7 +341,7 @@ af_unix_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, #define UNIX_PATH_MAX 108 #endif - if ((strlen(listen_path) + 1) > UNIX_PATH_MAX) { + if ((listen_path_data->len + 1) > UNIX_PATH_MAX) { gf_log(this->name, GF_LOG_ERROR, "option transport.unix.listen-path has value length " "%" GF_PRI_SIZET " > %d", @@ -362,14 +369,19 @@ af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, dict_t *options = NULL; int32_t ret = 0; + /* initializes addr_len */ + *addr_len = 0; + options = this->options; - listen_port_data = dict_get(options, "transport.socket.listen-port"); + listen_port_data = dict_get_sizen(options, "transport.socket.listen-port"); if (listen_port_data) { listen_port = data_to_uint16(listen_port_data); + } else { + listen_port = GF_DEFAULT_SOCKET_LISTEN_PORT; } - listen_host_data = dict_get(options, "transport.socket.bind-address"); + listen_host_data = dict_get_sizen(options, "transport.socket.bind-address"); if (listen_host_data) { listen_host = data_to_str(listen_host_data); } else { @@ -413,9 +425,13 @@ af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, } } - if (!(*addr_len) && res) { - memcpy(addr, res->ai_addr, res->ai_addrlen); - *addr_len = res->ai_addrlen; + if (!(*addr_len)) { + if (res && res->ai_addr) { + memcpy(addr, res->ai_addr, res->ai_addrlen); + *addr_len = res->ai_addrlen; + } else { + ret = -1; + } } freeaddrinfo(res); @@ -518,7 +534,10 @@ socket_client_get_remote_sockaddr(rpc_transport_t *this, ret = -1; } - if (*sa_family == AF_UNSPEC) { + /* Address-family is updated based on remote_host in + af_inet_client_get_remote_sockaddr + */ + if (*sa_family != sockaddr->sa_family) { *sa_family = sockaddr->sa_family; } @@ -526,23 +545,24 @@ err: return ret; } -int32_t +static int32_t server_fill_address_family(rpc_transport_t *this, sa_family_t *sa_family) { data_t *address_family_data = NULL; int32_t ret = -1; #ifdef IPV6_DEFAULT - char *addr_family = "inet6"; + const char *addr_family = "inet6"; sa_family_t default_family = AF_INET6; #else - char *addr_family = "inet"; + const char *addr_family = "inet"; sa_family_t default_family = AF_INET; #endif GF_VALIDATE_OR_GOTO("socket", sa_family, out); - address_family_data = dict_get(this->options, "transport.address-family"); + address_family_data = dict_get_sizen(this->options, + "transport.address-family"); if (address_family_data) { char *address_family = NULL; address_family = data_to_str(address_family_data); @@ -594,7 +614,7 @@ socket_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, switch (addr->sa_family) { case AF_INET_SDP: addr->sa_family = AF_INET; - /* Fall through */ + /* Fall through */ case AF_INET: case AF_INET6: case AF_UNSPEC: @@ -614,7 +634,7 @@ err: return ret; } -int32_t +static int32_t fill_inet6_inet_identifiers(rpc_transport_t *this, struct sockaddr_storage *addr, int32_t addr_len, char *identifier) diff --git a/rpc/rpc-transport/socket/src/name.h b/rpc/rpc-transport/socket/src/name.h index 85f8bb7040b..080c7588f5a 100644 --- a/rpc/rpc-transport/socket/src/name.h +++ b/rpc/rpc-transport/socket/src/name.h @@ -11,7 +11,7 @@ #ifndef _SOCKET_NAME_H #define _SOCKET_NAME_H -#include "compat.h" +#include <glusterfs/compat.h> int32_t client_bind(rpc_transport_t *this, struct sockaddr *sockaddr, diff --git a/rpc/rpc-transport/socket/src/socket-mem-types.h b/rpc/rpc-transport/socket/src/socket-mem-types.h index 81635b72320..241ce67f670 100644 --- a/rpc/rpc-transport/socket/src/socket-mem-types.h +++ b/rpc/rpc-transport/socket/src/socket-mem-types.h @@ -11,12 +11,11 @@ #ifndef __SOCKET_MEM_TYPES_H__ #define __SOCKET_MEM_TYPES_H__ -#include "mem-types.h" +#include <glusterfs/mem-types.h> typedef enum gf_sock_mem_types_ { gf_sock_connect_error_state_t = gf_common_mt_end + 1, gf_sock_mt_lock_array, - gf_sock_mt_tid_wrap, gf_sock_mt_end } gf_sock_mem_types_t; diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c index 5887ee741f7..ed8b473be23 100644 --- a/rpc/rpc-transport/socket/src/socket.c +++ b/rpc/rpc-transport/socket/src/socket.c @@ -10,22 +10,16 @@ #include "socket.h" #include "name.h" -#include "dict.h" -#include "rpc-transport.h" -#include "logging.h" -#include "xlator.h" -#include "syscall.h" -#include "byte-order.h" -#include "common-utils.h" -#include "compat-errno.h" +#include <glusterfs/dict.h> +#include <glusterfs/syscall.h> +#include <glusterfs/byte-order.h> +#include <glusterfs/compat-errno.h> #include "socket-mem-types.h" -#include "timer.h" /* ugly #includes below */ #include "protocol-common.h" #include "glusterfs3-xdr.h" #include "glusterfs4-xdr.h" -#include "xdr-nfs3.h" #include "rpcsvc.h" /* for TCP_USER_TIMEOUT */ @@ -35,7 +29,6 @@ #include <netinet/tcp.h> #endif -#include <fcntl.h> #include <errno.h> #include <rpc/xdr.h> #include <sys/ioctl.h> @@ -139,7 +132,7 @@ ssl_setup_connection_params(rpc_transport_t *this); \ gf_log(this->name, GF_LOG_TRACE, \ "partial read on non-blocking socket"); \ - \ + ret = 0; \ break; \ } \ } @@ -173,7 +166,7 @@ ssl_setup_connection_params(rpc_transport_t *this); \ ret = __socket_readv(this, in->pending_vector, 1, &in->pending_vector, \ &in->pending_count, &bytes_read); \ - if (ret == -1) \ + if (ret < 0) \ break; \ __socket_proto_update_priv_after_read(priv, ret, bytes_read); \ } @@ -198,7 +191,7 @@ socket_dump_info(struct sockaddr *sa, int is_server, int is_ssl, int sock, 0, }; char *addr = NULL; - char *peer_type = NULL; + const char *peer_type = NULL; int af = sa->sa_family; int so_error = -1; socklen_t slen = sizeof(so_error); @@ -253,7 +246,6 @@ ssl_do(rpc_transport_t *this, void *buf, size_t len, SSL_trinary_func *func) int r = (-1); socket_private_t *priv = NULL; - GF_VALIDATE_OR_GOTO(this->name, this->private, out); priv = this->private; if (buf) { @@ -269,11 +261,9 @@ ssl_do(rpc_transport_t *this, void *buf, size_t len, SSL_trinary_func *func) } r = func(priv->ssl_ssl, buf, len); } else { - /* - * We actually need these functions to get to - * priv->connected == 1. - */ - r = ((SSL_unary_func *)func)(priv->ssl_ssl); + /* This should be treated as error */ + gf_log(this->name, GF_LOG_ERROR, "buffer is empty %s", __func__); + goto out; } switch (SSL_get_error(priv->ssl_ssl, r)) { case SSL_ERROR_NONE: @@ -308,14 +298,69 @@ out: #define ssl_write_one(t, b, l) \ ssl_do((t), (b), (l), (SSL_trinary_func *)SSL_write) -int -ssl_setup_connection_prefix(rpc_transport_t *this) +/* set crl verify flags only for server */ +/* see man X509_VERIFY_PARAM_SET_FLAGS(3) + * X509_V_FLAG_CRL_CHECK enables CRL checking for the certificate chain + * leaf certificate. An error occurs if a suitable CRL cannot be found. + * Since we're never going to revoke a gluster node cert, we better disable + * CRL check for server certs to avoid getting error and failed connection + * attempts. + */ +static void +ssl_clear_crl_verify_flags(SSL_CTX *ssl_ctx) +{ +#ifdef X509_V_FLAG_CRL_CHECK_ALL +#ifdef HAVE_SSL_CTX_GET0_PARAM + X509_VERIFY_PARAM *vpm; + + vpm = SSL_CTX_get0_param(ssl_ctx); + if (vpm) { + X509_VERIFY_PARAM_clear_flags( + vpm, (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)); + } +#else + /* CRL verify flag need not be cleared for rhel6 kind of clients */ +#endif +#else + gf_log(this->name, GF_LOG_ERROR, "OpenSSL version does not support CRL"); +#endif + return; +} + +/* set crl verify flags only for server */ +static void +ssl_set_crl_verify_flags(SSL_CTX *ssl_ctx) +{ +#ifdef X509_V_FLAG_CRL_CHECK_ALL +#ifdef HAVE_SSL_CTX_GET0_PARAM + X509_VERIFY_PARAM *vpm; + + vpm = SSL_CTX_get0_param(ssl_ctx); + if (vpm) { + unsigned long flags; + + flags = X509_VERIFY_PARAM_get_flags(vpm); + flags |= (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL); + X509_VERIFY_PARAM_set_flags(vpm, flags); + } +#else + X509_STORE *x509store; + + x509store = SSL_CTX_get_cert_store(ssl_ctx); + X509_STORE_set_flags(x509store, + X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL); +#endif +#else + gf_log(this->name, GF_LOG_ERROR, "OpenSSL version does not support CRL"); +#endif +} + +static int +ssl_setup_connection_prefix(rpc_transport_t *this, gf_boolean_t server) { int ret = -1; socket_private_t *priv = NULL; - GF_VALIDATE_OR_GOTO(this->name, this->private, done); - priv = this->private; if (ssl_setup_connection_params(this) < 0) { @@ -332,6 +377,9 @@ ssl_setup_connection_prefix(rpc_transport_t *this) priv->ssl_accepted = _gf_false; priv->ssl_context_created = _gf_false; + if (!server && priv->crl_path) + ssl_clear_crl_verify_flags(priv->ssl_ctx); + priv->ssl_ssl = SSL_new(priv->ssl_ctx); if (!priv->ssl_ssl) { gf_log(this->name, GF_LOG_ERROR, "SSL_new failed"); @@ -364,7 +412,6 @@ ssl_setup_connection_postfix(rpc_transport_t *this) char peer_CN[256] = ""; socket_private_t *priv = NULL; - GF_VALIDATE_OR_GOTO(this->name, this->private, done); priv = this->private; /* Make sure _SSL verification_ succeeded, yielding an identity. */ @@ -386,6 +433,7 @@ ssl_setup_connection_postfix(rpc_transport_t *this) gf_log(this->name, GF_LOG_DEBUG, "SSL verification succeeded (client: %s) (server: %s)", this->peerinfo.identifier, this->myinfo.identifier); + X509_free(peer); return gf_strdup(peer_CN); /* Error paths. */ @@ -397,11 +445,10 @@ ssl_error: SSL_free(priv->ssl_ssl); priv->ssl_ssl = NULL; -done: return NULL; } -int +static int ssl_complete_connection(rpc_transport_t *this) { int ret = -1; /* 1 : implies go back to epoll_wait() @@ -640,7 +687,6 @@ __socket_rwv(rpc_transport_t *this, struct iovec *vector, int count, int opcount = 0; int moved = 0; - GF_VALIDATE_OR_GOTO("socket", this, out); GF_VALIDATE_OR_GOTO("socket", this->private, out); priv = this->private; @@ -679,26 +725,26 @@ __socket_rwv(rpc_transport_t *this, struct iovec *vector, int count, ret = sys_writev(sock, opvector, IOV_MIN(opcount)); } - if (ret == 0 || (ret == -1 && errno == EAGAIN)) { + if ((ret == 0) || ((ret < 0) && (errno == EAGAIN))) { /* done for now */ break; - } - this->total_bytes_write += ret; + } else if (ret > 0) + this->total_bytes_write += ret; } else { ret = __socket_cached_read(this, opvector, opcount); if (ret == 0) { - gf_log(this->name, GF_LOG_INFO, - "EOF on socket %d " - "(errno:%d:%s); returning ENODATA", + gf_log(this->name, GF_LOG_DEBUG, + "EOF on socket %d (errno:%d:%s); returning ENODATA", sock, errno, strerror(errno)); + errno = ENODATA; ret = -1; } - if (ret == -1 && errno == EAGAIN) { + if ((ret < 0) && (errno == EAGAIN)) { /* done for now */ break; - } - this->total_bytes_read += ret; + } else if (ret > 0) + this->total_bytes_read += ret; } if (ret == 0) { @@ -710,7 +756,7 @@ __socket_rwv(rpc_transport_t *this, struct iovec *vector, int count, errno = ENOTCONN; break; } - if (ret == -1) { + if (ret < 0) { if (errno == EINTR) continue; @@ -773,24 +819,16 @@ static int __socket_readv(rpc_transport_t *this, struct iovec *vector, int count, struct iovec **pending_vector, int *pending_count, size_t *bytes) { - int ret = -1; - - ret = __socket_rwv(this, vector, count, pending_vector, pending_count, - bytes, 0); - - return ret; + return __socket_rwv(this, vector, count, pending_vector, pending_count, + bytes, 0); } static int __socket_writev(rpc_transport_t *this, struct iovec *vector, int count, struct iovec **pending_vector, int *pending_count) { - int ret = -1; - - ret = __socket_rwv(this, vector, count, pending_vector, pending_count, NULL, - 1); - - return ret; + return __socket_rwv(this, vector, count, pending_vector, pending_count, + NULL, 1); } static int @@ -807,8 +845,8 @@ __socket_shutdown(rpc_transport_t *this) gf_log(this->name, GF_LOG_DEBUG, "shutdown() returned %d. %s", ret, strerror(errno)); } else { - gf_log(this->name, GF_LOG_INFO, "intentional socket shutdown(%d)", - priv->sock); + GF_LOG_OCCASIONALLY(priv->shutdown_log_ctr, this->name, GF_LOG_INFO, + "intentional socket shutdown(%d)", priv->sock); } return ret; @@ -817,20 +855,14 @@ __socket_shutdown(rpc_transport_t *this) static int __socket_teardown_connection(rpc_transport_t *this) { - int ret = -1; socket_private_t *priv = NULL; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; if (priv->use_ssl) ssl_teardown_connection(priv); - ret = __socket_shutdown(this); -out: - return ret; + return __socket_shutdown(this); } static int @@ -839,15 +871,12 @@ __socket_disconnect(rpc_transport_t *this) int ret = -1; socket_private_t *priv = NULL; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; gf_log(this->name, GF_LOG_TRACE, "disconnecting %p, sock=%d", this, priv->sock); - if (priv->sock != -1) { + if (priv->sock >= 0) { gf_log_callingfn(this->name, GF_LOG_TRACE, "tearing down socket connection"); ret = __socket_teardown_connection(this); @@ -858,7 +887,6 @@ __socket_disconnect(rpc_transport_t *this) } } -out: return ret; } @@ -872,9 +900,8 @@ __socket_server_bind(rpc_transport_t *this) int ret = -1; int opt = 1; int reuse_check_sock = -1; - - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); + uint16_t sin_port = 0; + int retries = 0; priv = this->private; ctx = this->ctx; @@ -882,7 +909,7 @@ __socket_server_bind(rpc_transport_t *this) ret = setsockopt(priv->sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); - if (ret == -1) { + if (ret != 0) { gf_log(this->name, GF_LOG_ERROR, "setsockopt() for SO_REUSEADDR failed (%s)", strerror(errno)); } @@ -895,7 +922,7 @@ __socket_server_bind(rpc_transport_t *this) if (reuse_check_sock >= 0) { ret = connect(reuse_check_sock, SA(&unix_addr), this->myinfo.sockaddr_len); - if ((ret == -1) && (ECONNREFUSED == errno)) { + if ((ret != 0) && (ECONNREFUSED == errno)) { sys_unlink(((struct sockaddr_un *)&unix_addr)->sun_path); } gf_log(this->name, GF_LOG_INFO, @@ -904,19 +931,47 @@ __socket_server_bind(rpc_transport_t *this) } } - ret = bind(priv->sock, (struct sockaddr *)&this->myinfo.sockaddr, - this->myinfo.sockaddr_len); + if (AF_UNIX != SA(&this->myinfo.sockaddr)->sa_family) { + sin_port = (int)ntohs( + ((struct sockaddr_in *)&this->myinfo.sockaddr)->sin_port); + if (!sin_port) { + sin_port = GF_DEFAULT_SOCKET_LISTEN_PORT; + ((struct sockaddr_in *)&this->myinfo.sockaddr)->sin_port = htons( + sin_port); + } + retries = 10; + while (retries) { + ret = bind(priv->sock, (struct sockaddr *)&this->myinfo.sockaddr, + this->myinfo.sockaddr_len); + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, "binding to %s failed: %s", + this->myinfo.identifier, strerror(errno)); + if (errno == EADDRINUSE) { + gf_log(this->name, GF_LOG_ERROR, "Port is already in use"); + sleep(1); + retries--; + } else { + break; + } + } else { + break; + } + } + } else { + ret = bind(priv->sock, (struct sockaddr *)&this->myinfo.sockaddr, + this->myinfo.sockaddr_len); - if (ret == -1) { - gf_log(this->name, GF_LOG_ERROR, "binding to %s failed: %s", - this->myinfo.identifier, strerror(errno)); - if (errno == EADDRINUSE) { - gf_log(this->name, GF_LOG_ERROR, "Port is already in use"); + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, "binding to %s failed: %s", + this->myinfo.identifier, strerror(errno)); + if (errno == EADDRINUSE) { + gf_log(this->name, GF_LOG_ERROR, "Port is already in use"); + } } } if (AF_UNIX != SA(&this->myinfo.sockaddr)->sa_family) { if (getsockname(priv->sock, SA(&this->myinfo.sockaddr), - &this->myinfo.sockaddr_len) == -1) { + &this->myinfo.sockaddr_len) != 0) { gf_log(this->name, GF_LOG_WARNING, "getsockname on (%d) failed (%s)", priv->sock, strerror(errno)); @@ -944,7 +999,7 @@ __socket_nonblock(int fd) flags = fcntl(fd, F_GETFL); - if (flags != -1) + if (flags >= 0) ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK); return ret; @@ -974,7 +1029,7 @@ __socket_keepalive(int fd, int family, int keepaliveintvl, int keepaliveidle, #endif ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)); - if (ret == -1) { + if (ret != 0) { gf_log("socket", GF_LOG_WARNING, "failed to set keep alive option on socket %d", fd); goto err; @@ -991,7 +1046,7 @@ __socket_keepalive(int fd, int family, int keepaliveintvl, int keepaliveidle, ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &keepaliveintvl, sizeof(keepaliveintvl)); #endif - if (ret == -1) { + if (ret != 0) { gf_log("socket", GF_LOG_WARNING, "failed to set keep alive interval on socket %d", fd); goto err; @@ -1002,7 +1057,7 @@ __socket_keepalive(int fd, int family, int keepaliveintvl, int keepaliveidle, ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepaliveidle, sizeof(keepaliveidle)); - if (ret == -1) { + if (ret != 0) { gf_log("socket", GF_LOG_WARNING, "failed to set keep idle %d on socket %d, %s", keepaliveidle, fd, strerror(errno)); @@ -1010,7 +1065,7 @@ __socket_keepalive(int fd, int family, int keepaliveintvl, int keepaliveidle, } ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &keepaliveintvl, sizeof(keepaliveintvl)); - if (ret == -1) { + if (ret != 0) { gf_log("socket", GF_LOG_WARNING, "failed to set keep interval %d on socket %d, %s", keepaliveintvl, fd, strerror(errno)); @@ -1022,7 +1077,7 @@ __socket_keepalive(int fd, int family, int keepaliveintvl, int keepaliveidle, goto done; ret = setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout_ms, sizeof(timeout_ms)); - if (ret == -1) { + if (ret != 0) { gf_log("socket", GF_LOG_WARNING, "failed to set " "TCP_USER_TIMEOUT %d on socket %d, %s", @@ -1033,7 +1088,7 @@ __socket_keepalive(int fd, int family, int keepaliveintvl, int keepaliveidle, #if defined(TCP_KEEPCNT) ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &keepalivecnt, sizeof(keepalivecnt)); - if (ret == -1) { + if (ret != 0) { gf_log("socket", GF_LOG_WARNING, "failed to set " "TCP_KEEPCNT %d on socket %d, %s", @@ -1075,9 +1130,6 @@ __socket_reset(rpc_transport_t *this) { socket_private_t *priv = NULL; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; /* TODO: use mem-pool on incoming data */ @@ -1096,8 +1148,16 @@ __socket_reset(rpc_transport_t *this) memset(&priv->incoming, 0, sizeof(priv->incoming)); - event_unregister_close(this->ctx->event_pool, priv->sock, priv->idx); - + gf_event_unregister_close(this->ctx->event_pool, priv->sock, priv->idx); + if (priv->use_ssl && priv->ssl_ssl) { + SSL_clear(priv->ssl_ssl); + SSL_free(priv->ssl_ssl); + priv->ssl_ssl = NULL; + } + if (priv->ssl_ctx) { + SSL_CTX_free(priv->ssl_ctx); + priv->ssl_ctx = NULL; + } priv->sock = -1; priv->idx = -1; priv->connected = -1; @@ -1117,8 +1177,6 @@ __socket_reset(rpc_transport_t *this) GF_FREE(priv->ssl_ca_list); priv->ssl_ca_list = NULL; } -out: - return; } static void @@ -1148,8 +1206,6 @@ __socket_ioq_new(rpc_transport_t *this, rpc_transport_msg_t *msg) int count = 0; uint32_t size = 0; - GF_VALIDATE_OR_GOTO("socket", this, out); - /* TODO: use mem-pool */ entry = GF_CALLOC(1, sizeof(*entry), gf_common_mt_ioq); if (!entry) @@ -1204,7 +1260,6 @@ __socket_ioq_new(rpc_transport_t *this, rpc_transport_msg_t *msg) INIT_LIST_HEAD(&entry->list); -out: return entry; } @@ -1225,27 +1280,18 @@ out: } static void -__socket_ioq_flush(rpc_transport_t *this) +__socket_ioq_flush(socket_private_t *priv) { - socket_private_t *priv = NULL; struct ioq *entry = NULL; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - - priv = this->private; - while (!list_empty(&priv->ioq)) { entry = priv->ioq_next; __socket_ioq_entry_free(entry); } - -out: - return; } static int -__socket_ioq_churn_entry(rpc_transport_t *this, struct ioq *entry, int direct) +__socket_ioq_churn_entry(rpc_transport_t *this, struct ioq *entry) { int ret = -1; @@ -1268,16 +1314,13 @@ __socket_ioq_churn(rpc_transport_t *this) int ret = 0; struct ioq *entry = NULL; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; while (!list_empty(&priv->ioq)) { /* pick next entry */ entry = priv->ioq_next; - ret = __socket_ioq_churn_entry(this, entry, 0); + ret = __socket_ioq_churn_entry(this, entry); if (ret != 0) break; @@ -1285,11 +1328,10 @@ __socket_ioq_churn(rpc_transport_t *this) if (list_empty(&priv->ioq)) { /* all pending writes done, not interested in POLLOUT */ - priv->idx = event_select_on(this->ctx->event_pool, priv->sock, - priv->idx, -1, 0); + priv->idx = gf_event_select_on(this->ctx->event_pool, priv->sock, + priv->idx, -1, 0); } -out: return ret; } @@ -1299,22 +1341,17 @@ socket_event_poll_err(rpc_transport_t *this, int gen, int idx) socket_private_t *priv = NULL; gf_boolean_t socket_closed = _gf_false; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; - pthread_mutex_lock(&priv->in_lock); pthread_mutex_lock(&priv->out_lock); { - if ((priv->gen == gen) && (priv->idx == idx) && (priv->sock != -1)) { - __socket_ioq_flush(this); + if ((priv->gen == gen) && (priv->idx == idx) && (priv->sock >= 0)) { + __socket_ioq_flush(priv); __socket_reset(this); socket_closed = _gf_true; } } pthread_mutex_unlock(&priv->out_lock); - pthread_mutex_unlock(&priv->in_lock); if (socket_closed) { pthread_mutex_lock(&priv->notify.lock); @@ -1327,7 +1364,6 @@ socket_event_poll_err(rpc_transport_t *this, int gen, int idx) rpc_transport_notify(this, RPC_TRANSPORT_DISCONNECT, this); } -out: return socket_closed; } @@ -1337,9 +1373,6 @@ socket_event_poll_out(rpc_transport_t *this) socket_private_t *priv = NULL; int ret = -1; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; pthread_mutex_lock(&priv->out_lock); @@ -1347,7 +1380,7 @@ socket_event_poll_out(rpc_transport_t *this) if (priv->connected == 1) { ret = __socket_ioq_churn(this); - if (ret == -1) { + if (ret < 0) { gf_log(this->name, GF_LOG_TRACE, "__socket_ioq_churn returned -1; " "disconnecting socket"); @@ -1358,9 +1391,11 @@ socket_event_poll_out(rpc_transport_t *this) pthread_mutex_unlock(&priv->out_lock); if (ret == 0) - ret = rpc_transport_notify(this, RPC_TRANSPORT_MSG_SENT, NULL); + rpc_transport_notify(this, RPC_TRANSPORT_MSG_SENT, NULL); + + if (ret > 0) + ret = 0; -out: return ret; } @@ -1403,7 +1438,7 @@ __socket_read_simple_msg(rpc_transport_t *this) &bytes_read); } - if (ret == -1) { + if (ret < 0) { gf_log(this->name, GF_LOG_WARNING, "reading from socket failed. Error (%s), " "peer (%s)", @@ -1417,6 +1452,7 @@ __socket_read_simple_msg(rpc_transport_t *this) if (ret > 0) { gf_log(this->name, GF_LOG_TRACE, "partial read on non-blocking socket."); + ret = 0; break; } @@ -1429,12 +1465,6 @@ out: return ret; } -static int -__socket_read_simple_request(rpc_transport_t *this) -{ - return __socket_read_simple_msg(this); -} - #define rpc_cred_addr(buf) (buf + RPC_MSGTYPE_SIZE + RPC_CALL_BODY_SIZE - 4) #define rpc_verf_addr(fragcurrent) (fragcurrent - 4) @@ -1461,9 +1491,6 @@ __socket_read_vectored_request(rpc_transport_t *this, struct gf_sock_incoming_frag *frag = NULL; sp_rpcfrag_request_state_t *request = NULL; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; /* used to reduce the indirection */ @@ -1600,8 +1627,8 @@ __socket_read_vectored_request(rpc_transport_t *this, remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; - if ((ret == -1) || ((ret == 0) && (remaining_size == 0) && - RPC_LASTFRAG(in->fraghdr))) { + if ((ret < 0) || ((ret == 0) && (remaining_size == 0) && + RPC_LASTFRAG(in->fraghdr))) { request->vector_state = SP_STATE_VECTORED_REQUEST_INIT; in->payload_vector.iov_len = ((unsigned long)frag->fragcurrent - (unsigned long) @@ -1610,7 +1637,6 @@ __socket_read_vectored_request(rpc_transport_t *this, break; } -out: return ret; } @@ -1627,9 +1653,6 @@ __socket_read_request(rpc_transport_t *this) struct gf_sock_incoming_frag *frag = NULL; sp_rpcfrag_request_state_t *request = NULL; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; /* used to reduce the indirection */ @@ -1673,20 +1696,19 @@ __socket_read_request(rpc_transport_t *this) if (vector_sizer) { ret = __socket_read_vectored_request(this, vector_sizer); } else { - ret = __socket_read_simple_request(this); + ret = __socket_read_simple_msg(this); } remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; - if ((ret == -1) || ((ret == 0) && (remaining_size == 0) && - (RPC_LASTFRAG(in->fraghdr)))) { + if ((ret < 0) || ((ret == 0) && (remaining_size == 0) && + (RPC_LASTFRAG(in->fraghdr)))) { request->header_state = SP_STATE_REQUEST_HEADER_INIT; } break; } -out: return ret; } @@ -1704,9 +1726,7 @@ __socket_read_accepted_successful_reply(rpc_transport_t *this) XDR xdr; struct gf_sock_incoming *in = NULL; struct gf_sock_incoming_frag *frag = NULL; - - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); + uint32_t remaining_size = 0; priv = this->private; @@ -1744,9 +1764,9 @@ __socket_read_accepted_successful_reply(rpc_transport_t *this) free(read_rsp.xdata.xdata_val); - /* need to round off to proper roof (%4), as XDR packing pads + /* need to round off to proper gf_roof (%4), as XDR packing pads the end of opaque object with '0' */ - size = roof(read_rsp.xdata.xdata_len, 4); + size = gf_roof(read_rsp.xdata.xdata_len, 4); if (!size) { frag->call_body.reply @@ -1807,7 +1827,9 @@ __socket_read_accepted_successful_reply(rpc_transport_t *this) case SP_STATE_READ_PROC_HEADER: /* now read the entire remaining msg into new iobuf */ ret = __socket_read_simple_msg(this); - if ((ret == -1) || ((ret == 0) && RPC_LASTFRAG(in->fraghdr))) { + remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; + if ((ret < 0) || ((ret == 0) && (remaining_size == 0) && + RPC_LASTFRAG(in->fraghdr))) { frag->call_body.reply.accepted_success_state = SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT; } @@ -1833,9 +1855,7 @@ __socket_read_accepted_successful_reply_v2(rpc_transport_t *this) XDR xdr; struct gf_sock_incoming *in = NULL; struct gf_sock_incoming_frag *frag = NULL; - - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); + uint32_t remaining_size = 0; priv = this->private; @@ -1874,9 +1894,9 @@ __socket_read_accepted_successful_reply_v2(rpc_transport_t *this) free(read_rsp.xdata.pairs.pairs_val); - /* need to round off to proper roof (%4), as XDR packing pads + /* need to round off to proper gf_roof (%4), as XDR packing pads the end of opaque object with '0' */ - size = roof(read_rsp.xdata.xdr_size, 4); + size = gf_roof(read_rsp.xdata.xdr_size, 4); if (!size) { frag->call_body.reply @@ -1937,7 +1957,9 @@ __socket_read_accepted_successful_reply_v2(rpc_transport_t *this) case SP_STATE_READ_PROC_HEADER: /* now read the entire remaining msg into new iobuf */ ret = __socket_read_simple_msg(this); - if ((ret == -1) || ((ret == 0) && RPC_LASTFRAG(in->fraghdr))) { + remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; + if ((ret < 0) || ((ret == 0) && (remaining_size == 0) && + RPC_LASTFRAG(in->fraghdr))) { frag->call_body.reply.accepted_success_state = SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT; } @@ -1963,9 +1985,6 @@ __socket_read_accepted_reply(rpc_transport_t *this) struct gf_sock_incoming *in = NULL; struct gf_sock_incoming_frag *frag = NULL; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; /* used to reduce the indirection */ in = &priv->incoming; @@ -2036,8 +2055,8 @@ __socket_read_accepted_reply(rpc_transport_t *this) remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; - if ((ret == -1) || ((ret == 0) && (remaining_size == 0) && - (RPC_LASTFRAG(in->fraghdr)))) { + if ((ret < 0) || ((ret == 0) && (remaining_size == 0) && + (RPC_LASTFRAG(in->fraghdr)))) { frag->call_body.reply .accepted_state = SP_STATE_ACCEPTED_REPLY_INIT; } @@ -2045,7 +2064,6 @@ __socket_read_accepted_reply(rpc_transport_t *this) break; } -out: return ret; } @@ -2067,9 +2085,6 @@ __socket_read_vectored_reply(rpc_transport_t *this) struct gf_sock_incoming *in = NULL; struct gf_sock_incoming_frag *frag = NULL; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; in = &priv->incoming; frag = &in->frag; @@ -2102,8 +2117,8 @@ __socket_read_vectored_reply(rpc_transport_t *this) remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; - if ((ret == -1) || ((ret == 0) && (remaining_size == 0) && - (RPC_LASTFRAG(in->fraghdr)))) { + if ((ret < 0) || ((ret == 0) && (remaining_size == 0) && + (RPC_LASTFRAG(in->fraghdr)))) { frag->call_body.reply .status_state = SP_STATE_VECTORED_REPLY_STATUS_INIT; in->payload_vector.iov_len = (unsigned long)frag->fragcurrent - @@ -2113,7 +2128,6 @@ __socket_read_vectored_reply(rpc_transport_t *this) break; } -out: return ret; } @@ -2136,9 +2150,6 @@ __socket_read_reply(rpc_transport_t *this) struct gf_sock_incoming *in = NULL; struct gf_sock_incoming_frag *frag = NULL; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; in = &priv->incoming; frag = &in->frag; @@ -2164,17 +2175,13 @@ __socket_read_reply(rpc_transport_t *this) * and priv->lock, since we are doing an upcall here. */ frag->state = SP_STATE_NOTIFYING_XID; - pthread_mutex_unlock(&priv->in_lock); - { - ret = rpc_transport_notify(this, RPC_TRANSPORT_MAP_XID_REQUEST, - in->request_info); - } - pthread_mutex_lock(&priv->in_lock); + ret = rpc_transport_notify(this, RPC_TRANSPORT_MAP_XID_REQUEST, + in->request_info); /* Transition back to externally visible state. */ frag->state = SP_STATE_READ_MSGTYPE; - if (ret == -1) { + if (ret < 0) { gf_log(this->name, GF_LOG_WARNING, "notify for event MAP_XID failed for %s", this->peerinfo.identifier); @@ -2208,9 +2215,6 @@ __socket_read_frag(rpc_transport_t *this) struct gf_sock_incoming *in = NULL; struct gf_sock_incoming_frag *frag = NULL; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; /* used to reduce the indirection */ in = &priv->incoming; @@ -2252,8 +2256,8 @@ __socket_read_frag(rpc_transport_t *this) remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; - if ((ret == -1) || ((ret == 0) && (remaining_size == 0) && - (RPC_LASTFRAG(in->fraghdr)))) { + if ((ret < 0) || ((ret == 0) && (remaining_size == 0) && + (RPC_LASTFRAG(in->fraghdr)))) { /* frag->state = SP_STATE_NADA; */ frag->state = SP_STATE_RPCFRAG_INIT; } @@ -2268,7 +2272,6 @@ __socket_read_frag(rpc_transport_t *this) break; } -out: return ret; } @@ -2337,13 +2340,14 @@ __socket_proto_state_machine(rpc_transport_t *this, ret = __socket_readv(this, in->pending_vector, 1, &in->pending_vector, &in->pending_count, NULL); - if (ret == -1) + if (ret < 0) goto out; if (ret > 0) { gf_log(this->name, GF_LOG_TRACE, "partial " "fragment header read"); + ret = 0; goto out; } @@ -2358,7 +2362,7 @@ __socket_proto_state_machine(rpc_transport_t *this, in->total_bytes_read += RPC_FRAGSIZE(in->fraghdr); if (in->total_bytes_read >= GF_UNIT_GB) { - ret = -ENOMEM; + ret = -1; goto out; } @@ -2366,7 +2370,7 @@ __socket_proto_state_machine(rpc_transport_t *this, this->ctx->iobuf_pool, (in->total_bytes_read + sizeof(in->fraghdr))); if (!iobuf) { - ret = -ENOMEM; + ret = -1; goto out; } @@ -2393,7 +2397,7 @@ __socket_proto_state_machine(rpc_transport_t *this, case SP_STATE_READING_FRAG: ret = __socket_read_frag(this); - if ((ret == -1) || + if ((ret < 0) || (frag->bytes_read != RPC_FRAGSIZE(in->fraghdr))) { goto out; } @@ -2474,10 +2478,6 @@ __socket_proto_state_machine(rpc_transport_t *this, } out: - if ((ret == -1) && (errno == EAGAIN)) { - ret = 0; - } - return ret; } @@ -2485,22 +2485,34 @@ static int socket_proto_state_machine(rpc_transport_t *this, rpc_transport_pollin_t **pollin) { - socket_private_t *priv = NULL; - int ret = 0; + return __socket_proto_state_machine(this, pollin); +} - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); +static void +socket_event_poll_in_async(xlator_t *xl, gf_async_t *async) +{ + rpc_transport_pollin_t *pollin; + rpc_transport_t *this; + socket_private_t *priv; + pollin = caa_container_of(async, rpc_transport_pollin_t, async); + this = pollin->trans; priv = this->private; - pthread_mutex_lock(&priv->in_lock); + rpc_transport_notify(this, RPC_TRANSPORT_MSG_RECEIVED, pollin); + + rpc_transport_unref(this); + + rpc_transport_pollin_destroy(pollin); + + pthread_mutex_lock(&priv->notify.lock); { - ret = __socket_proto_state_machine(this, pollin); - } - pthread_mutex_unlock(&priv->in_lock); + --priv->notify.in_progress; -out: - return ret; + if (!priv->notify.in_progress) + pthread_cond_signal(&priv->notify.cond); + } + pthread_mutex_unlock(&priv->notify.lock); } static int @@ -2523,22 +2535,12 @@ socket_event_poll_in(rpc_transport_t *this, gf_boolean_t notify_handled) pthread_mutex_unlock(&priv->notify.lock); } - if (notify_handled && (ret != -1)) - event_handled(ctx->event_pool, priv->sock, priv->idx, priv->gen); + if (notify_handled && (ret >= 0)) + gf_event_handled(ctx->event_pool, priv->sock, priv->idx, priv->gen); if (pollin) { - ret = rpc_transport_notify(this, RPC_TRANSPORT_MSG_RECEIVED, pollin); - - rpc_transport_pollin_destroy(pollin); - - pthread_mutex_lock(&priv->notify.lock); - { - --priv->notify.in_progress; - - if (!priv->notify.in_progress) - pthread_cond_signal(&priv->notify.cond); - } - pthread_mutex_unlock(&priv->notify.lock); + rpc_transport_ref(this); + gf_async(&pollin->async, THIS, socket_event_poll_in_async); } return ret; @@ -2552,12 +2554,8 @@ socket_connect_finish(rpc_transport_t *this) rpc_transport_event_t event = 0; char notify_rpc = 0; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; - pthread_mutex_lock(&priv->in_lock); pthread_mutex_lock(&priv->out_lock); { if (priv->connected != 0) @@ -2567,10 +2565,10 @@ socket_connect_finish(rpc_transport_t *this) ret = __socket_connect_finish(priv->sock); - if (ret == -1 && errno == EINPROGRESS) + if ((ret < 0) && (errno == EINPROGRESS)) ret = 1; - if (ret == -1 && errno != EINPROGRESS) { + if ((ret < 0) && (errno != EINPROGRESS)) { if (!priv->connect_finish_log) { gf_log(this->name, GF_LOG_ERROR, "connection to %s failed (%s); " @@ -2589,7 +2587,7 @@ socket_connect_finish(rpc_transport_t *this) ret = getsockname(priv->sock, SA(&this->myinfo.sockaddr), &this->myinfo.sockaddr_len); - if (ret == -1) { + if (ret != 0) { gf_log(this->name, GF_LOG_WARNING, "getsockname on (%d) failed (%s) - " "disconnecting socket", @@ -2606,12 +2604,11 @@ socket_connect_finish(rpc_transport_t *this) } unlock: pthread_mutex_unlock(&priv->out_lock); - pthread_mutex_unlock(&priv->in_lock); if (notify_rpc) { rpc_transport_notify(this, event, this); } -out: + return ret; } @@ -2620,12 +2617,8 @@ socket_disconnect(rpc_transport_t *this, gf_boolean_t wait); /* socket_is_connected() is for use only in socket_event_handler() */ static inline gf_boolean_t -socket_is_connected(rpc_transport_t *this) +socket_is_connected(socket_private_t *priv) { - socket_private_t *priv = NULL; - - priv = this->private; - if (priv->use_ssl) { return priv->is_server ? priv->ssl_accepted : priv->ssl_connected; } else { @@ -2650,10 +2643,10 @@ ssl_rearm_event_fd(rpc_transport_t *this) fd = priv->sock; if (priv->ssl_error_required == SSL_ERROR_WANT_READ) - event_select_on(ctx->event_pool, fd, idx, 1, -1); + gf_event_select_on(ctx->event_pool, fd, idx, 1, -1); if (priv->ssl_error_required == SSL_ERROR_WANT_WRITE) - event_select_on(ctx->event_pool, fd, idx, -1, 1); - event_handled(ctx->event_pool, fd, idx, gen); + gf_event_select_on(ctx->event_pool, fd, idx, -1, 1); + gf_event_handled(ctx->event_pool, fd, idx, gen); } static int @@ -2674,7 +2667,7 @@ ssl_handle_server_connection_attempt(rpc_transport_t *this) fd = priv->sock; if (!priv->ssl_context_created) { - ret = ssl_setup_connection_prefix(this); + ret = ssl_setup_connection_prefix(this, _gf_true); if (ret < 0) { gf_log(this->name, GF_LOG_TRACE, "> ssl_setup_connection_prefix() failed!"); @@ -2687,8 +2680,8 @@ ssl_handle_server_connection_attempt(rpc_transport_t *this) ret = ssl_complete_connection(this); if (ret == 0) { /* nothing to do */ - event_select_on(ctx->event_pool, fd, idx, 1, 0); - event_handled(ctx->event_pool, fd, idx, gen); + gf_event_select_on(ctx->event_pool, fd, idx, 1, 0); + gf_event_handled(ctx->event_pool, fd, idx, gen); ret = 1; } else { if (errno == EAGAIN) { @@ -2722,13 +2715,13 @@ ssl_handle_client_connection_attempt(rpc_transport_t *this) /* SSL client */ if (priv->connect_failed) { gf_log(this->name, GF_LOG_TRACE, ">>> disconnecting SSL socket"); - ret = socket_disconnect(this, _gf_false); + (void)socket_disconnect(this, _gf_false); /* Force ret to be -1, as we are officially done with this socket */ ret = -1; } else { if (!priv->ssl_context_created) { - ret = ssl_setup_connection_prefix(this); + ret = ssl_setup_connection_prefix(this, _gf_false); if (ret < 0) { gf_log(this->name, GF_LOG_TRACE, "> ssl_setup_connection_prefix() " @@ -2742,7 +2735,7 @@ ssl_handle_client_connection_attempt(rpc_transport_t *this) ret = ssl_complete_connection(this); if (ret == 0) { ret = socket_connect_finish(this); - event_select_on(ctx->event_pool, fd, idx, 1, 0); + gf_event_select_on(ctx->event_pool, fd, idx, 1, 0); gf_log(this->name, GF_LOG_TRACE, ">>> completed client connect"); } else { if (errno == EAGAIN) { @@ -2752,7 +2745,7 @@ ssl_handle_client_connection_attempt(rpc_transport_t *this) ret = 1; } else { /* this is a connection failure */ - ret = socket_connect_finish(this); + (void)socket_connect_finish(this); gf_log(this->name, GF_LOG_TRACE, "ssl_complete_connection " "returned error"); @@ -2811,7 +2804,7 @@ socket_handle_client_connection_attempt(rpc_transport_t *this) * return 1 */ ret = 1; - event_handled(ctx->event_pool, fd, idx, gen); + gf_event_handled(ctx->event_pool, fd, idx, gen); } } return ret; @@ -2847,7 +2840,7 @@ socket_complete_connection(rpc_transport_t *this) * socket_server_event_handler() */ priv->accepted = _gf_true; - event_handled(ctx->event_pool, fd, idx, gen); + gf_event_handled(ctx->event_pool, fd, idx, gen); ret = 1; } else { ret = socket_handle_client_connection_attempt(this); @@ -2857,9 +2850,9 @@ socket_complete_connection(rpc_transport_t *this) } /* reads rpc_requests during pollin */ -static int +static void socket_event_handler(int fd, int idx, int gen, void *data, int poll_in, - int poll_out, int poll_err) + int poll_out, int poll_err, char event_thread_died) { rpc_transport_t *this = NULL; socket_private_t *priv = NULL; @@ -2869,6 +2862,18 @@ socket_event_handler(int fd, int idx, int gen, void *data, int poll_in, this = data; + if (event_thread_died) { + /* to avoid duplicate notifications, notify only for listener sockets */ + return; + } + + /* At this point we are sure no other thread is using the transport because + * we cannot receive more events until we call gf_event_handled(). However + * this function may call gf_event_handled() in some cases. When this is + * done, the transport may be destroyed at any moment if another thread + * handled an error event. To prevent that we take a reference here. */ + rpc_transport_ref(this); + GF_VALIDATE_OR_GOTO("socket", this, out); GF_VALIDATE_OR_GOTO("socket", this->private, out); GF_VALIDATE_OR_GOTO("socket", this->xl, out); @@ -2877,21 +2882,19 @@ socket_event_handler(int fd, int idx, int gen, void *data, int poll_in, priv = this->private; ctx = this->ctx; - pthread_mutex_lock(&priv->in_lock); pthread_mutex_lock(&priv->out_lock); { priv->idx = idx; priv->gen = gen; } pthread_mutex_unlock(&priv->out_lock); - pthread_mutex_unlock(&priv->in_lock); gf_log(this->name, GF_LOG_TRACE, "%s (sock:%d) in:%d, out:%d, err:%d", (priv->is_server ? "server" : "client"), priv->sock, poll_in, poll_out, poll_err); if (!poll_err) { - if (!socket_is_connected(this)) { + if (!socket_is_connected(priv)) { gf_log(this->name, GF_LOG_TRACE, "%s (sock:%d) socket is not connected, " "completing connection", @@ -2907,7 +2910,7 @@ socket_event_handler(int fd, int idx, int gen, void *data, int poll_in, if (ret > 0) { gf_log(this->name, GF_LOG_TRACE, "(sock:%d) returning to wait on socket", priv->sock); - return 0; + goto out; } } else { char *sock_type = (priv->is_server ? "Server" : "Client"); @@ -2947,6 +2950,13 @@ socket_event_handler(int fd, int idx, int gen, void *data, int poll_in, socket_dump_info(sa, priv->is_server, priv->use_ssl, priv->sock, this->name, "disconnecting from"); + /* Dump the SSL error stack to clear any errors that may otherwise + * resurface in the future. + */ + if (priv->use_ssl && priv->ssl_ssl) { + ssl_dump_error_stack(this->name); + } + /* Logging has happened already in earlier cases */ gf_log("transport", ((ret >= 0) ? GF_LOG_INFO : GF_LOG_DEBUG), "EPOLLERR - disconnecting (sock:%d) (%s)", priv->sock, @@ -2958,16 +2968,16 @@ socket_event_handler(int fd, int idx, int gen, void *data, int poll_in, rpc_transport_unref(this); } else if (!notify_handled) { - event_handled(ctx->event_pool, fd, idx, gen); + gf_event_handled(ctx->event_pool, fd, idx, gen); } out: - return ret; + rpc_transport_unref(this); } -static int +static void socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, - int poll_out, int poll_err) + int poll_out, int poll_err, char event_thread_died) { rpc_transport_t *this = NULL; socket_private_t *priv = NULL; @@ -2991,6 +3001,12 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, priv = this->private; ctx = this->ctx; + if (event_thread_died) { + rpc_transport_notify(this, RPC_TRANSPORT_EVENT_THREAD_DIED, + (void *)(unsigned long)gen); + return; + } + /* NOTE: * We have done away with the critical section in this function. since * there's little that it helps with. There's no other code that @@ -2998,6 +3014,12 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, * thread context while we are using it here. */ priv->idx = idx; + priv->gen = gen; + + if (poll_err) { + socket_event_poll_err(this, gen, idx); + goto out; + } if (poll_in) { int aflags = 0; @@ -3007,31 +3029,33 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, new_sock = sys_accept(priv->sock, SA(&new_sockaddr), &addrlen, aflags); - event_handled(ctx->event_pool, fd, idx, gen); + gf_event_handled(ctx->event_pool, fd, idx, gen); - if (new_sock == -1) { + if (new_sock < 0) { gf_log(this->name, GF_LOG_WARNING, "accept on %d failed (%s)", priv->sock, strerror(errno)); goto out; } - if (priv->nodelay && (new_sockaddr.ss_family != AF_UNIX)) { - ret = __socket_nodelay(new_sock); - if (ret == -1) { - gf_log(this->name, GF_LOG_WARNING, - "setsockopt() failed for " - "NODELAY (%s)", - strerror(errno)); + if (new_sockaddr.ss_family != AF_UNIX) { + if (priv->nodelay) { + ret = __socket_nodelay(new_sock); + if (ret != 0) { + gf_log(this->name, GF_LOG_WARNING, + "setsockopt() failed for " + "NODELAY (%s)", + strerror(errno)); + } } - } - if (priv->keepalive && new_sockaddr.ss_family != AF_UNIX) { - ret = __socket_keepalive(new_sock, new_sockaddr.ss_family, - priv->keepaliveintvl, priv->keepaliveidle, - priv->keepalivecnt, priv->timeout); - if (ret == -1) - gf_log(this->name, GF_LOG_WARNING, - "Failed to set keep-alive: %s", strerror(errno)); + if (priv->keepalive) { + ret = __socket_keepalive( + new_sock, new_sockaddr.ss_family, priv->keepaliveintvl, + priv->keepaliveidle, priv->keepalivecnt, priv->timeout); + if (ret != 0) + gf_log(this->name, GF_LOG_WARNING, + "Failed to set keep-alive: %s", strerror(errno)); + } } new_trans = GF_CALLOC(1, sizeof(*new_trans), gf_common_mt_rpc_trans_t); @@ -3045,7 +3069,7 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, } ret = pthread_mutex_init(&new_trans->lock, NULL); - if (ret == -1) { + if (ret != 0) { gf_log(this->name, GF_LOG_WARNING, "pthread_mutex_init() failed: %s; closing newly accepted " "socket %d", @@ -3065,7 +3089,7 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, ret = getsockname(new_sock, SA(&new_trans->myinfo.sockaddr), &new_trans->myinfo.sockaddr_len); - if (ret == -1) { + if (ret != 0) { gf_log(this->name, GF_LOG_WARNING, "getsockname on socket %d " "failed (errno:%s); closing newly accepted socket", @@ -3080,7 +3104,30 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, gf_log(this->name, GF_LOG_TRACE, "XXX server:%s, client:%s", new_trans->myinfo.identifier, new_trans->peerinfo.identifier); + /* Make options available to local socket_init() to create new + * SSL_CTX per transport. A separate SSL_CTX per transport is + * required to avoid setting crl checking options for client + * connections. The verification options eventually get copied + * to the SSL object. Unfortunately, there's no way to identify + * whether socket_init() is being called after a client-side + * connect() or a server-side accept(). Although, we could pass + * a flag from the transport init() to the socket_init() and + * from this place, this doesn't identify the case where the + * server-side transport loading is done for the first time. + * Also, SSL doesn't apply for UNIX sockets. + */ + if (new_sockaddr.ss_family != AF_UNIX) + new_trans->options = dict_ref(this->options); + new_trans->ctx = this->ctx; + ret = socket_init(new_trans); + + /* reset options to NULL to avoid double free */ + if (new_sockaddr.ss_family != AF_UNIX) { + dict_unref(new_trans->options); + new_trans->options = NULL; + } + if (ret != 0) { gf_log(this->name, GF_LOG_WARNING, "initialization of new_trans " @@ -3099,6 +3146,7 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, new_trans->mydata = this->mydata; new_trans->notify = this->notify; new_trans->listener = this; + new_trans->notify_poller_death = this->poller_death_accept; new_priv = new_trans->private; if (new_sockaddr.ss_family == AF_UNIX) { @@ -3121,7 +3169,6 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, new_priv->sock = new_sock; new_priv->ssl_enabled = priv->ssl_enabled; - new_priv->ssl_ctx = priv->ssl_ctx; new_priv->connected = 1; new_priv->is_server = _gf_true; @@ -3148,10 +3195,10 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, */ ret = rpc_transport_notify(this, RPC_TRANSPORT_ACCEPT, new_trans); - if (ret != -1) { - new_priv->idx = event_register(ctx->event_pool, new_sock, - socket_event_handler, new_trans, - 1, 0); + if (ret >= 0) { + new_priv->idx = gf_event_register( + ctx->event_pool, new_sock, socket_event_handler, new_trans, + 1, 0, new_trans->notify_poller_death); if (new_priv->idx == -1) { ret = -1; gf_log(this->name, GF_LOG_ERROR, @@ -3186,7 +3233,7 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, rpc_transport_unref(new_trans); } - if (ret == -1) { + if (ret < 0) { gf_log(this->name, GF_LOG_WARNING, "closing newly accepted socket"); sys_close(new_sock); /* this unref is to actually cause the destruction of @@ -3196,7 +3243,7 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, } } out: - return ret; + return; } static int @@ -3205,20 +3252,14 @@ socket_disconnect(rpc_transport_t *this, gf_boolean_t wait) socket_private_t *priv = NULL; int ret = -1; - GF_VALIDATE_OR_GOTO("socket", this, out); - GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; - pthread_mutex_lock(&priv->in_lock); pthread_mutex_lock(&priv->out_lock); { ret = __socket_disconnect(this); } pthread_mutex_unlock(&priv->out_lock); - pthread_mutex_unlock(&priv->in_lock); -out: return ret; } @@ -3317,10 +3358,9 @@ socket_connect(rpc_transport_t *this, int port) goto err; } - pthread_mutex_lock(&priv->in_lock); pthread_mutex_lock(&priv->out_lock); { - if (priv->sock != -1) { + if (priv->sock >= 0) { gf_log_callingfn(this->name, GF_LOG_TRACE, "connect () called on transport " "already connected"); @@ -3334,7 +3374,7 @@ socket_connect(rpc_transport_t *this, int port) ret = socket_client_get_remote_sockaddr(this, &sock_union.sa, &sockaddr_len, &sa_family); - if (ret == -1) { + if (ret < 0) { /* logged inside client_get_remote_sockaddr */ goto unlock; } @@ -3353,7 +3393,7 @@ socket_connect(rpc_transport_t *this, int port) this->peerinfo.sockaddr_len = sockaddr_len; priv->sock = sys_socket(sa_family, SOCK_STREAM, 0); - if (priv->sock == -1) { + if (priv->sock < 0) { gf_log(this->name, GF_LOG_ERROR, "socket creation failed (%s)", strerror(errno)); ret = -1; @@ -3365,7 +3405,7 @@ socket_connect(rpc_transport_t *this, int port) */ if (priv->windowsize != 0) { if (setsockopt(priv->sock, SOL_SOCKET, SO_RCVBUF, &priv->windowsize, - sizeof(priv->windowsize)) < 0) { + sizeof(priv->windowsize)) != 0) { gf_log(this->name, GF_LOG_ERROR, "setting receive window " "size failed: %d: %d: %s", @@ -3373,7 +3413,7 @@ socket_connect(rpc_transport_t *this, int port) } if (setsockopt(priv->sock, SOL_SOCKET, SO_SNDBUF, &priv->windowsize, - sizeof(priv->windowsize)) < 0) { + sizeof(priv->windowsize)) != 0) { gf_log(this->name, GF_LOG_ERROR, "setting send window size " "failed: %d: %d: %s", @@ -3395,30 +3435,32 @@ socket_connect(rpc_transport_t *this, int port) } #endif - if (priv->nodelay && (sa_family != AF_UNIX)) { - ret = __socket_nodelay(priv->sock); - - if (ret == -1) { - gf_log(this->name, GF_LOG_ERROR, "NODELAY on %d failed (%s)", - priv->sock, strerror(errno)); + if (sa_family != AF_UNIX) { + if (priv->nodelay) { + ret = __socket_nodelay(priv->sock); + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, + "NODELAY on %d failed (%s)", priv->sock, + strerror(errno)); + } } - } - if (priv->keepalive && sa_family != AF_UNIX) { - ret = __socket_keepalive(priv->sock, sa_family, - priv->keepaliveintvl, priv->keepaliveidle, - priv->keepalivecnt, priv->timeout); - if (ret == -1) - gf_log(this->name, GF_LOG_ERROR, "Failed to set keep-alive: %s", - strerror(errno)); + if (priv->keepalive) { + ret = __socket_keepalive( + priv->sock, sa_family, priv->keepaliveintvl, + priv->keepaliveidle, priv->keepalivecnt, priv->timeout); + if (ret != 0) + gf_log(this->name, GF_LOG_ERROR, + "Failed to set keep-alive: %s", strerror(errno)); + } } SA(&this->myinfo.sockaddr)->sa_family = SA(&this->peerinfo.sockaddr) ->sa_family; /* If a source addr is explicitly specified, use it */ - ret = dict_get_str(this->options, "transport.socket.source-addr", - &local_addr); + ret = dict_get_str_sizen(this->options, "transport.socket.source-addr", + &local_addr); if (!ret && SA(&this->myinfo.sockaddr)->sa_family == AF_INET) { addr = (struct sockaddr_in *)(&this->myinfo.sockaddr); ret = inet_pton(AF_INET, local_addr, &(addr->sin_addr.s_addr)); @@ -3430,7 +3472,7 @@ socket_connect(rpc_transport_t *this, int port) ret = client_bind(this, SA(&this->myinfo.sockaddr), &this->myinfo.sockaddr_len, priv->sock); - if (ret == -1) { + if (ret < 0) { gf_log(this->name, GF_LOG_WARNING, "client bind failed: %s", strerror(errno)); goto handler; @@ -3439,7 +3481,7 @@ socket_connect(rpc_transport_t *this, int port) /* make socket non-blocking for all types of sockets */ if (!priv->bio) { ret = __socket_nonblock(priv->sock); - if (ret == -1) { + if (ret != 0) { gf_log(this->name, GF_LOG_ERROR, "NBIO on %d failed (%s)", priv->sock, strerror(errno)); goto handler; @@ -3466,7 +3508,7 @@ socket_connect(rpc_transport_t *this, int port) connect_attempted = _gf_true; - if (ret == -1 && errno == ENOENT && ign_enoent) { + if ((ret != 0) && (errno == ENOENT) && ign_enoent) { gf_log(this->name, GF_LOG_WARNING, "Ignore failed connection attempt on %s, (%s) ", this->peerinfo.identifier, strerror(errno)); @@ -3484,7 +3526,7 @@ socket_connect(rpc_transport_t *this, int port) goto handler; } - if (ret == -1 && ((errno != EINPROGRESS) && (errno != ENOENT))) { + if ((ret != 0) && (errno != EINPROGRESS) && (errno != ENOENT)) { /* For unix path based sockets, the socket path is * cryptic (md5sum of path) and may not be useful for * the user in debugging so log it in DEBUG @@ -3529,8 +3571,9 @@ socket_connect(rpc_transport_t *this, int port) refd = _gf_true; this->listener = this; - priv->idx = event_register(ctx->event_pool, priv->sock, - socket_event_handler, this, 1, 1); + priv->idx = gf_event_register(ctx->event_pool, priv->sock, + socket_event_handler, this, 1, 1, + this->notify_poller_death); if (priv->idx == -1) { gf_log("", GF_LOG_WARNING, "failed to register the event; " @@ -3545,11 +3588,10 @@ socket_connect(rpc_transport_t *this, int port) sock = priv->sock; } pthread_mutex_unlock(&priv->out_lock); - pthread_mutex_unlock(&priv->in_lock); err: - /* if sock != -1, then cleanup is done from the event handler */ - if (ret == -1 && sock == -1) { + /* if sock >= 0, then cleanup is done from the event handler */ + if ((ret < 0) && (sock < 0)) { /* Cleaup requires to send notification to upper layer which intern holds the big_lock. There can be dead-lock situation if big_lock is already held by the current thread. @@ -3597,29 +3639,26 @@ socket_listen(rpc_transport_t *this) myinfo = &this->myinfo; ctx = this->ctx; - pthread_mutex_lock(&priv->in_lock); pthread_mutex_lock(&priv->out_lock); { sock = priv->sock; } pthread_mutex_unlock(&priv->out_lock); - pthread_mutex_unlock(&priv->in_lock); - if (sock != -1) { + if (sock >= 0) { gf_log_callingfn(this->name, GF_LOG_DEBUG, "already listening"); return ret; } ret = socket_server_get_local_sockaddr(this, SA(&sockaddr), &sockaddr_len, &sa_family); - if (ret == -1) { + if (ret < 0) { return ret; } - pthread_mutex_lock(&priv->in_lock); pthread_mutex_lock(&priv->out_lock); { - if (priv->sock != -1) { + if (priv->sock >= 0) { gf_log(this->name, GF_LOG_DEBUG, "already listening"); goto unlock; } @@ -3629,7 +3668,7 @@ socket_listen(rpc_transport_t *this) priv->sock = sys_socket(sa_family, SOCK_STREAM, 0); - if (priv->sock == -1) { + if (priv->sock < 0) { gf_log(this->name, GF_LOG_ERROR, "socket creation failed (%s)", strerror(errno)); goto unlock; @@ -3640,7 +3679,7 @@ socket_listen(rpc_transport_t *this) */ if (priv->windowsize != 0) { if (setsockopt(priv->sock, SOL_SOCKET, SO_RCVBUF, &priv->windowsize, - sizeof(priv->windowsize)) < 0) { + sizeof(priv->windowsize)) != 0) { gf_log(this->name, GF_LOG_ERROR, "setting receive window size " "failed: %d: %d: %s", @@ -3648,7 +3687,7 @@ socket_listen(rpc_transport_t *this) } if (setsockopt(priv->sock, SOL_SOCKET, SO_SNDBUF, &priv->windowsize, - sizeof(priv->windowsize)) < 0) { + sizeof(priv->windowsize)) != 0) { gf_log(this->name, GF_LOG_ERROR, "setting send window size failed:" " %d: %d: %s", @@ -3658,7 +3697,7 @@ socket_listen(rpc_transport_t *this) if (priv->nodelay && (sa_family != AF_UNIX)) { ret = __socket_nodelay(priv->sock); - if (ret == -1) { + if (ret != 0) { gf_log(this->name, GF_LOG_ERROR, "setsockopt() failed for NODELAY (%s)", strerror(errno)); } @@ -3667,7 +3706,7 @@ socket_listen(rpc_transport_t *this) if (!priv->bio) { ret = __socket_nonblock(priv->sock); - if (ret == -1) { + if (ret != 0) { gf_log(this->name, GF_LOG_ERROR, "NBIO on socket %d failed " "(errno:%s); closing socket", @@ -3678,9 +3717,10 @@ socket_listen(rpc_transport_t *this) } } + /* coverity[SLEEP] */ ret = __socket_server_bind(this); - if ((ret == -EADDRINUSE) || (ret == -1)) { + if (ret < 0) { /* logged inside __socket_server_bind() */ gf_log(this->name, GF_LOG_ERROR, "__socket_server_bind failed;" @@ -3696,7 +3736,7 @@ socket_listen(rpc_transport_t *this) ret = listen(priv->sock, priv->backlog); - if (ret == -1) { + if (ret != 0) { gf_log(this->name, GF_LOG_ERROR, "could not set socket %d to listen mode (errno:%s); " "closing socket", @@ -3708,8 +3748,9 @@ socket_listen(rpc_transport_t *this) rpc_transport_ref(this); - priv->idx = event_register(ctx->event_pool, priv->sock, - socket_server_event_handler, this, 1, 0); + priv->idx = gf_event_register(ctx->event_pool, priv->sock, + socket_server_event_handler, this, 1, 0, + this->notify_poller_death); if (priv->idx == -1) { gf_log(this->name, GF_LOG_WARNING, @@ -3724,7 +3765,6 @@ socket_listen(rpc_transport_t *this) } unlock: pthread_mutex_unlock(&priv->out_lock); - pthread_mutex_unlock(&priv->in_lock); out: return ret; @@ -3763,7 +3803,7 @@ socket_submit_outgoing_msg(rpc_transport_t *this, rpc_transport_msg_t *msg) goto unlock; if (list_empty(&priv->ioq)) { - ret = __socket_ioq_churn_entry(this, entry, 1); + ret = __socket_ioq_churn_entry(this, entry); if (ret == 0) { need_append = 0; @@ -3779,8 +3819,8 @@ socket_submit_outgoing_msg(rpc_transport_t *this, rpc_transport_msg_t *msg) } if (need_poll_out) { /* first entry to wait. continue writing on POLLOUT */ - priv->idx = event_select_on(ctx->event_pool, priv->sock, priv->idx, - -1, 1); + priv->idx = gf_event_select_on(ctx->event_pool, priv->sock, + priv->idx, -1, 1); } } unlock: @@ -3889,7 +3929,6 @@ socket_throttle(rpc_transport_t *this, gf_boolean_t onoff) will never read() any more data until throttling is turned off. */ - pthread_mutex_lock(&priv->in_lock); pthread_mutex_lock(&priv->out_lock); { /* Throttling is useless on a disconnected transport. In fact, @@ -3898,11 +3937,10 @@ socket_throttle(rpc_transport_t *this, gf_boolean_t onoff) * registered fd mapping. */ if (priv->connected == 1) - priv->idx = event_select_on(this->ctx->event_pool, priv->sock, - priv->idx, (int)!onoff, -1); + priv->idx = gf_event_select_on(this->ctx->event_pool, priv->sock, + priv->idx, (int)!onoff, -1); } pthread_mutex_unlock(&priv->out_lock); - pthread_mutex_unlock(&priv->in_lock); return 0; } @@ -3925,31 +3963,23 @@ reconfigure(rpc_transport_t *this, dict_t *options) socket_private_t *priv = NULL; gf_boolean_t tmp_bool = _gf_false; char *optstr = NULL; - int ret = 0; + int ret = -1; uint32_t backlog = 0; uint64_t windowsize = 0; - uint32_t timeout = 42; - int keepaliveidle = GF_KEEPALIVE_TIME; - int keepaliveintvl = GF_KEEPALIVE_INTERVAL; - int keepalivecnt = GF_KEEPALIVE_COUNT; + data_t *data; GF_VALIDATE_OR_GOTO("socket", this, out); GF_VALIDATE_OR_GOTO("socket", this->private, out); - if (!this || !this->private) { - ret = -1; - goto out; - } - priv = this->private; - if (dict_get_str(options, "transport.socket.keepalive", &optstr) == 0) { - if (gf_string2boolean(optstr, &tmp_bool) == -1) { + if (dict_get_str_sizen(options, "transport.socket.keepalive", &optstr) == + 0) { + if (gf_string2boolean(optstr, &tmp_bool) != 0) { gf_log(this->name, GF_LOG_ERROR, "'transport.socket.keepalive' takes only " "boolean options, not taking any action"); priv->keepalive = 1; - ret = -1; goto out; } gf_log(this->name, GF_LOG_DEBUG, @@ -3959,48 +3989,43 @@ reconfigure(rpc_transport_t *this, dict_t *options) } else priv->keepalive = 1; - if (dict_get_int32(options, "transport.tcp-user-timeout", - &(priv->timeout)) != 0) - priv->timeout = timeout; + if (dict_get_int32_sizen(options, "transport.tcp-user-timeout", + &(priv->timeout)) != 0) + priv->timeout = GF_NETWORK_TIMEOUT; gf_log(this->name, GF_LOG_DEBUG, - "Reconfigued " - "transport.tcp-user-timeout=%d", - priv->timeout); + "Reconfigured transport.tcp-user-timeout=%d", priv->timeout); if (dict_get_uint32(options, "transport.listen-backlog", &backlog) == 0) { priv->backlog = backlog; gf_log(this->name, GF_LOG_DEBUG, - "Reconfigued " - "transport.listen-backlog=%d", - priv->backlog); + "Reconfigured transport.listen-backlog=%d", priv->backlog); } - if (dict_get_int32(options, "transport.socket.keepalive-time", - &(priv->keepaliveidle)) != 0) - priv->keepaliveidle = keepaliveidle; - gf_log(this->name, GF_LOG_DEBUG, - "Reconfigued " - "transport.socket.keepalive-time=%d", - priv->keepaliveidle); + if (priv->keepalive) { + if (dict_get_int32_sizen(options, "transport.socket.keepalive-time", + &(priv->keepaliveidle)) != 0) + priv->keepaliveidle = GF_KEEPALIVE_TIME; + gf_log(this->name, GF_LOG_DEBUG, + "Reconfigured transport.socket.keepalive-time=%d", + priv->keepaliveidle); - if (dict_get_int32(options, "transport.socket.keepalive-interval", - &(priv->keepaliveintvl)) != 0) - priv->keepaliveintvl = keepaliveintvl; - gf_log(this->name, GF_LOG_DEBUG, - "Reconfigued " - "transport.socket.keepalive-interval=%d", - priv->keepaliveintvl); + if (dict_get_int32_sizen(options, "transport.socket.keepalive-interval", + &(priv->keepaliveintvl)) != 0) + priv->keepaliveintvl = GF_KEEPALIVE_INTERVAL; + gf_log(this->name, GF_LOG_DEBUG, + "Reconfigured transport.socket.keepalive-interval=%d", + priv->keepaliveintvl); - if (dict_get_int32(options, "transport.socket.keepalive-count", - &(priv->keepalivecnt)) != 0) - priv->keepalivecnt = keepalivecnt; - gf_log(this->name, GF_LOG_DEBUG, - "Reconfigued " - "transport.socket.keepalive-count=%d", - priv->keepalivecnt); + if (dict_get_int32_sizen(options, "transport.socket.keepalive-count", + &(priv->keepalivecnt)) != 0) + priv->keepalivecnt = GF_KEEPALIVE_COUNT; + gf_log(this->name, GF_LOG_DEBUG, + "Reconfigured transport.socket.keepalive-count=%d", + priv->keepalivecnt); + } optstr = NULL; - if (dict_get_str(options, "tcp-window-size", &optstr) == 0) { + if (dict_get_str_sizen(options, "tcp-window-size", &optstr) == 0) { if (gf_string2uint64(optstr, &windowsize) != 0) { gf_log(this->name, GF_LOG_ERROR, "invalid number format: %s", optstr); @@ -4010,10 +4035,11 @@ reconfigure(rpc_transport_t *this, dict_t *options) priv->windowsize = (int)windowsize; - if (dict_get(options, "non-blocking-io")) { - optstr = data_to_str(dict_get(options, "non-blocking-io")); + data = dict_get_sizen(options, "non-blocking-io"); + if (data) { + optstr = data_to_str(data); - if (gf_string2boolean(optstr, &tmp_bool) == -1) { + if (gf_string2boolean(optstr, &tmp_bool) != 0) { gf_log(this->name, GF_LOG_ERROR, "'non-blocking-io' takes only boolean options," " not taking any action"); @@ -4028,7 +4054,7 @@ reconfigure(rpc_transport_t *this, dict_t *options) if (!priv->bio) { ret = __socket_nonblock(priv->sock); - if (ret == -1) { + if (ret != 0) { gf_log(this->name, GF_LOG_WARNING, "NBIO on %d failed (%s)", priv->sock, strerror(errno)); goto out; @@ -4142,6 +4168,34 @@ static void __attribute__((destructor)) fini_openssl_mt(void) ERR_free_strings(); } +/* The function returns 0 if AES bit is enabled on the CPU */ +static int +ssl_check_aes_bit(void) +{ + FILE *fp = fopen("/proc/cpuinfo", "r"); + int ret = 1; + size_t len = 0; + char *line = NULL; + char *match = NULL; + + GF_ASSERT(fp != NULL); + + while (getline(&line, &len, fp) > 0) { + if (!strncmp(line, "flags", 5)) { + match = strstr(line, " aes"); + if ((match != NULL) && ((match[4] == ' ') || (match[4] == 0))) { + ret = 0; + break; + } + } + } + + free(line); + fclose(fp); + + return ret; +} + static int ssl_setup_connection_params(rpc_transport_t *this) { @@ -4152,7 +4206,7 @@ ssl_setup_connection_params(rpc_transport_t *this) char *cipher_list = DEFAULT_CIPHER_LIST; char *dh_param = DEFAULT_DH_PARAM; char *ec_curve = DEFAULT_EC_CURVE; - char *crl_path = NULL; + gf_boolean_t dh_flag = _gf_false; priv = this->private; @@ -4161,8 +4215,16 @@ ssl_setup_connection_params(rpc_transport_t *this) return 0; } + if (!priv->ssl_enabled && !priv->mgmt_ssl) { + return 0; + } + + if (!ssl_check_aes_bit()) { + cipher_list = "AES128:" DEFAULT_CIPHER_LIST; + } + priv->ssl_own_cert = DEFAULT_CERT_PATH; - if (dict_get_str(this->options, SSL_OWN_CERT_OPT, &optstr) == 0) { + if (dict_get_str_sizen(this->options, SSL_OWN_CERT_OPT, &optstr) == 0) { if (!priv->ssl_enabled) { gf_log(this->name, GF_LOG_WARNING, "%s specified without %s (ignored)", SSL_OWN_CERT_OPT, @@ -4173,7 +4235,7 @@ ssl_setup_connection_params(rpc_transport_t *this) priv->ssl_own_cert = gf_strdup(priv->ssl_own_cert); priv->ssl_private_key = DEFAULT_KEY_PATH; - if (dict_get_str(this->options, SSL_PRIVATE_KEY_OPT, &optstr) == 0) { + if (dict_get_str_sizen(this->options, SSL_PRIVATE_KEY_OPT, &optstr) == 0) { if (!priv->ssl_enabled) { gf_log(this->name, GF_LOG_WARNING, "%s specified without %s (ignored)", SSL_PRIVATE_KEY_OPT, @@ -4184,7 +4246,7 @@ ssl_setup_connection_params(rpc_transport_t *this) priv->ssl_private_key = gf_strdup(priv->ssl_private_key); priv->ssl_ca_list = DEFAULT_CA_PATH; - if (dict_get_str(this->options, SSL_CA_LIST_OPT, &optstr) == 0) { + if (dict_get_str_sizen(this->options, SSL_CA_LIST_OPT, &optstr) == 0) { if (!priv->ssl_enabled) { gf_log(this->name, GF_LOG_WARNING, "%s specified without %s (ignored)", SSL_CA_LIST_OPT, @@ -4194,42 +4256,41 @@ ssl_setup_connection_params(rpc_transport_t *this) } priv->ssl_ca_list = gf_strdup(priv->ssl_ca_list); - if (dict_get_str(this->options, SSL_CRL_PATH_OPT, &optstr) == 0) { + optstr = NULL; + if (dict_get_str_sizen(this->options, SSL_CRL_PATH_OPT, &optstr) == 0) { if (!priv->ssl_enabled) { gf_log(this->name, GF_LOG_WARNING, "%s specified without %s (ignored)", SSL_CRL_PATH_OPT, SSL_ENABLED_OPT); } if (strcasecmp(optstr, "NULL") == 0) - crl_path = NULL; + priv->crl_path = NULL; else - crl_path = optstr; + priv->crl_path = gf_strdup(optstr); } - gf_log(this->name, priv->ssl_enabled ? GF_LOG_INFO : GF_LOG_DEBUG, - "SSL support on the I/O path is %s", - priv->ssl_enabled ? "ENABLED" : "NOT enabled"); - gf_log(this->name, priv->mgmt_ssl ? GF_LOG_INFO : GF_LOG_DEBUG, - "SSL support for glusterd is %s", - priv->mgmt_ssl ? "ENABLED" : "NOT enabled"); - if (!priv->mgmt_ssl) { - if (!dict_get_int32(this->options, SSL_CERT_DEPTH_OPT, &cert_depth)) { - gf_log(this->name, GF_LOG_INFO, "using certificate depth %d", - cert_depth); + if (!dict_get_int32_sizen(this->options, SSL_CERT_DEPTH_OPT, + &cert_depth)) { } } else { cert_depth = this->ctx->ssl_cert_depth; - gf_log(this->name, GF_LOG_INFO, "using certificate depth %d", - cert_depth); } - if (!dict_get_str(this->options, SSL_CIPHER_LIST_OPT, &cipher_list)) { + gf_log(this->name, priv->ssl_enabled ? GF_LOG_INFO : GF_LOG_DEBUG, + "SSL support for MGMT is %s IO path is %s certificate depth is %d " + "for peer %s", + (priv->mgmt_ssl ? "ENABLED" : "NOT enabled"), + (priv->ssl_enabled ? "ENABLED" : "NOT enabled"), cert_depth, + this->peerinfo.identifier); + + if (!dict_get_str_sizen(this->options, SSL_CIPHER_LIST_OPT, &cipher_list)) { gf_log(this->name, GF_LOG_INFO, "using cipher list %s", cipher_list); } - if (!dict_get_str(this->options, SSL_DH_PARAM_OPT, &dh_param)) { + if (!dict_get_str_sizen(this->options, SSL_DH_PARAM_OPT, &dh_param)) { + dh_flag = _gf_true; gf_log(this->name, GF_LOG_INFO, "using DH parameters %s", dh_param); } - if (!dict_get_str(this->options, SSL_EC_CURVE_OPT, &ec_curve)) { + if (!dict_get_str_sizen(this->options, SSL_EC_CURVE_OPT, &ec_curve)) { gf_log(this->name, GF_LOG_INFO, "using EC curve %s", ec_curve); } @@ -4261,12 +4322,15 @@ ssl_setup_connection_params(rpc_transport_t *this) #ifdef SSL_OP_NO_COMPRESSION SSL_CTX_set_options(priv->ssl_ctx, SSL_OP_NO_COMPRESSION); #endif - - if ((bio = BIO_new_file(dh_param, "r")) == NULL) { - gf_log(this->name, GF_LOG_INFO, - "failed to open %s, " - "DH ciphers are disabled", - dh_param); + /* Upload file to bio wrapper only if dh param is configured + */ + if (dh_flag) { + if ((bio = BIO_new_file(dh_param, "r")) == NULL) { + gf_log(this->name, GF_LOG_ERROR, + "failed to open %s, " + "DH ciphers are disabled", + dh_param); + } } if (bio != NULL) { @@ -4345,25 +4409,15 @@ ssl_setup_connection_params(rpc_transport_t *this) } if (!SSL_CTX_load_verify_locations(priv->ssl_ctx, priv->ssl_ca_list, - crl_path)) { + priv->crl_path)) { gf_log(this->name, GF_LOG_ERROR, "could not load CA list"); goto err; } SSL_CTX_set_verify_depth(priv->ssl_ctx, cert_depth); - if (crl_path) { -#ifdef X509_V_FLAG_CRL_CHECK_ALL - X509_STORE *x509store; - - x509store = SSL_CTX_get_cert_store(priv->ssl_ctx); - X509_STORE_set_flags( - x509store, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL); -#else - gf_log(this->name, GF_LOG_ERROR, - "OpenSSL version does not support CRL"); -#endif - } + if (priv->crl_path) + ssl_set_crl_verify_flags(priv->ssl_ctx); priv->ssl_session_id = session_id++; SSL_CTX_set_session_id_context(priv->ssl_ctx, @@ -4393,25 +4447,19 @@ socket_init(rpc_transport_t *this) gf_boolean_t tmp_bool = 0; uint64_t windowsize = GF_DEFAULT_SOCKET_WINDOW_SIZE; char *optstr = NULL; - uint32_t timeout = 42; - int keepaliveidle = GF_KEEPALIVE_TIME; - int keepaliveintvl = GF_KEEPALIVE_INTERVAL; - int keepalivecnt = GF_KEEPALIVE_COUNT; - uint32_t backlog = 0; + data_t *data; if (this->private) { gf_log_callingfn(this->name, GF_LOG_ERROR, "double init attempted"); return -1; } - priv = GF_MALLOC(sizeof(*priv), gf_common_mt_socket_private_t); + priv = GF_CALLOC(1, sizeof(*priv), gf_common_mt_socket_private_t); if (!priv) { return -1; } - memset(priv, 0, sizeof(*priv)); this->private = priv; - pthread_mutex_init(&priv->in_lock, NULL); pthread_mutex_init(&priv->out_lock, NULL); pthread_mutex_init(&priv->cond_lock, NULL); pthread_cond_init(&priv->cond, NULL); @@ -4434,10 +4482,11 @@ socket_init(rpc_transport_t *this) if (!this->options) goto out; - if (dict_get(this->options, "non-blocking-io")) { - optstr = data_to_str(dict_get(this->options, "non-blocking-io")); + data = dict_get_sizen(this->options, "non-blocking-io"); + if (data) { + optstr = data_to_str(data); - if (gf_string2boolean(optstr, &tmp_bool) == -1) { + if (gf_string2boolean(optstr, &tmp_bool) != 0) { gf_log(this->name, GF_LOG_ERROR, "'non-blocking-io' takes only boolean options," " not taking any action"); @@ -4453,11 +4502,11 @@ socket_init(rpc_transport_t *this) optstr = NULL; /* By default, we enable NODELAY */ - if (dict_get(this->options, "transport.socket.nodelay")) { - optstr = data_to_str( - dict_get(this->options, "transport.socket.nodelay")); + data = dict_get_sizen(this->options, "transport.socket.nodelay"); + if (data) { + optstr = data_to_str(data); - if (gf_string2boolean(optstr, &tmp_bool) == -1) { + if (gf_string2boolean(optstr, &tmp_bool) != 0) { gf_log(this->name, GF_LOG_ERROR, "'transport.socket.nodelay' takes only " "boolean options, not taking any action"); @@ -4470,7 +4519,7 @@ socket_init(rpc_transport_t *this) } optstr = NULL; - if (dict_get_str(this->options, "tcp-window-size", &optstr) == 0) { + if (dict_get_str_sizen(this->options, "tcp-window-size", &optstr) == 0) { if (gf_string2uint64(optstr, &windowsize) != 0) { gf_log(this->name, GF_LOG_ERROR, "invalid number format: %s", optstr); @@ -4486,9 +4535,9 @@ socket_init(rpc_transport_t *this) priv->keepaliveintvl = GF_KEEPALIVE_INTERVAL; priv->keepaliveidle = GF_KEEPALIVE_TIME; priv->keepalivecnt = GF_KEEPALIVE_COUNT; - if (dict_get_str(this->options, "transport.socket.keepalive", &optstr) == - 0) { - if (gf_string2boolean(optstr, &tmp_bool) == -1) { + if (dict_get_str_sizen(this->options, "transport.socket.keepalive", + &optstr) == 0) { + if (gf_string2boolean(optstr, &tmp_bool) != 0) { gf_log(this->name, GF_LOG_ERROR, "'transport.socket.keepalive' takes only " "boolean options, not taking any action"); @@ -4499,46 +4548,46 @@ socket_init(rpc_transport_t *this) priv->keepalive = 0; } - if (dict_get_int32(this->options, "transport.tcp-user-timeout", - &(priv->timeout)) != 0) - priv->timeout = timeout; - gf_log(this->name, GF_LOG_DEBUG, - "Configued " - "transport.tcp-user-timeout=%d", + if (dict_get_int32_sizen(this->options, "transport.tcp-user-timeout", + &(priv->timeout)) != 0) + priv->timeout = GF_NETWORK_TIMEOUT; + gf_log(this->name, GF_LOG_DEBUG, "Configured transport.tcp-user-timeout=%d", priv->timeout); - if (dict_get_int32(this->options, "transport.socket.keepalive-time", - &(priv->keepaliveidle)) != 0) { - priv->keepaliveidle = keepaliveidle; - } + if (priv->keepalive) { + if (dict_get_int32_sizen(this->options, + "transport.socket.keepalive-time", + &(priv->keepaliveidle)) != 0) { + priv->keepaliveidle = GF_KEEPALIVE_TIME; + } - if (dict_get_int32(this->options, "transport.socket.keepalive-interval", - &(priv->keepaliveintvl)) != 0) { - priv->keepaliveintvl = keepaliveintvl; - } + if (dict_get_int32_sizen(this->options, + "transport.socket.keepalive-interval", + &(priv->keepaliveintvl)) != 0) { + priv->keepaliveintvl = GF_KEEPALIVE_INTERVAL; + } - if (dict_get_int32(this->options, "transport.socket.keepalive-count", - &(priv->keepalivecnt)) != 0) - priv->keepalivecnt = keepalivecnt; - gf_log(this->name, GF_LOG_DEBUG, - "Reconfigued " - "transport.keepalivecnt=%d", - keepalivecnt); + if (dict_get_int32_sizen(this->options, + "transport.socket.keepalive-count", + &(priv->keepalivecnt)) != 0) + priv->keepalivecnt = GF_KEEPALIVE_COUNT; + gf_log(this->name, GF_LOG_DEBUG, + "Reconfigured transport.keepalivecnt=%d", priv->keepalivecnt); + } - if (dict_get_uint32(this->options, "transport.listen-backlog", &backlog) != - 0) { - backlog = GLUSTERFS_SOCKET_LISTEN_BACKLOG; + if (dict_get_uint32(this->options, "transport.listen-backlog", + &(priv->backlog)) != 0) { + priv->backlog = GLUSTERFS_SOCKET_LISTEN_BACKLOG; } - priv->backlog = backlog; optstr = NULL; /* Check if socket read failures are to be logged */ priv->read_fail_log = 1; - if (dict_get(this->options, "transport.socket.read-fail-log")) { - optstr = data_to_str( - dict_get(this->options, "transport.socket.read-fail-log")); - if (gf_string2boolean(optstr, &tmp_bool) == -1) { + data = dict_get_sizen(this->options, "transport.socket.read-fail-log"); + if (data) { + optstr = data_to_str(data); + if (gf_string2boolean(optstr, &tmp_bool) != 0) { gf_log(this->name, GF_LOG_WARNING, "'transport.socket.read-fail-log' takes only " "boolean options; logging socket read fails"); @@ -4550,7 +4599,7 @@ socket_init(rpc_transport_t *this) priv->windowsize = (int)windowsize; priv->ssl_enabled = _gf_false; - if (dict_get_str(this->options, SSL_ENABLED_OPT, &optstr) == 0) { + if (dict_get_str_sizen(this->options, SSL_ENABLED_OPT, &optstr) == 0) { if (gf_string2boolean(optstr, &priv->ssl_enabled) != 0) { gf_log(this->name, GF_LOG_ERROR, "invalid value given for ssl-enabled boolean"); @@ -4575,22 +4624,34 @@ fini(rpc_transport_t *this) priv = this->private; if (priv) { - if (priv->sock != -1) { - pthread_mutex_lock(&priv->in_lock); + if (priv->sock >= 0) { pthread_mutex_lock(&priv->out_lock); { - __socket_ioq_flush(this); + __socket_ioq_flush(priv); __socket_reset(this); } pthread_mutex_unlock(&priv->out_lock); - pthread_mutex_unlock(&priv->in_lock); } gf_log(this->name, GF_LOG_TRACE, "transport %p destroyed", this); - pthread_mutex_destroy(&priv->in_lock); pthread_mutex_destroy(&priv->out_lock); pthread_mutex_destroy(&priv->cond_lock); pthread_cond_destroy(&priv->cond); + + GF_ASSERT(priv->notify.in_progress == 0); + pthread_mutex_destroy(&priv->notify.lock); + pthread_cond_destroy(&priv->notify.cond); + + if (priv->use_ssl && priv->ssl_ssl) { + SSL_clear(priv->ssl_ssl); + SSL_free(priv->ssl_ssl); + priv->ssl_ssl = NULL; + } + if (priv->ssl_ctx) { + SSL_CTX_free(priv->ssl_ctx); + priv->ssl_ctx = NULL; + } + if (priv->ssl_private_key) { GF_FREE(priv->ssl_private_key); } @@ -4615,7 +4676,7 @@ init(rpc_transport_t *this) ret = socket_init(this); - if (ret == -1) { + if (ret < 0) { gf_log(this->name, GF_LOG_DEBUG, "socket_init() failed"); } @@ -4661,11 +4722,10 @@ struct volume_options options[] = { {.key = {"transport.tcp-user-timeout"}, .type = GF_OPTION_TYPE_INT, .op_version = {GD_OP_VERSION_3_10_2}, - .default_value = "42"}, + .default_value = TOSTRING(GF_NETWORK_TIMEOUT)}, {.key = {"transport.socket.nodelay"}, .type = GF_OPTION_TYPE_BOOL, .default_value = "1"}, - {.key = {"transport.socket.lowlat"}, .type = GF_OPTION_TYPE_BOOL}, {.key = {"transport.socket.keepalive"}, .type = GF_OPTION_TYPE_BOOL, .op_version = {1}, diff --git a/rpc/rpc-transport/socket/src/socket.h b/rpc/rpc-transport/socket/src/socket.h index 27db0ed427b..8a2eda70605 100644 --- a/rpc/rpc-transport/socket/src/socket.h +++ b/rpc/rpc-transport/socket/src/socket.h @@ -14,6 +14,7 @@ #include <openssl/ssl.h> #include <openssl/err.h> #include <openssl/x509v3.h> +#include <openssl/x509_vfy.h> #ifdef HAVE_OPENSSL_DH_H #include <openssl/dh.h> #endif @@ -21,13 +22,7 @@ #include <openssl/ecdh.h> #endif -#include "gf-event.h" #include "rpc-transport.h" -#include "logging.h" -#include "dict.h" -#include "mem-pool.h" -#include "globals.h" -#include "refcount.h" #ifndef MAX_IOVEC #define MAX_IOVEC 16 @@ -108,12 +103,13 @@ struct ioq { }; }; - uint32_t fraghdr; struct iovec vector[MAX_IOVEC]; - int count; struct iovec *pending_vector; + int count; int pending_count; struct iobref *iobref; + uint32_t fraghdr; + char _pad[4]; }; typedef struct { @@ -169,49 +165,30 @@ struct gf_sock_incoming_frag { #define GF_SOCKET_RA_MAX 1024 struct gf_sock_incoming { - sp_rpcrecord_state_t record_state; - struct gf_sock_incoming_frag frag; char *proghdr_base_addr; struct iobuf *iobuf; size_t iobuf_size; + struct gf_sock_incoming_frag frag; struct iovec vector[2]; - int count; struct iovec payload_vector; struct iobref *iobref; rpc_request_info_t *request_info; struct iovec *pending_vector; + int count; int pending_count; - uint32_t fraghdr; - char complete_record; - msg_type_t msg_type; size_t total_bytes_read; size_t ra_read; size_t ra_max; size_t ra_served; char *ra_buf; + uint32_t fraghdr; + msg_type_t msg_type; + sp_rpcrecord_state_t record_state; + char _pad[4]; }; -typedef enum { - OT_IDLE, /* Uninitialized or termination complete. */ - OT_SPAWNING, /* Past pthread_create but not in thread yet. */ - OT_RUNNING, /* Poller thread running normally. */ - OT_CALLBACK, /* Poller thread in the middle of a callback. */ - OT_PLEASE_DIE, /* Poller termination requested. */ -} ot_state_t; - typedef struct { - int32_t sock; - int32_t idx; - int32_t gen; - /* -1 = not connected. 0 = in progress. 1 = connected */ - char connected; - /* 1 = connect failed for reasons other than EINPROGRESS/ENOENT - see socket_connect for details */ - char connect_failed; - char bio; - char connect_finish_log; - char submit_log; union { struct list_head ioq; struct { @@ -219,37 +196,60 @@ typedef struct { struct ioq *ioq_prev; }; }; - struct gf_sock_incoming incoming; - pthread_mutex_t in_lock; pthread_mutex_t out_lock; pthread_mutex_t cond_lock; pthread_cond_t cond; int windowsize; - char lowlat; - char nodelay; int keepalive; int keepaliveidle; int keepaliveintvl; int keepalivecnt; int timeout; + int log_ctr; + int shutdown_log_ctr; + /* ssl_error_required is used only during the SSL connection setup + * phase. + * It holds the error code returned by SSL_get_error() and is used to + * arm the epoll event set for the required event for the specific fd. + */ + int ssl_error_required; + int ssl_session_id; + + GF_REF_DECL; /* refcount to keep track of socket_poller + threads */ + struct { + pthread_mutex_t lock; + pthread_cond_t cond; + uint64_t in_progress; + } notify; + int32_t sock; + int32_t idx; + int32_t gen; uint32_t backlog; - gf_boolean_t read_fail_log; - gf_boolean_t ssl_enabled; /* outbound I/O */ - gf_boolean_t mgmt_ssl; /* outbound mgmt */ - mgmt_ssl_t srvr_ssl; - gf_boolean_t use_ssl; SSL_METHOD *ssl_meth; SSL_CTX *ssl_ctx; - int ssl_session_id; BIO *ssl_sbio; SSL *ssl_ssl; char *ssl_own_cert; char *ssl_private_key; char *ssl_ca_list; - pthread_t thread; - int pipe[2]; + char *crl_path; + struct gf_sock_incoming incoming; + mgmt_ssl_t srvr_ssl; + /* -1 = not connected. 0 = in progress. 1 = connected */ + char connected; + /* 1 = connect failed for reasons other than EINPROGRESS/ENOENT + see socket_connect for details */ + char connect_failed; + char bio; + char connect_finish_log; + char submit_log; + char nodelay; + gf_boolean_t read_fail_log; + gf_boolean_t ssl_enabled; /* outbound I/O */ + gf_boolean_t mgmt_ssl; /* outbound mgmt */ gf_boolean_t is_server; - int log_ctr; + gf_boolean_t use_ssl; gf_boolean_t ssl_accepted; /* To indicate SSL_accept() */ gf_boolean_t ssl_connected; /* or SSL_connect() has been * been completed on this socket. @@ -270,21 +270,7 @@ typedef struct { * socket_event_handler() for * newly accepted socket */ - - /* ssl_error_required is used only during the SSL connection setup - * phase. - * It holds the error code returned by SSL_get_error() and is used to - * arm the epoll event set for the required event for the specific fd. - */ - int ssl_error_required; - - GF_REF_DECL; /* refcount to keep track of socket_poller - threads */ - struct { - pthread_mutex_t lock; - pthread_cond_t cond; - uint64_t in_progress; - } notify; + char _pad[4]; } socket_private_t; #endif diff --git a/rpc/xdr/gen/Makefile.am b/rpc/xdr/gen/Makefile.am deleted file mode 100644 index df379b80130..00000000000 --- a/rpc/xdr/gen/Makefile.am +++ /dev/null @@ -1,49 +0,0 @@ -XDRGENFILES = glusterfs3-xdr.x glusterfs4-xdr.x cli1-xdr.x nlm4-xdr.x nsm-xdr.x \ - rpc-common-xdr.x glusterd1-xdr.x acl3-xdr.x portmap-xdr.x \ - mount3udp.x changelog-xdr.x glusterfs-fops.x -XDRHEADERS = $(XDRGENFILES:.x=.h) -XDRSOURCES = $(XDRGENFILES:.x=.c) - -CLEANFILES = $(XDRSOURCES) $(XDRHEADERS) $(XDRGENFILES) - -# trick automake into doing BUILT_SOURCES magic -BUILT_SOURCES = $(XDRHEADERS) $(XDRSOURCES) - -xdrsrc=$(top_srcdir)/rpc/xdr/src -xdrdst=$(top_builddir)/rpc/xdr/src - -# make's dependency resolution may mean that it decides to run -# rpcgen again (unnecessarily), but as the .c file already exists, -# rpcgen will exit with an error, resulting in a build error. We -# could use a '-' (i.e. -@rpcgen ...) and suffer with noisy warnings -# in the build. Or we do this crufty thing instead. -$(XDRSOURCES): $(XDRGENFILES) - @if [ ! -e $(xdrdst)/$@ -o $(@:.c=.x) -nt $(xdrdst)/$@ ]; then \ - rpcgen -c -o $(xdrdst)/$@ $(@:.c=.x) ;\ - fi - -# d*mn sed in netbsd6 doesn't do -i (inline) -# (why are we still running smoke on netbsd6 and not netbsd7?) -$(XDRHEADERS): $(XDRGENFILES) - @if [ ! -e $(xdrdst)/$@ -o $(@:.h=.x) -nt $(xdrdst)/$@ ]; then \ - rpcgen -h -o $(@:.h=.tmp) $(@:.h=.x) && \ - sed -e '/#ifndef/ s/-/_/g' -e '/#define/ s/-/_/g' \ - -e '/#endif/ s/-/_/' -e 's/TMP_/H_/g' \ - $(@:.h=.tmp) > $(xdrdst)/$@ && \ - rm -f $(@:.h=.tmp) ; \ - fi - - -# link .x files when doing out-of-tree builds -# have to use .PHONY here to force it; all versions of make -# will think the file already exists "here" by virtue of the -# VPATH. And we have to have the .x file in $cwd in order to -# have rpcgen generate "nice" #include directives -# i.e. (nice): -# #include "acl3-xdr.h" -# versus (not nice): -# #include "../../../../foo/src/rpc/xdr/src/acl3-xdr.h" -.PHONY : $(XDRGENFILES) -$(XDRGENFILES): - @if [ ! -e $@ ]; then ln -s $(xdrsrc)/$@ . ; fi; - diff --git a/rpc/xdr/src/.gitignore b/rpc/xdr/src/.gitignore index 6728940f546..a0c8b7ca2b6 100644 --- a/rpc/xdr/src/.gitignore +++ b/rpc/xdr/src/.gitignore @@ -10,8 +10,6 @@ glusterfs3-xdr.c glusterfs3-xdr.h glusterfs4-xdr.c glusterfs4-xdr.h -glusterfs-fops.h -glusterfs-fops.c mount3udp.c mount3udp.h nlm4-xdr.c diff --git a/rpc/xdr/src/Makefile.am b/rpc/xdr/src/Makefile.am index 495b9999236..0e9c377ec93 100644 --- a/rpc/xdr/src/Makefile.am +++ b/rpc/xdr/src/Makefile.am @@ -1,10 +1,19 @@ -XDRGENFILES = glusterfs3-xdr.x glusterfs4-xdr.x cli1-xdr.x nlm4-xdr.x nsm-xdr.x \ - rpc-common-xdr.x glusterd1-xdr.x acl3-xdr.x portmap-xdr.x \ - mount3udp.x changelog-xdr.x glusterfs-fops.x +if BUILD_GNFS + NFS_XDRS = nlm4-xdr.x nsm-xdr.x acl3-xdr.x mount3udp.x + NFS_SRCS = xdr-nfs3.c msg-nfs3.c + NFS_HDRS = xdr-nfs3.h msg-nfs3.h +else + NFS_EXTRA_XDRS = nlm4-xdr.x nsm-xdr.x acl3-xdr.x mount3udp.x +endif + +XDRGENFILES = glusterfs3-xdr.x glusterfs4-xdr.x cli1-xdr.x \ + rpc-common-xdr.x glusterd1-xdr.x changelog-xdr.x \ + portmap-xdr.x ${NFS_XDRS} + XDRHEADERS = $(XDRGENFILES:.x=.h) XDRSOURCES = $(XDRGENFILES:.x=.c) -EXTRA_DIST = $(XDRGENFILES) libgfxdr.sym +EXTRA_DIST = $(XDRGENFILES) libgfxdr.sym ${NFS_EXTRA_XDRS} lib_LTLIBRARIES = libgfxdr.la @@ -19,17 +28,58 @@ libgfxdr_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la libgfxdr_la_LDFLAGS = -version-info $(LIBGFXDR_LT_VERSION) $(GF_LDFLAGS) \ -export-symbols $(top_srcdir)/rpc/xdr/src/libgfxdr.sym -libgfxdr_la_SOURCES = xdr-generic.c xdr-nfs3.c msg-nfs3.c +libgfxdr_la_SOURCES = xdr-generic.c ${NFS_SRCS} nodist_libgfxdr_la_SOURCES = $(XDRSOURCES) -libgfxdr_la_HEADERS = xdr-generic.h xdr-nfs3.h msg-nfs3.h glusterfs3.h \ - rpc-pragmas.h +libgfxdr_la_HEADERS = xdr-generic.h glusterfs3.h rpc-pragmas.h ${NFS_HDRS} nodist_libgfxdr_la_HEADERS = $(XDRHEADERS) libgfxdr_ladir = $(includedir)/glusterfs/rpc CLEANFILES = $(XDRSOURCES) $(XDRHEADERS) -# Generate the .c and .h symlinks from the ../gen/*.x files -$(XDRSOURCES) $(XDRHEADERS): - $(MAKE) -C ../gen $^ +# trick automake into doing BUILT_SOURCES magic +BUILT_SOURCES = $(XDRHEADERS) $(XDRSOURCES) + +xdrsrc=$(top_srcdir)/rpc/xdr/src +xdrdst=$(top_builddir)/rpc/xdr/src + +# make's dependency resolution may mean that it decides to run +# rpcgen again (unnecessarily), but as the .c file already exists, +# rpcgen will exit with an error, resulting in a build error. We +# could use a '-' (i.e. -@rpcgen ...) and suffer with noisy warnings +# in the build. Or we do this crufty thing instead. +$(XDRSOURCES): $(XDRGENFILES) + @if [ ! -e $(xdrdst)/$@ -o $(@:.c=.x) -nt $(xdrdst)/$@ ]; then \ + rpcgen -c -o $(xdrdst)/$@ $(@:.c=.x) ;\ + fi + +# d*mn sed in netbsd6 doesn't do -i (inline) +# (why are we still running smoke on netbsd6 and not netbsd7?) +$(XDRHEADERS): $(XDRGENFILES) + @if [ ! -e $(xdrdst)/$@ -o $(@:.h=.x) -nt $(xdrdst)/$@ ]; then \ + rpcgen -h -o $(@:.h=.tmp) $(@:.h=.x) && \ + sed -e '/#ifndef/ s/-/_/g' -e '/#define/ s/-/_/g' \ + -e '/#endif/ s/-/_/' -e 's/TMP_/H_/g' \ + $(@:.h=.tmp) > $(xdrdst)/$@ && \ + rm -f $(@:.h=.tmp) ; \ + fi + + +# link .x files when doing out-of-tree builds +# have to use .PHONY here to force it; all versions of make +# will think the file already exists "here" by virtue of the +# VPATH. And we have to have the .x file in $cwd in order to +# have rpcgen generate "nice" #include directives +# i.e. (nice): +# #include "acl3-xdr.h" +# versus (not nice): +# #include "../../../../foo/src/rpc/xdr/src/acl3-xdr.h" +.PHONY : $(XDRGENFILES) +$(XDRGENFILES): + @if [ ! -e $@ ]; then ln -s $(xdrsrc)/$@ . ; fi; + +clean-local: + @if [ $(top_builddir) != $(top_srcdir) ]; then \ + rm -f $(xdrdst)/*.x; \ + fi diff --git a/rpc/xdr/src/acl3-xdr.x b/rpc/xdr/src/acl3-xdr.x index 44f1ed4fac9..7f7364971e6 100644 --- a/rpc/xdr/src/acl3-xdr.x +++ b/rpc/xdr/src/acl3-xdr.x @@ -11,7 +11,7 @@ #ifdef RPC_XDR %#include "rpc-pragmas.h" #endif -%#include "compat.h" +%#include <glusterfs/compat.h> %#include "xdr-nfs3.h" struct aclentry { diff --git a/rpc/xdr/src/changelog-xdr.x b/rpc/xdr/src/changelog-xdr.x index 97cd4558ccb..5956245d5ce 100644 --- a/rpc/xdr/src/changelog-xdr.x +++ b/rpc/xdr/src/changelog-xdr.x @@ -11,7 +11,7 @@ #ifdef RPC_XDR %#include "rpc-pragmas.h" #endif -%#include "compat.h" +%#include <glusterfs/compat.h> /* XDR: libgfchangelog -> changelog */ diff --git a/rpc/xdr/src/cli1-xdr.x b/rpc/xdr/src/cli1-xdr.x index 6f5fd256954..777cb0046a2 100644 --- a/rpc/xdr/src/cli1-xdr.x +++ b/rpc/xdr/src/cli1-xdr.x @@ -11,7 +11,7 @@ #ifdef RPC_XDR %#include "rpc-pragmas.h" #endif -%#include "compat.h" +%#include <glusterfs/compat.h> enum gf_cli_defrag_type { GF_DEFRAG_CMD_NONE = 0, @@ -68,6 +68,7 @@ enum gf_bitrot_type { GF_BITROT_OPTION_TYPE_EXPIRY_TIME, GF_BITROT_CMD_SCRUB_STATUS, GF_BITROT_CMD_SCRUB_ONDEMAND, + GF_BITROT_OPTION_TYPE_SIGNER_THREADS, GF_BITROT_OPTION_TYPE_MAX }; diff --git a/rpc/xdr/src/glusterd1-xdr.x b/rpc/xdr/src/glusterd1-xdr.x index 1ce57392b5b..b631dea3502 100644 --- a/rpc/xdr/src/glusterd1-xdr.x +++ b/rpc/xdr/src/glusterd1-xdr.x @@ -11,7 +11,7 @@ #ifdef RPC_XDR %#include "rpc-pragmas.h" #endif -%#include "compat.h" +%#include <glusterfs/compat.h> enum glusterd_volume_status { GLUSTERD_STATUS_NONE = 0, @@ -132,6 +132,7 @@ struct gd1_mgmt_brick_op_req { string name<>; int op; opaque input<>; + opaque dict<>; } ; struct gd1_mgmt_brick_op_rsp { @@ -201,6 +202,21 @@ struct gd1_mgmt_v3_commit_rsp { string op_errstr<>; } ; +struct gd1_mgmt_v3_post_commit_req { + unsigned char uuid[16]; + int op; + opaque dict<>; +} ; + +struct gd1_mgmt_v3_post_commit_rsp { + unsigned char uuid[16]; + int op; + int op_ret; + int op_errno; + opaque dict<>; + string op_errstr<>; +} ; + struct gd1_mgmt_v3_post_val_req { unsigned char uuid[16]; int op; diff --git a/rpc/xdr/src/glusterfs-fops.x b/rpc/xdr/src/glusterfs-fops.x deleted file mode 100644 index 8ccc4658f6c..00000000000 --- a/rpc/xdr/src/glusterfs-fops.x +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com> - * This file is part of GlusterFS. - * - * This file is licensed to you under your choice of the GNU Lesser - * General Public License, version 3 or any later version (LGPLv3 or - * later), or the GNU General Public License, version 2 (GPLv2), in all - * cases as published by the Free Software Foundation. - */ - -#ifdef RPC_XDR -%#include "rpc-pragmas.h" -#endif -%#include "compat.h" - -/* NOTE: add members ONLY at the end (just before _MAXVALUE) */ -/* - * OTHER NOTE: fop_enum_to_str and fop_enum_to_pri_str (in common-utils.h) also - * contain lists of fops, so if you update this list UPDATE THOSE TOO. - */ -enum glusterfs_fop_t { - GF_FOP_NULL = 0, - GF_FOP_STAT, - GF_FOP_READLINK, - GF_FOP_MKNOD, - GF_FOP_MKDIR, - GF_FOP_UNLINK, - GF_FOP_RMDIR, - GF_FOP_SYMLINK, - GF_FOP_RENAME, - GF_FOP_LINK, - GF_FOP_TRUNCATE, - GF_FOP_OPEN, - GF_FOP_READ, - GF_FOP_WRITE, - GF_FOP_STATFS, - GF_FOP_FLUSH, - GF_FOP_FSYNC, /* 16 */ - GF_FOP_SETXATTR, - GF_FOP_GETXATTR, - GF_FOP_REMOVEXATTR, - GF_FOP_OPENDIR, - GF_FOP_FSYNCDIR, - GF_FOP_ACCESS, - GF_FOP_CREATE, - GF_FOP_FTRUNCATE, - GF_FOP_FSTAT, /* 25 */ - GF_FOP_LK, - GF_FOP_LOOKUP, - GF_FOP_READDIR, - GF_FOP_INODELK, - GF_FOP_FINODELK, - GF_FOP_ENTRYLK, - GF_FOP_FENTRYLK, - GF_FOP_XATTROP, - GF_FOP_FXATTROP, - GF_FOP_FGETXATTR, - GF_FOP_FSETXATTR, - GF_FOP_RCHECKSUM, - GF_FOP_SETATTR, - GF_FOP_FSETATTR, - GF_FOP_READDIRP, - GF_FOP_FORGET, - GF_FOP_RELEASE, - GF_FOP_RELEASEDIR, - GF_FOP_GETSPEC, - GF_FOP_FREMOVEXATTR, - GF_FOP_FALLOCATE, - GF_FOP_DISCARD, - GF_FOP_ZEROFILL, - GF_FOP_IPC, - GF_FOP_SEEK, - GF_FOP_LEASE, - GF_FOP_COMPOUND, - GF_FOP_GETACTIVELK, - GF_FOP_SETACTIVELK, - GF_FOP_PUT, - GF_FOP_ICREATE, - GF_FOP_NAMELINK, - GF_FOP_MAXVALUE -}; - -/* Note: Removed event GF_EVENT_CHILD_MODIFIED=8, hence - *to preserve backward compatibiliy, GF_EVENT_CLEANUP = 9 - */ -enum glusterfs_event_t { - GF_EVENT_PARENT_UP = 1, - GF_EVENT_POLLIN, - GF_EVENT_POLLOUT, - GF_EVENT_POLLERR, - GF_EVENT_CHILD_UP, - GF_EVENT_CHILD_DOWN, - GF_EVENT_CHILD_CONNECTING, - GF_EVENT_CLEANUP = 9, - GF_EVENT_TRANSPORT_CONNECTED, - GF_EVENT_VOLFILE_MODIFIED, - GF_EVENT_GRAPH_NEW, - GF_EVENT_TRANSLATOR_INFO, - GF_EVENT_TRANSLATOR_OP, - GF_EVENT_AUTH_FAILED, - GF_EVENT_VOLUME_DEFRAG, - GF_EVENT_PARENT_DOWN, - GF_EVENT_VOLUME_BARRIER_OP, - GF_EVENT_UPCALL, - GF_EVENT_SCRUB_STATUS, - GF_EVENT_SOME_DESCENDENT_DOWN, - GF_EVENT_SCRUB_ONDEMAND, - GF_EVENT_SOME_DESCENDENT_UP, - GF_EVENT_CHILD_PING, - GF_EVENT_MAXVAL -}; - -/* List of compound fops. Add fops at the end. */ -enum glusterfs_compound_fop_t { - GF_CFOP_NON_PREDEFINED = 0, /* needs single FOP inspection */ - GF_CFOP_XATTROP_WRITEV, - GF_CFOP_XATTROP_UNLOCK, - GF_CFOP_PUT, /* create+write+setxattr+fsync+close+rename */ - GF_CFOP_MAXVALUE -}; - -enum glusterfs_mgmt_t { - GF_MGMT_NULL = 0, - GF_MGMT_MAXVALUE -}; - -enum gf_op_type_t { - GF_OP_TYPE_NULL = 0, - GF_OP_TYPE_FOP, - GF_OP_TYPE_MGMT, - GF_OP_TYPE_MAX -}; - -/* NOTE: all the miscellaneous flags used by GlusterFS should be listed here */ -enum glusterfs_lk_cmds_t { - GF_LK_GETLK = 0, - GF_LK_SETLK, - GF_LK_SETLKW, - GF_LK_RESLK_LCK, - GF_LK_RESLK_LCKW, - GF_LK_RESLK_UNLCK, - GF_LK_GETLK_FD -}; - -enum glusterfs_lk_types_t { - GF_LK_F_RDLCK = 0, - GF_LK_F_WRLCK, - GF_LK_F_UNLCK, - GF_LK_EOL -}; - -/* Lease Types */ -enum gf_lease_types_t { - NONE = 0, - GF_RD_LEASE = 1, - GF_RW_LEASE = 2, - GF_LEASE_MAX_TYPE -}; - -/* Lease cmds */ -enum gf_lease_cmds_t { - GF_GET_LEASE = 1, - GF_SET_LEASE = 2, - GF_UNLK_LEASE = 3 -}; - -%#define LEASE_ID_SIZE 16 /* 128bits */ -struct gf_lease { - gf_lease_cmds_t cmd; - gf_lease_types_t lease_type; - char lease_id[LEASE_ID_SIZE]; - unsigned int lease_flags; -}; - -enum glusterfs_lk_recovery_cmds_t { - F_RESLK_LCK = 200, - F_RESLK_LCKW, - F_RESLK_UNLCK, - F_GETLK_FD -}; - -enum gf_lk_domain_t { - GF_LOCK_POSIX, - GF_LOCK_INTERNAL -}; - -enum entrylk_cmd { - ENTRYLK_LOCK, - ENTRYLK_UNLOCK, - ENTRYLK_LOCK_NB -}; - -enum entrylk_type { - ENTRYLK_RDLCK, - ENTRYLK_WRLCK -}; - -%#define GF_MAX_LOCK_OWNER_LEN 1024 /* 1kB as per NLM */ - -/* 16strings-16strings-... */ -%#define GF_LKOWNER_BUF_SIZE ((GF_MAX_LOCK_OWNER_LEN * 2) + (GF_MAX_LOCK_OWNER_LEN / 8)) - -struct gf_lkowner_t { - int len; - char data[GF_MAX_LOCK_OWNER_LEN]; -}; - -enum gf_xattrop_flags_t { - GF_XATTROP_ADD_ARRAY, - GF_XATTROP_ADD_ARRAY64, - GF_XATTROP_OR_ARRAY, - GF_XATTROP_AND_ARRAY, - GF_XATTROP_GET_AND_SET, - GF_XATTROP_ADD_ARRAY_WITH_DEFAULT, - GF_XATTROP_ADD_ARRAY64_WITH_DEFAULT -}; - -enum gf_seek_what_t { - GF_SEEK_DATA, - GF_SEEK_HOLE -}; - -enum gf_upcall_flags_t { - GF_UPCALL_NULL, - GF_UPCALL, - GF_UPCALL_CI_STAT, - GF_UPCALL_CI_XATTR, - GF_UPCALL_CI_RENAME, - GF_UPCALL_CI_NLINK, - GF_UPCALL_CI_FORGET, - GF_UPCALL_LEASE_RECALL, - GF_UPCALL_FLAGS_MAXVALUE -}; - -enum gf_dict_data_type_t { - GF_DATA_TYPE_UNKNOWN, - GF_DATA_TYPE_STR_OLD, /* Will be set by volgen and dict-serialize - and unserialize. Used to reduce warnings - if one is using old protocol */ - GF_DATA_TYPE_INT, - GF_DATA_TYPE_UINT, - GF_DATA_TYPE_DOUBLE, - GF_DATA_TYPE_STR, - GF_DATA_TYPE_PTR, - GF_DATA_TYPE_GFUUID, - GF_DATA_TYPE_IATT, - GF_DATA_TYPE_MAX -}; diff --git a/rpc/xdr/src/glusterfs3-xdr.x b/rpc/xdr/src/glusterfs3-xdr.x index c253db5de5b..1c99099a721 100644 --- a/rpc/xdr/src/glusterfs3-xdr.x +++ b/rpc/xdr/src/glusterfs3-xdr.x @@ -11,9 +11,8 @@ #ifdef RPC_XDR %#include "rpc-pragmas.h" #endif -%#include "compat.h" +%#include <glusterfs/glusterfs-fops.h> %#include "rpc-common-xdr.h" -%#include "glusterfs-fops.h" #define GF_REQUEST_MAXGROUPS 16 struct gf_statfs { @@ -859,126 +858,6 @@ struct gf_getsnap_name_uuid_rsp { opaque dict<>; }; -union compound_req switch (glusterfs_fop_t fop_enum) { - case GF_FOP_STAT: gfs3_stat_req compound_stat_req; - case GF_FOP_READLINK: gfs3_readlink_req compound_readlink_req; - case GF_FOP_MKNOD: gfs3_mknod_req compound_mknod_req; - case GF_FOP_MKDIR: gfs3_mkdir_req compound_mkdir_req; - case GF_FOP_UNLINK: gfs3_unlink_req compound_unlink_req; - case GF_FOP_RMDIR: gfs3_rmdir_req compound_rmdir_req; - case GF_FOP_SYMLINK: gfs3_symlink_req compound_symlink_req; - case GF_FOP_RENAME: gfs3_rename_req compound_rename_req; - case GF_FOP_LINK: gfs3_link_req compound_link_req; - case GF_FOP_TRUNCATE: gfs3_truncate_req compound_truncate_req; - case GF_FOP_OPEN: gfs3_open_req compound_open_req; - case GF_FOP_READ: gfs3_read_req compound_read_req; - case GF_FOP_WRITE: gfs3_write_req compound_write_req; - case GF_FOP_STATFS: gfs3_statfs_req compound_statfs_req; - case GF_FOP_FLUSH: gfs3_flush_req compound_flush_req; - case GF_FOP_FSYNC: gfs3_fsync_req compound_fsync_req; - case GF_FOP_GETXATTR: gfs3_getxattr_req compound_getxattr_req; - case GF_FOP_SETXATTR: gfs3_setxattr_req compound_setxattr_req; - case GF_FOP_REMOVEXATTR: gfs3_removexattr_req compound_removexattr_req; - case GF_FOP_OPENDIR: gfs3_opendir_req compound_opendir_req; - case GF_FOP_FSYNCDIR: gfs3_fsyncdir_req compound_fsyncdir_req; - case GF_FOP_ACCESS: gfs3_access_req compound_access_req; - case GF_FOP_CREATE: gfs3_create_req compound_create_req; - case GF_FOP_FTRUNCATE: gfs3_ftruncate_req compound_ftruncate_req; - case GF_FOP_FSTAT: gfs3_fstat_req compound_fstat_req; - case GF_FOP_LK: gfs3_lk_req compound_lk_req; - case GF_FOP_LOOKUP: gfs3_lookup_req compound_lookup_req; - case GF_FOP_READDIR: gfs3_readdir_req compound_readdir_req; - case GF_FOP_INODELK: gfs3_inodelk_req compound_inodelk_req; - case GF_FOP_FINODELK: gfs3_finodelk_req compound_finodelk_req; - case GF_FOP_ENTRYLK: gfs3_entrylk_req compound_entrylk_req; - case GF_FOP_FENTRYLK: gfs3_fentrylk_req compound_fentrylk_req; - case GF_FOP_XATTROP: gfs3_xattrop_req compound_xattrop_req; - case GF_FOP_FXATTROP: gfs3_fxattrop_req compound_fxattrop_req; - case GF_FOP_FGETXATTR: gfs3_fgetxattr_req compound_fgetxattr_req; - case GF_FOP_FSETXATTR: gfs3_fsetxattr_req compound_fsetxattr_req; - case GF_FOP_RCHECKSUM: gfs3_rchecksum_req compound_rchecksum_req; - case GF_FOP_SETATTR: gfs3_setattr_req compound_setattr_req; - case GF_FOP_FSETATTR: gfs3_fsetattr_req compound_fsetattr_req; - case GF_FOP_READDIRP: gfs3_readdirp_req compound_readdirp_req; - case GF_FOP_RELEASE: gfs3_release_req compound_release_req; - case GF_FOP_RELEASEDIR: gfs3_releasedir_req compound_releasedir_req; - case GF_FOP_FREMOVEXATTR: gfs3_fremovexattr_req compound_fremovexattr_req; - case GF_FOP_FALLOCATE: gfs3_fallocate_req compound_fallocate_req; - case GF_FOP_DISCARD: gfs3_discard_req compound_discard_req; - case GF_FOP_ZEROFILL: gfs3_zerofill_req compound_zerofill_req; - case GF_FOP_IPC: gfs3_ipc_req compound_ipc_req; - case GF_FOP_SEEK: gfs3_seek_req compound_seek_req; - case GF_FOP_LEASE: gfs3_lease_req compound_lease_req; - default: void; -}; - -struct gfs3_compound_req { - int compound_version; - glusterfs_compound_fop_t compound_fop_enum; - compound_req compound_req_array<>; - opaque xdata<>; -}; - -union compound_rsp switch (glusterfs_fop_t fop_enum) { - case GF_FOP_STAT: gfs3_stat_rsp compound_stat_rsp; - case GF_FOP_READLINK: gfs3_readlink_rsp compound_readlink_rsp; - case GF_FOP_MKNOD: gfs3_mknod_rsp compound_mknod_rsp; - case GF_FOP_MKDIR: gfs3_mkdir_rsp compound_mkdir_rsp; - case GF_FOP_UNLINK: gfs3_unlink_rsp compound_unlink_rsp; - case GF_FOP_RMDIR: gfs3_rmdir_rsp compound_rmdir_rsp; - case GF_FOP_SYMLINK: gfs3_symlink_rsp compound_symlink_rsp; - case GF_FOP_RENAME: gfs3_rename_rsp compound_rename_rsp; - case GF_FOP_LINK: gfs3_link_rsp compound_link_rsp; - case GF_FOP_TRUNCATE: gfs3_truncate_rsp compound_truncate_rsp; - case GF_FOP_OPEN: gfs3_open_rsp compound_open_rsp; - case GF_FOP_READ: gfs3_read_rsp compound_read_rsp; - case GF_FOP_WRITE: gfs3_write_rsp compound_write_rsp; - case GF_FOP_STATFS: gfs3_statfs_rsp compound_statfs_rsp; - case GF_FOP_FLUSH: gf_common_rsp compound_flush_rsp; - case GF_FOP_FSYNC: gfs3_fsync_rsp compound_fsync_rsp; - case GF_FOP_GETXATTR: gfs3_getxattr_rsp compound_getxattr_rsp; - case GF_FOP_SETXATTR: gf_common_rsp compound_setxattr_rsp; - case GF_FOP_REMOVEXATTR: gf_common_rsp compound_removexattr_rsp; - case GF_FOP_OPENDIR: gfs3_opendir_rsp compound_opendir_rsp; - case GF_FOP_FSYNCDIR: gf_common_rsp compound_fsyncdir_rsp; - case GF_FOP_ACCESS: gf_common_rsp compound_access_rsp; - case GF_FOP_CREATE: gfs3_create_rsp compound_create_rsp; - case GF_FOP_FTRUNCATE: gfs3_ftruncate_rsp compound_ftruncate_rsp; - case GF_FOP_FSTAT: gfs3_fstat_rsp compound_fstat_rsp; - case GF_FOP_LK: gfs3_lk_rsp compound_lk_rsp; - case GF_FOP_LOOKUP: gfs3_lookup_rsp compound_lookup_rsp; - case GF_FOP_READDIR: gfs3_readdir_rsp compound_readdir_rsp; - case GF_FOP_INODELK: gf_common_rsp compound_inodelk_rsp; - case GF_FOP_FINODELK: gf_common_rsp compound_finodelk_rsp; - case GF_FOP_ENTRYLK: gf_common_rsp compound_entrylk_rsp; - case GF_FOP_FENTRYLK: gf_common_rsp compound_fentrylk_rsp; - case GF_FOP_XATTROP: gfs3_xattrop_rsp compound_xattrop_rsp; - case GF_FOP_FXATTROP: gfs3_fxattrop_rsp compound_fxattrop_rsp; - case GF_FOP_FGETXATTR: gfs3_fgetxattr_rsp compound_fgetxattr_rsp; - case GF_FOP_FSETXATTR: gf_common_rsp compound_fsetxattr_rsp; - case GF_FOP_RCHECKSUM: gfs3_rchecksum_rsp compound_rchecksum_rsp; - case GF_FOP_SETATTR: gfs3_setattr_rsp compound_setattr_rsp; - case GF_FOP_FSETATTR: gfs3_fsetattr_rsp compound_fsetattr_rsp; - case GF_FOP_READDIRP: gfs3_readdirp_rsp compound_readdirp_rsp; - case GF_FOP_RELEASE: gf_common_rsp compound_release_rsp; - case GF_FOP_RELEASEDIR: gf_common_rsp compound_releasedir_rsp; - case GF_FOP_FREMOVEXATTR: gf_common_rsp compound_fremovexattr_rsp; - case GF_FOP_FALLOCATE: gfs3_fallocate_rsp compound_fallocate_rsp; - case GF_FOP_DISCARD: gfs3_discard_rsp compound_discard_rsp; - case GF_FOP_ZEROFILL: gfs3_zerofill_rsp compound_zerofill_rsp; - case GF_FOP_IPC: gfs3_ipc_rsp compound_ipc_rsp; - case GF_FOP_SEEK: gfs3_seek_rsp compound_seek_rsp; - case GF_FOP_LEASE: gfs3_lease_rsp compound_lease_rsp; - default: void; -}; - -struct gfs3_compound_rsp { - int op_ret; - int op_errno; - compound_rsp compound_rsp_array<>; - opaque xdata<>; -}; - struct gfs3_locklist { gf_proto_flock flock; string client_uid<>; diff --git a/rpc/xdr/src/glusterfs3.h b/rpc/xdr/src/glusterfs3.h index b8ef394abaf..86b3a4c0e5d 100644 --- a/rpc/xdr/src/glusterfs3.h +++ b/rpc/xdr/src/glusterfs3.h @@ -16,9 +16,9 @@ #include "xdr-generic.h" #include "glusterfs3-xdr.h" #include "glusterfs4-xdr.h" -#include "iatt.h" +#include <glusterfs/iatt.h> #include "protocol-common.h" -#include "upcall-utils.h" +#include <glusterfs/upcall-utils.h> #define xdr_decoded_remaining_addr(xdr) ((&xdr)->x_private) #define xdr_decoded_remaining_len(xdr) ((&xdr)->x_handy) @@ -585,6 +585,34 @@ out: } static inline void +gfx_mdata_iatt_to_mdata_iatt(struct gfx_mdata_iatt *gf_mdata_iatt, + struct mdata_iatt *mdata_iatt) +{ + if (!mdata_iatt || !gf_mdata_iatt) + return; + mdata_iatt->ia_atime = gf_mdata_iatt->ia_atime; + mdata_iatt->ia_atime_nsec = gf_mdata_iatt->ia_atime_nsec; + mdata_iatt->ia_mtime = gf_mdata_iatt->ia_mtime; + mdata_iatt->ia_mtime_nsec = gf_mdata_iatt->ia_mtime_nsec; + mdata_iatt->ia_ctime = gf_mdata_iatt->ia_ctime; + mdata_iatt->ia_ctime_nsec = gf_mdata_iatt->ia_ctime_nsec; +} + +static inline void +gfx_mdata_iatt_from_mdata_iatt(struct gfx_mdata_iatt *gf_mdata_iatt, + struct mdata_iatt *mdata_iatt) +{ + if (!mdata_iatt || !gf_mdata_iatt) + return; + gf_mdata_iatt->ia_atime = mdata_iatt->ia_atime; + gf_mdata_iatt->ia_atime_nsec = mdata_iatt->ia_atime_nsec; + gf_mdata_iatt->ia_mtime = mdata_iatt->ia_mtime; + gf_mdata_iatt->ia_mtime_nsec = mdata_iatt->ia_mtime_nsec; + gf_mdata_iatt->ia_ctime = mdata_iatt->ia_ctime; + gf_mdata_iatt->ia_ctime_nsec = mdata_iatt->ia_ctime_nsec; +} + +static inline void gfx_stat_to_iattx(struct gfx_iattx *gf_stat, struct iatt *iatt) { if (!iatt || !gf_stat) @@ -721,6 +749,12 @@ dict_to_xdr(dict_t *this, gfx_dict *dict) gfx_stat_from_iattx(&xpair->value.gfx_value_u.iatt, (struct iatt *)dpair->value->data); break; + case GF_DATA_TYPE_MDATA: + index++; + gfx_mdata_iatt_from_mdata_iatt( + &xpair->value.gfx_value_u.mdata_iatt, + (struct mdata_iatt *)dpair->value->data); + break; case GF_DATA_TYPE_GFUUID: index++; memcpy(&xpair->value.gfx_value_u.uuid, dpair->value->data, @@ -728,6 +762,7 @@ dict_to_xdr(dict_t *this, gfx_dict *dict) break; case GF_DATA_TYPE_PTR: + case GF_DATA_TYPE_STR_OLD: index++; /* Ideally, each type of data stored in dictionary should have type. A pointer type shouldn't be @@ -741,7 +776,7 @@ dict_to_xdr(dict_t *this, gfx_dict *dict) xpair->value.gfx_value_u.other.other_len = dpair->value->len; /* Change this to INFO, after taking the above down */ - gf_msg("dict", GF_LOG_INFO, EINVAL, LG_MSG_DICT_SERIAL_FAILED, + gf_msg("dict", GF_LOG_DEBUG, EINVAL, LG_MSG_DICT_SERIAL_FAILED, "key '%s' would not be sent on wire in the future", dpair->key); break; @@ -786,6 +821,7 @@ xdr_to_dict(gfx_dict *dict, dict_t **to) dict_t *this = NULL; unsigned char *uuid = NULL; struct iatt *iatt = NULL; + struct mdata_iatt *mdata_iatt = NULL; if (!to || !dict) goto out; @@ -853,7 +889,32 @@ xdr_to_dict(gfx_dict *dict, dict_t **to) gfx_stat_to_iattx(&xpair->value.gfx_value_u.iatt, iatt); ret = dict_set_iatt(this, key, iatt, false); break; + case GF_DATA_TYPE_MDATA: + mdata_iatt = GF_CALLOC(1, sizeof(struct mdata_iatt), + gf_common_mt_char); + if (!mdata_iatt) { + errno = ENOMEM; + gf_msg(THIS->name, GF_LOG_ERROR, ENOMEM, LG_MSG_NO_MEMORY, + "failed to allocate memory. key: %s", key); + ret = -1; + goto out; + } + gfx_mdata_iatt_to_mdata_iatt( + &xpair->value.gfx_value_u.mdata_iatt, mdata_iatt); + ret = dict_set_mdata(this, key, mdata_iatt, false); + if (ret != 0) { + GF_FREE(mdata_iatt); + gf_msg(THIS->name, GF_LOG_ERROR, ENOMEM, + LG_MSG_DICT_SET_FAILED, + "failed to set the key (%s)" + " into dict", + key); + ret = -1; + goto out; + } + break; case GF_DATA_TYPE_PTR: + case GF_DATA_TYPE_STR_OLD: value = GF_MALLOC(xpair->value.gfx_value_u.other.other_len + 1, gf_common_mt_char); if (!value) { diff --git a/rpc/xdr/src/glusterfs4-xdr.x b/rpc/xdr/src/glusterfs4-xdr.x index 5ee86c24a0b..d3b1d0dfaf0 100644 --- a/rpc/xdr/src/glusterfs4-xdr.x +++ b/rpc/xdr/src/glusterfs4-xdr.x @@ -11,11 +11,9 @@ #ifdef RPC_XDR %#include "rpc-pragmas.h" #endif -%#include "compat.h" -%#include "glusterfs-fops.h" +%#include <glusterfs/glusterfs-fops.h> %#include "glusterfs3-xdr.h" - /* Need to consume iattx and new dict in all the fops */ struct gfx_iattx { opaque ia_gfid[16]; @@ -46,7 +44,17 @@ struct gfx_iattx { unsigned int mode; /* type of file and rwx mode */ }; -union gfx_value switch (gf_dict_data_type_t type) { +struct gfx_mdata_iatt { + hyper ia_atime; /* last access time */ + hyper ia_mtime; /* last modification time */ + hyper ia_ctime; /* last status change time */ + + unsigned int ia_atime_nsec; + unsigned int ia_mtime_nsec; + unsigned int ia_ctime_nsec; +}; + +union gfx_value switch (int type) { case GF_DATA_TYPE_INT: hyper value_int; case GF_DATA_TYPE_UINT: @@ -60,7 +68,10 @@ union gfx_value switch (gf_dict_data_type_t type) { case GF_DATA_TYPE_GFUUID: opaque uuid[16]; case GF_DATA_TYPE_PTR: + case GF_DATA_TYPE_STR_OLD: opaque other<>; + case GF_DATA_TYPE_MDATA: + gfx_mdata_iatt mdata_iatt; }; /* AUTH */ @@ -628,6 +639,19 @@ struct gfx_seek_rsp { struct gfx_setvolume_req { gfx_dict dict; } ; + + struct gfx_copy_file_range_req { + opaque gfid1[16]; + opaque gfid2[16]; + quad_t fd_in; + quad_t fd_out; + u_quad_t off_in; + u_quad_t off_out; + unsigned int size; + unsigned int flag; + gfx_dict xdata; /* Extra data */ +}; + struct gfx_setvolume_rsp { int op_ret; int op_errno; @@ -755,126 +779,6 @@ struct gfx_setactivelk_req { gfx_dict xdata; }; -union compound_req_v2 switch (glusterfs_fop_t fop_enum) { - case GF_FOP_STAT: gfx_stat_req compound_stat_req; - case GF_FOP_READLINK: gfx_readlink_req compound_readlink_req; - case GF_FOP_MKNOD: gfx_mknod_req compound_mknod_req; - case GF_FOP_MKDIR: gfx_mkdir_req compound_mkdir_req; - case GF_FOP_UNLINK: gfx_unlink_req compound_unlink_req; - case GF_FOP_RMDIR: gfx_rmdir_req compound_rmdir_req; - case GF_FOP_SYMLINK: gfx_symlink_req compound_symlink_req; - case GF_FOP_RENAME: gfx_rename_req compound_rename_req; - case GF_FOP_LINK: gfx_link_req compound_link_req; - case GF_FOP_TRUNCATE: gfx_truncate_req compound_truncate_req; - case GF_FOP_OPEN: gfx_open_req compound_open_req; - case GF_FOP_READ: gfx_read_req compound_read_req; - case GF_FOP_WRITE: gfx_write_req compound_write_req; - case GF_FOP_STATFS: gfx_statfs_req compound_statfs_req; - case GF_FOP_FLUSH: gfx_flush_req compound_flush_req; - case GF_FOP_FSYNC: gfx_fsync_req compound_fsync_req; - case GF_FOP_GETXATTR: gfx_getxattr_req compound_getxattr_req; - case GF_FOP_SETXATTR: gfx_setxattr_req compound_setxattr_req; - case GF_FOP_REMOVEXATTR: gfx_removexattr_req compound_removexattr_req; - case GF_FOP_OPENDIR: gfx_opendir_req compound_opendir_req; - case GF_FOP_FSYNCDIR: gfx_fsyncdir_req compound_fsyncdir_req; - case GF_FOP_ACCESS: gfx_access_req compound_access_req; - case GF_FOP_CREATE: gfx_create_req compound_create_req; - case GF_FOP_FTRUNCATE: gfx_ftruncate_req compound_ftruncate_req; - case GF_FOP_FSTAT: gfx_fstat_req compound_fstat_req; - case GF_FOP_LK: gfx_lk_req compound_lk_req; - case GF_FOP_LOOKUP: gfx_lookup_req compound_lookup_req; - case GF_FOP_READDIR: gfx_readdir_req compound_readdir_req; - case GF_FOP_INODELK: gfx_inodelk_req compound_inodelk_req; - case GF_FOP_FINODELK: gfx_finodelk_req compound_finodelk_req; - case GF_FOP_ENTRYLK: gfx_entrylk_req compound_entrylk_req; - case GF_FOP_FENTRYLK: gfx_fentrylk_req compound_fentrylk_req; - case GF_FOP_XATTROP: gfx_xattrop_req compound_xattrop_req; - case GF_FOP_FXATTROP: gfx_fxattrop_req compound_fxattrop_req; - case GF_FOP_FGETXATTR: gfx_fgetxattr_req compound_fgetxattr_req; - case GF_FOP_FSETXATTR: gfx_fsetxattr_req compound_fsetxattr_req; - case GF_FOP_RCHECKSUM: gfx_rchecksum_req compound_rchecksum_req; - case GF_FOP_SETATTR: gfx_setattr_req compound_setattr_req; - case GF_FOP_FSETATTR: gfx_fsetattr_req compound_fsetattr_req; - case GF_FOP_READDIRP: gfx_readdirp_req compound_readdirp_req; - case GF_FOP_RELEASE: gfx_release_req compound_release_req; - case GF_FOP_RELEASEDIR: gfx_releasedir_req compound_releasedir_req; - case GF_FOP_FREMOVEXATTR: gfx_fremovexattr_req compound_fremovexattr_req; - case GF_FOP_FALLOCATE: gfx_fallocate_req compound_fallocate_req; - case GF_FOP_DISCARD: gfx_discard_req compound_discard_req; - case GF_FOP_ZEROFILL: gfx_zerofill_req compound_zerofill_req; - case GF_FOP_IPC: gfx_ipc_req compound_ipc_req; - case GF_FOP_SEEK: gfx_seek_req compound_seek_req; - case GF_FOP_LEASE: gfx_lease_req compound_lease_req; - default: void; -}; - -struct gfx_compound_req { - int compound_version; - glusterfs_compound_fop_t compound_fop_enum; - compound_req_v2 compound_req_array<>; - gfx_dict xdata; -}; - -union compound_rsp_v2 switch (glusterfs_fop_t fop_enum) { - case GF_FOP_STAT: gfx_common_iatt_rsp compound_stat_rsp; - case GF_FOP_READLINK: gfx_readlink_rsp compound_readlink_rsp; - case GF_FOP_MKNOD: gfx_common_3iatt_rsp compound_mknod_rsp; - case GF_FOP_MKDIR: gfx_common_3iatt_rsp compound_mkdir_rsp; - case GF_FOP_UNLINK: gfx_common_2iatt_rsp compound_unlink_rsp; - case GF_FOP_RMDIR: gfx_common_2iatt_rsp compound_rmdir_rsp; - case GF_FOP_SYMLINK: gfx_common_3iatt_rsp compound_symlink_rsp; - case GF_FOP_RENAME: gfx_rename_rsp compound_rename_rsp; - case GF_FOP_LINK: gfx_common_3iatt_rsp compound_link_rsp; - case GF_FOP_TRUNCATE: gfx_common_2iatt_rsp compound_truncate_rsp; - case GF_FOP_OPEN: gfx_open_rsp compound_open_rsp; - case GF_FOP_READ: gfx_read_rsp compound_read_rsp; - case GF_FOP_WRITE: gfx_common_2iatt_rsp compound_write_rsp; - case GF_FOP_STATFS: gfx_statfs_rsp compound_statfs_rsp; - case GF_FOP_FLUSH: gfx_common_rsp compound_flush_rsp; - case GF_FOP_FSYNC: gfx_common_2iatt_rsp compound_fsync_rsp; - case GF_FOP_GETXATTR: gfx_common_dict_rsp compound_getxattr_rsp; - case GF_FOP_SETXATTR: gfx_common_rsp compound_setxattr_rsp; - case GF_FOP_REMOVEXATTR: gfx_common_rsp compound_removexattr_rsp; - case GF_FOP_OPENDIR: gfx_open_rsp compound_opendir_rsp; - case GF_FOP_FSYNCDIR: gfx_common_rsp compound_fsyncdir_rsp; - case GF_FOP_ACCESS: gfx_common_rsp compound_access_rsp; - case GF_FOP_CREATE: gfx_create_rsp compound_create_rsp; - case GF_FOP_FTRUNCATE: gfx_common_2iatt_rsp compound_ftruncate_rsp; - case GF_FOP_FSTAT: gfx_common_iatt_rsp compound_fstat_rsp; - case GF_FOP_LK: gfx_lk_rsp compound_lk_rsp; - case GF_FOP_LOOKUP: gfx_common_2iatt_rsp compound_lookup_rsp; - case GF_FOP_READDIR: gfx_readdir_rsp compound_readdir_rsp; - case GF_FOP_INODELK: gfx_common_rsp compound_inodelk_rsp; - case GF_FOP_FINODELK: gfx_common_rsp compound_finodelk_rsp; - case GF_FOP_ENTRYLK: gfx_common_rsp compound_entrylk_rsp; - case GF_FOP_FENTRYLK: gfx_common_rsp compound_fentrylk_rsp; - case GF_FOP_XATTROP: gfx_common_dict_rsp compound_xattrop_rsp; - case GF_FOP_FXATTROP: gfx_common_dict_rsp compound_fxattrop_rsp; - case GF_FOP_FGETXATTR: gfx_common_dict_rsp compound_fgetxattr_rsp; - case GF_FOP_FSETXATTR: gfx_common_rsp compound_fsetxattr_rsp; - case GF_FOP_RCHECKSUM: gfx_rchecksum_rsp compound_rchecksum_rsp; - case GF_FOP_SETATTR: gfx_common_2iatt_rsp compound_setattr_rsp; - case GF_FOP_FSETATTR: gfx_common_2iatt_rsp compound_fsetattr_rsp; - case GF_FOP_READDIRP: gfx_readdirp_rsp compound_readdirp_rsp; - case GF_FOP_RELEASE: gfx_common_rsp compound_release_rsp; - case GF_FOP_RELEASEDIR: gfx_common_rsp compound_releasedir_rsp; - case GF_FOP_FREMOVEXATTR: gfx_common_rsp compound_fremovexattr_rsp; - case GF_FOP_FALLOCATE: gfx_common_2iatt_rsp compound_fallocate_rsp; - case GF_FOP_DISCARD: gfx_common_2iatt_rsp compound_discard_rsp; - case GF_FOP_ZEROFILL: gfx_common_2iatt_rsp compound_zerofill_rsp; - case GF_FOP_IPC: gfx_common_rsp compound_ipc_rsp; - case GF_FOP_SEEK: gfx_seek_rsp compound_seek_rsp; - case GF_FOP_LEASE: gfx_lease_rsp compound_lease_rsp; - default: void; -}; - -struct gfx_compound_rsp { - int op_ret; - int op_errno; - compound_rsp_v2 compound_rsp_array<>; - gfx_dict xdata; -}; - struct gfs4_inodelk_contention_req { opaque gfid[16]; struct gf_proto_flock flock; diff --git a/rpc/xdr/src/libgfxdr.sym b/rpc/xdr/src/libgfxdr.sym index bd9131be7c6..8fa0e0ddd8a 100644 --- a/rpc/xdr/src/libgfxdr.sym +++ b/rpc/xdr/src/libgfxdr.sym @@ -28,6 +28,8 @@ xdr_gd1_mgmt_v3_brick_op_req xdr_gd1_mgmt_v3_brick_op_rsp xdr_gd1_mgmt_v3_commit_req xdr_gd1_mgmt_v3_commit_rsp +xdr_gd1_mgmt_v3_post_commit_req +xdr_gd1_mgmt_v3_post_commit_rsp xdr_gd1_mgmt_v3_lock_req xdr_gd1_mgmt_v3_lock_rsp xdr_gd1_mgmt_v3_post_val_req @@ -251,6 +253,7 @@ xdr_to_write3args xdr_vector_round_up xdr_gfx_read_rsp xdr_gfx_iattx +xdr_gfx_mdata_iatt xdr_gfx_value xdr_gfx_dict_pair xdr_gfx_dict @@ -344,3 +347,4 @@ xdr_compound_req_v2 xdr_gfx_compound_req xdr_compound_rsp_v2 xdr_gfx_compound_rsp +xdr_gfx_copy_file_range_req diff --git a/rpc/xdr/src/mount3udp.x b/rpc/xdr/src/mount3udp.x index 4fafaa053f8..e8366df400c 100644 --- a/rpc/xdr/src/mount3udp.x +++ b/rpc/xdr/src/mount3udp.x @@ -11,7 +11,7 @@ #ifdef RPC_XDR %#include "rpc-pragmas.h" #endif -%#include "compat.h" +%#include <glusterfs/compat.h> /* This is used by rpcgen to auto generate the rpc stubs. * mount3udp_svc.c is heavily modified though diff --git a/rpc/xdr/src/nlm4-xdr.x b/rpc/xdr/src/nlm4-xdr.x index 0fb3a5945a1..847b0e64491 100644 --- a/rpc/xdr/src/nlm4-xdr.x +++ b/rpc/xdr/src/nlm4-xdr.x @@ -11,7 +11,7 @@ #ifdef RPC_XDR %#include "rpc-pragmas.h" #endif -%#include "compat.h" +%#include <glusterfs/compat.h> /* .x file defined as according to the RFC */ diff --git a/rpc/xdr/src/nsm-xdr.x b/rpc/xdr/src/nsm-xdr.x index 65b36b27d31..7c16a741f1d 100644 --- a/rpc/xdr/src/nsm-xdr.x +++ b/rpc/xdr/src/nsm-xdr.x @@ -11,7 +11,7 @@ #ifdef RPC_XDR %#include "rpc-pragmas.h" #endif -%#include "compat.h" +%#include <glusterfs/compat.h> /* * This defines the maximum length of the string diff --git a/rpc/xdr/src/portmap-xdr.x b/rpc/xdr/src/portmap-xdr.x index 66a86a1dae1..23515572b9f 100644 --- a/rpc/xdr/src/portmap-xdr.x +++ b/rpc/xdr/src/portmap-xdr.x @@ -11,7 +11,7 @@ #ifdef RPC_XDR %#include "rpc-pragmas.h" #endif -%#include "compat.h" +%#include <glusterfs/compat.h> struct pmap_port_by_brick_req { string brick<>; @@ -40,6 +40,7 @@ struct pmap_brick_by_port_rsp { struct pmap_signin_req { string brick<>; int port; + int pid; }; struct pmap_signin_rsp { diff --git a/rpc/xdr/src/rpc-common-xdr.x b/rpc/xdr/src/rpc-common-xdr.x index b01d282f368..baf8b4313c8 100644 --- a/rpc/xdr/src/rpc-common-xdr.x +++ b/rpc/xdr/src/rpc-common-xdr.x @@ -11,13 +11,12 @@ #ifdef RPC_XDR %#include "rpc-pragmas.h" #endif -%#include "compat.h" +%#include <glusterfs/glusterfs-fops.h> /* This file has definition of few XDR structures which are * not captured in any section specific file */ %#include "xdr-common.h" -%#include "glusterfs-fops.h" struct auth_glusterfs_parms_v2 { int pid; diff --git a/rpc/xdr/src/xdr-generic.h b/rpc/xdr/src/xdr-generic.h index 367ef555dd3..794dda508cc 100644 --- a/rpc/xdr/src/xdr-generic.h +++ b/rpc/xdr/src/xdr-generic.h @@ -15,7 +15,7 @@ #include <rpc/types.h> #include <rpc/xdr.h> -#include "compat.h" +#include <glusterfs/compat.h> #define xdr_decoded_remaining_addr(xdr) ((&xdr)->x_private) #define xdr_decoded_remaining_len(xdr) ((&xdr)->x_handy) diff --git a/rpc/xdr/src/xdr-nfs3.c b/rpc/xdr/src/xdr-nfs3.c index aca9a299b0e..cfccaaa89b8 100644 --- a/rpc/xdr/src/xdr-nfs3.c +++ b/rpc/xdr/src/xdr-nfs3.c @@ -23,7 +23,7 @@ #endif #include "xdr-nfs3.h" -#include "mem-pool.h" +#include <glusterfs/mem-pool.h> #include "xdr-common.h" bool_t |
