diff options
Diffstat (limited to 'rpc')
71 files changed, 19837 insertions, 22193 deletions
diff --git a/rpc/Makefile.am b/rpc/Makefile.am index ffb76e901fc..183b7a0352f 100644 --- a/rpc/Makefile.am +++ b/rpc/Makefile.am @@ -1 +1 @@ -SUBDIRS = rpc-lib rpc-transport xdr +SUBDIRS = xdr rpc-lib rpc-transport diff --git a/rpc/rpc-lib/src/Makefile.am b/rpc/rpc-lib/src/Makefile.am index fcf091e9b0c..35c9db07e7f 100644 --- a/rpc/rpc-lib/src/Makefile.am +++ b/rpc/rpc-lib/src/Makefile.am @@ -2,15 +2,28 @@ 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-common.c -libgfrpc_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la + rpc-drc.c rpc-clnt-ping.c \ + autoscale-threads.c mgmt-pmap.c -noinst_HEADERS = rpcsvc.h rpc-transport.h xdr-common.h xdr-rpc.h xdr-rpcclnt.h \ - rpc-clnt.h rpcsvc-common.h protocol-common.h +EXTRA_DIST = libgfrpc.sym -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \ +libgfrpc_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ + $(top_builddir)/rpc/xdr/src/libgfxdr.la +libgfrpc_la_LDFLAGS = -version-info $(LIBGFRPC_LT_VERSION) $(GF_LDFLAGS) \ + -export-symbols $(top_srcdir)/rpc/rpc-lib/src/libgfrpc.sym + +libgfrpc_la_HEADERS = rpcsvc.h rpc-transport.h xdr-common.h xdr-rpc.h xdr-rpcclnt.h \ + rpc-clnt.h rpcsvc-common.h protocol-common.h rpc-drc.h rpc-clnt-ping.h \ + rpc-lib-messages.h + +libgfrpc_ladir = $(includedir)/glusterfs/rpc + +AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ -I$(top_srcdir)/rpc/xdr/src \ - -DRPC_TRANSPORTDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/rpc-transport\" + -I$(top_builddir)/rpc/xdr/src \ + -DRPC_TRANSPORTDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/rpc-transport\" \ + -I$(top_srcdir)/contrib/rbtree + +AM_CFLAGS = -Wall $(GF_CFLAGS) CLEANFILES = *~ diff --git a/rpc/rpc-lib/src/auth-glusterfs.c b/rpc/rpc-lib/src/auth-glusterfs.c index 4faaddb9e7b..69a96f7512f 100644 --- a/rpc/rpc-lib/src/auth-glusterfs.c +++ b/rpc/rpc-lib/src/auth-glusterfs.c @@ -1,215 +1,386 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. + 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. +*/ - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. +#include "rpcsvc.h" +#include <glusterfs/dict.h> +#include "xdr-rpc.h" +#include "xdr-common.h" +#include "rpc-common-xdr.h" +#include "glusterfs4-xdr.h" - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ +/* V1 */ +ssize_t +xdr_to_glusterfs_auth(char *buf, struct auth_glusterfs_parms *req) +{ + XDR xdr; + ssize_t ret = -1; + if ((!buf) || (!req)) + return -1; -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif + xdrmem_create(&xdr, buf, sizeof(struct auth_glusterfs_parms), XDR_DECODE); + if (!xdr_auth_glusterfs_parms(&xdr, req)) { + gf_log("", GF_LOG_WARNING, "failed to decode glusterfs parameters"); + ret = -1; + goto ret; + } -#include "rpcsvc.h" -#include "list.h" -#include "dict.h" -#include "xdr-rpc.h" -#include "xdr-common.h" + ret = (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)); +ret: + return ret; +} +int +auth_glusterfs_request_init(rpcsvc_request_t *req, void *priv) +{ + return 0; +} + +int +auth_glusterfs_authenticate(rpcsvc_request_t *req, void *priv) +{ + struct auth_glusterfs_parms au = { + 0, + }; + + int ret = RPCSVC_AUTH_REJECT; + int j = 0; + int i = 0; + int gidcount = 0; + + if (!req) + return ret; + + ret = xdr_to_glusterfs_auth(req->cred.authdata, &au); + if (ret == -1) { + gf_log("", GF_LOG_WARNING, "failed to decode glusterfs credentials"); + ret = RPCSVC_AUTH_REJECT; + goto err; + } + + req->pid = au.pid; + req->uid = au.uid; + req->gid = au.gid; + req->lk_owner.len = 8; + { + for (i = 0; i < req->lk_owner.len; i++, j += 8) + req->lk_owner.data[i] = (char)((au.lk_owner >> j) & 0xff); + } + req->auxgidcount = au.ngrps; -bool_t -xdr_auth_glusterfs_parms (XDR *xdrs, auth_glusterfs_parms *objp) + if (req->auxgidcount > 16) { + gf_log("", GF_LOG_WARNING, + "more than 16 aux gids found, failing authentication"); + ret = RPCSVC_AUTH_REJECT; + goto err; + } + + if (req->auxgidcount > SMALL_GROUP_COUNT) { + req->auxgidlarge = GF_CALLOC(req->auxgidcount, sizeof(req->auxgids[0]), + gf_common_mt_auxgids); + req->auxgids = req->auxgidlarge; + } else { + req->auxgids = req->auxgidsmall; + } + + if (!req->auxgids) { + gf_log("auth-glusterfs", GF_LOG_WARNING, "cannot allocate gid list"); + ret = RPCSVC_AUTH_REJECT; + goto err; + } + + for (gidcount = 0; gidcount < au.ngrps; ++gidcount) + req->auxgids[gidcount] = au.groups[gidcount]; + + gf_log(GF_RPCSVC, GF_LOG_TRACE, + "Auth Info: pid: %u, uid: %d" + ", gid: %d, owner: %s", + req->pid, req->uid, req->gid, lkowner_utoa(&req->lk_owner)); + ret = RPCSVC_AUTH_ACCEPT; +err: + return ret; +} + +rpcsvc_auth_ops_t auth_glusterfs_ops = { + .transport_init = NULL, + .request_init = auth_glusterfs_request_init, + .authenticate = auth_glusterfs_authenticate}; + +rpcsvc_auth_t rpcsvc_auth_glusterfs = {.authname = "AUTH_GLUSTERFS", + .authnum = AUTH_GLUSTERFS, + .authops = &auth_glusterfs_ops, + .authprivate = NULL}; + +rpcsvc_auth_t * +rpcsvc_auth_glusterfs_init(rpcsvc_t *svc, dict_t *options) { - register int32_t *buf; - - int i; - - if (xdrs->x_op == XDR_ENCODE) { - if (!xdr_u_quad_t (xdrs, &objp->lk_owner)) - return FALSE; - buf = XDR_INLINE (xdrs, (4 + 16 )* BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_u_int (xdrs, &objp->pid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->uid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->gid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ngrps)) - return FALSE; - if (!xdr_vector (xdrs, (char *)objp->groups, 16, - sizeof (u_int), (xdrproc_t) xdr_u_int)) - return FALSE; - } else { - IXDR_PUT_U_LONG(buf, objp->pid); - IXDR_PUT_U_LONG(buf, objp->uid); - IXDR_PUT_U_LONG(buf, objp->gid); - IXDR_PUT_U_LONG(buf, objp->ngrps); - { - register u_int *genp; - - for (i = 0, genp = objp->groups; - i < 16; ++i) { - IXDR_PUT_U_LONG(buf, *genp++); - } - } - } - return TRUE; - } else if (xdrs->x_op == XDR_DECODE) { - if (!xdr_u_quad_t (xdrs, &objp->lk_owner)) - return FALSE; - buf = XDR_INLINE (xdrs, (4 + 16 )* BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_u_int (xdrs, &objp->pid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->uid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->gid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ngrps)) - return FALSE; - if (!xdr_vector (xdrs, (char *)objp->groups, 16, - sizeof (u_int), (xdrproc_t) xdr_u_int)) - return FALSE; - } else { - objp->pid = IXDR_GET_U_LONG(buf); - objp->uid = IXDR_GET_U_LONG(buf); - objp->gid = IXDR_GET_U_LONG(buf); - objp->ngrps = IXDR_GET_U_LONG(buf); - { - register u_int *genp; - - for (i = 0, genp = objp->groups; - i < 16; ++i) { - *genp++ = IXDR_GET_U_LONG(buf); - } - } - } - return TRUE; - } - - if (!xdr_u_quad_t (xdrs, &objp->lk_owner)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->pid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->uid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->gid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ngrps)) - return FALSE; - if (!xdr_vector (xdrs, (char *)objp->groups, 16, - sizeof (u_int), (xdrproc_t) xdr_u_int)) - return FALSE; - return TRUE; + return &rpcsvc_auth_glusterfs; } +/* V2 */ ssize_t -xdr_to_glusterfs_auth (char *buf, struct auth_glusterfs_parms *req) +xdr_to_glusterfs_auth_v2(char *buf, struct auth_glusterfs_parms_v2 *req) { - XDR xdr; - ssize_t ret = -1; - - if ((!buf) || (!req)) - return -1; - - xdrmem_create (&xdr, buf, sizeof (struct auth_glusterfs_parms), - XDR_DECODE); - if (!xdr_auth_glusterfs_parms (&xdr, req)) { - gf_log ("", GF_LOG_WARNING, - "failed to decode glusterfs parameters"); - ret = -1; - goto ret; - } - - ret = (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)); + XDR xdr; + ssize_t ret = -1; + + if ((!buf) || (!req)) + return -1; + + xdrmem_create(&xdr, buf, GF_MAX_AUTH_BYTES, XDR_DECODE); + if (!xdr_auth_glusterfs_parms_v2(&xdr, req)) { + gf_log("", GF_LOG_WARNING, "failed to decode glusterfs v2 parameters"); + ret = -1; + goto ret; + } + + ret = (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)); ret: + return ret; +} +int +auth_glusterfs_v2_request_init(rpcsvc_request_t *req, void *priv) +{ + return 0; +} + +int +auth_glusterfs_v2_authenticate(rpcsvc_request_t *req, void *priv) +{ + struct auth_glusterfs_parms_v2 au = { + 0, + }; + int ret = RPCSVC_AUTH_REJECT; + int i = 0; + int max_groups = 0; + int max_lk_owner_len = 0; + + if (!req) return ret; + ret = xdr_to_glusterfs_auth_v2(req->cred.authdata, &au); + if (ret == -1) { + gf_log("", GF_LOG_WARNING, "failed to decode glusterfs credentials"); + ret = RPCSVC_AUTH_REJECT; + goto err; + } + + req->pid = au.pid; + req->uid = au.uid; + req->gid = au.gid; + req->lk_owner.len = au.lk_owner.lk_owner_len; + req->auxgidcount = au.groups.groups_len; + + /* the number of groups and size of lk_owner depend on each other */ + max_groups = GF_AUTH_GLUSTERFS_MAX_GROUPS(req->lk_owner.len, + AUTH_GLUSTERFS_v2); + max_lk_owner_len = GF_AUTH_GLUSTERFS_MAX_LKOWNER(req->auxgidcount, + AUTH_GLUSTERFS_v2); + + if (req->auxgidcount > max_groups) { + gf_log("", GF_LOG_WARNING, + "more than max aux gids found (%d) , truncating it " + "to %d and continuing", + au.groups.groups_len, max_groups); + req->auxgidcount = max_groups; + } + + if (req->lk_owner.len > max_lk_owner_len) { + gf_log("", GF_LOG_WARNING, + "lkowner field to big (%d), depends on the number of " + "groups (%d), failing authentication", + req->lk_owner.len, req->auxgidcount); + ret = RPCSVC_AUTH_REJECT; + goto err; + } + + if (req->auxgidcount > SMALL_GROUP_COUNT) { + req->auxgidlarge = GF_CALLOC(req->auxgidcount, sizeof(req->auxgids[0]), + gf_common_mt_auxgids); + req->auxgids = req->auxgidlarge; + } else { + req->auxgids = req->auxgidsmall; + } + + if (!req->auxgids) { + gf_log("auth-glusterfs-v2", GF_LOG_WARNING, "cannot allocate gid list"); + ret = RPCSVC_AUTH_REJECT; + goto err; + } + + for (i = 0; i < req->auxgidcount; ++i) + req->auxgids[i] = au.groups.groups_val[i]; + + for (i = 0; i < au.lk_owner.lk_owner_len; ++i) + req->lk_owner.data[i] = au.lk_owner.lk_owner_val[i]; + + gf_log(GF_RPCSVC, GF_LOG_TRACE, + "Auth Info: pid: %u, uid: %d" + ", gid: %d, owner: %s", + req->pid, req->uid, req->gid, lkowner_utoa(&req->lk_owner)); + ret = RPCSVC_AUTH_ACCEPT; +err: + /* TODO: instead use alloca() for these variables */ + free(au.groups.groups_val); + free(au.lk_owner.lk_owner_val); + + return ret; } -int -auth_glusterfs_request_init (rpcsvc_request_t *req, void *priv) + +rpcsvc_auth_ops_t auth_glusterfs_ops_v2 = { + .transport_init = NULL, + .request_init = auth_glusterfs_v2_request_init, + .authenticate = auth_glusterfs_v2_authenticate}; + +rpcsvc_auth_t rpcsvc_auth_glusterfs_v2 = {.authname = "AUTH_GLUSTERFS-v2", + .authnum = AUTH_GLUSTERFS_v2, + .authops = &auth_glusterfs_ops_v2, + .authprivate = NULL}; + +rpcsvc_auth_t * +rpcsvc_auth_glusterfs_v2_init(rpcsvc_t *svc, dict_t *options) { - if (!req) - return -1; - memset (req->verf.authdata, 0, RPCSVC_MAX_AUTH_BYTES); - req->verf.datalen = 0; - req->verf.flavour = AUTH_NULL; + return &rpcsvc_auth_glusterfs_v2; +} + +/* V3 */ - return 0; +ssize_t +xdr_to_glusterfs_auth_v3(char *buf, struct auth_glusterfs_params_v3 *req) +{ + XDR xdr; + ssize_t ret = -1; + + if ((!buf) || (!req)) + return -1; + + xdrmem_create(&xdr, buf, GF_MAX_AUTH_BYTES, XDR_DECODE); + if (!xdr_auth_glusterfs_params_v3(&xdr, req)) { + gf_log("", GF_LOG_WARNING, "failed to decode glusterfs v3 parameters"); + ret = -1; + goto ret; + } + + ret = (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)); +ret: + return ret; } -int auth_glusterfs_authenticate (rpcsvc_request_t *req, void *priv) +int +auth_glusterfs_v3_request_init(rpcsvc_request_t *req, void *priv) { - int ret = RPCSVC_AUTH_REJECT; - struct auth_glusterfs_parms au = {0,}; - int gidcount = 0; - - if (!req) - return ret; - - ret = xdr_to_glusterfs_auth (req->cred.authdata, &au); - if (ret == -1) { - gf_log ("", GF_LOG_WARNING, - "failed to decode glusterfs credentials"); - ret = RPCSVC_AUTH_REJECT; - goto err; - } - - req->pid = au.pid; - req->uid = au.uid; - req->gid = au.gid; - req->lk_owner = au.lk_owner; - req->auxgidcount = au.ngrps; - - if (req->auxgidcount > 16) { - gf_log ("", GF_LOG_WARNING, - "more than 16 aux gids found, failing authentication"); - ret = RPCSVC_AUTH_REJECT; - goto err; - } - - for (gidcount = 0; gidcount < au.ngrps; ++gidcount) - req->auxgids[gidcount] = au.groups[gidcount]; - - gf_log (GF_RPCSVC, GF_LOG_TRACE, "Auth Info: pid: %u, uid: %d" - ", gid: %d, owner: %"PRId64, - req->pid, req->uid, req->gid, req->lk_owner); - ret = RPCSVC_AUTH_ACCEPT; -err: - return ret; + return 0; } -rpcsvc_auth_ops_t auth_glusterfs_ops = { - .transport_init = NULL, - .request_init = auth_glusterfs_request_init, - .authenticate = auth_glusterfs_authenticate -}; +int +auth_glusterfs_v3_authenticate(rpcsvc_request_t *req, void *priv) +{ + struct auth_glusterfs_params_v3 au = { + 0, + }; + int ret = RPCSVC_AUTH_REJECT; + int i = 0; + int max_groups = 0; + int max_lk_owner_len = 0; + + if (!req) + return ret; + + ret = xdr_to_glusterfs_auth_v3(req->cred.authdata, &au); + if (ret == -1) { + gf_log("", GF_LOG_WARNING, "failed to decode glusterfs credentials"); + ret = RPCSVC_AUTH_REJECT; + goto err; + } + + req->pid = au.pid; + req->uid = au.uid; + req->gid = au.gid; + req->lk_owner.len = au.lk_owner.lk_owner_len; + req->auxgidcount = au.groups.groups_len; + + /* the number of groups and size of lk_owner depend on each other */ + max_groups = GF_AUTH_GLUSTERFS_MAX_GROUPS(req->lk_owner.len, + AUTH_GLUSTERFS_v3); + max_lk_owner_len = GF_AUTH_GLUSTERFS_MAX_LKOWNER(req->auxgidcount, + AUTH_GLUSTERFS_v3); + + if (req->auxgidcount > max_groups) { + gf_log("", GF_LOG_WARNING, + "more than max aux gids found (%d) , truncating it " + "to %d and continuing", + au.groups.groups_len, max_groups); + req->auxgidcount = max_groups; + } + + if (req->lk_owner.len > max_lk_owner_len) { + gf_log("", GF_LOG_WARNING, + "lkowner field to big (%d), depends on the number of " + "groups (%d), failing authentication", + req->lk_owner.len, req->auxgidcount); + ret = RPCSVC_AUTH_REJECT; + goto err; + } + + if (req->auxgidcount > SMALL_GROUP_COUNT) { + req->auxgidlarge = GF_CALLOC(req->auxgidcount, sizeof(req->auxgids[0]), + gf_common_mt_auxgids); + req->auxgids = req->auxgidlarge; + } else { + req->auxgids = req->auxgidsmall; + } + + if (!req->auxgids) { + gf_log("auth-glusterfs-v2", GF_LOG_WARNING, "cannot allocate gid list"); + ret = RPCSVC_AUTH_REJECT; + goto err; + } + + for (i = 0; i < req->auxgidcount; ++i) + req->auxgids[i] = au.groups.groups_val[i]; + + for (i = 0; i < au.lk_owner.lk_owner_len; ++i) + req->lk_owner.data[i] = au.lk_owner.lk_owner_val[i]; + + /* All new things, starting glusterfs-4.0.0 */ + req->flags = au.flags; + req->ctime.tv_sec = au.ctime_sec; + req->ctime.tv_nsec = au.ctime_nsec; + + gf_log(GF_RPCSVC, GF_LOG_TRACE, + "Auth Info: pid: %u, uid: %d" + ", gid: %d, owner: %s, flags: %d", + req->pid, req->uid, req->gid, lkowner_utoa(&req->lk_owner), + req->flags); + ret = RPCSVC_AUTH_ACCEPT; +err: + /* TODO: instead use alloca() for these variables */ + free(au.groups.groups_val); + free(au.lk_owner.lk_owner_val); + + return ret; +} -rpcsvc_auth_t rpcsvc_auth_glusterfs = { - .authname = "AUTH_GLUSTERFS", - .authnum = AUTH_GLUSTERFS, - .authops = &auth_glusterfs_ops, - .authprivate = NULL -}; +rpcsvc_auth_ops_t auth_glusterfs_ops_v3 = { + .transport_init = NULL, + .request_init = auth_glusterfs_v3_request_init, + .authenticate = auth_glusterfs_v3_authenticate}; +rpcsvc_auth_t rpcsvc_auth_glusterfs_v3 = {.authname = "AUTH_GLUSTERFS-v3", + .authnum = AUTH_GLUSTERFS_v3, + .authops = &auth_glusterfs_ops_v3, + .authprivate = NULL}; rpcsvc_auth_t * -rpcsvc_auth_glusterfs_init (rpcsvc_t *svc, dict_t *options) +rpcsvc_auth_glusterfs_v3_init(rpcsvc_t *svc, dict_t *options) { - return &rpcsvc_auth_glusterfs; + return &rpcsvc_auth_glusterfs_v3; } diff --git a/rpc/rpc-lib/src/auth-null.c b/rpc/rpc-lib/src/auth-null.c index ee50ab66921..6d059b9da50 100644 --- a/rpc/rpc-lib/src/auth-null.c +++ b/rpc/rpc-lib/src/auth-null.c @@ -1,70 +1,40 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include "rpcsvc.h" -#include "list.h" -#include "dict.h" - +#include <glusterfs/dict.h> int -auth_null_request_init (rpcsvc_request_t *req, void *priv) +auth_null_request_init(rpcsvc_request_t *req, void *priv) { - if (!req) - return -1; - - memset (req->cred.authdata, 0, RPCSVC_MAX_AUTH_BYTES); - req->cred.datalen = 0; - - memset (req->verf.authdata, 0, RPCSVC_MAX_AUTH_BYTES); - req->verf.datalen = 0; - - return 0; + return 0; } -int auth_null_authenticate (rpcsvc_request_t *req, void *priv) +int +auth_null_authenticate(rpcsvc_request_t *req, void *priv) { - /* Always succeed. */ - return RPCSVC_AUTH_ACCEPT; + /* Always succeed. */ + return RPCSVC_AUTH_ACCEPT; } -rpcsvc_auth_ops_t auth_null_ops = { - .transport_init = NULL, - .request_init = auth_null_request_init, - .authenticate = auth_null_authenticate -}; - -rpcsvc_auth_t rpcsvc_auth_null = { - .authname = "AUTH_NULL", - .authnum = AUTH_NULL, - .authops = &auth_null_ops, - .authprivate = NULL -}; +rpcsvc_auth_ops_t auth_null_ops = {.transport_init = NULL, + .request_init = auth_null_request_init, + .authenticate = auth_null_authenticate}; +rpcsvc_auth_t rpcsvc_auth_null = {.authname = "AUTH_NULL", + .authnum = AUTH_NULL, + .authops = &auth_null_ops, + .authprivate = NULL}; rpcsvc_auth_t * -rpcsvc_auth_null_init (rpcsvc_t *svc, dict_t *options) +rpcsvc_auth_null_init(rpcsvc_t *svc, dict_t *options) { - return &rpcsvc_auth_null; + return &rpcsvc_auth_null; } diff --git a/rpc/rpc-lib/src/auth-unix.c b/rpc/rpc-lib/src/auth-unix.c index c48743db937..61d475a5e84 100644 --- a/rpc/rpc-lib/src/auth-unix.c +++ b/rpc/rpc-lib/src/auth-unix.c @@ -1,91 +1,66 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include "rpcsvc.h" -#include "list.h" -#include "dict.h" +#include <glusterfs/dict.h> #include "xdr-rpc.h" - int -auth_unix_request_init (rpcsvc_request_t *req, void *priv) +auth_unix_request_init(rpcsvc_request_t *req, void *priv) { - if (!req) - return -1; - memset (req->verf.authdata, 0, RPCSVC_MAX_AUTH_BYTES); - req->verf.datalen = 0; - req->verf.flavour = AUTH_NULL; - - return 0; + return 0; } -int auth_unix_authenticate (rpcsvc_request_t *req, void *priv) +int +auth_unix_authenticate(rpcsvc_request_t *req, void *priv) { - int ret = RPCSVC_AUTH_REJECT; - struct authunix_parms aup; - char machname[MAX_MACHINE_NAME]; - - if (!req) - return ret; - - ret = xdr_to_auth_unix_cred (req->cred.authdata, req->cred.datalen, - &aup, machname, req->auxgids); - if (ret == -1) { - gf_log ("", GF_LOG_WARNING, "failed to decode unix credentials"); - ret = RPCSVC_AUTH_REJECT; - goto err; - } + int ret = RPCSVC_AUTH_REJECT; + struct authunix_parms aup; + char machname[MAX_MACHINE_NAME]; - req->uid = aup.aup_uid; - req->gid = aup.aup_gid; - req->auxgidcount = aup.aup_len; + if (!req) + return ret; - gf_log (GF_RPCSVC, GF_LOG_TRACE, "Auth Info: machine name: %s, uid: %d" - ", gid: %d", machname, req->uid, req->gid); - ret = RPCSVC_AUTH_ACCEPT; + req->auxgids = req->auxgidsmall; + ret = xdr_to_auth_unix_cred(req->cred.authdata, req->cred.datalen, &aup, + machname, req->auxgids); + if (ret == -1) { + gf_log("", GF_LOG_WARNING, "failed to decode unix credentials"); + ret = RPCSVC_AUTH_REJECT; + goto err; + } + + req->uid = aup.aup_uid; + req->gid = aup.aup_gid; + req->auxgidcount = aup.aup_len; + + gf_log(GF_RPCSVC, GF_LOG_TRACE, + "Auth Info: machine name: %s, uid: %d" + ", gid: %d", + machname, req->uid, req->gid); + ret = RPCSVC_AUTH_ACCEPT; err: - return ret; + return ret; } -rpcsvc_auth_ops_t auth_unix_ops = { - .transport_init = NULL, - .request_init = auth_unix_request_init, - .authenticate = auth_unix_authenticate -}; - -rpcsvc_auth_t rpcsvc_auth_unix = { - .authname = "AUTH_UNIX", - .authnum = AUTH_UNIX, - .authops = &auth_unix_ops, - .authprivate = NULL -}; +rpcsvc_auth_ops_t auth_unix_ops = {.transport_init = NULL, + .request_init = auth_unix_request_init, + .authenticate = auth_unix_authenticate}; +rpcsvc_auth_t rpcsvc_auth_unix = {.authname = "AUTH_UNIX", + .authnum = AUTH_UNIX, + .authops = &auth_unix_ops, + .authprivate = NULL}; rpcsvc_auth_t * -rpcsvc_auth_unix_init (rpcsvc_t *svc, dict_t *options) +rpcsvc_auth_unix_init(rpcsvc_t *svc, dict_t *options) { - return &rpcsvc_auth_unix; + return &rpcsvc_auth_unix; } diff --git a/rpc/rpc-lib/src/autoscale-threads.c b/rpc/rpc-lib/src/autoscale-threads.c new file mode 100644 index 00000000000..a954ae7a27a --- /dev/null +++ b/rpc/rpc-lib/src/autoscale-threads.c @@ -0,0 +1,22 @@ +/* + Copyright (c) 2018 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 <glusterfs/gf-event.h> +#include "rpcsvc.h" + +void +rpcsvc_autoscale_threads(glusterfs_ctx_t *ctx, rpcsvc_t *rpc, int incr) +{ + struct event_pool *pool = ctx->event_pool; + int thread_count = pool->eventthreadcount; + + pool->auto_thread_count += incr; + (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 new file mode 100644 index 00000000000..e026d80259b --- /dev/null +++ b/rpc/rpc-lib/src/libgfrpc.sym @@ -0,0 +1,68 @@ +is_rpc_clnt_disconnected +rpcclnt_cbk_program_register +rpc_clnt_cleanup_and_start +rpc_clnt_connection_cleanup +rpc_clnt_disable +rpc_clnt_new +rpc_clnt_reconfig +rpc_clnt_reconnect +rpc_clnt_reconnect_cleanup +rpc_clnt_ref +rpc_clnt_register_notify +rpc_clnt_start +rpc_clnt_submit +rpc_clnt_unref +rpc_reply_to_xdr +rpcsvc_auth_array +rpcsvc_auth_check +rpcsvc_auth_reconf +rpcsvc_auth_unix_auxgids +rpcsvc_callback_submit +rpcsvc_create_listener +rpcsvc_create_listeners +rpcsvc_drc_init +rpcsvc_drc_priv +rpcsvc_drc_reconfigure +rpcsvc_get_program_vector_sizer +rpcsvc_init +rpcsvc_destroy +rpcsvc_init_options +rpcsvc_listener_destroy +rpcsvc_program_register +rpcsvc_program_register_portmap +rpcsvc_program_register_rpcbind6 +rpcsvc_program_unregister +rpcsvc_program_unregister_portmap +rpcsvc_program_unregister_rpcbind6 +rpcsvc_reconfigure_options +rpcsvc_register_notify +rpcsvc_register_portmap_enabled +rpcsvc_request_submit +rpcsvc_set_outstanding_rpc_limit +rpcsvc_set_throttle_on +rpcsvc_submit_generic +rpcsvc_submit_message +rpcsvc_transport_peeraddr +rpcsvc_transport_peername +rpcsvc_transport_privport_check +rpcsvc_transport_unix_options_build +rpcsvc_transport_volume_allowed +rpcsvc_transport_connect +rpcsvc_transport_getpeeraddr +rpcsvc_unregister_notify +rpcsvc_volume_allowed +rpc_transport_count +rpc_transport_connect +rpc_transport_disconnect +rpc_transport_get_peeraddr +rpc_transport_inet_options_build +rpc_transport_keepalive_options_set +rpc_transport_notify +rpc_transport_pollin_alloc +rpc_transport_pollin_destroy +rpc_transport_ref +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 new file mode 100644 index 00000000000..25a7148e5a3 --- /dev/null +++ b/rpc/rpc-lib/src/mgmt-pmap.c @@ -0,0 +1,147 @@ +/* + Copyright (c) 2018 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 "portmap-xdr.h" +#include "protocol-common.h" +#include "rpc-clnt.h" +#include "xdr-generic.h" + +/* Defining a minimal RPC client program for portmap signout + */ +char *clnt_pmap_signout_procs[GF_PMAP_MAXVALUE] = { + [GF_PMAP_SIGNOUT] = "SIGNOUT", +}; + +rpc_clnt_prog_t clnt_pmap_signout_prog = { + .progname = "Gluster Portmap", + .prognum = GLUSTER_PMAP_PROGRAM, + .progver = GLUSTER_PMAP_VERSION, + .procnames = clnt_pmap_signout_procs, +}; + +static int +mgmt_pmap_signout_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + pmap_signout_rsp rsp = { + 0, + }; + int ret = 0; + call_frame_t *frame = NULL; + + frame = myframe; + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_pmap_signout_rsp); + if (ret < 0) { + gf_log(THIS->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 == rsp.op_ret) { + gf_log(THIS->name, GF_LOG_ERROR, + "failed to register the port with glusterd"); + goto out; + } +out: + if (frame) { + STACK_DESTROY(frame->root); + } + + return 0; +} + +int +rpc_clnt_mgmt_pmap_signout(glusterfs_ctx_t *ctx, char *brickname) +{ + int ret = 0; + pmap_signout_req req = { + 0, + }; + call_frame_t *frame = NULL; + cmd_args_t *cmd_args = NULL; + char brick_name[PATH_MAX] = { + 0, + }; + struct iovec iov = { + 0, + }; + struct iobuf *iobuf = NULL; + struct iobref *iobref = NULL; + ssize_t xdr_size = 0; + + frame = create_frame(THIS, ctx->pool); + cmd_args = &ctx->cmd_args; + + if (!cmd_args->brick_port && (!cmd_args->brick_name || !brickname)) { + gf_log("fsd-mgmt", GF_LOG_DEBUG, + "portmapper signout arguments not given"); + goto out; + } + + if (cmd_args->volfile_server_transport && + !strcmp(cmd_args->volfile_server_transport, "rdma")) { + snprintf(brick_name, sizeof(brick_name), "%s.rdma", + cmd_args->brick_name); + req.brick = brick_name; + } else { + if (brickname) + req.brick = brickname; + else + req.brick = cmd_args->brick_name; + } + + req.port = cmd_args->brick_port; + req.rdma_port = cmd_args->brick_port2; + + /* mgmt_submit_request is not available in libglusterfs. + * Need to serialize and submit manually. + */ + iobref = iobref_new(); + if (!iobref) { + goto out; + } + + xdr_size = xdr_sizeof((xdrproc_t)xdr_pmap_signout_req, &req); + iobuf = iobuf_get2(ctx->iobuf_pool, xdr_size); + if (!iobuf) { + goto out; + }; + + iobref_add(iobref, iobuf); + + iov.iov_base = iobuf->ptr; + iov.iov_len = iobuf_pagesize(iobuf); + + /* Create the xdr payload */ + ret = xdr_serialize_generic(iov, &req, (xdrproc_t)xdr_pmap_signout_req); + if (ret == -1) { + gf_log(THIS->name, GF_LOG_WARNING, "failed to create XDR payload"); + goto out; + } + iov.iov_len = ret; + + ret = rpc_clnt_submit(ctx->mgmt, &clnt_pmap_signout_prog, GF_PMAP_SIGNOUT, + mgmt_pmap_signout_cbk, &iov, 1, NULL, 0, iobref, + frame, NULL, 0, NULL, 0, NULL); +out: + if (iobref) + iobref_unref(iobref); + + if (iobuf) + iobuf_unref(iobuf); + return ret; +} diff --git a/rpc/rpc-lib/src/protocol-common.h b/rpc/rpc-lib/src/protocol-common.h index c2540fa8d00..0cb5862e9a9 100644 --- a/rpc/rpc-lib/src/protocol-common.h +++ b/rpc/rpc-lib/src/protocol-common.h @@ -1,212 +1,382 @@ /* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _PROTOCOL_COMMON_H #define _PROTOCOL_COMMON_H enum gf_fop_procnum { - GFS3_OP_NULL, /* 0 */ - GFS3_OP_STAT, - GFS3_OP_READLINK, - GFS3_OP_MKNOD, - GFS3_OP_MKDIR, - GFS3_OP_UNLINK, - GFS3_OP_RMDIR, - GFS3_OP_SYMLINK, - GFS3_OP_RENAME, - GFS3_OP_LINK, - GFS3_OP_TRUNCATE, - GFS3_OP_OPEN, - GFS3_OP_READ, - GFS3_OP_WRITE, - GFS3_OP_STATFS, - GFS3_OP_FLUSH, - GFS3_OP_FSYNC, - GFS3_OP_SETXATTR, - GFS3_OP_GETXATTR, - GFS3_OP_REMOVEXATTR, - GFS3_OP_OPENDIR, - GFS3_OP_FSYNCDIR, - GFS3_OP_ACCESS, - GFS3_OP_CREATE, - GFS3_OP_FTRUNCATE, - GFS3_OP_FSTAT, - GFS3_OP_LK, - GFS3_OP_LOOKUP, - GFS3_OP_READDIR, - GFS3_OP_INODELK, - GFS3_OP_FINODELK, - GFS3_OP_ENTRYLK, - GFS3_OP_FENTRYLK, - GFS3_OP_XATTROP, - GFS3_OP_FXATTROP, - GFS3_OP_FGETXATTR, - GFS3_OP_FSETXATTR, - GFS3_OP_RCHECKSUM, - GFS3_OP_SETATTR, - GFS3_OP_FSETATTR, - GFS3_OP_READDIRP, - GFS3_OP_RELEASE, - GFS3_OP_RELEASEDIR, - GFS3_OP_MAXVALUE, -} ; + GFS3_OP_NULL, /* 0 */ + GFS3_OP_STAT, + GFS3_OP_READLINK, + GFS3_OP_MKNOD, + GFS3_OP_MKDIR, + GFS3_OP_UNLINK, + GFS3_OP_RMDIR, + GFS3_OP_SYMLINK, + GFS3_OP_RENAME, + GFS3_OP_LINK, + GFS3_OP_TRUNCATE, + GFS3_OP_OPEN, + GFS3_OP_READ, + GFS3_OP_WRITE, + GFS3_OP_STATFS, + GFS3_OP_FLUSH, + GFS3_OP_FSYNC, + GFS3_OP_SETXATTR, + GFS3_OP_GETXATTR, + GFS3_OP_REMOVEXATTR, + GFS3_OP_OPENDIR, + GFS3_OP_FSYNCDIR, + GFS3_OP_ACCESS, + GFS3_OP_CREATE, + GFS3_OP_FTRUNCATE, + GFS3_OP_FSTAT, + GFS3_OP_LK, + GFS3_OP_LOOKUP, + GFS3_OP_READDIR, + GFS3_OP_INODELK, + GFS3_OP_FINODELK, + GFS3_OP_ENTRYLK, + GFS3_OP_FENTRYLK, + GFS3_OP_XATTROP, + GFS3_OP_FXATTROP, + GFS3_OP_FGETXATTR, + GFS3_OP_FSETXATTR, + GFS3_OP_RCHECKSUM, + GFS3_OP_SETATTR, + GFS3_OP_FSETATTR, + GFS3_OP_READDIRP, + GFS3_OP_RELEASE, + GFS3_OP_RELEASEDIR, + GFS3_OP_FREMOVEXATTR, + GFS3_OP_FALLOCATE, + GFS3_OP_DISCARD, + GFS3_OP_ZEROFILL, + GFS3_OP_IPC, + GFS3_OP_SEEK, + GFS3_OP_COMPOUND, + GFS3_OP_LEASE, + GFS3_OP_GETACTIVELK, + GFS3_OP_SETACTIVELK, + GFS3_OP_ICREATE, + GFS3_OP_NAMELINK, + GFS3_OP_PUT, + GFS3_OP_COPY_FILE_RANGE, + GFS3_OP_MAXVALUE, +}; enum gf_handshake_procnum { - GF_HNDSK_NULL, - GF_HNDSK_SETVOLUME, - GF_HNDSK_GETSPEC, - GF_HNDSK_PING, - GF_HNDSK_MAXVALUE, + GF_HNDSK_NULL, + GF_HNDSK_SETVOLUME, + GF_HNDSK_GETSPEC, + GF_HNDSK_PING, + GF_HNDSK_SET_LK_VER, + GF_HNDSK_EVENT_NOTIFY, + GF_HNDSK_GET_VOLUME_INFO, + GF_HNDSK_GET_SNAPSHOT_INFO, + GF_HNDSK_MAXVALUE, }; enum gf_pmap_procnum { - GF_PMAP_NULL = 0, - GF_PMAP_PORTBYBRICK, - GF_PMAP_BRICKBYPORT, - GF_PMAP_SIGNUP, - GF_PMAP_SIGNIN, - GF_PMAP_SIGNOUT, - GF_PMAP_MAXVALUE, + GF_PMAP_NULL = 0, + GF_PMAP_PORTBYBRICK, + GF_PMAP_BRICKBYPORT, + /* + * SIGNUP is not used, and shouldn't be used. It was kept here only + * to avoid changing the numbers for things that come after it in this + * list. + */ + GF_PMAP_SIGNUP, + GF_PMAP_SIGNIN, + GF_PMAP_SIGNOUT, + GF_PMAP_MAXVALUE, +}; + +enum gf_aggregator_procnum { + GF_AGGREGATOR_NULL = 0, + GF_AGGREGATOR_LOOKUP, + GF_AGGREGATOR_GETLIMIT, + GF_AGGREGATOR_MAXVALUE, }; enum gf_pmap_port_type { - GF_PMAP_PORT_FREE = 0, - GF_PMAP_PORT_FOREIGN, - GF_PMAP_PORT_LEASED, - GF_PMAP_PORT_NONE, - GF_PMAP_PORT_BRICKSERVER, + GF_PMAP_PORT_FREE = 0, + GF_PMAP_PORT_FOREIGN, /* it actually means, not sure who is using it, but it + is in-use */ + GF_PMAP_PORT_LEASED, + GF_PMAP_PORT_ANY, + GF_PMAP_PORT_BRICKSERVER, /* port used by brick process */ }; typedef enum gf_pmap_port_type gf_pmap_port_type_t; enum gf_probe_resp { - GF_PROBE_SUCCESS, - GF_PROBE_LOCALHOST, - GF_PROBE_FRIEND, - GF_PROBE_ANOTHER_CLUSTER, - GF_PROBE_VOLUME_CONFLICT, - GF_PROBE_UNKNOWN_PEER, - GF_PROBE_ADD_FAILED + GF_PROBE_SUCCESS, + GF_PROBE_LOCALHOST, + GF_PROBE_FRIEND, + GF_PROBE_ANOTHER_CLUSTER, + GF_PROBE_VOLUME_CONFLICT, + GF_PROBE_SAME_UUID, + GF_PROBE_UNKNOWN_PEER, + GF_PROBE_ADD_FAILED, + GF_PROBE_QUORUM_NOT_MET, + GF_PROBE_MISSED_SNAP_CONFLICT, + GF_PROBE_SNAP_CONFLICT, + GF_PROBE_FRIEND_DETACHING, }; enum gf_deprobe_resp { - GF_DEPROBE_SUCCESS, - GF_DEPROBE_LOCALHOST, - GF_DEPROBE_NOT_FRIEND, - GF_DEPROBE_BRICK_EXIST, - GF_DEPROBE_FRIEND_DOWN + GF_DEPROBE_SUCCESS, + GF_DEPROBE_LOCALHOST, + GF_DEPROBE_NOT_FRIEND, + GF_DEPROBE_BRICK_EXIST, + GF_DEPROBE_FRIEND_DOWN, + GF_DEPROBE_QUORUM_NOT_MET, + GF_DEPROBE_FRIEND_DETACHING, + GF_DEPROBE_SNAP_BRICK_EXIST, }; enum gf_cbk_procnum { - GF_CBK_NULL = 0, - GF_CBK_FETCHSPEC, - GF_CBK_INO_FLUSH, - GF_CBK_MAXVALUE, + GF_CBK_NULL = 0, + GF_CBK_FETCHSPEC, + GF_CBK_INO_FLUSH, + GF_CBK_EVENT_NOTIFY, + GF_CBK_GET_SNAPS, + GF_CBK_CACHE_INVALIDATION, + GF_CBK_CHILD_UP, + GF_CBK_CHILD_DOWN, + GF_CBK_RECALL_LEASE, + GF_CBK_STATEDUMP, + GF_CBK_INODELK_CONTENTION, + GF_CBK_ENTRYLK_CONTENTION, + GF_CBK_MAXVALUE, }; enum gluster_cli_procnum { - GLUSTER_CLI_NULL, /* 0 */ - GLUSTER_CLI_PROBE, - GLUSTER_CLI_DEPROBE, - GLUSTER_CLI_LIST_FRIENDS, - GLUSTER_CLI_CREATE_VOLUME, - GLUSTER_CLI_GET_VOLUME, - GLUSTER_CLI_GET_NEXT_VOLUME, - GLUSTER_CLI_DELETE_VOLUME, - GLUSTER_CLI_START_VOLUME, - GLUSTER_CLI_STOP_VOLUME, - GLUSTER_CLI_RENAME_VOLUME, - GLUSTER_CLI_DEFRAG_VOLUME, - GLUSTER_CLI_SET_VOLUME, - GLUSTER_CLI_ADD_BRICK, - GLUSTER_CLI_REMOVE_BRICK, - GLUSTER_CLI_REPLACE_BRICK, - GLUSTER_CLI_LOG_ROTATE, - GLUSTER_CLI_GETSPEC, - GLUSTER_CLI_PMAP_PORTBYBRICK, - GLUSTER_CLI_SYNC_VOLUME, - GLUSTER_CLI_RESET_VOLUME, - GLUSTER_CLI_FSM_LOG, - GLUSTER_CLI_GSYNC_SET, - GLUSTER_CLI_PROFILE_VOLUME, - GLUSTER_CLI_QUOTA, - GLUSTER_CLI_TOP_VOLUME, - GLUSTER_CLI_GETWD, - GLUSTER_CLI_STATUS_VOLUME, - GLUSTER_CLI_STATUS_ALL, - GLUSTER_CLI_MOUNT, - GLUSTER_CLI_UMOUNT, - GLUSTER_CLI_HEAL_VOLUME, - GLUSTER_CLI_STATEDUMP_VOLUME, - GLUSTER_CLI_MAXVALUE, + GLUSTER_CLI_NULL, /* 0 */ + GLUSTER_CLI_PROBE, + GLUSTER_CLI_DEPROBE, + GLUSTER_CLI_LIST_FRIENDS, + GLUSTER_CLI_CREATE_VOLUME, + GLUSTER_CLI_GET_VOLUME, + GLUSTER_CLI_GET_NEXT_VOLUME, + GLUSTER_CLI_DELETE_VOLUME, + GLUSTER_CLI_START_VOLUME, + GLUSTER_CLI_STOP_VOLUME, + GLUSTER_CLI_RENAME_VOLUME, + GLUSTER_CLI_DEFRAG_VOLUME, + GLUSTER_CLI_SET_VOLUME, + GLUSTER_CLI_ADD_BRICK, + GLUSTER_CLI_REMOVE_BRICK, + GLUSTER_CLI_REPLACE_BRICK, + GLUSTER_CLI_LOG_ROTATE, + GLUSTER_CLI_GETSPEC, + GLUSTER_CLI_PMAP_PORTBYBRICK, + GLUSTER_CLI_SYNC_VOLUME, + GLUSTER_CLI_RESET_VOLUME, + GLUSTER_CLI_FSM_LOG, + GLUSTER_CLI_GSYNC_SET, + GLUSTER_CLI_PROFILE_VOLUME, + GLUSTER_CLI_QUOTA, + GLUSTER_CLI_TOP_VOLUME, + GLUSTER_CLI_GETWD, + GLUSTER_CLI_STATUS_VOLUME, + GLUSTER_CLI_STATUS_ALL, + GLUSTER_CLI_MOUNT, + GLUSTER_CLI_UMOUNT, + GLUSTER_CLI_HEAL_VOLUME, + GLUSTER_CLI_STATEDUMP_VOLUME, + GLUSTER_CLI_LIST_VOLUME, + GLUSTER_CLI_CLRLOCKS_VOLUME, + GLUSTER_CLI_UUID_RESET, + GLUSTER_CLI_UUID_GET, + GLUSTER_CLI_COPY_FILE, + GLUSTER_CLI_SYS_EXEC, + GLUSTER_CLI_SNAP, + GLUSTER_CLI_BARRIER_VOLUME, + GLUSTER_CLI_GET_VOL_OPT, + GLUSTER_CLI_GANESHA, + GLUSTER_CLI_BITROT, + GLUSTER_CLI_ATTACH_TIER, + GLUSTER_CLI_TIER, + GLUSTER_CLI_GET_STATE, + GLUSTER_CLI_RESET_BRICK, + GLUSTER_CLI_REMOVE_TIER_BRICK, + GLUSTER_CLI_ADD_TIER_BRICK, + GLUSTER_CLI_MAXVALUE, }; enum glusterd_mgmt_procnum { - GLUSTERD_MGMT_NULL, /* 0 */ - GLUSTERD_MGMT_CLUSTER_LOCK, - GLUSTERD_MGMT_CLUSTER_UNLOCK, - GLUSTERD_MGMT_STAGE_OP, - GLUSTERD_MGMT_COMMIT_OP, - GLUSTERD_MGMT_MAXVALUE, + GLUSTERD_MGMT_NULL, /* 0 */ + GLUSTERD_MGMT_CLUSTER_LOCK, + GLUSTERD_MGMT_CLUSTER_UNLOCK, + GLUSTERD_MGMT_STAGE_OP, + GLUSTERD_MGMT_COMMIT_OP, + GLUSTERD_MGMT_MAXVALUE, }; enum glusterd_friend_procnum { - GLUSTERD_FRIEND_NULL, /* 0 */ - GLUSTERD_PROBE_QUERY, - GLUSTERD_FRIEND_ADD, - GLUSTERD_FRIEND_REMOVE, - GLUSTERD_FRIEND_UPDATE, - GLUSTERD_FRIEND_MAXVALUE, + GLUSTERD_FRIEND_NULL, /* 0 */ + GLUSTERD_PROBE_QUERY, + GLUSTERD_FRIEND_ADD, + GLUSTERD_FRIEND_REMOVE, + GLUSTERD_FRIEND_UPDATE, + GLUSTERD_FRIEND_MAXVALUE, }; enum glusterd_brick_procnum { - GLUSTERD_BRICK_NULL, /* 0 */ - GLUSTERD_BRICK_TERMINATE, - GLUSTERD_BRICK_XLATOR_INFO, - GLUSTERD_BRICK_XLATOR_HEAL, - GLUSTERD_BRICK_OP, - GLUSTERD_BRICK_MAXVALUE, + GLUSTERD_BRICK_NULL, /* 0 */ + GLUSTERD_BRICK_TERMINATE, + GLUSTERD_BRICK_XLATOR_INFO, + GLUSTERD_BRICK_XLATOR_OP, + GLUSTERD_BRICK_STATUS, + GLUSTERD_BRICK_OP, + GLUSTERD_BRICK_XLATOR_DEFRAG, + GLUSTERD_NODE_PROFILE, + GLUSTERD_NODE_STATUS, + GLUSTERD_VOLUME_BARRIER_OP, + GLUSTERD_BRICK_BARRIER, + GLUSTERD_NODE_BITROT, + GLUSTERD_BRICK_ATTACH, + GLUSTERD_DUMP_METRICS, + GLUSTERD_SVC_ATTACH, + GLUSTERD_SVC_DETACH, + GLUSTERD_BRICK_MAXVALUE, +}; + +enum glusterd_mgmt_hndsk_procnum { + GD_MGMT_HNDSK_NULL, + GD_MGMT_HNDSK_VERSIONS, + GD_MGMT_HNDSK_VERSIONS_ACK, + GD_MGMT_HNDSK_MAXVALUE, +}; + +typedef enum { + GF_SHD_OP_INVALID, + GF_SHD_OP_HEAL_INDEX, + GF_SHD_OP_HEAL_FULL, + GF_SHD_OP_INDEX_SUMMARY, + GF_SHD_OP_HEALED_FILES, + GF_SHD_OP_HEAL_FAILED_FILES, + GF_SHD_OP_SPLIT_BRAIN_FILES, + GF_SHD_OP_STATISTICS, + GF_SHD_OP_STATISTICS_HEAL_COUNT, + GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA, + GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE, + GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK, + GF_SHD_OP_HEAL_ENABLE, + GF_SHD_OP_HEAL_DISABLE, + GF_SHD_OP_SBRAIN_HEAL_FROM_LATEST_MTIME, + GF_SHD_OP_GRANULAR_ENTRY_HEAL_ENABLE, + GF_SHD_OP_GRANULAR_ENTRY_HEAL_DISABLE, + GF_SHD_OP_HEAL_SUMMARY, +} gf_xl_afr_op_t; + +struct gf_gsync_detailed_status_ { + char node[NAME_MAX]; + char master[NAME_MAX]; + char brick[PATH_MAX]; + char slave_user[NAME_MAX]; + char slave[NAME_MAX]; + char slave_node[NAME_MAX]; + char worker_status[NAME_MAX]; + char crawl_status[NAME_MAX]; + char last_synced[NAME_MAX]; + char last_synced_utc[NAME_MAX]; + char entry[NAME_MAX]; + char data[NAME_MAX]; + char meta[NAME_MAX]; + char failures[NAME_MAX]; + char checkpoint_time[NAME_MAX]; + char checkpoint_time_utc[NAME_MAX]; + char checkpoint_completed[NAME_MAX]; + char checkpoint_completion_time[NAME_MAX]; + char checkpoint_completion_time_utc[NAME_MAX]; + char brick_host_uuid[NAME_MAX]; + char slavekey[NAME_MAX]; + char session_slave[NAME_MAX]; +}; + +enum glusterd_mgmt_v3_procnum { + GLUSTERD_MGMT_V3_NULL, /* 0 */ + GLUSTERD_MGMT_V3_LOCK, + 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, }; -#define GLUSTER_HNDSK_PROGRAM 14398633 /* Completely random */ -#define GLUSTER_HNDSK_VERSION 1 /* 0.0.1 */ +typedef struct gf_gsync_detailed_status_ gf_gsync_status_t; -#define GLUSTER_PMAP_PROGRAM 34123456 -#define GLUSTER_PMAP_VERSION 1 +enum gf_get_volume_info_type { + GF_GET_VOLUME_NONE, /* 0 */ + GF_GET_VOLUME_UUID +}; + +typedef enum gf_get_volume_info_type gf_get_volume_info_type; + +enum gf_get_snapshot_info_type { + GF_GET_SNAPSHOT_LIST, +}; +typedef enum gf_get_snapshot_info_type gf_get_snapshot_info_type; + +enum gf_getspec_flags_type { GF_GETSPEC_FLAG_SERVERS_LIST = 1 }; +typedef enum gf_getspec_flags_type gf_getspec_flags_type; + +#define GLUSTER_HNDSK_PROGRAM 14398633 /* Completely random */ +#define GLUSTER_HNDSK_VERSION 2 /* 0.0.2 */ -#define GLUSTER_CBK_PROGRAM 52743234 /* Completely random */ -#define GLUSTER_CBK_VERSION 1 /* 0.0.1 */ +#define GLUSTER_PMAP_PROGRAM 34123456 +#define GLUSTER_PMAP_VERSION 1 -#define GLUSTER3_1_FOP_PROGRAM 1298437 /* Completely random */ -#define GLUSTER3_1_FOP_VERSION 310 /* 3.1.0 */ -#define GLUSTER3_1_FOP_PROCCNT GFS3_OP_MAXVALUE +#define GLUSTER_CBK_PROGRAM 52743234 /* Completely random */ +#define GLUSTER_CBK_VERSION 1 /* 0.0.1 */ + +#define GLUSTER_FOP_PROGRAM 1298437 /* Completely random */ +#define GLUSTER_FOP_VERSION 330 /* 3.3.0 */ +#define GLUSTER_FOP_PROCCNT GFS3_OP_MAXVALUE + +#define GLUSTER_FOP_VERSION_v2 400 /* 4.0.0 */ + +/* Aggregator */ +#define GLUSTER_AGGREGATOR_PROGRAM 29852134 /* Completely random */ +#define GLUSTER_AGGREGATOR_VERSION 1 /* Second version */ -#define GD_MGMT_PROGRAM 1238433 /* Completely random */ -#define GD_MGMT_VERSION 2 /* 0.0.2 */ +#define GD_MGMT_PROGRAM 1238433 /* Completely random */ +#define GD_MGMT_VERSION 2 /* 0.0.2 */ + +#define GD_FRIEND_PROGRAM 1238437 /* Completely random */ +#define GD_FRIEND_VERSION 2 /* 0.0.2 */ + +#define GLUSTER_CLI_PROGRAM 1238463 /* Completely random */ +#define GLUSTER_CLI_VERSION 2 /* 0.0.2 */ + +#define GD_BRICK_PROGRAM 4867634 /*Completely random*/ +#define GD_BRICK_VERSION 2 -#define GD_FRIEND_PROGRAM 1238437 /* Completely random */ -#define GD_FRIEND_VERSION 2 /* 0.0.2 */ +/* Third version */ +#define GD_MGMT_V3_VERSION 3 -#define GLUSTER_CLI_PROGRAM 1238463 /* Completely random */ -#define GLUSTER_CLI_VERSION 2 /* 0.0.2 */ +/* OP-VERSION handshake */ +#define GD_MGMT_HNDSK_PROGRAM 1239873 /* Completely random */ +#define GD_MGMT_HNDSK_VERSION 1 -#define GD_BRICK_PROGRAM 4867634 /*Completely random*/ -#define GD_BRICK_VERSION 2 +#define GD_VOLUME_NAME_MAX \ + ((NAME_MAX + 1) - 5) /* Maximum size of volume name */ +#define GD_VOLUME_NAME_MAX_TIER \ + (GD_VOLUME_NAME_MAX + 5) /* +5 needed for '-hot' \ + and '-cold' suffixes*/ +#define GLUSTER_PROCESS_UUID_FMT \ + "CTX_ID:%s-GRAPH_ID:%d-PID:%d-HOST:%s-PC_NAME:%s-RECON_NO:%s" #endif /* !_PROTOCOL_COMMON_H */ diff --git a/rpc/rpc-lib/src/rpc-clnt-ping.c b/rpc/rpc-lib/src/rpc-clnt-ping.c new file mode 100644 index 00000000000..31f17841bea --- /dev/null +++ b/rpc/rpc-lib/src/rpc-clnt-ping.c @@ -0,0 +1,357 @@ +/* + Copyright (c) 2014 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 "rpc-clnt.h" +#include "rpc-clnt-ping.h" +#include <glusterfs/byte-order.h> +#include "xdr-rpcclnt.h" +#include "rpc-transport.h" +#include "protocol-common.h" +#include <glusterfs/mem-pool.h> +#include "xdr-rpc.h" +#include "rpc-common-xdr.h" +#include <glusterfs/timespec.h> + +char *clnt_ping_procs[GF_DUMP_MAXVALUE] = { + [GF_DUMP_PING] = "NULL", +}; +struct rpc_clnt_program clnt_ping_prog = { + .progname = "GF-DUMP", + .prognum = GLUSTER_DUMP_PROGRAM, + .progver = GLUSTER_DUMP_VERSION, + .procnames = clnt_ping_procs, +}; + +struct ping_local { + struct rpc_clnt *rpc; + struct timespec submit_time; +}; + +/* Must be called under conn->lock */ +static int +__rpc_clnt_rearm_ping_timer(struct rpc_clnt *rpc, gf_timer_cbk_t cbk) +{ + rpc_clnt_connection_t *conn = &rpc->conn; + rpc_transport_t *trans = conn->trans; + struct timespec timeout = { + 0, + }; + gf_timer_t *timer = NULL; + + if (conn->ping_timer) { + gf_log_callingfn("", GF_LOG_CRITICAL, + "%s: ping timer event already scheduled", + conn->trans->peerinfo.identifier); + return -1; + } + + timeout.tv_sec = conn->ping_timeout; + timeout.tv_nsec = 0; + + rpc_clnt_ref(rpc); + timer = gf_timer_call_after(rpc->ctx, timeout, cbk, (void *)rpc); + if (timer == NULL) { + gf_log(trans->name, GF_LOG_WARNING, "unable to setup ping timer"); + + /* This unref can't be the last. We just took a ref few lines + * above. So this can be performed under conn->lock. */ + rpc_clnt_unref(rpc); + conn->ping_started = 0; + return -1; + } + + conn->ping_timer = timer; + conn->ping_started = 1; + return 0; +} + +/* Must be called under conn->lock */ +int +rpc_clnt_remove_ping_timer_locked(struct rpc_clnt *rpc) +{ + rpc_clnt_connection_t *conn = &rpc->conn; + gf_timer_t *timer = NULL; + + if (conn->ping_timer) { + timer = conn->ping_timer; + conn->ping_timer = NULL; + gf_timer_call_cancel(rpc->ctx, timer); + conn->ping_started = 0; + return 1; + } + + /* This is to account for rpc_clnt_disable that might have set + * conn->trans to NULL. */ + if (conn->trans) + gf_log_callingfn("", GF_LOG_DEBUG, + "%s: ping timer event " + "already removed", + conn->trans->peerinfo.identifier); + + return 0; +} + +static void +rpc_clnt_start_ping(void *rpc_ptr); + +void +rpc_clnt_ping_timer_expired(void *rpc_ptr) +{ + struct rpc_clnt *rpc = NULL; + rpc_transport_t *trans = NULL; + rpc_clnt_connection_t *conn = NULL; + int disconnect = 0; + struct timespec current = { + 0, + }; + int unref = 0; + + rpc = (struct rpc_clnt *)rpc_ptr; + conn = &rpc->conn; + trans = conn->trans; + + if (!trans) { + gf_log("ping-timer", GF_LOG_WARNING, "transport not initialized"); + goto out; + } + + timespec_now_realtime(¤t); + pthread_mutex_lock(&conn->lock); + { + unref = rpc_clnt_remove_ping_timer_locked(rpc); + + if (((current.tv_sec - conn->last_received.tv_sec) < + conn->ping_timeout) || + ((current.tv_sec - conn->last_sent.tv_sec) < conn->ping_timeout)) { + 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; + } + } + pthread_mutex_unlock(&conn->lock); + + if (unref) + rpc_clnt_unref(rpc); + + if (disconnect) { + gf_log(trans->name, GF_LOG_CRITICAL, + "server %s has not responded in the last %d " + "seconds, disconnecting.", + trans->peerinfo.identifier, conn->ping_timeout); + + rpc_transport_disconnect(conn->trans, _gf_false); + } + +out: + return; +} + +int +rpc_clnt_ping_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + struct ping_local *local = NULL; + xlator_t *this = NULL; + rpc_clnt_connection_t *conn = NULL; + call_frame_t *frame = NULL; + int unref = 0; + gf_boolean_t call_notify = _gf_false; + + struct timespec now; + struct timespec delta; + int64_t latency_msec = 0; + int ret = 0; + + if (!myframe) { + gf_log(THIS->name, GF_LOG_WARNING, "frame with the request is NULL"); + goto out; + } + + frame = myframe; + this = frame->this; + local = frame->local; + conn = &local->rpc->conn; + + timespec_now(&now); + 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); + { + unref = rpc_clnt_remove_ping_timer_locked(local->rpc); + if (req->rpc_status == -1) { + conn->ping_started = 0; + pthread_mutex_unlock(&conn->lock); + if (unref) { + gf_log(this->name, GF_LOG_WARNING, + "socket or ib related error"); + + } else { + /* timer expired and transport bailed out */ + gf_log(this->name, GF_LOG_WARNING, "socket disconnected"); + } + goto after_unlock; + } + + 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); + } + } +after_unlock: + if (call_notify) { + ret = local->rpc->notifyfn(local->rpc, this, RPC_CLNT_PING, + (void *)(uintptr_t)latency_msec); + if (ret) { + gf_log(this->name, GF_LOG_WARNING, "RPC_CLNT_PING notify failed"); + } + } +out: + if (unref) + rpc_clnt_unref(local->rpc); + + if (frame) { + GF_FREE(frame->local); + frame->local = NULL; + STACK_DESTROY(frame->root); + } + return 0; +} + +int +rpc_clnt_ping(struct rpc_clnt *rpc) +{ + call_frame_t *frame = NULL; + int32_t ret = -1; + rpc_clnt_connection_t *conn = NULL; + struct ping_local *local = NULL; + + conn = &rpc->conn; + local = GF_MALLOC(sizeof(struct ping_local), gf_common_ping_local_t); + if (!local) + return ret; + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) { + GF_FREE(local); + return ret; + } + + local->rpc = rpc; + timespec_now(&local->submit_time); + frame->local = local; + + ret = rpc_clnt_submit(rpc, &clnt_ping_prog, GF_DUMP_PING, rpc_clnt_ping_cbk, + NULL, 0, NULL, 0, NULL, frame, NULL, 0, NULL, 0, + NULL); + if (ret) { + /* FIXME: should we free the frame here? Methinks so! */ + gf_log(THIS->name, GF_LOG_ERROR, "failed to start ping timer"); + } else { + /* ping successfully queued in list of saved frames + * for the connection*/ + pthread_mutex_lock(&conn->lock); + conn->pingcnt++; + pthread_mutex_unlock(&conn->lock); + } + + return ret; +} + +static void +rpc_clnt_start_ping(void *rpc_ptr) +{ + struct rpc_clnt *rpc = NULL; + rpc_clnt_connection_t *conn = NULL; + int frame_count = 0; + int unref = 0; + + rpc = (struct rpc_clnt *)rpc_ptr; + conn = &rpc->conn; + + if (conn->ping_timeout == 0) { + gf_log(THIS->name, GF_LOG_DEBUG, + "ping timeout is 0," + " returning"); + return; + } + + pthread_mutex_lock(&conn->lock); + { + unref = rpc_clnt_remove_ping_timer_locked(rpc); + + if (conn->saved_frames) { + GF_ASSERT(conn->saved_frames->count >= 0); + /* treat the case where conn->saved_frames is NULL + as no pending frames */ + frame_count = conn->saved_frames->count; + } + + if ((frame_count == 0) || !conn->connected) { + gf_log(THIS->name, GF_LOG_DEBUG, + "returning as transport is already disconnected" + " OR there are no frames (%d || %d)", + !conn->connected, frame_count); + + pthread_mutex_unlock(&conn->lock); + if (unref) + rpc_clnt_unref(rpc); + return; + } + + if (__rpc_clnt_rearm_ping_timer(rpc, rpc_clnt_ping_timer_expired) == + -1) { + gf_log(THIS->name, GF_LOG_WARNING, "unable to setup ping timer"); + pthread_mutex_unlock(&conn->lock); + if (unref) + rpc_clnt_unref(rpc); + return; + } + } + pthread_mutex_unlock(&conn->lock); + if (unref) + rpc_clnt_unref(rpc); + + rpc_clnt_ping(rpc); +} + +void +rpc_clnt_check_and_start_ping(struct rpc_clnt *rpc) +{ + char start_ping = 0; + + pthread_mutex_lock(&rpc->conn.lock); + { + if (!rpc->conn.ping_started) + start_ping = 1; + } + pthread_mutex_unlock(&rpc->conn.lock); + + if (start_ping) + rpc_clnt_start_ping((void *)rpc); + + return; +} diff --git a/rpc/rpc-lib/src/rpc-clnt-ping.h b/rpc/rpc-lib/src/rpc-clnt-ping.h new file mode 100644 index 00000000000..e5466a828c2 --- /dev/null +++ b/rpc/rpc-lib/src/rpc-clnt-ping.h @@ -0,0 +1,16 @@ +/* + Copyright (c) 2014 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. +*/ + +struct rpc_clnt; +#define RPC_DEFAULT_PING_TIMEOUT 30 +void +rpc_clnt_check_and_start_ping(struct rpc_clnt *rpc_ptr); +int +rpc_clnt_remove_ping_timer_locked(struct rpc_clnt *rpc); diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c index 43791dc57e1..517037c4a5d 100644 --- a/rpc/rpc-lib/src/rpc-clnt.c +++ b/rpc/rpc-lib/src/rpc-clnt.c @@ -1,524 +1,480 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#define RPC_CLNT_DEFAULT_REQUEST_COUNT 4096 +#define RPC_CLNT_DEFAULT_REQUEST_COUNT 512 #include "rpc-clnt.h" -#include "byte-order.h" +#include "rpc-clnt-ping.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" void -rpc_clnt_reply_deinit (struct rpc_req *req, struct mem_pool *pool); +rpc_clnt_reply_deinit(struct rpc_req *req, struct mem_pool *pool); -uint64_t -rpc_clnt_new_callid (struct rpc_clnt *clnt) +struct saved_frame * +__saved_frames_get_timedout(struct saved_frames *frames, uint32_t timeout, + struct timeval *current) { - uint64_t callid = 0; + struct saved_frame *bailout_frame = NULL, *tmp = NULL; - pthread_mutex_lock (&clnt->lock); - { - callid = ++clnt->xid; + if (!list_empty(&frames->sf.list)) { + tmp = list_entry(frames->sf.list.next, typeof(*tmp), list); + if ((tmp->saved_at.tv_sec + timeout) <= current->tv_sec) { + bailout_frame = tmp; + list_del_init(&bailout_frame->list); + frames->count--; } - pthread_mutex_unlock (&clnt->lock); + } - return callid; -} - - -struct saved_frame * -__saved_frames_get_timedout (struct saved_frames *frames, uint32_t timeout, - struct timeval *current) -{ - struct saved_frame *bailout_frame = NULL, *tmp = NULL; - - if (!list_empty(&frames->sf.list)) { - tmp = list_entry (frames->sf.list.next, typeof (*tmp), list); - if ((tmp->saved_at.tv_sec + timeout) < current->tv_sec) { - bailout_frame = tmp; - list_del_init (&bailout_frame->list); - frames->count--; - } - } - - return bailout_frame; + return bailout_frame; } static int -_is_lock_fop (struct saved_frame *sframe) +_is_lock_fop(struct saved_frame *sframe) { - int fop = 0; + int fop = 0; - if (SFRAME_GET_PROGNUM (sframe) == GLUSTER3_1_FOP_PROGRAM && - SFRAME_GET_PROGVER (sframe) == GLUSTER3_1_FOP_VERSION) - fop = SFRAME_GET_PROCNUM (sframe); + if (SFRAME_GET_PROGNUM(sframe) == GLUSTER_FOP_PROGRAM && + SFRAME_GET_PROGVER(sframe) == GLUSTER_FOP_VERSION) + fop = SFRAME_GET_PROCNUM(sframe); - return ((fop == GFS3_OP_LK) || - (fop == GFS3_OP_INODELK) || - (fop == GFS3_OP_FINODELK) || - (fop == GFS3_OP_ENTRYLK) || - (fop == GFS3_OP_FENTRYLK)); + return ((fop == GFS3_OP_LK) || (fop == GFS3_OP_INODELK) || + (fop == GFS3_OP_FINODELK) || (fop == GFS3_OP_ENTRYLK) || + (fop == GFS3_OP_FENTRYLK)); } -struct saved_frame * -__saved_frames_put (struct saved_frames *frames, void *frame, - struct rpc_req *rpcreq) +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 */ + 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); + 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); + 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); - else - list_add_tail (&saved_frame->list, &frames->sf.list); + if (_is_lock_fop(saved_frame)) + list_add_tail(&saved_frame->list, &frames->lk_sf.list); + else + list_add_tail(&saved_frame->list, &frames->sf.list); - frames->count++; + frames->count++; out: - return saved_frame; + return saved_frame; } - -void -saved_frames_delete (struct saved_frame *saved_frame, - rpc_clnt_connection_t *conn) -{ - GF_VALIDATE_OR_GOTO ("rpc-clnt", saved_frame, out); - GF_VALIDATE_OR_GOTO ("rpc-clnt", conn, out); - - pthread_mutex_lock (&conn->lock); - { - list_del_init (&saved_frame->list); - conn->saved_frames->count--; - } - pthread_mutex_unlock (&conn->lock); - - if (saved_frame->rpcreq != NULL) { - rpc_clnt_reply_deinit (saved_frame->rpcreq, - conn->rpc_clnt->reqpool); - } - - mem_put (saved_frame); -out: - return; -} - - static void -call_bail (void *data) +call_bail(void *data) { - struct rpc_clnt *clnt = NULL; - rpc_clnt_connection_t *conn = NULL; - struct timeval current; - struct list_head list; - struct saved_frame *saved_frame = NULL; - struct saved_frame *trav = NULL; - struct saved_frame *tmp = NULL; - struct tm frame_sent_tm; - char frame_sent[256] = {0,}; - struct timeval timeout = {0,}; - struct iovec iov = {0,}; - - GF_VALIDATE_OR_GOTO ("client", data, out); - - clnt = data; - - conn = &clnt->conn; - - gettimeofday (¤t, NULL); - INIT_LIST_HEAD (&list); - - pthread_mutex_lock (&conn->lock); - { - /* Chaining to get call-always functionality from - call-once timer */ - if (conn->timer) { - timeout.tv_sec = 10; - timeout.tv_usec = 0; - - gf_timer_call_cancel (clnt->ctx, conn->timer); - conn->timer = gf_timer_call_after (clnt->ctx, - timeout, - call_bail, - (void *) clnt); - - if (conn->timer == NULL) { - gf_log (conn->trans->name, GF_LOG_WARNING, - "Cannot create bailout timer"); - } - } - - do { - saved_frame = - __saved_frames_get_timedout (conn->saved_frames, - conn->frame_timeout, - ¤t); - if (saved_frame) - list_add (&saved_frame->list, &list); - - } while (saved_frame); - } - pthread_mutex_unlock (&conn->lock); - - list_for_each_entry_safe (trav, tmp, &list, list) { - localtime_r (&trav->saved_at.tv_sec, &frame_sent_tm); - strftime (frame_sent, 32, "%Y-%m-%d %H:%M:%S", &frame_sent_tm); - snprintf (frame_sent + strlen (frame_sent), - 256 - strlen (frame_sent), - ".%"GF_PRI_SUSECONDS, trav->saved_at.tv_usec); - - gf_log (conn->trans->name, GF_LOG_ERROR, - "bailing out frame type(%s) op(%s(%d)) xid = 0x%ux " - "sent = %s. timeout = %d", - trav->rpcreq->prog->progname, - (trav->rpcreq->prog->procnames) ? - trav->rpcreq->prog->procnames[trav->rpcreq->procnum] : - "--", - trav->rpcreq->procnum, trav->rpcreq->xid, frame_sent, - conn->frame_timeout); - - clnt = rpc_clnt_ref (clnt); - trav->rpcreq->rpc_status = -1; - trav->rpcreq->cbkfn (trav->rpcreq, &iov, 1, trav->frame); - - rpc_clnt_reply_deinit (trav->rpcreq, clnt->reqpool); - clnt = rpc_clnt_unref (clnt); - list_del_init (&trav->list); - mem_put (trav); - } + rpc_transport_t *trans = NULL; + struct rpc_clnt *clnt = NULL; + rpc_clnt_connection_t *conn = NULL; + struct timeval current; + struct list_head list; + struct saved_frame *saved_frame = NULL; + struct saved_frame *trav = NULL; + struct saved_frame *tmp = NULL; + char frame_sent[GF_TIMESTR_SIZE] = { + 0, + }; + struct timespec timeout = { + 0, + }; + char peerid[UNIX_PATH_MAX] = {0}; + gf_boolean_t need_unref = _gf_false; + + GF_VALIDATE_OR_GOTO("client", data, out); + + clnt = data; + + conn = &clnt->conn; + pthread_mutex_lock(&conn->lock); + { + trans = conn->trans; + if (trans) { + (void)snprintf(peerid, sizeof(peerid), "%s", + conn->trans->peerinfo.identifier); + } + } + pthread_mutex_unlock(&conn->lock); + /*rpc_clnt_connection_cleanup will be unwinding all saved frames, + * bailed or otherwise*/ + if (!trans) + goto out; + + gettimeofday(¤t, NULL); + INIT_LIST_HEAD(&list); + + pthread_mutex_lock(&conn->lock); + { + /* Chaining to get call-always functionality from + call-once timer */ + if (conn->timer) { + timeout.tv_sec = 10; + timeout.tv_nsec = 0; + + /* Ref rpc as it's added to timer event queue */ + rpc_clnt_ref(clnt); + gf_timer_call_cancel(clnt->ctx, conn->timer); + conn->timer = gf_timer_call_after(clnt->ctx, timeout, call_bail, + (void *)clnt); + + if (conn->timer == NULL) { + gf_log(conn->name, GF_LOG_WARNING, + "Cannot create bailout timer for %s", peerid); + need_unref = _gf_true; + } + } + + do { + saved_frame = __saved_frames_get_timedout( + conn->saved_frames, conn->frame_timeout, ¤t); + if (saved_frame) + list_add(&saved_frame->list, &list); + + } while (saved_frame); + } + pthread_mutex_unlock(&conn->lock); + + if (list_empty(&list)) + goto out; + + list_for_each_entry_safe(trav, tmp, &list, list) + { + 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, " + "unique = %" PRIu64 ", sent = %s, timeout = %d for %s", + trav->rpcreq->prog->progname, + (trav->rpcreq->prog->procnames) + ? trav->rpcreq->prog->procnames[trav->rpcreq->procnum] + : "--", + trav->rpcreq->procnum, trav->rpcreq->xid, + ((call_frame_t *)(trav->frame))->root->unique, frame_sent, + conn->frame_timeout, peerid); + + clnt = rpc_clnt_ref(clnt); + trav->rpcreq->rpc_status = -1; + trav->rpcreq->cbkfn(trav->rpcreq, NULL, 0, trav->frame); + + rpc_clnt_reply_deinit(trav->rpcreq, clnt->reqpool); + clnt = rpc_clnt_unref(clnt); + list_del_init(&trav->list); + mem_put(trav); + } out: - return; + rpc_clnt_unref(clnt); + if (need_unref) + rpc_clnt_unref(clnt); + return; } - /* to be called with conn->lock held */ -struct saved_frame * -__save_frame (struct rpc_clnt *rpc_clnt, call_frame_t *frame, - struct rpc_req *rpcreq) +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; - struct timeval timeout = {0, }; - struct saved_frame *saved_frame = NULL; - - conn = &rpc_clnt->conn; - - saved_frame = __saved_frames_put (conn->saved_frames, frame, rpcreq); - - if (saved_frame == NULL) { - goto out; - } - - /* TODO: make timeout configurable */ - if (conn->timer == NULL) { - timeout.tv_sec = 10; - timeout.tv_usec = 0; - conn->timer = gf_timer_call_after (rpc_clnt->ctx, - timeout, - call_bail, - (void *) rpc_clnt); - } + rpc_clnt_connection_t *conn = &rpc_clnt->conn; + struct timespec timeout = { + 0, + }; + struct saved_frame *saved_frame = __saved_frames_put(conn->saved_frames, + frame, rpcreq); + + if (saved_frame == NULL) { + goto out; + } + + /* TODO: make timeout configurable */ + if (conn->timer == NULL) { + timeout.tv_sec = 10; + timeout.tv_nsec = 0; + rpc_clnt_ref(rpc_clnt); + conn->timer = gf_timer_call_after(rpc_clnt->ctx, timeout, call_bail, + (void *)rpc_clnt); + } out: - return saved_frame; + return saved_frame; } - struct saved_frames * -saved_frames_new (void) +saved_frames_new(void) { - struct saved_frames *saved_frames = NULL; + struct saved_frames *saved_frames = NULL; - saved_frames = GF_CALLOC (1, sizeof (*saved_frames), - gf_common_mt_rpcclnt_savedframe_t); - if (!saved_frames) { - return NULL; - } + saved_frames = GF_CALLOC(1, sizeof(*saved_frames), + gf_common_mt_rpcclnt_savedframe_t); + if (!saved_frames) { + return NULL; + } - INIT_LIST_HEAD (&saved_frames->sf.list); - INIT_LIST_HEAD (&saved_frames->lk_sf.list); + INIT_LIST_HEAD(&saved_frames->sf.list); + INIT_LIST_HEAD(&saved_frames->lk_sf.list); - return saved_frames; + return saved_frames; } - int -__saved_frame_copy (struct saved_frames *frames, int64_t callid, - struct saved_frame *saved_frame) +__saved_frame_copy(struct saved_frames *frames, int64_t callid, + struct saved_frame *saved_frame) { - struct saved_frame *tmp = NULL; - int ret = -1; + struct saved_frame *tmp = NULL; + int ret = -1; - if (!saved_frame) { - ret = 0; - goto out; + if (!saved_frame) { + ret = 0; + goto out; + } + + list_for_each_entry(tmp, &frames->sf.list, list) + { + if (tmp->rpcreq->xid == callid) { + *saved_frame = *tmp; + ret = 0; + goto out; } + } - list_for_each_entry (tmp, &frames->sf.list, list) { - if (tmp->rpcreq->xid == callid) { - *saved_frame = *tmp; - ret = 0; - goto out; - } - } - - list_for_each_entry (tmp, &frames->lk_sf.list, list) { - if (tmp->rpcreq->xid == callid) { - *saved_frame = *tmp; - ret = 0; - goto out; - } - } + list_for_each_entry(tmp, &frames->lk_sf.list, list) + { + if (tmp->rpcreq->xid == callid) { + *saved_frame = *tmp; + ret = 0; + goto out; + } + } out: - return ret; + return ret; } - struct saved_frame * -__saved_frame_get (struct saved_frames *frames, int64_t callid) +__saved_frame_get(struct saved_frames *frames, int64_t callid) { - struct saved_frame *saved_frame = NULL; - struct saved_frame *tmp = NULL; - - list_for_each_entry (tmp, &frames->sf.list, list) { - if (tmp->rpcreq->xid == callid) { - list_del_init (&tmp->list); - frames->count--; - saved_frame = tmp; - goto out; - } - } - - list_for_each_entry (tmp, &frames->lk_sf.list, list) { - if (tmp->rpcreq->xid == callid) { - list_del_init (&tmp->list); - frames->count--; - saved_frame = tmp; - goto out; - } - } + struct saved_frame *saved_frame = NULL; + struct saved_frame *tmp = NULL; -out: - if (saved_frame) { - THIS = saved_frame->capital_this; + list_for_each_entry(tmp, &frames->sf.list, list) + { + if (tmp->rpcreq->xid == callid) { + list_del_init(&tmp->list); + frames->count--; + saved_frame = tmp; + goto out; } + } - return saved_frame; -} + list_for_each_entry(tmp, &frames->lk_sf.list, list) + { + if (tmp->rpcreq->xid == callid) { + list_del_init(&tmp->list); + frames->count--; + saved_frame = tmp; + goto out; + } + } + +out: + if (saved_frame) { + THIS = saved_frame->capital_this; + } + return saved_frame; +} void -saved_frames_unwind (struct saved_frames *saved_frames) +saved_frames_unwind(struct saved_frames *saved_frames) { - struct rpc_clnt *clnt = NULL; - struct saved_frame *trav = NULL; - struct saved_frame *tmp = NULL; - struct tm *frame_sent_tm = NULL; - char timestr[256] = {0,}; - - struct iovec iov = {0,}; - - list_splice_init (&saved_frames->lk_sf.list, &saved_frames->sf.list); - - list_for_each_entry_safe (trav, tmp, &saved_frames->sf.list, list) { - frame_sent_tm = localtime (&trav->saved_at.tv_sec); - strftime (timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", - frame_sent_tm); - snprintf (timestr + strlen (timestr), - sizeof(timestr) - strlen (timestr), - ".%"GF_PRI_SUSECONDS, trav->saved_at.tv_usec); - - if (!trav->rpcreq || !trav->rpcreq->prog) - continue; - - gf_log_callingfn (trav->rpcreq->conn->trans->name, - GF_LOG_ERROR, - "forced unwinding frame type(%s) op(%s(%d)) " - "called at %s", - trav->rpcreq->prog->progname, - ((trav->rpcreq->prog->procnames) ? - trav->rpcreq->prog->procnames[trav->rpcreq->procnum] - : "--"), - trav->rpcreq->procnum, timestr); - saved_frames->count--; - - clnt = rpc_clnt_ref (trav->rpcreq->conn->rpc_clnt); - trav->rpcreq->rpc_status = -1; - trav->rpcreq->cbkfn (trav->rpcreq, &iov, 1, trav->frame); - - rpc_clnt_reply_deinit (trav->rpcreq, - trav->rpcreq->conn->rpc_clnt->reqpool); - - clnt = rpc_clnt_unref (clnt); - list_del_init (&trav->list); - mem_put (trav); - } + struct saved_frame *trav = NULL; + struct saved_frame *tmp = NULL; + char timestr[GF_TIMESTR_SIZE] = { + 0, + }; + + 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_tv(timestr, sizeof timestr, &trav->saved_at, gf_timefmt_FT); + + if (!trav->rpcreq || !trav->rpcreq->prog) + continue; + + gf_log_callingfn( + trav->rpcreq->conn->name, GF_LOG_ERROR, + "forced unwinding frame type(%s) op(%s(%d)) " + "called at %s (xid=0x%x)", + trav->rpcreq->prog->progname, + ((trav->rpcreq->prog->procnames) + ? trav->rpcreq->prog->procnames[trav->rpcreq->procnum] + : "--"), + trav->rpcreq->procnum, timestr, trav->rpcreq->xid); + saved_frames->count--; + + trav->rpcreq->rpc_status = -1; + trav->rpcreq->cbkfn(trav->rpcreq, NULL, 0, trav->frame); + + rpc_clnt_reply_deinit(trav->rpcreq, + trav->rpcreq->conn->rpc_clnt->reqpool); + + list_del_init(&trav->list); + mem_put(trav); + } } - void -saved_frames_destroy (struct saved_frames *frames) +saved_frames_destroy(struct saved_frames *frames) { - if (!frames) - return; + if (!frames) + return; - saved_frames_unwind (frames); + saved_frames_unwind(frames); - GF_FREE (frames); + GF_FREE(frames); } - void -rpc_clnt_reconnect (void *trans_ptr) +rpc_clnt_reconnect(void *conn_ptr) { - rpc_transport_t *trans = NULL; - rpc_clnt_connection_t *conn = NULL; - struct timeval tv = {0, 0}; - int32_t ret = 0; - struct rpc_clnt *clnt = NULL; - - trans = trans_ptr; - if (!trans || !trans->mydata) - return; - - conn = trans->mydata; - clnt = conn->rpc_clnt; - - pthread_mutex_lock (&conn->lock); - { - if (conn->reconnect) - gf_timer_call_cancel (clnt->ctx, - conn->reconnect); - conn->reconnect = 0; - - if (conn->connected == 0) { - tv.tv_sec = 3; - - gf_log (trans->name, GF_LOG_TRACE, - "attempting reconnect"); - ret = rpc_transport_connect (trans, - conn->config.remote_port); - /* Every time there is a disconnection, processes - should try to connect to 'glusterd' (ie, default - port) or whichever port given as 'option remote-port' - in volume file. */ - /* Below code makes sure the (re-)configured port lasts - for just one successful attempt */ - if (!ret) - conn->config.remote_port = 0; - - conn->reconnect = - gf_timer_call_after (clnt->ctx, tv, - rpc_clnt_reconnect, - trans); - } else { - gf_log (trans->name, GF_LOG_TRACE, - "breaking reconnect chain"); - } - } - pthread_mutex_unlock (&conn->lock); - - if ((ret == -1) && (errno != EINPROGRESS) && (clnt->notifyfn)) { - clnt->notifyfn (clnt, clnt->mydata, RPC_CLNT_DISCONNECT, NULL); - } - - return; + rpc_transport_t *trans = NULL; + rpc_clnt_connection_t *conn = NULL; + 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) + goto out_unlock; + + if (conn->reconnect) { + if (!gf_timer_call_cancel(clnt->ctx, conn->reconnect)) + canceled_unref = _gf_true; + } + conn->reconnect = 0; + + if ((conn->connected == 0) && !clnt->disabled) { + ts.tv_sec = 3; + ts.tv_nsec = 0; + + gf_log(conn->name, GF_LOG_TRACE, "attempting reconnect"); + (void)rpc_transport_connect(trans, conn->config.remote_port); + rpc_clnt_ref(clnt); + conn->reconnect = gf_timer_call_after(clnt->ctx, ts, + rpc_clnt_reconnect, conn); + if (!conn->reconnect) { + need_unref = _gf_true; + gf_log(conn->name, GF_LOG_ERROR, + "Error adding to timer event queue"); + } + } else { + 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; } - int -rpc_clnt_fill_request_info (struct rpc_clnt *clnt, rpc_request_info_t *info) +rpc_clnt_fill_request_info(struct rpc_clnt *clnt, rpc_request_info_t *info) { - struct saved_frame saved_frame = {{}, 0}; - int ret = -1; - - pthread_mutex_lock (&clnt->conn.lock); - { - ret = __saved_frame_copy (clnt->conn.saved_frames, info->xid, - &saved_frame); - } - pthread_mutex_unlock (&clnt->conn.lock); - - if (ret == -1) { - gf_log (clnt->conn.trans->name, GF_LOG_CRITICAL, - "cannot lookup the saved " - "frame corresponding to xid (%d)", info->xid); - goto out; - } - - info->prognum = saved_frame.rpcreq->prog->prognum; - info->procnum = saved_frame.rpcreq->procnum; - info->progver = saved_frame.rpcreq->prog->progver; - info->rpc_req = saved_frame.rpcreq; - info->rsp = saved_frame.rsp; - - ret = 0; + struct saved_frame saved_frame; + int ret = -1; + + pthread_mutex_lock(&clnt->conn.lock); + { + ret = __saved_frame_copy(clnt->conn.saved_frames, info->xid, + &saved_frame); + } + pthread_mutex_unlock(&clnt->conn.lock); + + if (ret == -1) { + gf_log(clnt->conn.name, GF_LOG_CRITICAL, + "cannot lookup the saved " + "frame corresponding to xid (%d)", + info->xid); + goto out; + } + + info->prognum = saved_frame.rpcreq->prog->prognum; + info->procnum = saved_frame.rpcreq->procnum; + info->progver = saved_frame.rpcreq->prog->progver; + info->rpc_req = saved_frame.rpcreq; + info->rsp = saved_frame.rsp; + + ret = 0; out: - return ret; + return ret; } int -rpc_clnt_reconnect_cleanup (rpc_clnt_connection_t *conn) +rpc_clnt_reconnect_cleanup(rpc_clnt_connection_t *conn) { - struct rpc_clnt *clnt = NULL; - - if (!conn) { - goto out; - } + struct rpc_clnt *clnt = NULL; + int ret = 0; + gf_boolean_t reconnect_unref = _gf_false; - clnt = conn->rpc_clnt; + if (!conn) { + goto out; + } - pthread_mutex_lock (&conn->lock); - { - - if (conn->reconnect) { - gf_timer_call_cancel (clnt->ctx, conn->reconnect); - conn->reconnect = NULL; - } + clnt = conn->rpc_clnt; + pthread_mutex_lock(&conn->lock); + { + if (conn->reconnect) { + ret = gf_timer_call_cancel(clnt->ctx, conn->reconnect); + if (!ret) { + reconnect_unref = _gf_true; + conn->cleanup_gen++; + } + conn->reconnect = NULL; } - pthread_mutex_unlock (&conn->lock); + } + pthread_mutex_unlock(&conn->lock); + + if (reconnect_unref) + rpc_clnt_unref(clnt); out: - return 0; + return 0; } /* @@ -527,39 +483,62 @@ out: * */ int -rpc_clnt_connection_cleanup (rpc_clnt_connection_t *conn) +rpc_clnt_connection_cleanup(rpc_clnt_connection_t *conn) { - struct saved_frames *saved_frames = NULL; - struct rpc_clnt *clnt = NULL; - - if (!conn) { - goto out; - } - - clnt = conn->rpc_clnt; - - gf_log (conn->trans->name, GF_LOG_TRACE, - "cleaning up state in transport object %p", conn->trans); - - pthread_mutex_lock (&conn->lock); - { - saved_frames = conn->saved_frames; - conn->saved_frames = saved_frames_new (); - - /* bailout logic cleanup */ - if (conn->timer) { - gf_timer_call_cancel (clnt->ctx, conn->timer); - conn->timer = NULL; - } - - conn->connected = 0; - } - pthread_mutex_unlock (&conn->lock); - - saved_frames_destroy (saved_frames); - + struct saved_frames *saved_frames = NULL; + struct rpc_clnt *clnt = NULL; + int unref = 0; + int ret = 0; + gf_boolean_t timer_unref = _gf_false; + gf_boolean_t reconnect_unref = _gf_false; + + if (!conn) { + goto out; + } + + clnt = conn->rpc_clnt; + + pthread_mutex_lock(&conn->lock); + { + saved_frames = conn->saved_frames; + conn->saved_frames = saved_frames_new(); + + /* bailout logic cleanup */ + if (conn->timer) { + ret = gf_timer_call_cancel(clnt->ctx, conn->timer); + if (!ret) + 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; + + unref = rpc_clnt_remove_ping_timer_locked(clnt); + /*reset rpc msgs stats*/ + conn->pingcnt = 0; + conn->msgcnt = 0; + conn->cleanup_gen++; + } + pthread_mutex_unlock(&conn->lock); + + saved_frames_destroy(saved_frames); + if (unref) + rpc_clnt_unref(clnt); + + if (timer_unref) + rpc_clnt_unref(clnt); + + if (reconnect_unref) + rpc_clnt_unref(clnt); out: - return 0; + return 0; } /* @@ -571,1100 +550,1430 @@ out: */ static struct saved_frame * -lookup_frame (rpc_clnt_connection_t *conn, int64_t callid) +lookup_frame(rpc_clnt_connection_t *conn, int64_t callid) { - struct saved_frame *frame = NULL; + struct saved_frame *frame = NULL; - pthread_mutex_lock (&conn->lock); - { - frame = __saved_frame_get (conn->saved_frames, callid); - } - pthread_mutex_unlock (&conn->lock); + pthread_mutex_lock(&conn->lock); + { + frame = __saved_frame_get(conn->saved_frames, callid); + } + pthread_mutex_unlock(&conn->lock); - return frame; + return frame; } - int -rpc_clnt_reply_fill (rpc_transport_pollin_t *msg, - rpc_clnt_connection_t *conn, - struct rpc_msg *replymsg, struct iovec progmsg, - struct rpc_req *req, - struct saved_frame *saved_frame) +rpc_clnt_reply_fill(rpc_transport_pollin_t *msg, rpc_clnt_connection_t *conn, + struct rpc_msg *replymsg, struct iovec progmsg, + struct rpc_req *req, struct saved_frame *saved_frame) { - int ret = -1; - - if ((!conn) || (!replymsg)|| (!req) || (!saved_frame) || (!msg)) { - goto out; - } - - req->rpc_status = 0; - if ((rpc_reply_status (replymsg) == MSG_DENIED) - || (rpc_accepted_reply_status (replymsg) != SUCCESS)) { - req->rpc_status = -1; - } - - req->rsp[0] = progmsg; - req->rsp_iobref = iobref_ref (msg->iobref); - - if (msg->vectored) { - req->rsp[1] = msg->vector[1]; - req->rspcnt = 2; - } else { - req->rspcnt = 1; - } - - /* By this time, the data bytes for the auth scheme would have already - * been copied into the required sections of the req structure, - * we just need to fill in the meta-data about it now. + int ret = -1; + + if ((!conn) || (!replymsg) || (!req) || (!saved_frame) || (!msg)) { + goto out; + } + + req->rpc_status = 0; + if ((rpc_reply_status(replymsg) == MSG_DENIED) || + (rpc_accepted_reply_status(replymsg) != SUCCESS)) { + req->rpc_status = -1; + } + + req->rsp[0] = progmsg; + req->rsp_iobref = iobref_ref(msg->iobref); + + if (msg->vectored) { + req->rsp[1] = msg->vector[1]; + req->rspcnt = 2; + } else { + req->rspcnt = 1; + } + + /* By this time, the data bytes for the auth scheme would have already + * been copied into the required sections of the req structure, + * we just need to fill in the meta-data about it now. + */ + if (req->rpc_status == 0) { + /* + * req->verf.flavour = rpc_reply_verf_flavour (replymsg); + * req->verf.datalen = rpc_reply_verf_len (replymsg); */ - if (req->rpc_status == 0) { - /* - * req->verf.flavour = rpc_reply_verf_flavour (replymsg); - * req->verf.datalen = rpc_reply_verf_len (replymsg); - */ - } + } - ret = 0; + ret = 0; out: - return ret; + return ret; } - void -rpc_clnt_reply_deinit (struct rpc_req *req, struct mem_pool *pool) +rpc_clnt_reply_deinit(struct rpc_req *req, struct mem_pool *pool) { - if (!req) { - goto out; - } + if (!req) { + goto out; + } - if (req->rsp_iobref) { - iobref_unref (req->rsp_iobref); - } + if (req->rsp_iobref) { + iobref_unref(req->rsp_iobref); + } - mem_put (req); + mem_put(req); out: - return; + return; } - /* TODO: use mem-pool for allocating requests */ int -rpc_clnt_reply_init (rpc_clnt_connection_t *conn, rpc_transport_pollin_t *msg, - struct rpc_req *req, struct saved_frame *saved_frame) +rpc_clnt_reply_init(rpc_clnt_connection_t *conn, rpc_transport_pollin_t *msg, + struct rpc_req *req, struct saved_frame *saved_frame) { - char *msgbuf = NULL; - struct rpc_msg rpcmsg; - struct iovec progmsg; /* RPC Program payload */ - size_t msglen = 0; - int ret = -1; - - msgbuf = msg->vector[0].iov_base; - msglen = msg->vector[0].iov_len; - - ret = xdr_to_rpc_reply (msgbuf, msglen, &rpcmsg, &progmsg, - req->verf.authdata); - if (ret != 0) { - gf_log (conn->trans->name, GF_LOG_WARNING, - "RPC reply decoding failed"); - goto out; - } - - ret = rpc_clnt_reply_fill (msg, conn, &rpcmsg, progmsg, req, - saved_frame); - if (ret != 0) { - goto out; - } - - gf_log (conn->trans->name, GF_LOG_TRACE, - "received rpc message (RPC XID: 0x%ux" - " Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)", - saved_frame->rpcreq->xid, - saved_frame->rpcreq->prog->progname, - saved_frame->rpcreq->prog->progver, - saved_frame->rpcreq->procnum, conn->trans->name); - - req->rpc_status = 0; + char *msgbuf = NULL; + struct rpc_msg rpcmsg; + struct iovec progmsg; /* RPC Program payload */ + size_t msglen = 0; + int ret = -1; + + msgbuf = msg->vector[0].iov_base; + msglen = msg->vector[0].iov_len; + + ret = xdr_to_rpc_reply(msgbuf, msglen, &rpcmsg, &progmsg, + req->verf.authdata); + if (ret != 0) { + gf_log(conn->name, GF_LOG_WARNING, "RPC reply decoding failed"); + goto out; + } + + ret = rpc_clnt_reply_fill(msg, conn, &rpcmsg, progmsg, req, saved_frame); + if (ret != 0) { + goto out; + } + + gf_log(conn->name, GF_LOG_TRACE, + "received rpc message (RPC XID: 0x%x" + " Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)", + saved_frame->rpcreq->xid, saved_frame->rpcreq->prog->progname, + saved_frame->rpcreq->prog->progver, saved_frame->rpcreq->procnum, + conn->name); out: - if (ret != 0) { - req->rpc_status = -1; - } + if (ret != 0) { + req->rpc_status = -1; + } - return ret; + return ret; } int -rpc_clnt_handle_cbk (struct rpc_clnt *clnt, rpc_transport_pollin_t *msg) +rpc_clnt_handle_cbk(struct rpc_clnt *clnt, rpc_transport_pollin_t *msg) { - char *msgbuf = NULL; - rpcclnt_cb_program_t *program = NULL; - struct rpc_msg rpcmsg; - struct iovec progmsg; /* RPC Program payload */ - size_t msglen = 0; - int found = 0; - int ret = -1; - int procnum = 0; - - msgbuf = msg->vector[0].iov_base; - msglen = msg->vector[0].iov_len; - - clnt = rpc_clnt_ref (clnt); - ret = xdr_to_rpc_call (msgbuf, msglen, &rpcmsg, &progmsg, NULL,NULL); - if (ret == -1) { - gf_log (clnt->conn.trans->name, GF_LOG_WARNING, - "RPC call decoding failed"); - goto out; - } - - gf_log (clnt->conn.trans->name, GF_LOG_TRACE, - "received rpc message (XID: 0x%lx, " - "Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) " - "from rpc-transport (%s)", rpc_call_xid (&rpcmsg), - rpc_call_rpcvers (&rpcmsg), rpc_call_program (&rpcmsg), - rpc_call_progver (&rpcmsg), rpc_call_progproc (&rpcmsg), - clnt->conn.trans->name); - - procnum = rpc_call_progproc (&rpcmsg); - - pthread_mutex_lock (&clnt->lock); + char *msgbuf = NULL; + rpcclnt_cb_program_t *program = NULL; + struct rpc_msg rpcmsg; + struct iovec progmsg; /* RPC Program payload */ + size_t msglen = 0; + int found = 0; + int ret = -1; + int procnum = 0; + + msgbuf = msg->vector[0].iov_base; + msglen = msg->vector[0].iov_len; + + clnt = rpc_clnt_ref(clnt); + ret = xdr_to_rpc_call(msgbuf, msglen, &rpcmsg, &progmsg, NULL, NULL); + if (ret == -1) { + gf_log(clnt->conn.name, GF_LOG_WARNING, "RPC call decoding failed"); + goto out; + } + + gf_log(clnt->conn.name, GF_LOG_TRACE, + "receivd rpc message (XID: 0x%" GF_PRI_RPC_XID + ", " + "Ver: %" GF_PRI_RPC_VERSION ", Program: %" GF_PRI_RPC_PROG_ID + ", " + "ProgVers: %" GF_PRI_RPC_PROG_VERS ", Proc: %" GF_PRI_RPC_PROC + ") " + "from rpc-transport (%s)", + rpc_call_xid(&rpcmsg), rpc_call_rpcvers(&rpcmsg), + rpc_call_program(&rpcmsg), rpc_call_progver(&rpcmsg), + rpc_call_progproc(&rpcmsg), clnt->conn.name); + + procnum = rpc_call_progproc(&rpcmsg); + + pthread_mutex_lock(&clnt->lock); + { + list_for_each_entry(program, &clnt->programs, program) { - list_for_each_entry (program, &clnt->programs, program) { - if ((program->prognum == rpc_call_program (&rpcmsg)) - && (program->progver - == rpc_call_progver (&rpcmsg))) { - found = 1; - break; - } - } + if ((program->prognum == rpc_call_program(&rpcmsg)) && + (program->progver == rpc_call_progver(&rpcmsg))) { + found = 1; + break; + } } - pthread_mutex_unlock (&clnt->lock); + } + pthread_mutex_unlock(&clnt->lock); - if (found && (procnum < program->numactors) && - (program->actors[procnum].actor)) { - program->actors[procnum].actor (&progmsg); - } + if (found && (procnum < program->numactors) && + (program->actors[procnum].actor)) { + program->actors[procnum].actor(clnt, program->mydata, &progmsg); + } out: - clnt = rpc_clnt_unref (clnt); - return ret; + rpc_clnt_unref(clnt); + return ret; } int -rpc_clnt_handle_reply (struct rpc_clnt *clnt, rpc_transport_pollin_t *pollin) +rpc_clnt_handle_reply(struct rpc_clnt *clnt, rpc_transport_pollin_t *pollin) { - rpc_clnt_connection_t *conn = NULL; - struct saved_frame *saved_frame = NULL; - int ret = -1; - struct rpc_req *req = NULL; - uint32_t xid = 0; - - clnt = rpc_clnt_ref (clnt); - conn = &clnt->conn; - - xid = ntoh32 (*((uint32_t *)pollin->vector[0].iov_base)); - saved_frame = lookup_frame (conn, xid); - if (saved_frame == NULL) { - gf_log (conn->trans->name, GF_LOG_ERROR, - "cannot lookup the saved frame for reply with xid (%u)", - xid); - goto out; - } - - req = saved_frame->rpcreq; - if (req == NULL) { - gf_log (conn->trans->name, GF_LOG_ERROR, - "no request with frame for xid (%u)", xid); - goto out; - } - - ret = rpc_clnt_reply_init (conn, pollin, req, saved_frame); - if (ret != 0) { - req->rpc_status = -1; - gf_log (conn->trans->name, GF_LOG_WARNING, - "initialising rpc reply failed"); - } - - req->cbkfn (req, req->rsp, req->rspcnt, saved_frame->frame); - - if (req) { - rpc_clnt_reply_deinit (req, conn->rpc_clnt->reqpool); - } + rpc_clnt_connection_t *conn = NULL; + struct saved_frame *saved_frame = NULL; + int ret = -1; + struct rpc_req *req = NULL; + uint32_t xid = 0; + + clnt = rpc_clnt_ref(clnt); + conn = &clnt->conn; + + xid = ntoh32(*((uint32_t *)pollin->vector[0].iov_base)); + saved_frame = lookup_frame(conn, xid); + if (saved_frame == NULL) { + gf_log(conn->name, GF_LOG_ERROR, + "cannot lookup the saved frame for reply with xid (%u)", xid); + goto out; + } + + req = saved_frame->rpcreq; + if (req == NULL) { + gf_log(conn->name, GF_LOG_ERROR, "no request with frame for xid (%u)", + xid); + goto out; + } + + ret = rpc_clnt_reply_init(conn, pollin, req, saved_frame); + if (ret != 0) { + req->rpc_status = -1; + gf_log(conn->name, GF_LOG_WARNING, "initialising rpc reply failed"); + } + + req->cbkfn(req, req->rsp, req->rspcnt, saved_frame->frame); + + if (req) { + rpc_clnt_reply_deinit(req, conn->rpc_clnt->reqpool); + } out: - if (saved_frame) { - mem_put (saved_frame); - } + if (saved_frame) { + mem_put(saved_frame); + } - clnt = rpc_clnt_unref (clnt); - return ret; + rpc_clnt_unref(clnt); + return ret; } - -inline void -rpc_clnt_set_connected (rpc_clnt_connection_t *conn) +gf_boolean_t +is_rpc_clnt_disconnected(rpc_clnt_connection_t *conn) { - if (!conn) { - goto out; - } + gf_boolean_t disconnected = _gf_true; - pthread_mutex_lock (&conn->lock); - { - conn->connected = 1; - } - pthread_mutex_unlock (&conn->lock); + if (!conn) + return disconnected; -out: - return; + pthread_mutex_lock(&conn->lock); + { + disconnected = conn->disconnected; + } + pthread_mutex_unlock(&conn->lock); + + return disconnected; } +static void +rpc_clnt_destroy(struct rpc_clnt *rpc); -void -rpc_clnt_unset_connected (rpc_clnt_connection_t *conn) -{ - if (!conn) { - goto out; - } +#define RPC_THIS_SAVE(xl) \ + do { \ + old_THIS = THIS; \ + if (!old_THIS) \ + gf_log_callingfn("rpc", GF_LOG_CRITICAL, \ + "THIS is not initialised."); \ + THIS = xl; \ + } while (0) - pthread_mutex_lock (&conn->lock); - { - conn->connected = 0; - } - pthread_mutex_unlock (&conn->lock); +#define RPC_THIS_RESTORE (THIS = old_THIS) -out: - return; +static int +rpc_clnt_handle_disconnect(struct rpc_clnt *clnt, rpc_clnt_connection_t *conn) +{ + struct timespec ts = { + 0, + }; + gf_boolean_t unref_clnt = _gf_false; + uint64_t pre_notify_gen = 0, post_notify_gen = 0; + + pthread_mutex_lock(&conn->lock); + { + pre_notify_gen = conn->cleanup_gen; + } + pthread_mutex_unlock(&conn->lock); + + if (clnt->notifyfn) + clnt->notifyfn(clnt, clnt->mydata, RPC_CLNT_DISCONNECT, NULL); + + pthread_mutex_lock(&conn->lock); + { + post_notify_gen = conn->cleanup_gen; + } + pthread_mutex_unlock(&conn->lock); + + if (pre_notify_gen == post_notify_gen) { + /* program didn't invoke cleanup, so rpc has to do it */ + rpc_clnt_connection_cleanup(conn); + } + + pthread_mutex_lock(&conn->lock); + { + if (!conn->rpc_clnt->disabled && (conn->reconnect == NULL)) { + ts.tv_sec = 3; + ts.tv_nsec = 0; + + rpc_clnt_ref(clnt); + conn->reconnect = gf_timer_call_after(clnt->ctx, ts, + rpc_clnt_reconnect, conn); + if (conn->reconnect == NULL) { + gf_log(conn->name, GF_LOG_WARNING, + "Cannot create rpc_clnt_reconnect timer"); + unref_clnt = _gf_true; + } + } + } + pthread_mutex_unlock(&conn->lock); + + if (unref_clnt) + rpc_clnt_unref(clnt); + + return 0; } - int -rpc_clnt_notify (rpc_transport_t *trans, void *mydata, - rpc_transport_event_t event, void *data, ...) +rpc_clnt_notify(rpc_transport_t *trans, void *mydata, + rpc_transport_event_t event, void *data, ...) { - rpc_clnt_connection_t *conn = NULL; - struct rpc_clnt *clnt = NULL; - int ret = -1; - rpc_request_info_t *req_info = NULL; - rpc_transport_pollin_t *pollin = NULL; - struct timeval tv = {0, }; - - conn = mydata; - if (conn == NULL) { - goto out; - } - clnt = conn->rpc_clnt; - if (!clnt) - goto out; - - switch (event) { - case RPC_TRANSPORT_DISCONNECT: - { - rpc_clnt_connection_cleanup (conn); - - pthread_mutex_lock (&conn->lock); - { - if (conn->reconnect == NULL) { - tv.tv_sec = 10; - - conn->reconnect = - gf_timer_call_after (clnt->ctx, tv, - rpc_clnt_reconnect, - conn->trans); - } - } - pthread_mutex_unlock (&conn->lock); - - if (clnt->notifyfn) - ret = clnt->notifyfn (clnt, clnt->mydata, - RPC_CLNT_DISCONNECT, NULL); - break; + rpc_clnt_connection_t *conn = NULL; + struct rpc_clnt *clnt = NULL; + int ret = -1; + rpc_request_info_t *req_info = NULL; + rpc_transport_pollin_t *pollin = NULL; + void *clnt_mydata = NULL; + DECLARE_OLD_THIS; + + conn = mydata; + if (conn == NULL) { + goto out; + } + clnt = conn->rpc_clnt; + if (!clnt) + goto out; + + RPC_THIS_SAVE(clnt->owner); + + switch (event) { + case RPC_TRANSPORT_DISCONNECT: { + rpc_clnt_handle_disconnect(clnt, conn); + /* 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. + */ + break; } case RPC_TRANSPORT_CLEANUP: - /* this event should not be received on a client for, a - * transport is only disconnected, but never destroyed. - */ - ret = 0; - break; - - case RPC_TRANSPORT_MAP_XID_REQUEST: - { - req_info = data; - ret = rpc_clnt_fill_request_info (clnt, req_info); - break; - } - - case RPC_TRANSPORT_MSG_RECEIVED: - { - pthread_mutex_lock (&conn->lock); - { - gettimeofday (&conn->last_received, NULL); + if (clnt->notifyfn) { + clnt_mydata = clnt->mydata; + clnt->mydata = NULL; + ret = clnt->notifyfn(clnt, clnt_mydata, RPC_CLNT_DESTROY, NULL); + if (ret < 0) { + gf_log(trans->name, GF_LOG_WARNING, + "client notify handler returned error " + "while handling RPC_CLNT_DESTROY"); } - pthread_mutex_unlock (&conn->lock); - - pollin = data; - if (pollin->is_reply) - ret = rpc_clnt_handle_reply (clnt, pollin); - else - ret = rpc_clnt_handle_cbk (clnt, pollin); - /* ret = clnt->notifyfn (clnt, clnt->mydata, RPC_CLNT_MSG, - * data); - */ - break; - } + } + rpc_clnt_destroy(clnt); + ret = 0; + break; + + case RPC_TRANSPORT_MAP_XID_REQUEST: { + req_info = data; + ret = rpc_clnt_fill_request_info(clnt, req_info); + break; + } + + case RPC_TRANSPORT_MSG_RECEIVED: { + timespec_now_realtime(&conn->last_received); + + pollin = data; + if (pollin->is_reply) + ret = rpc_clnt_handle_reply(clnt, pollin); + else + ret = rpc_clnt_handle_cbk(clnt, pollin); + /* ret = clnt->notifyfn (clnt, clnt->mydata, RPC_CLNT_MSG, + * data); + */ + break; + } + + case RPC_TRANSPORT_MSG_SENT: { + timespec_now_realtime(&conn->last_sent); + ret = 0; + break; + } + + case RPC_TRANSPORT_CONNECT: { + pthread_mutex_lock(&conn->lock); + { + /* Every time there is a disconnection, processes + * should try to connect to 'glusterd' (ie, default + * port) or whichever port given as 'option remote-port' + * in volume file. */ + /* Below code makes sure the (re-)configured port lasts + * for just one successful attempt */ + conn->config.remote_port = 0; + conn->connected = 1; + conn->disconnected = 0; + pthread_cond_broadcast(&conn->cond); + } + pthread_mutex_unlock(&conn->lock); - case RPC_TRANSPORT_MSG_SENT: - { - pthread_mutex_lock (&conn->lock); - { - gettimeofday (&conn->last_sent, NULL); - } - pthread_mutex_unlock (&conn->lock); + /* auth value should be set to lower version available + * and will be set to appropriate version supported by + * server after the handshake. + */ + if (clnt->auth_value) + clnt->auth_value = AUTH_GLUSTERFS_v2; + if (clnt->notifyfn) + ret = clnt->notifyfn(clnt, clnt->mydata, RPC_CLNT_CONNECT, + NULL); - ret = 0; - break; - } - - case RPC_TRANSPORT_CONNECT: - { - if (clnt->notifyfn) - ret = clnt->notifyfn (clnt, clnt->mydata, - RPC_CLNT_CONNECT, NULL); - break; + break; } case RPC_TRANSPORT_ACCEPT: - /* only meaningful on a server, no need of handling this event - * in a client. - */ - ret = 0; - break; - } + /* only meaningful on a server, no need of handling this event + * in a client. + */ + 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: - return ret; + RPC_THIS_RESTORE; + return ret; } - -void -rpc_clnt_connection_deinit (rpc_clnt_connection_t *conn) -{ - return; -} - - -inline int -rpc_clnt_connection_init (struct rpc_clnt *clnt, glusterfs_ctx_t *ctx, - dict_t *options, char *name) +static int +rpc_clnt_connection_init(struct rpc_clnt *clnt, glusterfs_ctx_t *ctx, + dict_t *options, char *name) { - int ret = -1; - rpc_clnt_connection_t *conn = NULL; - - conn = &clnt->conn; - pthread_mutex_init (&clnt->conn.lock, NULL); - - ret = dict_get_int32 (options, "frame-timeout", - &conn->frame_timeout); - if (ret >= 0) { - gf_log (name, GF_LOG_INFO, - "setting frame-timeout to %d", conn->frame_timeout); - } else { - gf_log (name, GF_LOG_DEBUG, - "defaulting frame-timeout to 30mins"); - conn->frame_timeout = 1800; - } + int ret = -1; + rpc_clnt_connection_t *conn = NULL; + rpc_transport_t *trans = NULL; - conn->trans = rpc_transport_load (ctx, options, name); - if (!conn->trans) { - gf_log (name, GF_LOG_WARNING, "loading of new rpc-transport" - " failed"); - ret = -1; - goto out; - } - - rpc_transport_ref (conn->trans); - - conn->rpc_clnt = clnt; - - ret = rpc_transport_register_notify (conn->trans, rpc_clnt_notify, - conn); - if (ret == -1) { - gf_log (name, GF_LOG_WARNING, "registering notify failed"); - rpc_clnt_connection_cleanup (conn); - conn = NULL; - goto out; - } + conn = &clnt->conn; + pthread_mutex_init(&clnt->conn.lock, NULL); + pthread_cond_init(&clnt->conn.cond, NULL); - conn->saved_frames = saved_frames_new (); - if (!conn->saved_frames) { - gf_log (name, GF_LOG_WARNING, "creation of saved_frames " - "failed"); - rpc_clnt_connection_cleanup (conn); - goto out; - } + conn->name = gf_strdup(name); + if (!conn->name) { + ret = -1; + goto out; + } + + ret = dict_get_int32(options, "frame-timeout", &conn->frame_timeout); + if (ret >= 0) { + gf_log(name, GF_LOG_INFO, "setting frame-timeout to %d", + conn->frame_timeout); + } else { + gf_log(name, GF_LOG_DEBUG, "defaulting frame-timeout to 30mins"); + conn->frame_timeout = 1800; + } + conn->rpc_clnt = clnt; + + ret = dict_get_int32(options, "ping-timeout", &conn->ping_timeout); + if (ret >= 0) { + gf_log(name, GF_LOG_DEBUG, "setting ping-timeout to %d", + conn->ping_timeout); + } else { + /*TODO: Once the epoll thread model is fixed, + change the default ping-timeout to 30sec */ + gf_log(name, GF_LOG_DEBUG, "disable ping-timeout"); + conn->ping_timeout = 0; + } + + trans = rpc_transport_load(ctx, options, name); + if (!trans) { + gf_log(name, GF_LOG_WARNING, + "loading of new rpc-transport" + " failed"); + ret = -1; + goto out; + } + rpc_transport_ref(trans); + + pthread_mutex_lock(&conn->lock); + { + conn->trans = trans; + trans = NULL; + } + pthread_mutex_unlock(&conn->lock); + + ret = rpc_transport_register_notify(conn->trans, rpc_clnt_notify, conn); + if (ret == -1) { + gf_log(name, GF_LOG_WARNING, "registering notify failed"); + goto out; + } + + conn->saved_frames = saved_frames_new(); + if (!conn->saved_frames) { + gf_log(name, GF_LOG_WARNING, + "creation of saved_frames " + "failed"); + ret = -1; + goto out; + } - ret = 0; + ret = 0; out: - return ret; + if (ret) { + pthread_mutex_lock(&conn->lock); + { + trans = conn->trans; + conn->trans = NULL; + } + pthread_mutex_unlock(&conn->lock); + if (trans) + rpc_transport_unref(trans); + // conn cleanup needs to be done since we might have failed to + // register notification. + rpc_clnt_connection_cleanup(conn); + } + return ret; } struct rpc_clnt * -rpc_clnt_new (dict_t *options, - glusterfs_ctx_t *ctx, char *name) +rpc_clnt_new(dict_t *options, xlator_t *owner, char *name, + uint32_t reqpool_size) { - int ret = -1; - struct rpc_clnt *rpc = NULL; + int ret = -1; + struct rpc_clnt *rpc = NULL; + glusterfs_ctx_t *ctx = owner->ctx; + + rpc = GF_CALLOC(1, sizeof(*rpc), gf_common_mt_rpcclnt_t); + if (!rpc) { + goto out; + } + + pthread_mutex_init(&rpc->lock, NULL); + rpc->ctx = ctx; + rpc->owner = owner; + GF_ATOMIC_INIT(rpc->xid, 1); + + if (!reqpool_size) + reqpool_size = RPC_CLNT_DEFAULT_REQUEST_COUNT; + + rpc->reqpool = mem_pool_new(struct rpc_req, reqpool_size); + if (rpc->reqpool == NULL) { + pthread_mutex_destroy(&rpc->lock); + GF_FREE(rpc); + rpc = NULL; + goto out; + } + + rpc->saved_frames_pool = mem_pool_new(struct saved_frame, reqpool_size); + if (rpc->saved_frames_pool == NULL) { + pthread_mutex_destroy(&rpc->lock); + mem_pool_destroy(rpc->reqpool); + GF_FREE(rpc); + rpc = NULL; + goto out; + } + + ret = rpc_clnt_connection_init(rpc, ctx, options, name); + if (ret == -1) { + pthread_mutex_destroy(&rpc->lock); + mem_pool_destroy(rpc->reqpool); + mem_pool_destroy(rpc->saved_frames_pool); + GF_FREE(rpc); + rpc = NULL; + goto out; + } + + /* This is handled to make sure we have modularity in getting the + auth data changed */ + gf_boolean_t auth_null = dict_get_str_boolean(options, "auth-null", 0); + + rpc->auth_value = (auth_null) ? 0 : AUTH_GLUSTERFS_v2; + + rpc = rpc_clnt_ref(rpc); + INIT_LIST_HEAD(&rpc->programs); - rpc = GF_CALLOC (1, sizeof (*rpc), gf_common_mt_rpcclnt_t); - if (!rpc) { - goto out; - } - - pthread_mutex_init (&rpc->lock, NULL); - rpc->ctx = ctx; +out: + return rpc; +} - rpc->reqpool = mem_pool_new (struct rpc_req, - RPC_CLNT_DEFAULT_REQUEST_COUNT); - if (rpc->reqpool == NULL) { - pthread_mutex_destroy (&rpc->lock); - GF_FREE (rpc); - rpc = NULL; - goto out; - } +int +rpc_clnt_start(struct rpc_clnt *rpc) +{ + struct rpc_clnt_connection *conn = NULL; - rpc->saved_frames_pool = mem_pool_new (struct saved_frame, - RPC_CLNT_DEFAULT_REQUEST_COUNT); - if (rpc->saved_frames_pool == NULL) { - pthread_mutex_destroy (&rpc->lock); - mem_pool_destroy (rpc->reqpool); - GF_FREE (rpc); - rpc = NULL; - goto out; - } + if (!rpc) + return -1; - ret = rpc_clnt_connection_init (rpc, ctx, options, name); - if (ret == -1) { - pthread_mutex_destroy (&rpc->lock); - mem_pool_destroy (rpc->reqpool); - mem_pool_destroy (rpc->saved_frames_pool); - GF_FREE (rpc); - rpc = NULL; - if (options) - dict_unref (options); - goto out; - } + conn = &rpc->conn; - rpc = rpc_clnt_ref (rpc); - INIT_LIST_HEAD (&rpc->programs); + pthread_mutex_lock(&conn->lock); + { + rpc->disabled = 0; + } + pthread_mutex_unlock(&conn->lock); + /* Corresponding unref will be either on successful timer cancel or last + * rpc_clnt_reconnect fire event. + */ + rpc_clnt_ref(rpc); + rpc_clnt_reconnect(conn); -out: - return rpc; + return 0; } - int -rpc_clnt_start (struct rpc_clnt *rpc) +rpc_clnt_cleanup_and_start(struct rpc_clnt *rpc) { - struct rpc_clnt_connection *conn = NULL; + struct rpc_clnt_connection *conn = NULL; - if (!rpc) - return -1; + if (!rpc) + return -1; - conn = &rpc->conn; + conn = &rpc->conn; - rpc_clnt_reconnect (conn->trans); + rpc_clnt_connection_cleanup(conn); - return 0; -} + pthread_mutex_lock(&conn->lock); + { + rpc->disabled = 0; + } + pthread_mutex_unlock(&conn->lock); + /* Corresponding unref will be either on successful timer cancel or last + * rpc_clnt_reconnect fire event. + */ + rpc_clnt_ref(rpc); + rpc_clnt_reconnect(conn); + return 0; +} int -rpc_clnt_register_notify (struct rpc_clnt *rpc, rpc_clnt_notify_t fn, - void *mydata) +rpc_clnt_register_notify(struct rpc_clnt *rpc, rpc_clnt_notify_t fn, + void *mydata) { - rpc->mydata = mydata; - rpc->notifyfn = fn; + rpc->mydata = mydata; + rpc->notifyfn = fn; - return 0; + return 0; } -ssize_t -xdr_serialize_glusterfs_auth (char *dest, struct auth_glusterfs_parms *au) +/* used for GF_LOG_OCCASIONALLY() */ +static int gf_auth_max_groups_log = 0; + +static inline int +setup_glusterfs_auth_param_v3(call_frame_t *frame, auth_glusterfs_params_v3 *au, + int lk_owner_len, char *owner_data) { - ssize_t ret = -1; - XDR xdr; + int ret = -1; + unsigned int max_groups = 0; + int max_lkowner_len = 0; + + au->pid = frame->root->pid; + au->uid = frame->root->uid; + au->gid = frame->root->gid; + + au->flags = frame->root->flags; + au->ctime_sec = frame->root->ctime.tv_sec; + au->ctime_nsec = frame->root->ctime.tv_nsec; + + au->lk_owner.lk_owner_val = owner_data; + au->lk_owner.lk_owner_len = lk_owner_len; + au->groups.groups_val = frame->root->groups; + au->groups.groups_len = frame->root->ngrps; + + /* The number of groups and the size of lk_owner depend on oneother. + * We can truncate the groups, but should not touch the lk_owner. */ + max_groups = GF_AUTH_GLUSTERFS_MAX_GROUPS(lk_owner_len, AUTH_GLUSTERFS_v3); + if (au->groups.groups_len > max_groups) { + GF_LOG_OCCASIONALLY(gf_auth_max_groups_log, "rpc-auth", GF_LOG_WARNING, + "truncating grouplist " + "from %d to %d", + au->groups.groups_len, max_groups); + + au->groups.groups_len = max_groups; + } + + max_lkowner_len = GF_AUTH_GLUSTERFS_MAX_LKOWNER(au->groups.groups_len, + AUTH_GLUSTERFS_v3); + if (lk_owner_len > max_lkowner_len) { + gf_log("rpc-clnt", GF_LOG_ERROR, + "lkowner field is too " + "big (%d), it does not fit in the rpc-header", + au->lk_owner.lk_owner_len); + errno = E2BIG; + goto out; + } + + ret = 0; +out: + return ret; +} - if ((!dest) || (!au)) - return -1; +static inline int +setup_glusterfs_auth_param_v2(call_frame_t *frame, auth_glusterfs_parms_v2 *au, + int lk_owner_len, char *owner_data) +{ + unsigned int max_groups = 0; + int max_lkowner_len = 0; + int ret = -1; + + au->pid = frame->root->pid; + au->uid = frame->root->uid; + au->gid = frame->root->gid; + + au->lk_owner.lk_owner_val = owner_data; + au->lk_owner.lk_owner_len = lk_owner_len; + au->groups.groups_val = frame->root->groups; + au->groups.groups_len = frame->root->ngrps; + + /* The number of groups and the size of lk_owner depend on oneother. + * We can truncate the groups, but should not touch the lk_owner. */ + max_groups = GF_AUTH_GLUSTERFS_MAX_GROUPS(lk_owner_len, AUTH_GLUSTERFS_v2); + if (au->groups.groups_len > max_groups) { + GF_LOG_OCCASIONALLY(gf_auth_max_groups_log, "rpc-auth", GF_LOG_WARNING, + "truncating grouplist " + "from %d to %d", + au->groups.groups_len, max_groups); + + au->groups.groups_len = max_groups; + } + + max_lkowner_len = GF_AUTH_GLUSTERFS_MAX_LKOWNER(au->groups.groups_len, + AUTH_GLUSTERFS_v2); + if (lk_owner_len > max_lkowner_len) { + gf_log("rpc-auth", GF_LOG_ERROR, + "lkowner field is too " + "big (%d), it does not fit in the rpc-header", + au->lk_owner.lk_owner_len); + errno = E2BIG; + goto out; + } + + ret = 0; +out: + return ret; +} - xdrmem_create (&xdr, dest, 1024, - XDR_ENCODE); +static ssize_t +xdr_serialize_glusterfs_auth(struct rpc_clnt *clnt, call_frame_t *frame, + char *dest) +{ + ssize_t ret = -1; + XDR xdr; + char owner[4] = { + 0, + }; + int32_t pid = 0; + char *lk_owner_data = NULL; + int lk_owner_len = 0; + + if ((!dest)) + return -1; + + xdrmem_create(&xdr, dest, GF_MAX_AUTH_BYTES, XDR_ENCODE); + + if (frame->root->lk_owner.len) { + lk_owner_data = frame->root->lk_owner.data; + lk_owner_len = frame->root->lk_owner.len; + } else { + pid = frame->root->pid; + owner[0] = (char)(pid & 0xff); + owner[1] = (char)((pid >> 8) & 0xff); + owner[2] = (char)((pid >> 16) & 0xff); + owner[3] = (char)((pid >> 24) & 0xff); + + lk_owner_data = owner; + lk_owner_len = 4; + } + + if (clnt->auth_value == AUTH_GLUSTERFS_v2) { + auth_glusterfs_parms_v2 au_v2 = { + 0, + }; + + ret = setup_glusterfs_auth_param_v2(frame, &au_v2, lk_owner_len, + lk_owner_data); + if (ret) + goto out; + if (!xdr_auth_glusterfs_parms_v2(&xdr, &au_v2)) { + gf_log(THIS->name, GF_LOG_WARNING, + "failed to encode auth glusterfs elements"); + ret = -1; + goto out; + } + } else if (clnt->auth_value == AUTH_GLUSTERFS_v3) { + auth_glusterfs_params_v3 au_v3 = { + 0, + }; + + ret = setup_glusterfs_auth_param_v3(frame, &au_v3, lk_owner_len, + lk_owner_data); + if (ret) + goto out; - if (!xdr_auth_glusterfs_parms (&xdr, au)) { - gf_log (THIS->name, GF_LOG_WARNING, - "failed to encode auth glusterfs elements"); - ret = -1; - goto ret; + if (!xdr_auth_glusterfs_params_v3(&xdr, &au_v3)) { + gf_log(THIS->name, GF_LOG_WARNING, + "failed to encode auth glusterfs elements"); + ret = -1; + goto out; } + } else { + gf_log(THIS->name, GF_LOG_WARNING, + "failed to encode auth glusterfs elements"); + ret = -1; + goto out; + } - ret = (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)); + ret = (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)); -ret: - return ret; +out: + return ret; } - int -rpc_clnt_fill_request (int prognum, int progver, int procnum, int payload, - uint64_t xid, struct auth_glusterfs_parms *au, - struct rpc_msg *request, char *auth_data) +rpc_clnt_fill_request(struct rpc_clnt *clnt, int prognum, int progver, + int procnum, uint64_t xid, call_frame_t *fr, + struct rpc_msg *request, char *auth_data) { - int ret = -1; + int ret = -1; - if (!request) { - goto out; - } + if (!request) { + goto out; + } - memset (request, 0, sizeof (*request)); + memset(request, 0, sizeof(*request)); - request->rm_xid = xid; - request->rm_direction = CALL; + request->rm_xid = xid; + request->rm_direction = CALL; - request->rm_call.cb_rpcvers = 2; - request->rm_call.cb_prog = prognum; - request->rm_call.cb_vers = progver; - request->rm_call.cb_proc = procnum; + request->rm_call.cb_rpcvers = 2; + request->rm_call.cb_prog = prognum; + request->rm_call.cb_vers = progver; + request->rm_call.cb_proc = procnum; - /* TODO: Using AUTH_GLUSTERFS for time-being. Make it modular in - * future so it is easy to plug-in new authentication schemes. - */ - ret = xdr_serialize_glusterfs_auth (auth_data, au); + if (!clnt->auth_value) { + request->rm_call.cb_cred.oa_flavor = AUTH_NULL; + request->rm_call.cb_cred.oa_base = NULL; + request->rm_call.cb_cred.oa_length = 0; + } else { + ret = xdr_serialize_glusterfs_auth(clnt, fr, auth_data); if (ret == -1) { - gf_log ("rpc-clnt", GF_LOG_DEBUG, "cannot encode credentials"); - goto out; + gf_log("rpc-clnt", GF_LOG_WARNING, + "cannot encode auth credentials"); + goto out; } - request->rm_call.cb_cred.oa_flavor = AUTH_GLUSTERFS; - request->rm_call.cb_cred.oa_base = auth_data; + request->rm_call.cb_cred.oa_flavor = clnt->auth_value; + request->rm_call.cb_cred.oa_base = auth_data; request->rm_call.cb_cred.oa_length = ret; + } + request->rm_call.cb_verf.oa_flavor = AUTH_NONE; + request->rm_call.cb_verf.oa_base = NULL; + request->rm_call.cb_verf.oa_length = 0; - request->rm_call.cb_verf.oa_flavor = AUTH_NONE; - request->rm_call.cb_verf.oa_base = NULL; - request->rm_call.cb_verf.oa_length = 0; - - ret = 0; + ret = 0; out: - return ret; + return ret; } - struct iovec -rpc_clnt_record_build_header (char *recordstart, size_t rlen, - struct rpc_msg *request, size_t payload) +rpc_clnt_record_build_header(char *recordstart, size_t rlen, + struct rpc_msg *request, size_t payload) { - struct iovec requesthdr = {0, }; - struct iovec txrecord = {0, 0}; - int ret = -1; - size_t fraglen = 0; - - ret = rpc_request_to_xdr (request, recordstart, rlen, &requesthdr); - if (ret == -1) { - gf_log ("rpc-clnt", GF_LOG_DEBUG, - "Failed to create RPC request"); - goto out; - } - - fraglen = payload + requesthdr.iov_len; - gf_log ("rpc-clnt", GF_LOG_TRACE, "Request fraglen %zu, payload: %zu, " - "rpc hdr: %zu", fraglen, payload, requesthdr.iov_len); - - - txrecord.iov_base = recordstart; - - /* Remember, this is only the vec for the RPC header and does not - * include the payload above. We needed the payload only to calculate - * the size of the full fragment. This size is sent in the fragment - * header. - */ - txrecord.iov_len = requesthdr.iov_len; + struct iovec requesthdr = { + 0, + }; + struct iovec txrecord = {0, 0}; + int ret = -1; + size_t fraglen = 0; + + ret = rpc_request_to_xdr(request, recordstart, rlen, &requesthdr); + if (ret == -1) { + gf_log("rpc-clnt", GF_LOG_DEBUG, "Failed to create RPC request"); + goto out; + } + + fraglen = payload + requesthdr.iov_len; + gf_log("rpc-clnt", GF_LOG_TRACE, + "Request fraglen %zu, payload: %zu, " + "rpc hdr: %zu", + fraglen, payload, requesthdr.iov_len); + + txrecord.iov_base = recordstart; + + /* Remember, this is only the vec for the RPC header and does not + * include the payload above. We needed the payload only to calculate + * the size of the full fragment. This size is sent in the fragment + * header. + */ + txrecord.iov_len = requesthdr.iov_len; out: - return txrecord; + return txrecord; } - struct iobuf * -rpc_clnt_record_build_record (struct rpc_clnt *clnt, int prognum, int progver, - int procnum, size_t payload, uint64_t xid, - struct auth_glusterfs_parms *au, - struct iovec *recbuf) +rpc_clnt_record_build_record(struct rpc_clnt *clnt, call_frame_t *fr, + int prognum, int progver, int procnum, + size_t hdrsize, uint64_t xid, struct iovec *recbuf) { - struct rpc_msg request = {0, }; - struct iobuf *request_iob = NULL; - char *record = NULL; - struct iovec recordhdr = {0, }; - size_t pagesize = 0; - int ret = -1; - char auth_data[RPC_CLNT_MAX_AUTH_BYTES] = {0, }; - - if ((!clnt) || (!recbuf) || (!au)) { - goto out; - } - - /* First, try to get a pointer into the buffer which the RPC - * layer can use. - */ - request_iob = iobuf_get (clnt->ctx->iobuf_pool); - if (!request_iob) { - goto out; - } - - pagesize = iobuf_pagesize (request_iob); - - record = iobuf_ptr (request_iob); /* Now we have it. */ - - /* Fill the rpc structure and XDR it into the buffer got above. */ - ret = rpc_clnt_fill_request (prognum, progver, procnum, payload, xid, - au, &request, auth_data); - if (ret == -1) { - gf_log (clnt->conn.trans->name, GF_LOG_WARNING, - "cannot build a rpc-request xid (%"PRIu64")", xid); - goto out; - } - - recordhdr = rpc_clnt_record_build_header (record, pagesize, &request, - payload); - - //GF_FREE (request.rm_call.cb_cred.oa_base); - - if (!recordhdr.iov_base) { - gf_log (clnt->conn.trans->name, GF_LOG_ERROR, - "Failed to build record header"); - iobuf_unref (request_iob); - request_iob = NULL; - recbuf->iov_base = NULL; - goto out; - } - - recbuf->iov_base = recordhdr.iov_base; - recbuf->iov_len = recordhdr.iov_len; + struct rpc_msg request = { + 0, + }; + struct iobuf *request_iob = NULL; + char *record = NULL; + struct iovec recordhdr = { + 0, + }; + size_t pagesize = 0; + int ret = -1; + size_t xdr_size = 0; + char auth_data[GF_MAX_AUTH_BYTES] = { + 0, + }; + + if ((!clnt) || (!recbuf)) { + goto out; + } + + /* Fill the rpc structure and XDR it into the buffer got above. */ + ret = rpc_clnt_fill_request(clnt, prognum, progver, procnum, xid, fr, + &request, auth_data); + + if (ret == -1) { + gf_log(clnt->conn.name, GF_LOG_WARNING, + "cannot build a rpc-request xid (%" PRIu64 ")", xid); + goto out; + } + + xdr_size = xdr_sizeof((xdrproc_t)xdr_callmsg, &request); + + /* First, try to get a pointer into the buffer which the RPC + * layer can use. + */ + request_iob = iobuf_get2(clnt->ctx->iobuf_pool, (xdr_size + hdrsize)); + if (!request_iob) { + goto out; + } + + pagesize = iobuf_pagesize(request_iob); + + record = iobuf_ptr(request_iob); /* Now we have it. */ + + recordhdr = rpc_clnt_record_build_header(record, pagesize, &request, + hdrsize); + + if (!recordhdr.iov_base) { + gf_log(clnt->conn.name, GF_LOG_ERROR, "Failed to build record header"); + iobuf_unref(request_iob); + request_iob = NULL; + recbuf->iov_base = NULL; + goto out; + } + + recbuf->iov_base = recordhdr.iov_base; + recbuf->iov_len = recordhdr.iov_len; out: - return request_iob; + return request_iob; } - -struct iobuf * -rpc_clnt_record (struct rpc_clnt *clnt, call_frame_t *call_frame, - rpc_clnt_prog_t *prog,int procnum, size_t payload_len, - struct iovec *rpchdr, uint64_t callid) +static inline struct iobuf * +rpc_clnt_record(struct rpc_clnt *clnt, call_frame_t *call_frame, + rpc_clnt_prog_t *prog, int procnum, size_t hdrlen, + struct iovec *rpchdr, uint64_t callid) { - struct auth_glusterfs_parms au = {0, }; - struct iobuf *request_iob = NULL; - - if (!prog || !rpchdr || !call_frame) { - goto out; - } - - au.pid = call_frame->root->pid; - au.uid = call_frame->root->uid; - au.gid = call_frame->root->gid; - au.ngrps = call_frame->root->ngrps; - au.lk_owner = call_frame->root->lk_owner; - if (!au.lk_owner) - au.lk_owner = au.pid; + if (!prog || !rpchdr || !call_frame) { + return NULL; + } - gf_log (clnt->conn.trans->name, GF_LOG_TRACE, "Auth Info: pid: %u, uid: %d" - ", gid: %d, owner: %"PRId64, - au.pid, au.uid, au.gid, au.lk_owner); - - memcpy (au.groups, call_frame->root->groups, sizeof (au.groups)); - - //rpc_transport_get_myname (clnt->conn.trans, myname, UNIX_PATH_MAX); - //au.aup_machname = myname; - - /* Assuming the client program would like to speak to the same version of - * program on server. - */ - request_iob = rpc_clnt_record_build_record (clnt, prog->prognum, - prog->progver, - procnum, payload_len, - callid, &au, - rpchdr); - if (!request_iob) { - gf_log (clnt->conn.trans->name, GF_LOG_WARNING, - "cannot build rpc-record"); - goto out; - } - -out: - return request_iob; + return rpc_clnt_record_build_record(clnt, call_frame, prog->prognum, + prog->progver, procnum, hdrlen, callid, + rpchdr); } int -rpcclnt_cbk_program_register (struct rpc_clnt *clnt, - rpcclnt_cb_program_t *program) +rpcclnt_cbk_program_register(struct rpc_clnt *clnt, + rpcclnt_cb_program_t *program, void *mydata) { - int ret = -1; - char already_registered = 0; - rpcclnt_cb_program_t *tmp = NULL; + int ret = -1; + char already_registered = 0; + rpcclnt_cb_program_t *tmp = NULL; - if (!clnt) - goto out; + if (!clnt) + goto out; - if (program->actors == NULL) - goto out; + if (program->actors == NULL) + goto out; - pthread_mutex_lock (&clnt->lock); + pthread_mutex_lock(&clnt->lock); + { + list_for_each_entry(tmp, &clnt->programs, program) { - list_for_each_entry (tmp, &clnt->programs, program) { - if ((program->prognum == tmp->prognum) - && (program->progver == tmp->progver)) { - already_registered = 1; - break; - } - } + if ((program->prognum == tmp->prognum) && + (program->progver == tmp->progver)) { + already_registered = 1; + break; + } } - pthread_mutex_unlock (&clnt->lock); + } + pthread_mutex_unlock(&clnt->lock); - if (already_registered) { - gf_log_callingfn (clnt->conn.trans->name, GF_LOG_DEBUG, - "already registered"); - ret = 0; - goto out; - } + if (already_registered) { + gf_log_callingfn(clnt->conn.name, GF_LOG_DEBUG, "already registered"); + ret = 0; + goto out; + } - tmp = GF_CALLOC (1, sizeof (*tmp), - gf_common_mt_rpcclnt_cb_program_t); - if (tmp == NULL) { - goto out; - } + tmp = GF_MALLOC(sizeof(*tmp), gf_common_mt_rpcclnt_cb_program_t); + if (tmp == NULL) { + goto out; + } - memcpy (tmp, program, sizeof (*tmp)); - INIT_LIST_HEAD (&tmp->program); + memcpy(tmp, program, sizeof(*tmp)); + INIT_LIST_HEAD(&tmp->program); - pthread_mutex_lock (&clnt->lock); - { - list_add_tail (&tmp->program, &clnt->programs); - } - pthread_mutex_unlock (&clnt->lock); + tmp->mydata = mydata; - ret = 0; - gf_log (clnt->conn.trans->name, GF_LOG_DEBUG, - "New program registered: %s, Num: %d, Ver: %d", - program->progname, program->prognum, - program->progver); + pthread_mutex_lock(&clnt->lock); + { + list_add_tail(&tmp->program, &clnt->programs); + } + pthread_mutex_unlock(&clnt->lock); -out: - if (ret == -1) { - gf_log (clnt->conn.trans->name, GF_LOG_ERROR, - "Program registration failed:" - " %s, Num: %d, Ver: %d", program->progname, - program->prognum, program->progver); - } + ret = 0; + gf_log(clnt->conn.name, GF_LOG_DEBUG, + "New program registered: %s, Num: %d, Ver: %d", program->progname, + program->prognum, program->progver); - return ret; +out: + if (ret == -1 && clnt) { + gf_log(clnt->conn.name, GF_LOG_ERROR, + "Program registration failed:" + " %s, Num: %d, Ver: %d", + program->progname, program->prognum, program->progver); + } + + return ret; } - int -rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, - int procnum, fop_cbk_fn_t cbkfn, - struct iovec *proghdr, int proghdrcount, - struct iovec *progpayload, int progpayloadcount, - struct iobref *iobref, void *frame, struct iovec *rsphdr, - int rsphdr_count, struct iovec *rsp_payload, - int rsp_payload_count, struct iobref *rsp_iobref) +rpc_clnt_submit(struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, int procnum, + fop_cbk_fn_t cbkfn, struct iovec *proghdr, int proghdrcount, + struct iovec *progpayload, int progpayloadcount, + struct iobref *iobref, void *frame, struct iovec *rsphdr, + int rsphdr_count, struct iovec *rsp_payload, + int rsp_payload_count, struct iobref *rsp_iobref) { - rpc_clnt_connection_t *conn = NULL; - struct iobuf *request_iob = NULL; - struct iovec rpchdr = {0,}; - struct rpc_req *rpcreq = NULL; - rpc_transport_req_t req; - int ret = -1; - int proglen = 0; - char new_iobref = 0; - uint64_t callid = 0; - - if (!rpc || !prog || !frame) { - goto out; - } - - rpcreq = mem_get (rpc->reqpool); - if (rpcreq == NULL) { - goto out; - } - - memset (rpcreq, 0, sizeof (*rpcreq)); - memset (&req, 0, sizeof (req)); - + rpc_clnt_connection_t *conn = NULL; + struct iobuf *request_iob = NULL; + struct iovec rpchdr = { + 0, + }; + struct rpc_req *rpcreq = NULL; + rpc_transport_req_t req; + int ret = -1; + int proglen = 0; + char new_iobref = 0; + uint64_t callid = 0; + gf_boolean_t need_unref = _gf_false; + call_frame_t *cframe = frame; + + if (!rpc || !prog || !frame) { + goto out; + } + + conn = &rpc->conn; + + rpcreq = mem_get(rpc->reqpool); + if (rpcreq == NULL) { + goto out; + } + + memset(rpcreq, 0, sizeof(*rpcreq)); + memset(&req, 0, sizeof(req)); + + if (!iobref) { + iobref = iobref_new(); if (!iobref) { - iobref = iobref_new (); - if (!iobref) { - goto out; - } - - new_iobref = 1; - } - - callid = rpc_clnt_new_callid (rpc); - - conn = &rpc->conn; - - rpcreq->prog = prog; - rpcreq->procnum = procnum; - rpcreq->conn = conn; - rpcreq->xid = callid; - rpcreq->cbkfn = cbkfn; - - ret = -1; - - if (proghdr) { - proglen += iov_length (proghdr, proghdrcount); - } - - if (progpayload) { - proglen += iov_length (progpayload, - progpayloadcount); - } - - request_iob = rpc_clnt_record (rpc, frame, prog, - procnum, proglen, - &rpchdr, callid); - if (!request_iob) { - gf_log (conn->trans->name, GF_LOG_WARNING, - "cannot build rpc-record"); - goto out; - } - - iobref_add (iobref, request_iob); - - req.msg.rpchdr = &rpchdr; - req.msg.rpchdrcount = 1; - req.msg.proghdr = proghdr; - req.msg.proghdrcount = proghdrcount; - req.msg.progpayload = progpayload; - req.msg.progpayloadcount = progpayloadcount; - req.msg.iobref = iobref; - - req.rsp.rsphdr = rsphdr; - req.rsp.rsphdr_count = rsphdr_count; - req.rsp.rsp_payload = rsp_payload; - req.rsp.rsp_payload_count = rsp_payload_count; - req.rsp.rsp_iobref = rsp_iobref; - req.rpc_req = rpcreq; - - pthread_mutex_lock (&conn->lock); - { - if (conn->connected == 0) { - ret = rpc_transport_connect (conn->trans, - conn->config.remote_port); - /* Below code makes sure the (re-)configured port lasts - for just one successful connect attempt */ - if (!ret) - conn->config.remote_port = 0; - } - - ret = rpc_transport_submit_request (rpc->conn.trans, - &req); - if (ret == -1) { - gf_log (conn->trans->name, GF_LOG_WARNING, - "failed to submit rpc-request " - "(XID: 0x%ux Program: %s, ProgVers: %d, " - "Proc: %d) to rpc-transport (%s)", rpcreq->xid, - rpcreq->prog->progname, rpcreq->prog->progver, - rpcreq->procnum, rpc->conn.trans->name); - } - - if ((ret >= 0) && frame) { - gettimeofday (&conn->last_sent, NULL); - /* Save the frame in queue */ - __save_frame (rpc, frame, rpcreq); - - gf_log ("rpc-clnt", GF_LOG_TRACE, "submitted request " - "(XID: 0x%ux Program: %s, ProgVers: %d, " - "Proc: %d) to rpc-transport (%s)", rpcreq->xid, - rpcreq->prog->progname, rpcreq->prog->progver, - rpcreq->procnum, rpc->conn.trans->name); - } - } - pthread_mutex_unlock (&conn->lock); - + goto out; + } + + new_iobref = 1; + } + + callid = GF_ATOMIC_INC(rpc->xid); + + rpcreq->prog = prog; + rpcreq->procnum = procnum; + rpcreq->conn = conn; + rpcreq->xid = callid; + rpcreq->cbkfn = cbkfn; + + ret = -1; + + if (proghdr) { + proglen += iov_length(proghdr, proghdrcount); + } + + request_iob = rpc_clnt_record(rpc, frame, prog, procnum, proglen, &rpchdr, + callid); + if (!request_iob) { + gf_log(conn->name, GF_LOG_WARNING, "cannot build rpc-record"); + goto out; + } + + iobref_add(iobref, request_iob); + + req.msg.rpchdr = &rpchdr; + req.msg.rpchdrcount = 1; + req.msg.proghdr = proghdr; + req.msg.proghdrcount = proghdrcount; + req.msg.progpayload = progpayload; + req.msg.progpayloadcount = progpayloadcount; + req.msg.iobref = iobref; + + req.rsp.rsphdr = rsphdr; + req.rsp.rsphdr_count = rsphdr_count; + req.rsp.rsp_payload = rsp_payload; + req.rsp.rsp_payload_count = rsp_payload_count; + req.rsp.rsp_iobref = rsp_iobref; + req.rpc_req = rpcreq; + + pthread_mutex_lock(&conn->lock); + { + if (conn->connected == 0) { + if (rpc->disabled) + goto unlock; + ret = rpc_transport_connect(conn->trans, conn->config.remote_port); + if (ret < 0) { + 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); if (ret == -1) { - goto out; - } - - ret = 0; + gf_log(conn->name, GF_LOG_WARNING, + "failed to submit rpc-request " + "(unique: %" PRIu64 + ", XID: 0x%x Program: %s, " + "ProgVers: %d, Proc: %d) to rpc-transport (%s)", + cframe->root->unique, rpcreq->xid, rpcreq->prog->progname, + rpcreq->prog->progver, rpcreq->procnum, conn->name); + } else if ((ret >= 0) && frame) { + /* Save the frame in queue */ + __save_frame(rpc, frame, rpcreq); + + /* A ref on rpc-clnt object is taken while registering + * call_bail to timer in __save_frame. If it fails to + * register, it needs an unref and should happen outside + * conn->lock which otherwise leads to deadlocks */ + if (conn->timer == NULL) + need_unref = _gf_true; + + conn->msgcnt++; + + gf_log("rpc-clnt", GF_LOG_TRACE, + "submitted request " + "(unique: %" PRIu64 + ", XID: 0x%x, Program: %s, " + "ProgVers: %d, Proc: %d) to rpc-transport (%s)", + cframe->root->unique, rpcreq->xid, rpcreq->prog->progname, + rpcreq->prog->progver, rpcreq->procnum, conn->name); + } + } +unlock: + pthread_mutex_unlock(&conn->lock); + + if (need_unref) + rpc_clnt_unref(rpc); + + if (ret == -1) { + goto out; + } + + rpc_clnt_check_and_start_ping(rpc); + ret = 0; out: - iobuf_unref (request_iob); - - if (new_iobref && iobref) { - iobref_unref (iobref); - } - - if (frame && (ret == -1)) { - if (rpcreq) { - rpcreq->rpc_status = -1; - cbkfn (rpcreq, NULL, 0, frame); - mem_put (rpcreq); - } - } - return ret; + if (request_iob) { + iobuf_unref(request_iob); + } + + if (new_iobref && iobref) { + iobref_unref(iobref); + } + + if (frame && (ret == -1)) { + if (rpcreq) { + rpcreq->rpc_status = -1; + cbkfn(rpcreq, NULL, 0, frame); + mem_put(rpcreq); + } + } + return ret; } - struct rpc_clnt * -rpc_clnt_ref (struct rpc_clnt *rpc) +rpc_clnt_ref(struct rpc_clnt *rpc) { - if (!rpc) - return NULL; - pthread_mutex_lock (&rpc->lock); - { - rpc->refcount++; - } - pthread_mutex_unlock (&rpc->lock); - return rpc; -} + if (!rpc) + return NULL; + GF_ATOMIC_INC(rpc->refcount); + return rpc; +} static void -rpc_clnt_destroy (struct rpc_clnt *rpc) +rpc_clnt_trigger_destroy(struct rpc_clnt *rpc) { - if (!rpc) - return; + rpc_clnt_connection_t *conn = NULL; + rpc_transport_t *trans = NULL; - if (rpc->conn.trans) { - rpc->conn.trans->mydata = NULL; - rpc_transport_unref (rpc->conn.trans); - //rpc_transport_destroy (rpc->conn.trans); - } + if (!rpc) + return; - rpc_clnt_connection_cleanup (&rpc->conn); - rpc_clnt_reconnect_cleanup (&rpc->conn); - saved_frames_destroy (rpc->conn.saved_frames); - pthread_mutex_destroy (&rpc->lock); - pthread_mutex_destroy (&rpc->conn.lock); + /* reading conn->trans outside conn->lock is OK, since this is the last + * ref*/ + conn = &rpc->conn; + trans = conn->trans; + rpc_clnt_disable(rpc); + + /* This is to account for rpc_clnt_disable that might have been called + * before rpc_clnt_unref */ + if (trans) { + /* set conn->trans to NULL before rpc_transport_unref + * as rpc_transport_unref can potentially free conn + */ + conn->trans = NULL; + rpc_transport_unref(trans); + } +} - /* mem-pool should be destroyed, otherwise, - it will cause huge memory leaks */ - mem_pool_destroy (rpc->reqpool); - mem_pool_destroy (rpc->saved_frames_pool); +static void +rpc_clnt_destroy(struct rpc_clnt *rpc) +{ + rpcclnt_cb_program_t *program = NULL; + rpcclnt_cb_program_t *tmp = NULL; + struct saved_frames *saved_frames = NULL; + rpc_clnt_connection_t *conn = NULL; - GF_FREE (rpc); + if (!rpc) return; + + conn = &rpc->conn; + GF_FREE(rpc->conn.name); + /* Access saved_frames in critical-section to avoid + crash in rpc_clnt_connection_cleanup at the time + of destroying saved frames + */ + pthread_mutex_lock(&conn->lock); + { + saved_frames = conn->saved_frames; + conn->saved_frames = NULL; + } + pthread_mutex_unlock(&conn->lock); + + 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 */ + mem_pool_destroy(rpc->reqpool); + mem_pool_destroy(rpc->saved_frames_pool); + + list_for_each_entry_safe(program, tmp, &rpc->programs, program) + { + GF_FREE(program); + } + + GF_FREE(rpc); + return; } struct rpc_clnt * -rpc_clnt_unref (struct rpc_clnt *rpc) +rpc_clnt_unref(struct rpc_clnt *rpc) { - int count = 0; - - if (!rpc) - return NULL; - pthread_mutex_lock (&rpc->lock); - { - count = --rpc->refcount; - } - pthread_mutex_unlock (&rpc->lock); - if (!count) { - rpc_clnt_destroy (rpc); - return NULL; - } - return rpc; -} - + int count = 0; -void -rpc_clnt_reconfig (struct rpc_clnt *rpc, struct rpc_clnt_config *config) -{ - if (config->rpc_timeout) { - if (config->rpc_timeout != rpc->conn.config.rpc_timeout) - gf_log (rpc->conn.trans->name, GF_LOG_INFO, - "changing timeout to %d (from %d)", - config->rpc_timeout, - rpc->conn.config.rpc_timeout); - rpc->conn.config.rpc_timeout = config->rpc_timeout; - } + if (!rpc) + return NULL; - if (config->remote_port) { - if (config->remote_port != rpc->conn.config.remote_port) - gf_log (rpc->conn.trans->name, GF_LOG_INFO, - "changing port to %d (from %d)", - config->remote_port, - rpc->conn.config.remote_port); + count = GF_ATOMIC_DEC(rpc->refcount); - rpc->conn.config.remote_port = config->remote_port; - } - - if (config->remote_host) { - if (rpc->conn.config.remote_host) { - if (strcmp (rpc->conn.config.remote_host, - config->remote_host)) - gf_log (rpc->conn.trans->name, GF_LOG_INFO, - "changing port to %s (from %s)", - config->remote_host, - rpc->conn.config.remote_host); - FREE (rpc->conn.config.remote_host); - } else { - gf_log (rpc->conn.trans->name, GF_LOG_INFO, - "setting hostname to %s", - config->remote_host); - } - - rpc->conn.config.remote_host = gf_strdup (config->remote_host); - } + if (!count) { + rpc_clnt_trigger_destroy(rpc); + return NULL; + } + return rpc; } int -rpc_clnt_transport_unix_options_build (dict_t **options, char *filepath) +rpc_clnt_disable(struct rpc_clnt *rpc) { - dict_t *dict = NULL; - char *fpath = NULL; - int ret = -1; - - GF_ASSERT (filepath); - GF_ASSERT (options); - - dict = dict_new (); - if (!dict) - goto out; - - fpath = gf_strdup (filepath); - if (!fpath) { - ret = -1; - goto out; - } + 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 it. + */ + 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); + + ret = -1; + if (trans) { + 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; + * 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); - ret = dict_set_dynstr (dict, "transport.socket.connect-path", fpath); - if (ret) - goto out; + if (timer_unref) + rpc_clnt_unref(rpc); - ret = dict_set_str (dict, "transport.address-family", "unix"); - if (ret) - goto out; + if (reconnect_unref) + rpc_clnt_unref(rpc); - ret = dict_set_str (dict, "transport.socket.nodelay", "off"); - if (ret) - goto out; - - ret = dict_set_str (dict, "transport-type", "socket"); - if (ret) - goto out; +out: + return ret; +} - ret = dict_set_str (dict, "transport.socket.keepalive", "off"); - if (ret) - goto out; +void +rpc_clnt_reconfig(struct rpc_clnt *rpc, struct rpc_clnt_config *config) +{ + if (config->ping_timeout) { + if (config->ping_timeout != rpc->conn.ping_timeout) + gf_log(rpc->conn.name, GF_LOG_INFO, + "changing ping timeout to %d (from %d)", + config->ping_timeout, rpc->conn.ping_timeout); - *options = dict; -out: - if (ret) { - if (fpath) - GF_FREE (fpath); - if (dict) - dict_unref (dict); + pthread_mutex_lock(&rpc->conn.lock); + { + rpc->conn.ping_timeout = config->ping_timeout; + } + pthread_mutex_unlock(&rpc->conn.lock); + } + + if (config->rpc_timeout) { + if (config->rpc_timeout != rpc->conn.config.rpc_timeout) + gf_log(rpc->conn.name, GF_LOG_INFO, + "changing timeout to %d (from %d)", config->rpc_timeout, + rpc->conn.config.rpc_timeout); + rpc->conn.config.rpc_timeout = config->rpc_timeout; + } + + if (config->remote_port) { + if (config->remote_port != rpc->conn.config.remote_port) + gf_log(rpc->conn.name, GF_LOG_INFO, "changing port to %d (from %d)", + config->remote_port, rpc->conn.config.remote_port); + + rpc->conn.config.remote_port = config->remote_port; + } + + if (config->remote_host) { + if (rpc->conn.config.remote_host) { + if (strcmp(rpc->conn.config.remote_host, config->remote_host)) + gf_log(rpc->conn.name, GF_LOG_INFO, + "changing hostname to %s (from %s)", config->remote_host, + rpc->conn.config.remote_host); + GF_FREE(rpc->conn.config.remote_host); + } else { + gf_log(rpc->conn.name, GF_LOG_INFO, "setting hostname to %s", + config->remote_host); } - return ret; + + rpc->conn.config.remote_host = gf_strdup(config->remote_host); + } } diff --git a/rpc/rpc-lib/src/rpc-clnt.h b/rpc/rpc-lib/src/rpc-clnt.h index e3b2ec3f1a2..2945265200b 100644 --- a/rpc/rpc-lib/src/rpc-clnt.h +++ b/rpc/rpc-lib/src/rpc-clnt.h @@ -1,103 +1,92 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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_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" typedef enum { - RPC_CLNT_CONNECT, - RPC_CLNT_DISCONNECT, - RPC_CLNT_MSG + RPC_CLNT_CONNECT, + RPC_CLNT_DISCONNECT, + RPC_CLNT_PING, + RPC_CLNT_MSG, + RPC_CLNT_DESTROY } rpc_clnt_event_t; -#define AUTH_GLUSTERFS 5 -#define RPC_CLNT_MAX_AUTH_BYTES 1024 - #define SFRAME_GET_PROGNUM(sframe) (sframe->rpcreq->prog->prognum) #define SFRAME_GET_PROGVER(sframe) (sframe->rpcreq->prog->progver) #define SFRAME_GET_PROCNUM(sframe) (sframe->rpcreq->procnum) -struct xptr_clnt; struct rpc_req; struct rpc_clnt; struct rpc_clnt_config; struct rpc_clnt_program; -typedef int (*rpc_clnt_notify_t) (struct rpc_clnt *rpc, void *mydata, - rpc_clnt_event_t fn, void *data); +typedef int (*rpc_clnt_notify_t)(struct rpc_clnt *rpc, void *mydata, + rpc_clnt_event_t fn, void *data); -typedef int (*fop_cbk_fn_t) (struct rpc_req *req, struct iovec *iov, int count, - void *myframe); +typedef int (*fop_cbk_fn_t)(struct rpc_req *req, struct iovec *iov, int count, + void *myframe); -typedef int (*clnt_fn_t) (call_frame_t *fr, xlator_t *xl, void *args); +typedef int (*clnt_fn_t)(call_frame_t *fr, xlator_t *xl, void *args); struct saved_frame { - union { - struct list_head list; - struct { - struct saved_frame *frame_next; - struct saved_frame *frame_prev; - }; - }; - void *capital_this; - void *frame; - struct timeval saved_at; - struct rpc_req *rpcreq; - rpc_transport_rsp_t rsp; + union { + struct list_head list; + struct { + struct saved_frame *frame_next; + struct saved_frame *frame_prev; + }; + }; + void *capital_this; + void *frame; + struct rpc_req *rpcreq; + struct timeval saved_at; + rpc_transport_rsp_t rsp; }; struct saved_frames { - int64_t count; - struct saved_frame sf; - struct saved_frame lk_sf; + int64_t count; + struct saved_frame sf; + struct saved_frame lk_sf; }; - /* Initialized by procnum */ typedef struct rpc_clnt_procedure { - char *procname; - clnt_fn_t fn; + char *procname; + clnt_fn_t fn; } rpc_clnt_procedure_t; typedef struct rpc_clnt_program { - char *progname; - int prognum; - int progver; - rpc_clnt_procedure_t *proctable; - char **procnames; - int numproc; + char *progname; + int prognum; + int progver; + rpc_clnt_procedure_t *proctable; + char **procnames; + int numproc; } rpc_clnt_prog_t; -typedef int (*rpcclnt_cb_fn) (void *data); +typedef int (*rpcclnt_cb_fn)(struct rpc_clnt *rpc, void *mydata, void *data); /* The descriptor for each procedure/actor that runs * over the RPC service. */ typedef struct rpcclnt_actor_desc { - char procname[32]; - int procnum; - rpcclnt_cb_fn actor; + char procname[32]; + rpcclnt_cb_fn actor; + int procnum; } rpcclnt_cb_actor_t; /* Describes a program and its version along with the function pointers @@ -105,100 +94,113 @@ typedef struct rpcclnt_actor_desc { * Never changed ever by any thread so no need for a lock. */ typedef struct rpcclnt_cb_program { - char progname[32]; - int prognum; - int progver; - rpcclnt_cb_actor_t *actors; /* All procedure handlers */ - int numactors; /* Num actors in actor array */ + char progname[32]; + int prognum; + int progver; + rpcclnt_cb_actor_t *actors; /* All procedure handlers */ + /* Program specific state handed to actors */ + void *private; - /* Program specific state handed to actors */ - void *private; + /* list member to link to list of registered services with rpc_clnt */ + struct list_head program; + /* Needed for passing back in cb_actor */ + void *mydata; + int numactors; /* Num actors in actor array */ - /* list member to link to list of registered services with rpc_clnt */ - struct list_head program; } rpcclnt_cb_program_t; - - -#define RPC_MAX_AUTH_BYTES 400 typedef struct rpc_auth_data { - int flavour; - int datalen; - char authdata[RPC_MAX_AUTH_BYTES]; + int flavour; + int datalen; + char authdata[GF_MAX_AUTH_BYTES]; } rpc_auth_data_t; - struct rpc_clnt_config { - int rpc_timeout; - int remote_port; - char * remote_host; + int rpc_timeout; + int remote_port; + char *remote_host; + int ping_timeout; }; - -#define rpc_auth_flavour(au) ((au).flavour) +#define rpc_auth_flavour(au) ((au).flavour) struct rpc_clnt_connection { - pthread_mutex_t lock; - 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; - struct saved_frames *saved_frames; - int32_t frame_timeout; - struct timeval last_sent; - struct timeval last_received; - int32_t ping_started; + 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; + struct saved_frames *saved_frames; + struct timespec last_sent; + struct timespec last_received; + 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; - struct iobref *rsp_iobref; - int rpc_status; - rpc_auth_data_t verf; - rpc_clnt_prog_t *prog; - int procnum; - fop_cbk_fn_t cbkfn; - void *conn_private; + rpc_clnt_connection_t *conn; + struct iovec req[2]; + struct iobref *req_iobref; + struct iovec rsp[2]; + int rspcnt; + int reqcnt; + struct iobref *rsp_iobref; + rpc_clnt_prog_t *prog; + rpc_auth_data_t verf; + fop_cbk_fn_t cbkfn; + void *conn_private; + int procnum; + int rpc_status; + uint32_t xid; }; -struct rpc_clnt { - pthread_mutex_t lock; - rpc_clnt_notify_t notifyfn; - rpc_clnt_connection_t conn; - void *mydata; - uint64_t xid; +typedef struct rpc_clnt { + pthread_mutex_t lock; + rpc_clnt_notify_t notifyfn; + rpc_clnt_connection_t conn; + void *mydata; + gf_atomic_t xid; - /* list of cb programs registered with rpc-clnt */ - struct list_head programs; + /* list of cb programs registered with rpc-clnt */ + struct list_head programs; - /* Memory pool for rpc_req_t */ - struct mem_pool *reqpool; + /* Memory pool for rpc_req_t */ + struct mem_pool *reqpool; - struct mem_pool *saved_frames_pool; + struct mem_pool *saved_frames_pool; - glusterfs_ctx_t *ctx; - int refcount; -}; + glusterfs_ctx_t *ctx; + gf_atomic_t refcount; + xlator_t *owner; + int auth_value; + char disabled; +} rpc_clnt_t; +struct rpc_clnt * +rpc_clnt_new(dict_t *options, xlator_t *owner, char *name, + uint32_t reqpool_size); -struct rpc_clnt *rpc_clnt_new (dict_t *options, glusterfs_ctx_t *ctx, - char *name); +int +rpc_clnt_start(struct rpc_clnt *rpc); -int rpc_clnt_start (struct rpc_clnt *rpc); +int +rpc_clnt_cleanup_and_start(struct rpc_clnt *rpc); -int rpc_clnt_register_notify (struct rpc_clnt *rpc, rpc_clnt_notify_t fn, - void *mydata); +int +rpc_clnt_register_notify(struct rpc_clnt *rpc, rpc_clnt_notify_t fn, + void *mydata); /* Some preconditions related to vectors holding responses. * @rsphdr: should contain pointer to buffer which can hold response header @@ -215,34 +217,44 @@ int rpc_clnt_register_notify (struct rpc_clnt *rpc, rpc_clnt_notify_t fn, * of the header. */ -int rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, - int procnum, fop_cbk_fn_t cbkfn, - struct iovec *proghdr, int proghdrcount, - struct iovec *progpayload, int progpayloadcount, - struct iobref *iobref, void *frame, struct iovec *rsphdr, - int rsphdr_count, struct iovec *rsp_payload, - int rsp_payload_count, struct iobref *rsp_iobref); +int +rpc_clnt_submit(struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, int procnum, + fop_cbk_fn_t cbkfn, struct iovec *proghdr, int proghdrcount, + struct iovec *progpayload, int progpayloadcount, + struct iobref *iobref, void *frame, struct iovec *rsphdr, + int rsphdr_count, struct iovec *rsp_payload, + int rsp_payload_count, struct iobref *rsp_iobref); struct rpc_clnt * -rpc_clnt_ref (struct rpc_clnt *rpc); +rpc_clnt_ref(struct rpc_clnt *rpc); struct rpc_clnt * -rpc_clnt_unref (struct rpc_clnt *rpc); +rpc_clnt_unref(struct rpc_clnt *rpc); -void rpc_clnt_set_connected (rpc_clnt_connection_t *conn); - -void rpc_clnt_unset_connected (rpc_clnt_connection_t *conn); +int +rpc_clnt_connection_cleanup(rpc_clnt_connection_t *conn); +int +rpc_clnt_reconnect_cleanup(rpc_clnt_connection_t *conn); +gf_boolean_t +is_rpc_clnt_disconnected(rpc_clnt_connection_t *conn); -void rpc_clnt_reconnect (void *trans_ptr); +void +rpc_clnt_reconnect(void *trans_ptr); -void rpc_clnt_reconfig (struct rpc_clnt *rpc, struct rpc_clnt_config *config); +void +rpc_clnt_reconfig(struct rpc_clnt *rpc, struct rpc_clnt_config *config); /* All users of RPC services should use this API to register their * procedure handlers. */ -int rpcclnt_cbk_program_register (struct rpc_clnt *svc, - rpcclnt_cb_program_t *program); +int +rpcclnt_cbk_program_register(struct rpc_clnt *svc, + rpcclnt_cb_program_t *program, void *mydata); int -rpc_clnt_transport_unix_options_build (dict_t **options, char *filepath); +rpc_clnt_disable(struct rpc_clnt *rpc); + +int +rpc_clnt_mgmt_pmap_signout(glusterfs_ctx_t *ctx, char *brick_name); + #endif /* !_RPC_CLNT_H */ diff --git a/rpc/rpc-lib/src/rpc-common.c b/rpc/rpc-lib/src/rpc-common.c deleted file mode 100644 index ff8785c6700..00000000000 --- a/rpc/rpc-lib/src/rpc-common.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#include "logging.h" -#include "xdr-common.h" - -ssize_t -xdr_serialize_generic (struct iovec outmsg, void *res, xdrproc_t proc) -{ - ssize_t ret = -1; - XDR xdr; - - if ((!outmsg.iov_base) || (!res) || (!proc)) - return -1; - - xdrmem_create (&xdr, outmsg.iov_base, (unsigned int)outmsg.iov_len, - XDR_ENCODE); - - if (!proc (&xdr, res)) { - gf_log_callingfn ("xdr", GF_LOG_WARNING, - "XDR encoding failed"); - ret = -1; - goto ret; - } - - ret = xdr_encoded_length (xdr); - -ret: - return ret; -} - - -ssize_t -xdr_to_generic (struct iovec inmsg, void *args, xdrproc_t proc) -{ - XDR xdr; - ssize_t ret = -1; - - if ((!inmsg.iov_base) || (!args) || (!proc)) - return -1; - - xdrmem_create (&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len, - XDR_DECODE); - - if (!proc (&xdr, args)) { - gf_log_callingfn ("xdr", GF_LOG_WARNING, - "XDR decoding failed"); - ret = -1; - goto ret; - } - - ret = xdr_decoded_length (xdr); -ret: - return ret; -} - - -bool_t -xdr_gf_dump_req (XDR *xdrs, gf_dump_req *objp) -{ - if (!xdr_u_quad_t (xdrs, &objp->gfs_id)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_prog_detail (XDR *xdrs, gf_prog_detail *objp) -{ - if (!xdr_string (xdrs, &objp->progname, ~0)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->prognum)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->progver)) - return FALSE; - if (!xdr_pointer (xdrs, (char **)&objp->next, sizeof (gf_prog_detail), - (xdrproc_t) xdr_gf_prog_detail)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_dump_rsp (XDR *xdrs, gf_dump_rsp *objp) -{ - if (!xdr_u_quad_t (xdrs, &objp->gfs_id)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_pointer (xdrs, (char **)&objp->prog, sizeof (gf_prog_detail), - (xdrproc_t) xdr_gf_prog_detail)) - return FALSE; - return TRUE; -} - - -ssize_t -xdr_serialize_dump_rsp (struct iovec outmsg, void *rsp) -{ - return xdr_serialize_generic (outmsg, (void *)rsp, - (xdrproc_t)xdr_gf_dump_rsp); -} - -ssize_t -xdr_to_dump_req (struct iovec inmsg, void *args) -{ - return xdr_to_generic (inmsg, (void *)args, - (xdrproc_t)xdr_gf_dump_req); -} - - -ssize_t -xdr_from_dump_req (struct iovec outmsg, void *rsp) -{ - return xdr_serialize_generic (outmsg, (void *)rsp, - (xdrproc_t)xdr_gf_dump_req); -} - -ssize_t -xdr_to_dump_rsp (struct iovec inmsg, void *args) -{ - return xdr_to_generic (inmsg, (void *)args, - (xdrproc_t)xdr_gf_dump_rsp); -} diff --git a/rpc/rpc-lib/src/rpc-drc.c b/rpc/rpc-lib/src/rpc-drc.c new file mode 100644 index 00000000000..de8dc630626 --- /dev/null +++ b/rpc/rpc-lib/src/rpc-drc.c @@ -0,0 +1,855 @@ +/* + Copyright (c) 2013 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 "rpcsvc.h" +#ifndef RPC_DRC_H +#include "rpc-drc.h" +#endif +#include <glusterfs/locking.h> +#include <glusterfs/statedump.h> +#include <glusterfs/mem-pool.h> + +#include <netinet/in.h> +#include <unistd.h> + +/** + * rpcsvc_drc_op_destroy - Destroys the cached reply + * + * @param drc - the main drc structure + * @param reply - the cached reply to destroy + * @return NULL if reply is destroyed, reply otherwise + */ +static drc_cached_op_t * +rpcsvc_drc_op_destroy(rpcsvc_drc_globals_t *drc, drc_cached_op_t *reply) +{ + GF_ASSERT(drc); + GF_ASSERT(reply); + + if (reply->state == DRC_OP_IN_TRANSIT) + return reply; + + iobref_unref(reply->msg.iobref); + if (reply->msg.rpchdr) + GF_FREE(reply->msg.rpchdr); + if (reply->msg.proghdr) + GF_FREE(reply->msg.proghdr); + if (reply->msg.progpayload) + GF_FREE(reply->msg.progpayload); + + list_del(&reply->global_list); + reply->client->op_count--; + drc->op_count--; + mem_put(reply); + reply = NULL; + + return reply; +} + +/** + * rpcsvc_drc_op_rb_unref - This function is used in rb tree cleanup only + * + * @param reply - the cached reply to unref + * @param drc - the main drc structure + * @return void + */ +static void +rpcsvc_drc_rb_op_destroy(void *reply, void *drc) +{ + rpcsvc_drc_op_destroy(drc, (drc_cached_op_t *)reply); +} + +/** + * rpcsvc_remove_drc_client - Cleanup the drc client + * + * @param client - the drc client to be removed + * @return void + */ +static void +rpcsvc_remove_drc_client(drc_client_t *client) +{ + rb_destroy(client->rbtree, rpcsvc_drc_rb_op_destroy); + list_del(&client->client_list); + GF_FREE(client); +} + +/** + * rpcsvc_client_lookup - Given a sockaddr_storage, find the client if it exists + * + * @param drc - the main drc structure + * @param sockaddr - the network address of the client to be looked up + * @return drc client if it exists, NULL otherwise + */ +static drc_client_t * +rpcsvc_client_lookup(rpcsvc_drc_globals_t *drc, + struct sockaddr_storage *sockaddr) +{ + drc_client_t *client = NULL; + + GF_ASSERT(drc); + GF_ASSERT(sockaddr); + + if (list_empty(&drc->clients_head)) + return NULL; + + list_for_each_entry(client, &drc->clients_head, client_list) + { + if (gf_sock_union_equal_addr(&client->sock_union, + (union gf_sock_union *)sockaddr)) + return client; + } + + return NULL; +} + +/** + * drc_compare_reqs - Used by rbtree to determine if incoming req matches with + * an existing node(cached reply) in rbtree + * + * @param item - pointer to the incoming req + * @param rb_node_data - pointer to an rbtree node (cached reply) + * @param param - drc pointer - unused here, but used in *op_destroy + * @return 0 if req matches reply, else (req->xid - reply->xid) + */ +int +drc_compare_reqs(const void *item, const void *rb_node_data, void *param) +{ + int ret = -1; + drc_cached_op_t *req = NULL; + drc_cached_op_t *reply = NULL; + + GF_ASSERT(item); + GF_ASSERT(rb_node_data); + GF_ASSERT(param); + + req = (drc_cached_op_t *)item; + reply = (drc_cached_op_t *)rb_node_data; + + ret = req->xid - reply->xid; + if (ret != 0) + return ret; + + if (req->prognum == reply->prognum && req->procnum == reply->procnum && + req->progversion == reply->progversion) + return 0; + + return 1; +} + +/** + * drc_init_client_cache - initialize a drc client and its rb tree + * + * @param drc - the main drc structure + * @param client - the drc client to be initialized + * @return 0 on success, -1 on failure + */ +static int +drc_init_client_cache(rpcsvc_drc_globals_t *drc, drc_client_t *client) +{ + GF_ASSERT(drc); + GF_ASSERT(client); + + client->rbtree = rb_create(drc_compare_reqs, drc, NULL); + if (!client->rbtree) { + gf_log(GF_RPCSVC, GF_LOG_DEBUG, "rb tree creation failed"); + return -1; + } + + return 0; +} + +/** + * rpcsvc_get_drc_client - find the drc client with given sockaddr, else + * allocate and initialize a new drc client + * + * @param drc - the main drc structure + * @param sockaddr - network address of client + * @return drc client on success, NULL on failure + */ +static drc_client_t * +rpcsvc_get_drc_client(rpcsvc_drc_globals_t *drc, + struct sockaddr_storage *sockaddr) +{ + drc_client_t *client = NULL; + + GF_ASSERT(drc); + GF_ASSERT(sockaddr); + + client = rpcsvc_client_lookup(drc, sockaddr); + if (client) + goto out; + + /* if lookup fails, allocate cache for the new client */ + client = GF_CALLOC(1, sizeof(drc_client_t), gf_common_mt_drc_client_t); + if (!client) + goto out; + + GF_ATOMIC_INIT(client->ref, 0); + client->sock_union = (union gf_sock_union) * sockaddr; + client->op_count = 0; + INIT_LIST_HEAD(&client->client_list); + + if (drc_init_client_cache(drc, client)) { + gf_log(GF_RPCSVC, GF_LOG_DEBUG, "initialization of drc client failed"); + GF_FREE(client); + client = NULL; + goto out; + } + drc->client_count++; + + list_add(&client->client_list, &drc->clients_head); + +out: + return client; +} + +/** + * rpcsvc_need_drc - Determine if a request needs DRC service + * + * @param req - incoming request + * @return 1 if DRC is needed for req, 0 otherwise + */ +int +rpcsvc_need_drc(rpcsvc_request_t *req) +{ + rpcsvc_actor_t *actor = NULL; + rpcsvc_drc_globals_t *drc = NULL; + + GF_ASSERT(req); + GF_ASSERT(req->svc); + + drc = req->svc->drc; + + if (!drc || drc->status == DRC_UNINITIATED) + return 0; + + actor = rpcsvc_program_actor(req); + if (!actor) + return 0; + + return (actor->op_type == DRC_NON_IDEMPOTENT && drc->type != DRC_TYPE_NONE); +} + +/** + * rpcsvc_drc_client_ref - ref the drc client + * + * @param client - the drc client to ref + * @return client + */ +static drc_client_t * +rpcsvc_drc_client_ref(drc_client_t *client) +{ + GF_ASSERT(client); + GF_ATOMIC_INC(client->ref); + return client; +} + +/** + * rpcsvc_drc_client_unref - unref the drc client, and destroy + * the client on last unref + * + * @param drc - the main drc structure + * @param client - the drc client to unref + * @return NULL if it is the last unref, client otherwise + */ +static drc_client_t * +rpcsvc_drc_client_unref(rpcsvc_drc_globals_t *drc, drc_client_t *client) +{ + uint32_t refcount; + + GF_ASSERT(drc); + + refcount = GF_ATOMIC_DEC(client->ref); + if (!refcount) { + drc->client_count--; + rpcsvc_remove_drc_client(client); + client = NULL; + } + + return client; +} + +/** + * rpcsvc_drc_lookup - lookup a request to see if it is already cached + * + * @param req - incoming request + * @return cached reply of req if found, NULL otherwise + */ +drc_cached_op_t * +rpcsvc_drc_lookup(rpcsvc_request_t *req) +{ + drc_client_t *client = NULL; + drc_cached_op_t *reply = NULL; + drc_cached_op_t new = { + .xid = req->xid, + .prognum = req->prognum, + .progversion = req->progver, + .procnum = req->procnum, + }; + + GF_ASSERT(req); + + if (!req->trans->drc_client) { + client = rpcsvc_get_drc_client(req->svc->drc, + &req->trans->peerinfo.sockaddr); + if (!client) + goto out; + + req->trans->drc_client = rpcsvc_drc_client_ref(client); + } + + client = req->trans->drc_client; + + if (client->op_count == 0) + goto out; + + reply = rb_find(client->rbtree, &new); + +out: + return reply; +} + +/** + * rpcsvc_send_cached_reply - send the cached reply for the incoming request + * + * @param req - incoming request (which is a duplicate in this case) + * @param reply - the cached reply for req + * @return 0 on successful reply submission, -1 or other non-zero value + * otherwise + */ +int +rpcsvc_send_cached_reply(rpcsvc_request_t *req, drc_cached_op_t *reply) +{ + int ret = 0; + + GF_ASSERT(req); + GF_ASSERT(reply); + + gf_log(GF_RPCSVC, GF_LOG_DEBUG, + "sending cached reply: xid: %d, " + "client: %s", + req->xid, req->trans->peerinfo.identifier); + + rpcsvc_drc_client_ref(reply->client); + ret = rpcsvc_transport_submit( + req->trans, reply->msg.rpchdr, reply->msg.rpchdrcount, + reply->msg.proghdr, reply->msg.proghdrcount, reply->msg.progpayload, + reply->msg.progpayloadcount, reply->msg.iobref, req->trans_private); + rpcsvc_drc_client_unref(req->svc->drc, reply->client); + + return ret; +} + +/** + * rpcsvc_cache_reply - cache the reply for the processed request 'req' + * + * @param req - processed request + * @param iobref - iobref structure of the reply + * @param rpchdr - rpc header of the reply + * @param rpchdrcount - size of rpchdr + * @param proghdr - program header of the reply + * @param proghdrcount - size of proghdr + * @param payload - payload of the reply if any + * @param payloadcount - size of payload + * @return 0 on success, -1 on failure + */ +int +rpcsvc_cache_reply(rpcsvc_request_t *req, struct iobref *iobref, + struct iovec *rpchdr, int rpchdrcount, struct iovec *proghdr, + int proghdrcount, struct iovec *payload, int payloadcount) +{ + int ret = -1; + drc_cached_op_t *reply = NULL; + + GF_ASSERT(req); + GF_ASSERT(req->reply); + + reply = req->reply; + + reply->state = DRC_OP_CACHED; + + reply->msg.iobref = iobref_ref(iobref); + + reply->msg.rpchdrcount = rpchdrcount; + reply->msg.rpchdr = iov_dup(rpchdr, rpchdrcount); + + reply->msg.proghdrcount = proghdrcount; + reply->msg.proghdr = iov_dup(proghdr, proghdrcount); + + reply->msg.progpayloadcount = payloadcount; + if (payloadcount) + reply->msg.progpayload = iov_dup(payload, payloadcount); + + // rpcsvc_drc_client_unref (req->svc->drc, req->trans->drc_client); + // rpcsvc_drc_op_unref (req->svc->drc, reply); + ret = 0; + + return ret; +} + +/** + * rpcsvc_vacate_drc_entries - free up some percentage of drc cache + * based on the lru factor + * + * @param drc - the main drc structure + * @return void + */ +static void +rpcsvc_vacate_drc_entries(rpcsvc_drc_globals_t *drc) +{ + uint32_t i = 0; + uint32_t n = 0; + drc_cached_op_t *reply = NULL; + drc_cached_op_t *tmp = NULL; + drc_client_t *client = NULL; + + GF_ASSERT(drc); + + n = drc->global_cache_size / drc->lru_factor; + + list_for_each_entry_safe_reverse(reply, tmp, &drc->cache_head, global_list) + { + /* Don't delete ops that are in transit */ + if (reply->state == DRC_OP_IN_TRANSIT) + continue; + + client = reply->client; + + rb_delete(client->rbtree, reply); + + rpcsvc_drc_op_destroy(drc, reply); + rpcsvc_drc_client_unref(drc, client); + i++; + if (i >= n) + break; + } +} + +/** + * rpcsvc_add_op_to_cache - insert the cached op into the client rbtree and drc + * list + * + * @param drc - the main drc structure + * @param reply - the op to be inserted + * @return 0 on success, -1 on failure + */ +static int +rpcsvc_add_op_to_cache(rpcsvc_drc_globals_t *drc, drc_cached_op_t *reply) +{ + drc_client_t *client = NULL; + drc_cached_op_t **tmp_reply = NULL; + + GF_ASSERT(drc); + GF_ASSERT(reply); + + client = reply->client; + + /* cache is full, free up some space */ + if (drc->op_count >= drc->global_cache_size) + rpcsvc_vacate_drc_entries(drc); + + tmp_reply = (drc_cached_op_t **)rb_probe(client->rbtree, reply); + if (!tmp_reply) { + /* mem alloc failed */ + return -1; + } else if (*tmp_reply != reply) { + /* should never happen */ + gf_log(GF_RPCSVC, GF_LOG_ERROR, "DRC failed to detect duplicates"); + return -1; + } + + client->op_count++; + list_add(&reply->global_list, &drc->cache_head); + drc->op_count++; + + return 0; +} + +/** + * rpcsvc_cache_request - cache the in-transition incoming request + * + * @param req - incoming request + * @return 0 on success, -1 on failure + */ +int +rpcsvc_cache_request(rpcsvc_request_t *req) +{ + int ret = -1; + drc_client_t *client = NULL; + drc_cached_op_t *reply = NULL; + rpcsvc_drc_globals_t *drc = NULL; + + GF_ASSERT(req); + + drc = req->svc->drc; + + client = req->trans->drc_client; + if (!client) { + gf_log(GF_RPCSVC, GF_LOG_DEBUG, "drc client is NULL"); + goto out; + } + + reply = mem_get0(drc->mempool); + if (!reply) + goto out; + + reply->client = rpcsvc_drc_client_ref(client); + reply->xid = req->xid; + reply->prognum = req->prognum; + reply->progversion = req->progver; + reply->procnum = req->procnum; + reply->state = DRC_OP_IN_TRANSIT; + req->reply = reply; + INIT_LIST_HEAD(&reply->global_list); + + ret = rpcsvc_add_op_to_cache(drc, reply); + if (ret) { + req->reply = NULL; + rpcsvc_drc_op_destroy(drc, reply); + rpcsvc_drc_client_unref(drc, client); + gf_log(GF_RPCSVC, GF_LOG_DEBUG, "Failed to add op to drc cache"); + } + +out: + return ret; +} + +/** + * + * rpcsvc_drc_priv - function which dumps the drc state + * + * @param drc - the main drc structure + * @return 0 on success, -1 on failure + */ +int32_t +rpcsvc_drc_priv(rpcsvc_drc_globals_t *drc) +{ + int i = 0; + char key[GF_DUMP_MAX_BUF_LEN] = {0}; + drc_client_t *client = NULL; + char ip[INET6_ADDRSTRLEN] = {0}; + + if (!drc || drc->status == DRC_UNINITIATED) { + gf_log(GF_RPCSVC, GF_LOG_DEBUG, + "DRC is " + "uninitialized, not dumping its state"); + return 0; + } + + gf_proc_dump_add_section("rpc.drc"); + + if (TRY_LOCK(&drc->lock)) + return -1; + + gf_proc_dump_build_key(key, "drc", "type"); + gf_proc_dump_write(key, "%d", drc->type); + + gf_proc_dump_build_key(key, "drc", "client_count"); + gf_proc_dump_write(key, "%d", drc->client_count); + + gf_proc_dump_build_key(key, "drc", "current_cache_size"); + gf_proc_dump_write(key, "%d", drc->op_count); + + gf_proc_dump_build_key(key, "drc", "max_cache_size"); + gf_proc_dump_write(key, "%d", drc->global_cache_size); + + gf_proc_dump_build_key(key, "drc", "lru_factor"); + gf_proc_dump_write(key, "%d", drc->lru_factor); + + gf_proc_dump_build_key(key, "drc", "duplicate_request_count"); + gf_proc_dump_write(key, "%" PRIu64, drc->cache_hits); + + gf_proc_dump_build_key(key, "drc", "in_transit_duplicate_requests"); + gf_proc_dump_write(key, "%" PRIu64, drc->intransit_hits); + + list_for_each_entry(client, &drc->clients_head, client_list) + { + gf_proc_dump_build_key(key, "client", "%d.ip-address", i); + memset(ip, 0, INET6_ADDRSTRLEN); + switch (client->sock_union.storage.ss_family) { + case AF_INET: + gf_proc_dump_write( + key, "%s", + inet_ntop(AF_INET, &client->sock_union.sin.sin_addr.s_addr, + ip, INET_ADDRSTRLEN)); + break; + case AF_INET6: + gf_proc_dump_write( + key, "%s", + inet_ntop(AF_INET6, &client->sock_union.sin6.sin6_addr, ip, + INET6_ADDRSTRLEN)); + break; + default: + gf_proc_dump_write(key, "%s", "N/A"); + } + + gf_proc_dump_build_key(key, "client", "%d.ref_count", i); + 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++; + } + + UNLOCK(&drc->lock); + return 0; +} + +/** + * rpcsvc_drc_notify - function which is notified of RPC transport events + * + * @param svc - pointer to rpcsvc_t structure of the rpc + * @param xl - pointer to the xlator + * @param event - the event which triggered this notify + * @param data - the transport structure + * @return 0 on success, -1 on failure + */ +int +rpcsvc_drc_notify(rpcsvc_t *svc, void *xl, rpcsvc_event_t event, void *data) +{ + int ret = -1; + rpc_transport_t *trans = NULL; + drc_client_t *client = NULL; + rpcsvc_drc_globals_t *drc = NULL; + + GF_ASSERT(svc); + GF_ASSERT(svc->drc); + GF_ASSERT(data); + + drc = svc->drc; + + if (drc->status == DRC_UNINITIATED || drc->type == DRC_TYPE_NONE) + return 0; + + LOCK(&drc->lock); + { + trans = (rpc_transport_t *)data; + client = rpcsvc_get_drc_client(drc, &trans->peerinfo.sockaddr); + if (!client) + goto unlock; + + switch (event) { + case RPCSVC_EVENT_ACCEPT: + trans->drc_client = rpcsvc_drc_client_ref(client); + ret = 0; + break; + + case RPCSVC_EVENT_DISCONNECT: + ret = 0; + if (list_empty(&drc->clients_head)) + break; + /* should be the last unref */ + trans->drc_client = NULL; + rpcsvc_drc_client_unref(drc, client); + break; + + default: + break; + } + } +unlock: + UNLOCK(&drc->lock); + return ret; +} + +/** + * rpcsvc_drc_init - Initialize the duplicate request cache service + * + * @param svc - pointer to rpcsvc_t structure of the rpc + * @param options - the options dictionary which configures drc + * @return 0 on success, non-zero integer on failure + */ +int +rpcsvc_drc_init(rpcsvc_t *svc, dict_t *options) +{ + int ret = 0; + uint32_t drc_type = 0; + uint32_t drc_size = 0; + uint32_t drc_factor = 0; + rpcsvc_drc_globals_t *drc = NULL; + + GF_ASSERT(svc); + GF_ASSERT(options); + + /* Toggle DRC on/off, when more drc types(persistent/cluster) + * are added, we shouldn't treat this as boolean. */ + ret = dict_get_str_boolean(options, "nfs.drc", _gf_false); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_INFO, "drc user options need second look"); + ret = _gf_false; + } + + gf_log(GF_RPCSVC, GF_LOG_INFO, "DRC is turned %s", (ret ? "ON" : "OFF")); + + /*DRC off, nothing to do */ + if (ret == _gf_false) + return (0); + + drc = GF_CALLOC(1, sizeof(rpcsvc_drc_globals_t), + gf_common_mt_drc_globals_t); + if (!drc) + return (-1); + + LOCK_INIT(&drc->lock); + svc->drc = drc; + + /* 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 = DRC_DEFAULT_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 = 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_size); + ret = -1; + 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_factor = DRC_DEFAULT_LRU_FACTOR; + } + + drc->lru_factor = (drc_lru_factor_t)drc_factor; + + INIT_LIST_HEAD(&drc->clients_head); + INIT_LIST_HEAD(&drc->cache_head); + + 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 post_unlock; + } + + drc->status = DRC_INITIATED; + 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); + drc->mempool = NULL; + } + GF_FREE(drc); + svc->drc = NULL; + } + return ret; +} + +int +rpcsvc_drc_deinit(rpcsvc_t *svc) +{ + rpcsvc_drc_globals_t *drc = NULL; + + if (!svc) + return (-1); + + drc = svc->drc; + if (!drc) + return (0); + + LOCK(&drc->lock); + (void)rpcsvc_unregister_notify(svc, rpcsvc_drc_notify, THIS); + if (drc->mempool) { + mem_pool_destroy(drc->mempool); + drc->mempool = NULL; + } + UNLOCK(&drc->lock); + + GF_FREE(drc); + svc->drc = NULL; + + return (0); +} + +int +rpcsvc_drc_reconfigure(rpcsvc_t *svc, dict_t *options) +{ + int ret = -1; + gf_boolean_t enable_drc = _gf_false; + rpcsvc_drc_globals_t *drc = NULL; + uint32_t drc_size = 0; + + /* Input sanitization */ + if ((!svc) || (!options)) + return (-1); + + /* If DRC was not enabled before, Let rpcsvc_drc_init() to + * take care of DRC initialization part. + */ + drc = svc->drc; + if (!drc) { + return rpcsvc_drc_init(svc, options); + } + + /* DRC was already enabled before. Going to be reconfigured. Check + * if reconfigured options contain "nfs.drc" and "nfs.drc-size". + * + * NB: If DRC is "OFF", "drc-size" has no role to play. + * So, "drc-size" gets evaluated IFF DRC is "ON". + * + * If DRC is reconfigured, + * case 1: DRC is "ON" + * sub-case 1: drc-size remains same + * ACTION: Nothing to do. + * sub-case 2: drc-size just changed + * ACTION: rpcsvc_drc_deinit() followed by + * rpcsvc_drc_init(). + * + * case 2: DRC is "OFF" + * ACTION: rpcsvc_drc_deinit() + */ + ret = dict_get_str_boolean(options, "nfs.drc", _gf_false); + if (ret < 0) + ret = _gf_false; + + enable_drc = ret; + gf_log(GF_RPCSVC, GF_LOG_INFO, "DRC is turned %s", (ret ? "ON" : "OFF")); + + /* case 1: DRC is "ON"*/ + if (enable_drc) { + /* Fetch drc-size if reconfigured */ + if (dict_get_uint32(options, "nfs.drc-size", &drc_size)) + drc_size = DRC_DEFAULT_CACHE_SIZE; + + /* case 1: sub-case 1*/ + if (drc->global_cache_size == drc_size) + return (0); + + /* case 1: sub-case 2*/ + (void)rpcsvc_drc_deinit(svc); + return rpcsvc_drc_init(svc, options); + } + + /* case 2: DRC is "OFF" */ + return rpcsvc_drc_deinit(svc); +} diff --git a/rpc/rpc-lib/src/rpc-drc.h b/rpc/rpc-lib/src/rpc-drc.h new file mode 100644 index 00000000000..ce66430809b --- /dev/null +++ b/rpc/rpc-lib/src/rpc-drc.h @@ -0,0 +1,97 @@ +/* + Copyright (c) 2013 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_DRC_H +#define RPC_DRC_H + +#include "rpcsvc-common.h" +#include "rpcsvc.h" +#include <glusterfs/locking.h> +#include <glusterfs/dict.h> +#include "rb.h" + +/* per-client cache structure */ +struct drc_client { + 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; + int prognum; + int progversion; + int procnum; + rpc_transport_msg_t msg; + drc_client_t *client; + struct list_head client_list; + struct list_head global_list; + int32_t ref; + uint32_t xid; +}; + +/* global drc definitions */ +enum drc_status { DRC_UNINITIATED, DRC_INITIATED }; +typedef enum drc_status drc_status_t; + +struct drc_globals { + /* allocator must be the first member since + * it is used so in gf_libavl_allocator + */ + struct libavl_allocator allocator; + /* configurable size parameter */ + gf_lock_t lock; + uint64_t cache_hits; + uint64_t intransit_hits; + struct mem_pool *mempool; + struct list_head cache_head; + 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 +rpcsvc_need_drc(rpcsvc_request_t *req); + +drc_cached_op_t * +rpcsvc_drc_lookup(rpcsvc_request_t *req); + +int +rpcsvc_send_cached_reply(rpcsvc_request_t *req, drc_cached_op_t *reply); + +int +rpcsvc_cache_reply(rpcsvc_request_t *req, struct iobref *iobref, + struct iovec *rpchdr, int rpchdrcount, struct iovec *proghdr, + int proghdrcount, struct iovec *payload, int payloadcount); + +int +rpcsvc_cache_request(rpcsvc_request_t *req); + +int32_t +rpcsvc_drc_priv(rpcsvc_drc_globals_t *drc); + +int +rpcsvc_drc_init(rpcsvc_t *svc, dict_t *options); + +int +rpcsvc_drc_deinit(rpcsvc_t *svc); + +int +rpcsvc_drc_reconfigure(rpcsvc_t *svc, dict_t *options); + +#endif /* RPC_DRC_H */ diff --git a/rpc/rpc-lib/src/rpc-lib-messages.h b/rpc/rpc-lib/src/rpc-lib-messages.h new file mode 100644 index 00000000000..2c0b820dbf9 --- /dev/null +++ b/rpc/rpc-lib/src/rpc-lib-messages.h @@ -0,0 +1,34 @@ +/* + 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_LIB_MESSAGES_H_ +#define _RPC_LIB_MESSAGES_H_ + +#include <glusterfs/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_LIB, TRANS_MSG_ADDR_FAMILY_NOT_SPECIFIED, + TRANS_MSG_UNKNOWN_ADDR_FAMILY, TRANS_MSG_REMOTE_HOST_ERROR, + TRANS_MSG_DNS_RESOL_FAILED, TRANS_MSG_LISTEN_PATH_ERROR, + TRANS_MSG_CONNECT_PATH_ERROR, TRANS_MSG_GET_ADDR_INFO_FAILED, + TRANS_MSG_PORT_BIND_FAILED, TRANS_MSG_INET_ERROR, + TRANS_MSG_GET_NAME_INFO_FAILED, TRANS_MSG_TRANSPORT_ERROR, + TRANS_MSG_TIMEOUT_EXCEEDED, TRANS_MSG_SOCKET_BIND_ERROR); + +#endif /* !_RPC_LIB_MESSAGES_H_ */ diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c index b97ba61bf2b..a6e201a9b36 100644 --- a/rpc/rpc-lib/src/rpc-transport.c +++ b/rpc/rpc-lib/src/rpc-transport.c @@ -1,607 +1,672 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 <dlfcn.h> #include <stdlib.h> #include <stdio.h> #include <sys/poll.h> -#include <fnmatch.h> #include <stdint.h> -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#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) #endif +int32_t +rpc_transport_count(const char *transport_type) +{ + char *transport_dup = NULL; + char *saveptr = NULL; + char *ptr = NULL; + int count = 0; + + if (transport_type == NULL) + return -1; + + transport_dup = gf_strdup(transport_type); + if (transport_dup == NULL) { + return -1; + } + + ptr = strtok_r(transport_dup, ",", &saveptr); + while (ptr != NULL) { + count++; + ptr = strtok_r(NULL, ",", &saveptr); + } + + GF_FREE(transport_dup); + return count; +} int -rpc_transport_get_myaddr (rpc_transport_t *this, char *peeraddr, int addrlen, - struct sockaddr_storage *sa, size_t salen) +rpc_transport_get_myaddr(rpc_transport_t *this, char *peeraddr, int addrlen, + struct sockaddr_storage *sa, size_t salen) { - int32_t ret = -1; - GF_VALIDATE_OR_GOTO ("rpc", this, out); + int32_t ret = -1; + GF_VALIDATE_OR_GOTO("rpc", this, out); - ret = this->ops->get_myaddr (this, peeraddr, addrlen, sa, salen); + ret = this->ops->get_myaddr(this, peeraddr, addrlen, sa, salen); out: - return ret; + return ret; } int32_t -rpc_transport_get_myname (rpc_transport_t *this, char *hostname, int hostlen) +rpc_transport_get_peername(rpc_transport_t *this, char *hostname, int hostlen) { - int32_t ret = -1; - GF_VALIDATE_OR_GOTO ("rpc", this, out); + int32_t ret = -1; + GF_VALIDATE_OR_GOTO("rpc", this, out); - ret = this->ops->get_myname (this, hostname, hostlen); + ret = this->ops->get_peername(this, hostname, hostlen); out: - return ret; + return ret; } -int32_t -rpc_transport_get_peername (rpc_transport_t *this, char *hostname, int hostlen) +int +rpc_transport_throttle(rpc_transport_t *this, gf_boolean_t onoff) { - int32_t ret = -1; - GF_VALIDATE_OR_GOTO ("rpc", this, out); + if (!this->ops->throttle) + return -ENOSYS; - ret = this->ops->get_peername (this, hostname, hostlen); -out: - return ret; + return this->ops->throttle(this, onoff); } int32_t -rpc_transport_get_peeraddr (rpc_transport_t *this, char *peeraddr, int addrlen, - struct sockaddr_storage *sa, size_t salen) +rpc_transport_get_peeraddr(rpc_transport_t *this, char *peeraddr, int addrlen, + struct sockaddr_storage *sa, size_t salen) { - int32_t ret = -1; - GF_VALIDATE_OR_GOTO ("rpc", this, out); + int32_t ret = -1; + GF_VALIDATE_OR_GOTO("rpc", this, out); - ret = this->ops->get_peeraddr (this, peeraddr, addrlen, sa, salen); + ret = this->ops->get_peeraddr(this, peeraddr, addrlen, sa, salen); out: - return ret; + return ret; } void -rpc_transport_pollin_destroy (rpc_transport_pollin_t *pollin) +rpc_transport_pollin_destroy(rpc_transport_pollin_t *pollin) { - GF_VALIDATE_OR_GOTO ("rpc", pollin, out); + GF_VALIDATE_OR_GOTO("rpc", pollin, out); - if (pollin->iobref) { - iobref_unref (pollin->iobref); - } + if (pollin->iobref) { + iobref_unref(pollin->iobref); + } - if (pollin->hdr_iobuf) { - iobuf_unref (pollin->hdr_iobuf); - } + if (pollin->private) { + /* */ + GF_FREE(pollin->private); + } - if (pollin->private) { - /* */ - GF_FREE (pollin->private); - } - - GF_FREE (pollin); + GF_FREE(pollin); out: - return; + return; } - rpc_transport_pollin_t * -rpc_transport_pollin_alloc (rpc_transport_t *this, struct iovec *vector, - int count, struct iobuf *hdr_iobuf, - struct iobref *iobref, void *private) +rpc_transport_pollin_alloc(rpc_transport_t *this, struct iovec *vector, + int count, struct iobuf *hdr_iobuf, + struct iobref *iobref, void *private) { - rpc_transport_pollin_t *msg = NULL; - msg = GF_CALLOC (1, sizeof (*msg), gf_common_mt_rpc_trans_pollin_t); - if (!msg) { - goto out; - } + rpc_transport_pollin_t *msg = NULL; + msg = GF_CALLOC(1, sizeof(*msg), gf_common_mt_rpc_trans_pollin_t); + if (!msg) { + goto out; + } - if (count > 1) { - msg->vectored = 1; - } + msg->trans = this; + + if (count > 1) { + msg->vectored = 1; + } - memcpy (msg->vector, vector, count * sizeof (*vector)); - msg->count = count; - msg->iobref = iobref_ref (iobref); - msg->private = private; - if (hdr_iobuf) - msg->hdr_iobuf = iobuf_ref (hdr_iobuf); + memcpy(msg->vector, vector, count * sizeof(*vector)); + msg->count = count; + msg->iobref = iobref_ref(iobref); + msg->private = private; + if (hdr_iobuf) + iobref_add(iobref, hdr_iobuf); out: - return msg; + 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) +rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) { - struct rpc_transport *trans = NULL, *return_trans = NULL; - char *name = NULL; - void *handle = NULL; - char *type = NULL; - char str[] = "ERROR"; - int32_t ret = -1; - int8_t is_tcp = 0, is_unix = 0, is_ibsdp = 0; - volume_opt_list_t *vol_opt = NULL; - gf_boolean_t bind_insecure = _gf_false; - - GF_VALIDATE_OR_GOTO("rpc-transport", options, fail); - GF_VALIDATE_OR_GOTO("rpc-transport", ctx, fail); - GF_VALIDATE_OR_GOTO("rpc-transport", trans_name, fail); - - trans = GF_CALLOC (1, sizeof (struct rpc_transport), gf_common_mt_rpc_trans_t); - if (!trans) - goto fail; - - trans->name = gf_strdup (trans_name); - if (!trans->name) - goto fail; - - trans->ctx = ctx; - type = str; - - /* Backward compatibility */ - ret = dict_get_str (options, "transport-type", &type); - if (ret < 0) { - ret = dict_set_str (options, "transport-type", "socket"); - if (ret < 0) - gf_log ("dict", GF_LOG_DEBUG, - "setting transport-type failed"); - else - gf_log ("rpc-transport", GF_LOG_WARNING, - "missing 'option transport-type'. defaulting to " - "\"socket\""); - } else { - { - /* Backword compatibility to handle * /client, - * * /server. - */ - char *tmp = strchr (type, '/'); - if (tmp) - *tmp = '\0'; - } - - is_tcp = strcmp (type, "tcp"); - is_unix = strcmp (type, "unix"); - 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"); - if (is_ibsdp == 0) - ret = dict_set_str (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"); - if (ret < 0) - gf_log ("dict", GF_LOG_DEBUG, - "setting transport-type failed"); - } - } - - /* client-bind-insecure is for clients protocol, and - * bind-insecure for glusterd. Both mutually exclusive - */ - ret = dict_get_str (options, "client-bind-insecure", &type); - if (ret) - ret = dict_get_str (options, "bind-insecure", &type); - if (ret == 0) { - ret = gf_string2boolean (type, &bind_insecure); - if (ret < 0) { - gf_log ("rcp-transport", GF_LOG_WARNING, - "bind-insecure option %s is not a" - " valid bool option", type); - goto fail; - } - if (_gf_true == bind_insecure) - trans->bind_insecure = 1; - else - trans->bind_insecure = 0; - } else { - trans->bind_insecure = 0; + struct rpc_transport *trans = NULL, *return_trans = NULL; + char *name = NULL; + void *handle = NULL; + char *type = NULL; + 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; + gf_boolean_t bind_insecure = _gf_false; + xlator_t *this = NULL; + gf_boolean_t success = _gf_false; + + GF_VALIDATE_OR_GOTO("rpc-transport", options, fail); + GF_VALIDATE_OR_GOTO("rpc-transport", ctx, fail); + GF_VALIDATE_OR_GOTO("rpc-transport", trans_name, fail); + + trans = GF_CALLOC(1, sizeof(struct rpc_transport), + gf_common_mt_rpc_trans_t); + if (!trans) + goto fail; + + trans->name = gf_strdup(trans_name); + if (!trans->name) + goto fail; + + trans->ctx = ctx; + type = str; + + /* Backward compatibility */ + ret = dict_get_str_sizen(options, "transport-type", &type); + if (ret < 0) { + ret = dict_set_str_sizen(options, "transport-type", "socket"); + if (ret < 0) + gf_log("dict", GF_LOG_DEBUG, "setting transport-type failed"); + else + gf_log("rpc-transport", GF_LOG_DEBUG, + "missing 'option transport-type'. defaulting to " + "\"socket\""); + } else { + { + /* Backward compatibility to handle * /client, + * * /server. + */ + char *tmp = strchr(type, '/'); + if (tmp) + *tmp = '\0'; } - ret = dict_get_str (options, "transport-type", &type); - if (ret < 0) { - gf_log ("rpc-transport", GF_LOG_ERROR, - "'option transport-type <xx>' missing in volume '%s'", - trans_name); - goto fail; - } - - ret = gf_asprintf (&name, "%s/%s.so", RPC_TRANSPORTDIR, type); - if (-1 == ret) { - goto fail; + is_tcp = strcmp(type, "tcp"); + is_unix = strcmp(type, "unix"); + is_ibsdp = strcmp(type, "ib-sdp"); + if ((is_tcp == 0) || (is_unix == 0) || (is_ibsdp == 0)) { + if (is_unix == 0) + ret = dict_set_str_sizen(options, "transport.address-family", + "unix"); + if (is_ibsdp == 0) + 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_sizen(options, "transport-type", "socket"); + if (ret < 0) + gf_log("dict", GF_LOG_DEBUG, "setting transport-type failed"); } - - gf_log ("rpc-transport", GF_LOG_DEBUG, - "attempt to load file %s", name); - - handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL); - if (handle == NULL) { - gf_log ("rpc-transport", GF_LOG_ERROR, "%s", dlerror ()); - gf_log ("rpc-transport", GF_LOG_ERROR, - "volume '%s': transport-type '%s' is not valid or " - "not found on this machine", - trans_name, type); - goto fail; - } - - trans->ops = dlsym (handle, "tops"); - if (trans->ops == NULL) { - gf_log ("rpc-transport", GF_LOG_ERROR, - "dlsym (rpc_transport_ops) on %s", dlerror ()); - goto fail; - } - - trans->init = dlsym (handle, "init"); - if (trans->init == NULL) { - gf_log ("rpc-transport", GF_LOG_ERROR, - "dlsym (gf_rpc_transport_init) on %s", dlerror ()); - goto fail; - } - - trans->fini = dlsym (handle, "fini"); - if (trans->fini == NULL) { - gf_log ("rpc-transport", GF_LOG_ERROR, - "dlsym (gf_rpc_transport_fini) on %s", dlerror ()); - goto fail; - } - - trans->reconfigure = dlsym (handle, "reconfigure"); - if (trans->fini == NULL) { - gf_log ("rpc-transport", GF_LOG_DEBUG, - "dlsym (gf_rpc_transport_reconfigure) on %s", dlerror()); + } + + /* client-bind-insecure is for clients protocol, and + * bind-insecure for glusterd. Both mutually exclusive + */ + ret = dict_get_str_sizen(options, "client-bind-insecure", &type); + if (ret) + ret = dict_get_str_sizen(options, "bind-insecure", &type); + if (ret == 0) { + ret = gf_string2boolean(type, &bind_insecure); + if (ret < 0) { + gf_log("rcp-transport", GF_LOG_WARNING, + "bind-insecure option %s is not a" + " valid bool option", + type); + goto fail; } - - vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), - gf_common_mt_volume_opt_list_t); - if (!vol_opt) { - goto fail; + if (_gf_true == bind_insecure) + trans->bind_insecure = 1; + else + trans->bind_insecure = 0; + } else { + /* By default allow bind insecure */ + trans->bind_insecure = 1; + } + + 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'", + trans_name); + goto fail; + } + + ret = gf_asprintf(&name, "%s/%s.so", RPC_TRANSPORTDIR, type); + if (-1 == ret) { + 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); + if (handle == NULL) { + gf_log("rpc-transport", GF_LOG_ERROR, "%s", dlerror()); + gf_log("rpc-transport", GF_LOG_WARNING, + "volume '%s': transport-type '%s' is not valid or " + "not found on this machine", + trans_name, type); + goto fail; + } + + trans->dl_handle = handle; + + trans->ops = dlsym(handle, "tops"); + if (trans->ops == NULL) { + gf_log("rpc-transport", GF_LOG_ERROR, "dlsym (rpc_transport_ops) on %s", + dlerror()); + goto fail; + } + + *VOID(&(trans->init)) = dlsym(handle, "init"); + if (trans->init == NULL) { + gf_log("rpc-transport", GF_LOG_ERROR, + "dlsym (gf_rpc_transport_init) on %s", dlerror()); + goto fail; + } + + *VOID(&(trans->fini)) = dlsym(handle, "fini"); + if (trans->fini == NULL) { + gf_log("rpc-transport", GF_LOG_ERROR, + "dlsym (gf_rpc_transport_fini) on %s", dlerror()); + goto fail; + } + + *VOID(&(trans->reconfigure)) = dlsym(handle, "reconfigure"); + if (trans->reconfigure == NULL) { + gf_log("rpc-transport", GF_LOG_DEBUG, + "dlsym (gf_rpc_transport_reconfigure) on %s", dlerror()); + } + + vol_opt = GF_CALLOC(1, sizeof(volume_opt_list_t), + gf_common_mt_volume_opt_list_t); + if (!vol_opt) { + goto fail; + } + + this = THIS; + vol_opt->given_opt = dlsym(handle, "options"); + if (vol_opt->given_opt == NULL) { + gf_log("rpc-transport", GF_LOG_DEBUG, + "volume option validation not specified"); + } else { + INIT_LIST_HEAD(&vol_opt->list); + list_add_tail(&vol_opt->list, &(this->volume_options)); + if (xlator_options_validate_list(this, options, vol_opt, NULL)) { + gf_log("rpc-transport", GF_LOG_ERROR, + "volume option validation failed"); + goto fail; } + } - vol_opt->given_opt = dlsym (handle, "options"); - if (vol_opt->given_opt == NULL) { - gf_log ("rpc-transport", GF_LOG_DEBUG, - "volume option validation not specified"); - } else { - INIT_LIST_HEAD (&vol_opt->list); - list_add_tail (&vol_opt->list, &(THIS->volume_options)); - if (xlator_options_validate_list (THIS, options, vol_opt, - NULL)) { - gf_log ("rpc-transport", GF_LOG_ERROR, - "volume option validation failed"); - goto fail; - } - } - - trans->options = options; - - pthread_mutex_init (&trans->lock, NULL); - trans->xl = THIS; - - ret = trans->init (trans); - if (ret != 0) { - gf_log ("rpc-transport", GF_LOG_ERROR, - "'%s' initialization failed", type); - goto fail; - } - - return_trans = trans; - - if (name) { - GF_FREE (name); - } + trans->options = dict_ref(options); + + pthread_mutex_init(&trans->lock, NULL); + trans->xl = this; + + ret = trans->init(trans); + if (ret != 0) { + gf_log("rpc-transport", GF_LOG_WARNING, "'%s' initialization failed", + type); + goto fail; + } - return return_trans; + INIT_LIST_HEAD(&trans->list); + GF_ATOMIC_INIT(trans->disconnect_progress, 0); + + return_trans = trans; + + GF_FREE(name); + + success = _gf_true; fail: - if (trans) { - if (trans->name) { - GF_FREE (trans->name); - } + if (!success) { + rpc_transport_cleanup(trans); + GF_FREE(name); - GF_FREE (trans); - } + return_trans = NULL; + } - if (name) { - GF_FREE (name); + if (vol_opt) { + if (!list_empty(&vol_opt->list)) { + list_del_init(&vol_opt->list); } + GF_FREE(vol_opt); + } - return NULL; + return return_trans; } - int32_t -rpc_transport_submit_request (rpc_transport_t *this, rpc_transport_req_t *req) +rpc_transport_submit_request(rpc_transport_t *this, rpc_transport_req_t *req) { - int32_t ret = -1; + int32_t ret = -1; - GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); - GF_VALIDATE_OR_GOTO("rpc_transport", this->ops, fail); + GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); + GF_VALIDATE_OR_GOTO("rpc_transport", this->ops, fail); - ret = this->ops->submit_request (this, req); + ret = this->ops->submit_request(this, req); fail: - return ret; + return ret; } - int32_t -rpc_transport_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply) +rpc_transport_submit_reply(rpc_transport_t *this, rpc_transport_reply_t *reply) { - int32_t ret = -1; + int32_t ret = -1; - GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); - GF_VALIDATE_OR_GOTO("rpc_transport", this->ops, fail); + GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); + GF_VALIDATE_OR_GOTO("rpc_transport", this->ops, fail); - ret = this->ops->submit_reply (this, reply); + ret = this->ops->submit_reply(this, reply); fail: - return ret; + return ret; } - int32_t -rpc_transport_connect (rpc_transport_t *this, int port) +rpc_transport_connect(rpc_transport_t *this, int port) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); + GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); - ret = this->ops->connect (this, port); + ret = this->ops->connect(this, port); fail: - return ret; + return ret; } - int32_t -rpc_transport_listen (rpc_transport_t *this) +rpc_transport_listen(rpc_transport_t *this) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); + GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); - ret = this->ops->listen (this); + ret = this->ops->listen(this); fail: - return ret; + return ret; } - int32_t -rpc_transport_disconnect (rpc_transport_t *this) +rpc_transport_disconnect(rpc_transport_t *this, gf_boolean_t wait) { - int32_t ret = -1; + int32_t ret = -1; - GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); + GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); + + ret = this->ops->disconnect(this, wait); - ret = this->ops->disconnect (this); fail: - return ret; + return ret; } - -int32_t -rpc_transport_destroy (rpc_transport_t *this) +static void +rpc_transport_destroy(rpc_transport_t *this) { - int32_t ret = -1; + struct dnscache6 *cache = NULL; - GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); + if (this->clnt_options) + dict_unref(this->clnt_options); + if (this->options) + dict_unref(this->options); + if (this->fini) + this->fini(this); - if (this->options) - dict_unref (this->options); - if (this->fini) - this->fini (this); + pthread_mutex_destroy(&this->lock); - pthread_mutex_destroy (&this->lock); + GF_FREE(this->name); - if (this->name) - GF_FREE (this->name); + if (this->dl_handle) + dlclose(this->dl_handle); - GF_FREE (this); -fail: - return ret; -} + if (this->ssl_name) { + GF_FREE(this->ssl_name); + } + if (this->dnscache) { + cache = this->dnscache; + if (cache->first) + freeaddrinfo(cache->first); + GF_FREE(this->dnscache); + } + + GF_FREE(this); +} rpc_transport_t * -rpc_transport_ref (rpc_transport_t *this) +rpc_transport_ref(rpc_transport_t *this) { - rpc_transport_t *return_this = NULL; + rpc_transport_t *return_this = NULL; - GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); + GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); - pthread_mutex_lock (&this->lock); - { - this->refcount ++; - } - pthread_mutex_unlock (&this->lock); + GF_ATOMIC_INC(this->refcount); - return_this = this; + return_this = this; fail: - return return_this; + return return_this; } - int32_t -rpc_transport_unref (rpc_transport_t *this) +rpc_transport_unref(rpc_transport_t *this) { - int32_t refcount = 0; - int32_t ret = -1; + int32_t refcount = 0; + int32_t ret = -1; - GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); + GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); - pthread_mutex_lock (&this->lock); - { - refcount = --this->refcount; - } - pthread_mutex_unlock (&this->lock); + refcount = GF_ATOMIC_DEC(this->refcount); - if (refcount == 0) { - if (this->mydata) - this->notify (this, this->mydata, RPC_TRANSPORT_CLEANUP, - NULL); - rpc_transport_destroy (this); - } + if (refcount == 0) { + if (this->mydata) + this->notify(this, this->mydata, RPC_TRANSPORT_CLEANUP, NULL); + this->mydata = NULL; + this->notify = NULL; + rpc_transport_destroy(this); + } - ret = 0; + ret = 0; fail: - return ret; + return ret; } - int32_t -rpc_transport_notify (rpc_transport_t *this, rpc_transport_event_t event, - void *data, ...) +rpc_transport_notify(rpc_transport_t *this, rpc_transport_event_t event, + void *data, ...) { - int32_t ret = -1; - GF_VALIDATE_OR_GOTO ("rpc", this, out); + int32_t ret = -1; + GF_VALIDATE_OR_GOTO("rpc", this, out); - if (this->notify != NULL) { - ret = this->notify (this, this->mydata, event, data); - } else { - ret = 0; - } + if (this->notify != NULL) { + ret = this->notify(this, this->mydata, event, data); + } else { + ret = 0; + } out: - return ret; + return ret; } - - -inline int -rpc_transport_register_notify (rpc_transport_t *trans, - rpc_transport_notify_t notify, void *mydata) +int +rpc_transport_register_notify(rpc_transport_t *trans, + rpc_transport_notify_t notify, void *mydata) { - int32_t ret = -1; - GF_VALIDATE_OR_GOTO ("rpc", trans, out); + int32_t ret = -1; + GF_VALIDATE_OR_GOTO("rpc", trans, out); - trans->notify = notify; - trans->mydata = mydata; + trans->notify = notify; + trans->mydata = mydata; - ret = 0; + ret = 0; out: - return ret; + return ret; } -//give negative values to skip setting that value -//this function asserts if both the values are negative. -//why call it if you dont set it. +// give negative values to skip setting that value +// this function asserts if both the values are negative. +// why call it if you don't set it. int -rpc_transport_keepalive_options_set (dict_t *options, int32_t interval, - int32_t time) +rpc_transport_keepalive_options_set(dict_t *options, int32_t interval, + int32_t time, int32_t timeout) { - int ret = -1; + int ret = -1; - GF_ASSERT (options); - GF_ASSERT ((interval > 0) || (time > 0)); + GF_ASSERT(options); + GF_ASSERT((interval > 0) || (time > 0)); - ret = dict_set_int32 (options, - "transport.socket.keepalive-interval", interval); - if (ret) - goto out; + 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); - if (ret) - goto out; + ret = dict_set_int32_sizen(options, "transport.socket.keepalive-time", + time); + if (ret) + goto out; + + ret = dict_set_int32_sizen(options, "transport.tcp-user-timeout", timeout); + if (ret) + goto out; out: - return ret; + return ret; } int -rpc_transport_inet_options_build (dict_t **options, const char *hostname, - int port) +rpc_transport_unix_options_build(dict_t *dict, char *filepath, + int frame_timeout) { - dict_t *dict = NULL; - char *host = NULL; - int ret = -1; - - GF_ASSERT (options); - GF_ASSERT (hostname); - GF_ASSERT (port >= 1024); - - dict = dict_new (); - if (!dict) - goto out; - - host = gf_strdup ((char*)hostname); - if (!hostname) { - ret = -1; - goto out; - } - - ret = dict_set_dynstr (dict, "remote-host", host); - if (ret) { - gf_log (THIS->name, GF_LOG_WARNING, - "failed to set remote-host with %s", host); - goto out; - } - - ret = dict_set_int32 (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, "transport.address-family", "inet/inet6"); - if (ret) { - gf_log (THIS->name, GF_LOG_WARNING, - "failed to set addr-family with inet"); - goto out; - } + char *fpath = NULL; + int ret = -1; + + GF_ASSERT(filepath); + GF_VALIDATE_OR_GOTO("rpc-transport", dict, out); + + fpath = gf_strdup(filepath); + if (!fpath) { + ret = -1; + goto out; + } + + ret = dict_set_dynstr_sizen(dict, "transport.socket.connect-path", fpath); + if (ret) { + GF_FREE(fpath); + goto out; + } + + ret = dict_set_str_sizen(dict, "transport.address-family", "unix"); + if (ret) + goto out; + + ret = dict_set_str_sizen(dict, "transport.socket.nodelay", "off"); + if (ret) + goto out; + + ret = dict_set_str_sizen(dict, "transport-type", "socket"); + if (ret) + goto out; + + ret = dict_set_str_sizen(dict, "transport.socket.keepalive", "off"); + if (ret) + goto out; + + if (frame_timeout > 0) { + ret = dict_set_int32_sizen(dict, "frame-timeout", frame_timeout); + if (ret) + goto out; + } +out: + return ret; +} - ret = dict_set_str (dict, "transport-type", "socket"); - if (ret) { - gf_log (THIS->name, GF_LOG_WARNING, - "failed to set trans-type with socket"); - goto out; - } +int +rpc_transport_inet_options_build(dict_t *dict, const char *hostname, int port, + char *af) +{ + char *host = NULL; + int ret = -1; +#ifdef IPV6_DEFAULT + static char *addr_family = "inet6"; +#else + static char *addr_family = "inet"; +#endif - *options = dict; + GF_ASSERT(hostname); + GF_ASSERT(port >= 1024); + GF_VALIDATE_OR_GOTO("rpc-transport", dict, out); + + host = gf_strdup((char *)hostname); + if (!host) { + ret = -1; + goto out; + } + + 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); + GF_FREE(host); + goto out; + } + + 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_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_sizen(dict, "transport-type", "socket"); + if (ret) { + gf_log(THIS->name, GF_LOG_WARNING, + "failed to set trans-type with socket"); + goto out; + } out: - if (ret) { - if (host) - GF_FREE (host); - if (dict) - dict_unref (dict); - } - - return ret; + return ret; } diff --git a/rpc/rpc-lib/src/rpc-transport.h b/rpc/rpc-lib/src/rpc-transport.h index f838d4baf2c..c499f0bb955 100644 --- a/rpc/rpc-lib/src/rpc-transport.h +++ b/rpc/rpc-lib/src/rpc-transport.h @@ -1,31 +1,16 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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_TRANSPORT_H__ #define __RPC_TRANSPORT_H__ -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - - #include <inttypes.h> #ifdef GF_SOLARIS_HOST_OS #include <rpc/auth.h> @@ -35,7 +20,6 @@ #include <rpc/rpc_msg.h> - #ifndef MAX_IOVEC #define MAX_IOVEC 16 #endif @@ -57,39 +41,45 @@ */ #define RPC_FRAGSIZE(fraghdr) ((uint32_t)(fraghdr & 0x7fffffffU)) -#define RPC_FRAGHDR_SIZE 4 -#define RPC_MSGTYPE_SIZE 8 +#define RPC_FRAGHDR_SIZE 4 +#define RPC_MSGTYPE_SIZE 8 /* size of the msg from the start of call-body till and including credlen */ -#define RPC_CALL_BODY_SIZE 24 +#define RPC_CALL_BODY_SIZE 24 -#define RPC_REPLY_STATUS_SIZE 4 +#define RPC_REPLY_STATUS_SIZE 4 #define RPC_AUTH_FLAVOUR_N_LENGTH_SIZE 8 -#define RPC_ACCEPT_STATUS_LEN 4 +#define RPC_ACCEPT_STATUS_LEN 4 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]; }; typedef struct peer_info peer_info_t; typedef enum msg_type msg_type_t; typedef enum { - RPC_TRANSPORT_ACCEPT, /* New client has been accepted */ - RPC_TRANSPORT_DISCONNECT, /* Connection is disconnected */ - RPC_TRANSPORT_CLEANUP, /* connection is about to be freed */ - /*RPC_TRANSPORT_READ,*/ /* An event used to enable rpcsvc to instruct + RPC_TRANSPORT_ACCEPT, /* New client has been accepted */ + RPC_TRANSPORT_DISCONNECT, /* Connection is disconnected */ + RPC_TRANSPORT_CLEANUP, /* connection is about to be freed */ + /*RPC_TRANSPORT_READ,*/ /* An event used to enable rpcsvc to instruct * transport the number of bytes to read. * This helps in reading large msgs, wherein * the rpc actors might decide to place the @@ -101,54 +91,55 @@ typedef enum { * reading a single msg, this event may be * delivered more than once. */ - RPC_TRANSPORT_MAP_XID_REQUEST, /* receiver of this event should send - * the prognum and procnum corresponding - * to xid. - */ - RPC_TRANSPORT_MSG_RECEIVED, /* Complete rpc msg has been read */ - RPC_TRANSPORT_CONNECT, /* client is connected to server */ - RPC_TRANSPORT_MSG_SENT, + RPC_TRANSPORT_MAP_XID_REQUEST, /* receiver of this event should send + * the prognum and procnum corresponding + * to xid. + */ + 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 proghdrcount; - struct iovec *progpayload; - int progpayloadcount; - struct iobref *iobref; + struct iovec *rpchdr; + struct iovec *proghdr; + int rpchdrcount; + int proghdrcount; + struct iovec *progpayload; + 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 rsp_payload_count; - struct iobref *rsp_iobref; + struct iovec *rsphdr; + 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 { - rpc_transport_msg_t msg; - rpc_transport_rsp_t rsp; - struct rpc_req *rpc_req; + struct rpc_req *rpc_req; + rpc_transport_msg_t msg; + rpc_transport_rsp_t rsp; }; typedef struct rpc_transport_req rpc_transport_req_t; struct rpc_transport_reply { - rpc_transport_msg_t msg; - void *private; + 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; + union { + rpc_transport_req_t req; + rpc_transport_reply_t reply; + } data; + char is_request; }; typedef struct rpc_transport_data rpc_transport_data_t; @@ -156,151 +147,166 @@ 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 prognum; + int progver; + 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; +typedef int (*rpc_transport_notify_t)(rpc_transport_t *, void *mydata, + rpc_transport_event_t, void *data, ...); -struct rpc_transport_pollin { - struct iovec vector[2]; - int count; - char vectored; - void *private; - struct iobref *iobref; - struct iobuf *hdr_iobuf; - char is_reply; +struct rpc_transport { + struct rpc_transport_ops *ops; + rpc_transport_t *listener; /* listener transport to which + * request for creation of this + * transport came from. valid only + * on server process. + */ + + void *private; + struct _client *xl_private; + void *xl; /* Used for THIS */ + void *mydata; + pthread_mutex_t lock; + gf_atomic_t refcount; + glusterfs_ctx_t *ctx; + dict_t *options; + char *name; + void *dnscache; + void *drc_client; + data_t *buf; + int32_t (*init)(rpc_transport_t *this); + void (*fini)(rpc_transport_t *this); + int (*reconfigure)(rpc_transport_t *this, dict_t *options); + rpc_transport_notify_t notify; + void *notify_data; + peer_info_t peerinfo; + peer_info_t myinfo; + + 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; + 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; }; -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, ...); - -struct rpc_transport { - struct rpc_transport_ops *ops; - rpc_transport_t *listener; /* listener transport to which - * request for creation of this - * transport came from. valid only - * on server process. - */ - - void *private; - void *xl_private; - void *xl; /* Used for THIS */ - void *mydata; - pthread_mutex_t lock; - int32_t refcount; - - glusterfs_ctx_t *ctx; - dict_t *options; - char *name; - void *dnscache; - data_t *buf; - int32_t (*init) (rpc_transport_t *this); - void (*fini) (rpc_transport_t *this); - int (*reconfigure) (rpc_transport_t *this, dict_t *options); - rpc_transport_notify_t notify; - void *notify_data; - peer_info_t peerinfo; - peer_info_t myinfo; - - uint64_t total_bytes_read; - uint64_t total_bytes_write; - - struct list_head list; - int bind_insecure; +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 - */ - int32_t (*submit_request) (rpc_transport_t *this, - rpc_transport_req_t *req); - int32_t (*submit_reply) (rpc_transport_t *this, - rpc_transport_reply_t *reply); - int32_t (*connect) (rpc_transport_t *this, int port); - int32_t (*listen) (rpc_transport_t *this); - int32_t (*disconnect) (rpc_transport_t *this); - int32_t (*get_peername) (rpc_transport_t *this, char *hostname, - int hostlen); - int32_t (*get_peeraddr) (rpc_transport_t *this, char *peeraddr, - int addrlen, struct sockaddr_storage *sa, - socklen_t sasize); - int32_t (*get_myname) (rpc_transport_t *this, char *hostname, - int hostlen); - int32_t (*get_myaddr) (rpc_transport_t *this, char *peeraddr, - int addrlen, struct sockaddr_storage *sa, - socklen_t sasize); + /* no need of receive op, msg will be delivered through an event + * notification + */ + int32_t (*submit_request)(rpc_transport_t *this, rpc_transport_req_t *req); + int32_t (*submit_reply)(rpc_transport_t *this, + rpc_transport_reply_t *reply); + int32_t (*connect)(rpc_transport_t *this, int port); + int32_t (*listen)(rpc_transport_t *this); + int32_t (*disconnect)(rpc_transport_t *this, gf_boolean_t wait); + int32_t (*get_peername)(rpc_transport_t *this, char *hostname, int hostlen); + int32_t (*get_peeraddr)(rpc_transport_t *this, char *peeraddr, int addrlen, + struct sockaddr_storage *sa, socklen_t sasize); + int32_t (*get_myname)(rpc_transport_t *this, char *hostname, int hostlen); + int32_t (*get_myaddr)(rpc_transport_t *this, char *peeraddr, int addrlen, + struct sockaddr_storage *sa, socklen_t sasize); + int32_t (*throttle)(rpc_transport_t *this, gf_boolean_t onoff); }; - int32_t -rpc_transport_listen (rpc_transport_t *this); +rpc_transport_count(const char *transport_type); int32_t -rpc_transport_connect (rpc_transport_t *this, int port); +rpc_transport_listen(rpc_transport_t *this); int32_t -rpc_transport_disconnect (rpc_transport_t *this); +rpc_transport_connect(rpc_transport_t *this, int port); int32_t -rpc_transport_destroy (rpc_transport_t *this); +rpc_transport_disconnect(rpc_transport_t *this, gf_boolean_t wait); int32_t -rpc_transport_notify (rpc_transport_t *this, rpc_transport_event_t event, - void *data, ...); +rpc_transport_notify(rpc_transport_t *this, rpc_transport_event_t event, + void *data, ...); int32_t -rpc_transport_submit_request (rpc_transport_t *this, rpc_transport_req_t *req); +rpc_transport_submit_request(rpc_transport_t *this, rpc_transport_req_t *req); int32_t -rpc_transport_submit_reply (rpc_transport_t *this, - rpc_transport_reply_t *reply); +rpc_transport_submit_reply(rpc_transport_t *this, rpc_transport_reply_t *reply); rpc_transport_t * -rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *name); +rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *name); rpc_transport_t * -rpc_transport_ref (rpc_transport_t *trans); +rpc_transport_ref(rpc_transport_t *trans); int32_t -rpc_transport_unref (rpc_transport_t *trans); +rpc_transport_unref(rpc_transport_t *trans); int -rpc_transport_register_notify (rpc_transport_t *trans, rpc_transport_notify_t, - void *mydata); +rpc_transport_register_notify(rpc_transport_t *trans, rpc_transport_notify_t, + void *mydata); int32_t -rpc_transport_get_peername (rpc_transport_t *this, char *hostname, int hostlen); +rpc_transport_get_peername(rpc_transport_t *this, char *hostname, int hostlen); int32_t -rpc_transport_get_peeraddr (rpc_transport_t *this, char *peeraddr, int addrlen, - struct sockaddr_storage *sa, size_t salen); +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); +rpc_transport_get_myaddr(rpc_transport_t *this, char *peeraddr, int addrlen, + struct sockaddr_storage *sa, size_t salen); -int32_t -rpc_transport_get_myaddr (rpc_transport_t *this, char *peeraddr, int addrlen, - struct sockaddr_storage *sa, size_t salen); +int +rpc_transport_throttle(rpc_transport_t *this, gf_boolean_t onoff); rpc_transport_pollin_t * -rpc_transport_pollin_alloc (rpc_transport_t *this, struct iovec *vector, - int count, struct iobuf *hdr_iobuf, - struct iobref *iobref, void *private); +rpc_transport_pollin_alloc(rpc_transport_t *this, struct iovec *vector, + int count, struct iobuf *hdr_iobuf, + struct iobref *iobref, void *private); void -rpc_transport_pollin_destroy (rpc_transport_pollin_t *pollin); +rpc_transport_pollin_destroy(rpc_transport_pollin_t *pollin); + +int +rpc_transport_keepalive_options_set(dict_t *options, int32_t interval, + int32_t time, int32_t timeout); int -rpc_transport_keepalive_options_set (dict_t *options, int32_t interval, - int32_t time); +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 d62bd100be5..8e76b4188bb 100644 --- a/rpc/rpc-lib/src/rpcsvc-auth.c +++ b/rpc/rpc-lib/src/rpcsvc-auth.c @@ -1,448 +1,561 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 "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); +rpcsvc_auth_null_init(rpcsvc_t *svc, dict_t *options); extern rpcsvc_auth_t * -rpcsvc_auth_unix_init (rpcsvc_t *svc, dict_t *options); +rpcsvc_auth_unix_init(rpcsvc_t *svc, dict_t *options); extern rpcsvc_auth_t * -rpcsvc_auth_glusterfs_init (rpcsvc_t *svc, dict_t *options); +rpcsvc_auth_glusterfs_init(rpcsvc_t *svc, dict_t *options); +extern rpcsvc_auth_t * +rpcsvc_auth_glusterfs_v2_init(rpcsvc_t *svc, dict_t *options); +extern rpcsvc_auth_t * +rpcsvc_auth_glusterfs_v3_init(rpcsvc_t *svc, dict_t *options); int -rpcsvc_auth_add_initer (struct list_head *list, char *idfier, - rpcsvc_auth_initer_t init) +rpcsvc_auth_add_initer(struct list_head *list, char *idfier, + rpcsvc_auth_initer_t init) { - struct rpcsvc_auth_list *new = NULL; + struct rpcsvc_auth_list *new = NULL; - if ((!list) || (!init) || (!idfier)) - return -1; + if ((!list) || (!init) || (!idfier)) + return -1; - new = GF_CALLOC (1, sizeof (*new), gf_common_mt_rpcsvc_auth_list); - if (!new) { - return -1; - } + new = GF_CALLOC(1, sizeof(*new), gf_common_mt_rpcsvc_auth_list); + if (!new) { + return -1; + } - new->init = init; - strcpy (new->name, idfier); - INIT_LIST_HEAD (&new->authlist); - list_add_tail (&new->authlist, list); - return 0; + new->init = init; + strncpy(new->name, idfier, sizeof(new->name) - 1); + INIT_LIST_HEAD(&new->authlist); + list_add_tail(&new->authlist, list); + return 0; } - - int -rpcsvc_auth_add_initers (rpcsvc_t *svc) +rpcsvc_auth_add_initers(rpcsvc_t *svc) { - int ret = -1; - - ret = rpcsvc_auth_add_initer (&svc->authschemes, "auth-glusterfs", - (rpcsvc_auth_initer_t) - rpcsvc_auth_glusterfs_init); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to add AUTH_GLUSTERFS"); - goto err; - } - - ret = rpcsvc_auth_add_initer (&svc->authschemes, "auth-unix", - (rpcsvc_auth_initer_t) - rpcsvc_auth_unix_init); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to add AUTH_UNIX"); - goto err; - } - - ret = rpcsvc_auth_add_initer (&svc->authschemes, "auth-null", - (rpcsvc_auth_initer_t) - rpcsvc_auth_null_init); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to add AUTH_NULL"); - goto err; - } - - ret = 0; + int ret = -1; + + ret = rpcsvc_auth_add_initer( + &svc->authschemes, "auth-glusterfs", + (rpcsvc_auth_initer_t)rpcsvc_auth_glusterfs_init); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Failed to add AUTH_GLUSTERFS"); + goto err; + } + + ret = rpcsvc_auth_add_initer( + &svc->authschemes, "auth-glusterfs-v2", + (rpcsvc_auth_initer_t)rpcsvc_auth_glusterfs_v2_init); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Failed to add AUTH_GLUSTERFS-v2"); + goto err; + } + + ret = rpcsvc_auth_add_initer( + &svc->authschemes, "auth-glusterfs-v3", + (rpcsvc_auth_initer_t)rpcsvc_auth_glusterfs_v3_init); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Failed to add AUTH_GLUSTERFS-v3"); + goto err; + } + + ret = rpcsvc_auth_add_initer(&svc->authschemes, "auth-unix", + (rpcsvc_auth_initer_t)rpcsvc_auth_unix_init); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Failed to add AUTH_UNIX"); + goto err; + } + + ret = rpcsvc_auth_add_initer(&svc->authschemes, "auth-null", + (rpcsvc_auth_initer_t)rpcsvc_auth_null_init); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Failed to add AUTH_NULL"); + goto err; + } + + ret = 0; err: - return ret; + return ret; } - int -rpcsvc_auth_init_auth (rpcsvc_t *svc, dict_t *options, - struct rpcsvc_auth_list *authitem) +rpcsvc_auth_init_auth(rpcsvc_t *svc, dict_t *options, + struct rpcsvc_auth_list *authitem) { - int ret = -1; - - if ((!svc) || (!options) || (!authitem)) - return -1; - - if (!authitem->init) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "No init function defined"); - ret = -1; - goto err; - } + int ret = -1; + + if ((!svc) || (!options) || (!authitem)) + return -1; + + if (!authitem->init) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "No init function defined"); + ret = -1; + goto err; + } + + authitem->auth = authitem->init(svc, options); + if (!authitem->auth) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Registration of auth failed:" + " %s", + authitem->name); + ret = -1; + goto err; + } + + authitem->enable = 1; + gf_log(GF_RPCSVC, GF_LOG_TRACE, "Authentication enabled: %s", + authitem->auth->authname); + + ret = 0; +err: + return ret; +} - authitem->auth = authitem->init (svc, options); - if (!authitem->auth) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Registration of auth failed:" - " %s", authitem->name); - ret = -1; - goto err; - } +int +rpcsvc_auth_init_auths(rpcsvc_t *svc, dict_t *options) +{ + int ret = -1; + struct rpcsvc_auth_list *auth = NULL; + struct rpcsvc_auth_list *tmp = NULL; - authitem->enable = 1; - gf_log (GF_RPCSVC, GF_LOG_TRACE, "Authentication enabled: %s", - authitem->auth->authname); + if (!svc) + return -1; + if (list_empty(&svc->authschemes)) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, "No authentication!"); ret = 0; + goto err; + } + + /* If auth null and sys are not disabled by the user, we must enable + * it by default. This is a globally default rule, the user is still + * allowed to disable the two for particular subvolumes. + */ + if (!dict_get(options, "rpc-auth.auth-null")) { + ret = dict_set_str(options, "rpc-auth.auth-null", "on"); + if (ret) + gf_log("rpc-auth", GF_LOG_DEBUG, "dict_set failed for 'auth-nill'"); + } + + if (!dict_get(options, "rpc-auth.auth-unix")) { + ret = dict_set_str(options, "rpc-auth.auth-unix", "on"); + if (ret) + gf_log("rpc-auth", GF_LOG_DEBUG, "dict_set failed for 'auth-unix'"); + } + + if (!dict_get(options, "rpc-auth.auth-glusterfs")) { + ret = dict_set_str(options, "rpc-auth.auth-glusterfs", "on"); + if (ret) + gf_log("rpc-auth", GF_LOG_DEBUG, "dict_set failed for 'auth-unix'"); + } + + list_for_each_entry_safe(auth, tmp, &svc->authschemes, authlist) + { + ret = rpcsvc_auth_init_auth(svc, options, auth); + if (ret == -1) + goto err; + } + + ret = 0; err: - return ret; + return ret; } - int -rpcsvc_auth_init_auths (rpcsvc_t *svc, dict_t *options) +rpcsvc_set_addr_namelookup(rpcsvc_t *svc, dict_t *options) { - int ret = -1; - struct rpcsvc_auth_list *auth = NULL; - struct rpcsvc_auth_list *tmp = NULL; - - if (!svc) - return -1; - - if (list_empty (&svc->authschemes)) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, "No authentication!"); - ret = 0; - goto err; - } - - /* If auth null and sys are not disabled by the user, we must enable - * it by default. This is a globally default rule, the user is still - * allowed to disable the two for particular subvolumes. - */ - if (!dict_get (options, "rpc-auth.auth-null")) { - ret = dict_set_str (options, "rpc-auth.auth-null", "on"); - if (ret) - gf_log ("rpc-auth", GF_LOG_DEBUG, - "dict_set failed for 'auth-nill'"); - } + int ret; + static char *addrlookup_key = "rpc-auth.addr.namelookup"; - if (!dict_get (options, "rpc-auth.auth-unix")) { - ret = dict_set_str (options, "rpc-auth.auth-unix", "on"); - if (ret) - gf_log ("rpc-auth", GF_LOG_DEBUG, - "dict_set failed for 'auth-unix'"); - } - - if (!dict_get (options, "rpc-auth.auth-glusterfs")) { - ret = dict_set_str (options, "rpc-auth.auth-glusterfs", "on"); - if (ret) - gf_log ("rpc-auth", GF_LOG_DEBUG, - "dict_set failed for 'auth-unix'"); - } + if (!svc || !options) + return (-1); - list_for_each_entry_safe (auth, tmp, &svc->authschemes, authlist) { - ret = rpcsvc_auth_init_auth (svc, options, auth); - if (ret == -1) - goto err; - } + /* By default it's disabled */ + ret = dict_get_str_boolean(options, addrlookup_key, _gf_false); + if (ret < 0) { + svc->addr_namelookup = _gf_false; + } else { + svc->addr_namelookup = ret; + } - ret = 0; -err: - return ret; + if (svc->addr_namelookup) + gf_log(GF_RPCSVC, GF_LOG_DEBUG, "Addr-Name lookup enabled"); + return (0); } int -rpcsvc_set_allow_insecure (rpcsvc_t *svc, dict_t *options) +rpcsvc_set_allow_insecure(rpcsvc_t *svc, dict_t *options) { - int ret = -1; - char *allow_insecure_str = NULL; - gf_boolean_t is_allow_insecure = _gf_false; + int ret = -1; + char *allow_insecure_str = NULL; + gf_boolean_t is_allow_insecure = _gf_false; - GF_ASSERT (svc); - GF_ASSERT (options); + GF_ASSERT(svc); + GF_ASSERT(options); - ret = dict_get_str (options, "rpc-auth-allow-insecure", - &allow_insecure_str); + ret = dict_get_str(options, "rpc-auth-allow-insecure", &allow_insecure_str); + if (0 == ret) { + ret = gf_string2boolean(allow_insecure_str, &is_allow_insecure); if (0 == ret) { - ret = gf_string2boolean (allow_insecure_str, - &is_allow_insecure); - if (0 == ret) { - if (_gf_true == is_allow_insecure) - svc->allow_insecure = 1; - else - svc->allow_insecure = 0; - } + if (_gf_true == is_allow_insecure) + svc->allow_insecure = 1; + else + svc->allow_insecure = 0; } + } else { + /* By default set allow-insecure to true */ + svc->allow_insecure = 1; - return 0; + /* setting in options for the sake of functions that look + * configuration params for allow insecure, eg: gf_auth + */ + ret = dict_set_str(options, "rpc-auth-allow-insecure", "on"); + if (ret < 0) + gf_log("rpc-auth", GF_LOG_DEBUG, + "dict_set failed for 'allow-insecure'"); + } + + return ret; } int -rpcsvc_auth_init (rpcsvc_t *svc, dict_t *options) +rpcsvc_set_root_squash(rpcsvc_t *svc, dict_t *options) { - int ret = -1; - - if ((!svc) || (!options)) - return -1; + int ret = -1; + uid_t anonuid = -1; + gid_t anongid = -1; + + GF_ASSERT(svc); + GF_ASSERT(options); + + ret = dict_get_str_boolean(options, "root-squash", 0); + if (ret != -1) + svc->root_squash = ret; + else + svc->root_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->root_squash) + gf_log(GF_RPCSVC, GF_LOG_DEBUG, + "root squashing enabled " + "(uid=%d, gid=%d)", + svc->anonuid, svc->anongid); + + return 0; +} - (void) rpcsvc_set_allow_insecure (svc, options); - ret = rpcsvc_auth_add_initers (svc); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to add initers"); - goto out; - } +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; +} - ret = rpcsvc_auth_init_auths (svc, options); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to init auth schemes"); - goto out; - } +int +rpcsvc_auth_init(rpcsvc_t *svc, dict_t *options) +{ + int ret = -1; + + if ((!svc) || (!options)) + return -1; + + (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) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Failed to add initers"); + goto out; + } + + ret = rpcsvc_auth_init_auths(svc, options); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Failed to init auth schemes"); + goto out; + } out: - return ret; + return ret; } - -rpcsvc_auth_t * -__rpcsvc_auth_get_handler (rpcsvc_request_t *req) +int +rpcsvc_auth_reconf(rpcsvc_t *svc, dict_t *options) { - struct rpcsvc_auth_list *auth = NULL; - struct rpcsvc_auth_list *tmp = NULL; - rpcsvc_t *svc = NULL; + int ret = 0; - if (!req) - return NULL; + if ((!svc) || (!options)) + return (-1); - svc = req->svc; - if (!svc) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "!svc"); - goto err; - } + ret = rpcsvc_set_allow_insecure(svc, options); + if (ret) + return (-1); - if (list_empty (&svc->authschemes)) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, "No authentication!"); - goto err; - } + ret = rpcsvc_set_root_squash(svc, options); + if (ret) + return (-1); - list_for_each_entry_safe (auth, tmp, &svc->authschemes, authlist) { - if (!auth->enable) - continue; - if (auth->auth->authnum == req->cred.flavour) - goto err; + ret = rpcsvc_set_all_squash(svc, options); + if (ret) + return (-1); - } + return rpcsvc_set_addr_namelookup(svc, options); +} - auth = NULL; +rpcsvc_auth_t * +__rpcsvc_auth_get_handler(rpcsvc_request_t *req) +{ + struct rpcsvc_auth_list *auth = NULL; + struct rpcsvc_auth_list *tmp = NULL; + rpcsvc_t *svc = NULL; + + if (!req) + return NULL; + + svc = req->svc; + if (!svc) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "!svc"); + goto err; + } + + if (list_empty(&svc->authschemes)) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, "No authentication!"); + goto err; + } + + list_for_each_entry_safe(auth, tmp, &svc->authschemes, authlist) + { + if (!auth->enable) + continue; + if (auth->auth->authnum == req->cred.flavour) + goto err; + } + + auth = NULL; err: - if (auth) - return auth->auth; - else - return NULL; + if (auth) + return auth->auth; + else + return NULL; } rpcsvc_auth_t * -rpcsvc_auth_get_handler (rpcsvc_request_t *req) +rpcsvc_auth_get_handler(rpcsvc_request_t *req) { - rpcsvc_auth_t *auth = NULL; + rpcsvc_auth_t *auth = NULL; - auth = __rpcsvc_auth_get_handler (req); - if (auth) - goto ret; + auth = __rpcsvc_auth_get_handler(req); + if (auth) + goto ret; - gf_log (GF_RPCSVC, GF_LOG_TRACE, "No auth handler: %d", - req->cred.flavour); + gf_log(GF_RPCSVC, GF_LOG_TRACE, "No auth handler: %d", req->cred.flavour); - /* The requested scheme was not available so fall back the to one - * scheme that will always be present. - */ - req->cred.flavour = AUTH_NULL; - req->verf.flavour = AUTH_NULL; - auth = __rpcsvc_auth_get_handler (req); + /* The requested scheme was not available so fall back the to one + * scheme that will always be present. + */ + req->cred.flavour = AUTH_NULL; + req->verf.flavour = AUTH_NULL; + auth = __rpcsvc_auth_get_handler(req); ret: - return auth; + return auth; } - int -rpcsvc_auth_request_init (rpcsvc_request_t *req) +rpcsvc_auth_request_init(rpcsvc_request_t *req, struct rpc_msg *callmsg) { - int ret = -1; - rpcsvc_auth_t *auth = NULL; - - if (!req) - return -1; - - auth = rpcsvc_auth_get_handler (req); - if (!auth) - goto err; - ret = 0; - gf_log (GF_RPCSVC, GF_LOG_TRACE, "Auth handler: %s", auth->authname); - if (!auth->authops->request_init) - ret = auth->authops->request_init (req, auth->authprivate); - + int32_t ret = 0; + rpcsvc_auth_t *auth = NULL; + + if (!req || !callmsg) { + ret = -1; + goto err; + } + + req->cred.flavour = rpc_call_cred_flavour(callmsg); + req->cred.datalen = rpc_call_cred_len(callmsg); + req->verf.flavour = rpc_call_verf_flavour(callmsg); + req->verf.datalen = rpc_call_verf_len(callmsg); + + auth = rpcsvc_auth_get_handler(req); + if (!auth) { + ret = -1; + goto err; + } + + gf_log(GF_RPCSVC, GF_LOG_TRACE, "Auth handler: %s", auth->authname); + + if (auth->authops->request_init) + ret = auth->authops->request_init(req, auth->authprivate); + + /* reset to auxgidlarge during + unsersialize if necessary */ + req->auxgids = req->auxgidsmall; + req->auxgidlarge = NULL; err: - return ret; + return ret; } - int -rpcsvc_authenticate (rpcsvc_request_t *req) +rpcsvc_authenticate(rpcsvc_request_t *req) { - int ret = RPCSVC_AUTH_REJECT; - rpcsvc_auth_t *auth = NULL; - int minauth = 0; - - if (!req) - return ret; - - /* FIXME use rpcsvc_request_prog_minauth() */ - minauth = 0; - if (minauth > rpcsvc_request_cred_flavour (req)) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, "Auth too weak"); - rpcsvc_request_set_autherr (req, AUTH_TOOWEAK); - goto err; - } + int ret = RPCSVC_AUTH_REJECT; + rpcsvc_auth_t *auth = NULL; + int minauth = 0; - auth = rpcsvc_auth_get_handler (req); - if (!auth) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, "No auth handler found"); - goto err; - } + if (!req) + return ret; + + /* FIXME use rpcsvc_request_prog_minauth() */ + minauth = 0; + if (minauth > rpcsvc_request_cred_flavour(req)) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, "Auth too weak"); + rpcsvc_request_set_autherr(req, AUTH_TOOWEAK); + goto err; + } + + auth = rpcsvc_auth_get_handler(req); + if (!auth) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, "No auth handler found"); + goto err; + } - if (auth->authops->authenticate) - ret = auth->authops->authenticate (req, auth->authprivate); + if (auth->authops->authenticate) + ret = auth->authops->authenticate(req, auth->authprivate); err: - return ret; + return ret; } int -rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen) +rpcsvc_auth_array(rpcsvc_t *svc, char *volname, int *autharr, int arrlen) { - int count = 0; - int gen = RPCSVC_AUTH_REJECT; - int spec = RPCSVC_AUTH_REJECT; - int final = RPCSVC_AUTH_REJECT; - char *srchstr = NULL; - char *valstr = NULL; - gf_boolean_t boolval = _gf_false; - int ret = 0; - - struct rpcsvc_auth_list *auth = NULL; - struct rpcsvc_auth_list *tmp = NULL; - - if ((!svc) || (!autharr) || (!volname)) - return -1; - - memset (autharr, 0, arrlen * sizeof(int)); - if (list_empty (&svc->authschemes)) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "No authentication!"); - goto err; + int count = 0; + int result = RPCSVC_AUTH_REJECT; + char *srchstr = NULL; + int ret = 0; + + struct rpcsvc_auth_list *auth = NULL; + struct rpcsvc_auth_list *tmp = NULL; + + if ((!svc) || (!autharr) || (!volname)) + return -1; + + memset(autharr, 0, arrlen * sizeof(int)); + if (list_empty(&svc->authschemes)) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "No authentication!"); + goto err; + } + + list_for_each_entry_safe(auth, tmp, &svc->authschemes, authlist) + { + if (count >= arrlen) + break; + + result = gf_asprintf(&srchstr, "rpc-auth.%s.%s", auth->name, volname); + if (result == -1) { + count = -1; + goto err; } - list_for_each_entry_safe (auth, tmp, &svc->authschemes, authlist) { - if (count >= arrlen) - break; - - gen = gf_asprintf (&srchstr, "rpc-auth.%s", auth->name); - if (gen == -1) { - count = -1; - goto err; - } - - gen = RPCSVC_AUTH_REJECT; - if (dict_get (svc->options, srchstr)) { - ret = dict_get_str (svc->options, srchstr, &valstr); - if (ret == 0) { - ret = gf_string2boolean (valstr, &boolval); - if (ret == 0) { - if (boolval == _gf_true) - gen = RPCSVC_AUTH_ACCEPT; - } else - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile" - "d to read auth val"); - } else - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile" - "d to read auth val"); - } - - GF_FREE (srchstr); - spec = gf_asprintf (&srchstr, "rpc-auth.%s.%s", auth->name, - volname); - if (spec == -1) { - count = -1; - goto err; - } - - spec = RPCSVC_AUTH_DONTCARE; - if (dict_get (svc->options, srchstr)) { - ret = dict_get_str (svc->options, srchstr, &valstr); - if (ret == 0) { - ret = gf_string2boolean (valstr, &boolval); - if (ret == 0) { - if (boolval == _gf_true) - spec = RPCSVC_AUTH_ACCEPT; - else - spec = RPCSVC_AUTH_REJECT; - } else - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile" - "d to read auth val"); - } else - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile" - "d to read auth val"); - } - - GF_FREE (srchstr); - final = rpcsvc_combine_gen_spec_volume_checks (gen, spec); - if (final == RPCSVC_AUTH_ACCEPT) { - autharr[count] = auth->auth->authnum; - ++count; - } + ret = dict_get_str_boolean(svc->options, srchstr, 0xC00FFEE); + GF_FREE(srchstr); + + switch (ret) { + case _gf_true: + autharr[count] = auth->auth->authnum; + ++count; + break; + + default: + /* nothing to do */ + break; } + } err: - return count; + return count; } gid_t * -rpcsvc_auth_unix_auxgids (rpcsvc_request_t *req, int *arrlen) +rpcsvc_auth_unix_auxgids(rpcsvc_request_t *req, int *arrlen) { - if ((!req) || (!arrlen)) - return NULL; - - /* In case of AUTH_NULL auxgids are not used */ - if ((req->cred.flavour != AUTH_UNIX) && - (req->cred.flavour != AUTH_GLUSTERFS)) { - gf_log ("rpc", GF_LOG_DEBUG, "auth type not unix or glusterfs"); - return NULL; - } - - *arrlen = req->auxgidcount; - if (*arrlen == 0) - return NULL; - - return &req->auxgids[0]; + if ((!req) || (!arrlen)) + return NULL; + + /* In case of AUTH_NULL auxgids are not used */ + switch (req->cred.flavour) { + case AUTH_UNIX: + case AUTH_GLUSTERFS: + case AUTH_GLUSTERFS_v2: + case AUTH_GLUSTERFS_v3: + break; + default: + gf_log("rpc", GF_LOG_DEBUG, "auth type not unix or glusterfs"); + return NULL; + } + + *arrlen = req->auxgidcount; + if (*arrlen == 0) + return NULL; + + return &req->auxgids[0]; } diff --git a/rpc/rpc-lib/src/rpcsvc-common.h b/rpc/rpc-lib/src/rpcsvc-common.h index b03776deeb5..6c4ec49a6ef 100644 --- a/rpc/rpc-lib/src/rpcsvc-common.h +++ b/rpc/rpc-lib/src/rpcsvc-common.h @@ -1,82 +1,113 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _RPCSVC_COMMON_H #define _RPCSVC_COMMON_H #include <pthread.h> -#include "list.h" -#include "compat.h" -#include "glusterfs.h" -#include "dict.h" +#include <glusterfs/compat.h> +#include <glusterfs/dict.h> typedef enum { - RPCSVC_EVENT_ACCEPT, - RPCSVC_EVENT_DISCONNECT, - RPCSVC_EVENT_TRANSPORT_DESTROY, - RPCSVC_EVENT_LISTENER_DEAD, + RPCSVC_EVENT_ACCEPT, + RPCSVC_EVENT_DISCONNECT, + RPCSVC_EVENT_TRANSPORT_DESTROY, + RPCSVC_EVENT_LISTENER_DEAD, } rpcsvc_event_t; - struct rpcsvc_state; -typedef int (*rpcsvc_notify_t) (struct rpcsvc_state *, void *mydata, - rpcsvc_event_t, void *data); +typedef int (*rpcsvc_notify_t)(struct rpcsvc_state *, void *mydata, + rpcsvc_event_t, void *data); +struct drc_globals; +typedef struct drc_globals rpcsvc_drc_globals_t; /* Contains global state required for all the RPC services. */ typedef struct rpcsvc_state { + /* Contains list of (program, version) handlers. + * other options. + */ + + pthread_rwlock_t rpclock; + + /* List of the authentication schemes available. */ + struct list_head authschemes; + + /* Reference to the options */ + dict_t *options; + + uid_t anonuid; + gid_t anongid; + glusterfs_ctx_t *ctx; + + /* list of connections which will listen for incoming connections */ + struct list_head listeners; + + /* list of programs registered with rpcsvc */ + struct list_head programs; + + /* list of notification callbacks */ + struct list_head notify; + int notify_count; + + unsigned int memfactor; + + xlator_t *xl; /* xlator */ + void *mydata; + rpcsvc_notify_t notifyfn; + struct mem_pool *rxpool; + rpcsvc_drc_globals_t *drc; + + /* per-client limit of outstanding rpc requests */ + int outstanding_rpc_limit; + 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; - /* Contains list of (program, version) handlers. - * other options. - */ - - pthread_mutex_t rpclock; - - unsigned int memfactor; - - /* List of the authentication schemes available. */ - struct list_head authschemes; +/* DRC START */ +enum drc_op_type { DRC_NA = 0, DRC_IDEMPOTENT = 1, DRC_NON_IDEMPOTENT = 2 }; +typedef enum drc_op_type drc_op_type_t; - /* Reference to the options */ - dict_t *options; +enum drc_type { DRC_TYPE_NONE = 0, DRC_TYPE_IN_MEMORY = 1 }; +typedef enum drc_type drc_type_t; - /* Allow insecure ports. */ - int allow_insecure; - gf_boolean_t register_portmap; - glusterfs_ctx_t *ctx; +enum drc_lru_factor { + DRC_LRU_5_PC = 20, + DRC_LRU_10_PC = 10, + DRC_LRU_25_PC = 4, + DRC_LRU_50_PC = 2 +}; +typedef enum drc_lru_factor drc_lru_factor_t; - /* list of connections which will listen for incoming connections */ - struct list_head listeners; +enum drc_xid_state { DRC_XID_MONOTONOUS = 0, DRC_XID_WRAPPED = 1 }; +typedef enum drc_xid_state drc_xid_state_t; - /* list of programs registered with rpcsvc */ - struct list_head programs; +enum drc_op_state { DRC_OP_IN_TRANSIT = 0, DRC_OP_CACHED = 1 }; +typedef enum drc_op_state drc_op_state_t; - /* list of notification callbacks */ - struct list_head notify; - int notify_count; +enum drc_policy { DRC_LRU = 0 }; +typedef enum drc_policy drc_policy_t; - void *mydata; /* This is xlator */ - rpcsvc_notify_t notifyfn; - struct mem_pool *rxpool; -} rpcsvc_t; +/* Default policies for DRC */ +#define DRC_DEFAULT_TYPE DRC_TYPE_IN_MEMORY +#define DRC_DEFAULT_CACHE_SIZE 0x20000 +#define DRC_DEFAULT_LRU_FACTOR DRC_LRU_25_PC +/* DRC END */ #endif /* #ifndef _RPCSVC_COMMON_H */ diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c index 5805f8a5cd6..39910d481bf 100644 --- a/rpc/rpc-lib/src/rpcsvc.c +++ b/rpc/rpc-lib/src/rpcsvc.c @@ -1,39 +1,27 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #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 <glusterfs/syncop.h> +#include "rpc-drc.h" +#include "protocol-common.h" #include <errno.h> #include <pthread.h> @@ -45,887 +33,1364 @@ #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/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 { \ - request = (rpcsvc_request_t *) mem_get ((svc)->rxpool); \ - memset (request, 0, sizeof (rpcsvc_request_t)); \ - } while (0) +#define rpcsvc_alloc_request(svc, request) \ + do { \ + request = (rpcsvc_request_t *)mem_get((svc)->rxpool); \ + if (request) { \ + memset(request, 0, sizeof(rpcsvc_request_t)); \ + } else { \ + gf_log("rpcsvc", GF_LOG_ERROR, \ + "error getting memory for rpc request"); \ + } \ + } while (0) rpcsvc_listener_t * -rpcsvc_get_listener (rpcsvc_t *svc, uint16_t port, rpc_transport_t *trans); +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, ...); +rpcsvc_notify(rpc_transport_t *trans, void *mydata, rpc_transport_event_t event, + void *data, ...); +void * +rpcsvc_request_handler(void *arg); -rpcsvc_notify_wrapper_t * -rpcsvc_notify_wrapper_alloc (void) +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[]) { - rpcsvc_notify_wrapper_t *wrapper = NULL; + unsigned queue_index = queue - prog->request_queue; - wrapper = GF_CALLOC (1, sizeof (*wrapper), gf_common_mt_rpcsvc_wrapper_t); - if (!wrapper) { - goto out; + 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; } - INIT_LIST_HEAD (&wrapper->list); -out: - return wrapper; + 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) +{ + rpcsvc_notify_wrapper_t *wrapper = NULL; + + wrapper = GF_CALLOC(1, sizeof(*wrapper), gf_common_mt_rpcsvc_wrapper_t); + if (!wrapper) { + goto out; + } + + INIT_LIST_HEAD(&wrapper->list); +out: + return wrapper; +} void -rpcsvc_listener_destroy (rpcsvc_listener_t *listener) +rpcsvc_listener_destroy(rpcsvc_listener_t *listener) { - rpcsvc_t *svc = NULL; + rpcsvc_t *svc = NULL; - if (!listener) { - goto out; - } + if (!listener) { + goto out; + } - svc = listener->svc; - if (!svc) { - goto listener_free; - } + svc = listener->svc; + if (!svc) { + goto listener_free; + } - pthread_mutex_lock (&svc->rpclock); - { - list_del_init (&listener->list); - } - pthread_mutex_unlock (&svc->rpclock); + pthread_rwlock_wrlock(&svc->rpclock); + { + list_del_init(&listener->list); + } + pthread_rwlock_unlock(&svc->rpclock); listener_free: - GF_FREE (listener); + GF_FREE(listener); out: - return; + return; } rpcsvc_vector_sizer -rpcsvc_get_program_vector_sizer (rpcsvc_t *svc, uint32_t prognum, - uint32_t progver, uint32_t procnum) +rpcsvc_get_program_vector_sizer(rpcsvc_t *svc, uint32_t prognum, + uint32_t progver, int procnum) { - rpcsvc_program_t *program = NULL; - char found = 0; + rpcsvc_program_t *program = NULL; + char found = 0; - if (!svc) - return NULL; + if (!svc) + return NULL; - pthread_mutex_lock (&svc->rpclock); + pthread_rwlock_rdlock(&svc->rpclock); + { + /* Find the matching RPC program from registered list */ + list_for_each_entry(program, &svc->programs, program) { - list_for_each_entry (program, &svc->programs, program) { - if ((program->prognum == prognum) - && (program->progver == progver)) { - found = 1; - break; - } - } + if ((program->prognum == prognum) && + (program->progver == progver)) { + found = 1; + break; + } } - pthread_mutex_unlock (&svc->rpclock); + } + pthread_rwlock_unlock(&svc->rpclock); - if (found) - return program->actors[procnum].vector_sizer; - else - return NULL; + if (found) { + /* Make sure the requested procnum is supported by RPC prog */ + if ((procnum < 0) || (procnum >= program->numactors)) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "RPC procedure %d not available for Program %s", procnum, + program->progname); + return NULL; + } + + /* SUCCESS: Supported procedure */ + return program->actors[procnum].vector_sizer; + } + + return NULL; /* FAIL */ } -/* This needs to change to returning errors, since - * we need to return RPC specific error messages when some - * of the pointers below are NULL. - */ -rpcsvc_actor_t * -rpcsvc_program_actor (rpcsvc_request_t *req) +gf_boolean_t +rpcsvc_can_outstanding_req_be_ignored(rpcsvc_request_t *req) { - rpcsvc_program_t *program = NULL; - int err = SYSTEM_ERR; - rpcsvc_actor_t *actor = NULL; - rpcsvc_t *svc = NULL; - char found = 0; + /* + * If outstanding_rpc_limit is reached because of blocked locks and + * throttling is attempted then no unlock requests will be received. So + * the outstanding request count will never change i.e. it will always + * be equal to the limit. This also leads to ping timer expiry on + * client. + */ + + /* + * This is a hack and a necessity until grantedlock == fop completion. + * Ideally if we get a blocking lock request which cannot be granted + * right now, we should unwind the fop saying “request registered, will + * notify you when granted”, which is very hard to implement at the + * moment. Until we bring in such mechanism, we will need to live with + * not rate-limiting INODELK/ENTRYLK/LK fops + */ + + if ((req->prognum == GLUSTER_FOP_PROGRAM) && + (req->progver == GLUSTER_FOP_VERSION)) { + if ((req->procnum == GFS3_OP_INODELK) || + (req->procnum == GFS3_OP_FINODELK) || + (req->procnum == GFS3_OP_ENTRYLK) || + (req->procnum == GFS3_OP_FENTRYLK) || (req->procnum == GFS3_OP_LK)) + return _gf_true; + } + return _gf_false; +} - if (!req) - goto err; +int +rpcsvc_request_outstanding(rpcsvc_request_t *req, int delta) +{ + int ret = -1; + int old_count = 0; + int new_count = 0; + int limit = 0; + gf_boolean_t throttle = _gf_false; - svc = req->svc; - pthread_mutex_lock (&svc->rpclock); - { - list_for_each_entry (program, &svc->programs, program) { - if (program->prognum == req->prognum) { - err = PROG_MISMATCH; - } + if (!req) + goto out; - if ((program->prognum == req->prognum) - && (program->progver == req->progver)) { - found = 1; - break; - } - } - } - pthread_mutex_unlock (&svc->rpclock); - - if (!found) { - if (err != PROG_MISMATCH) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, - "RPC program not available (req %u %u)", - req->prognum, req->progver); - err = PROG_UNAVAIL; - goto err; - } + throttle = rpcsvc_get_throttle(req->svc); + if (!throttle) { + ret = 0; + goto out; + } - gf_log (GF_RPCSVC, GF_LOG_WARNING, - "RPC program version not available (req %u %u)", - req->prognum, req->progver); - goto err; - } - req->prog = program; - if (!program->actors) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, - "RPC Actor not found for program %s %d", - program->progname, program->prognum); - err = SYSTEM_ERR; - goto err; - } + if (rpcsvc_can_outstanding_req_be_ignored(req)) { + ret = 0; + goto out; + } - if ((req->procnum < 0) || (req->procnum >= program->numactors)) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC Program procedure not" - " available for procedure %d in %s", req->procnum, - program->progname); - err = PROC_UNAVAIL; - goto err; - } + pthread_mutex_lock(&req->trans->lock); + { + limit = req->svc->outstanding_rpc_limit; + if (!limit) + goto unlock; - actor = &program->actors[req->procnum]; - if (!actor->actor) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC Program procedure not" - " available for procedure %d in %s", req->procnum, - program->progname); - err = PROC_UNAVAIL; - actor = NULL; - goto err; - } + old_count = req->trans->outstanding_rpc_count; + req->trans->outstanding_rpc_count += delta; + new_count = req->trans->outstanding_rpc_count; - err = SUCCESS; - gf_log (GF_RPCSVC, GF_LOG_TRACE, "Actor found: %s - %s", - program->progname, actor->procname); -err: - if (req) - req->rpc_err = err; + if (old_count <= limit && new_count > limit) + ret = rpc_transport_throttle(req->trans, _gf_true); + + if (old_count > limit && new_count <= limit) + ret = rpc_transport_throttle(req->trans, _gf_false); + } +unlock: + pthread_mutex_unlock(&req->trans->lock); - return actor; +out: + return ret; } +/* This needs to change to returning errors, since + * we need to return RPC specific error messages when some + * of the pointers below are NULL. + */ +rpcsvc_actor_t * +rpcsvc_program_actor(rpcsvc_request_t *req) +{ + rpcsvc_program_t *program = NULL; + int err = SYSTEM_ERR; + rpcsvc_actor_t *actor = NULL; + rpcsvc_t *svc = NULL; + char found = 0; + char *peername = NULL; + + if (!req) + goto err; + + svc = req->svc; + peername = req->trans->peerinfo.identifier; + pthread_rwlock_rdlock(&svc->rpclock); + { + list_for_each_entry(program, &svc->programs, program) + { + if (program->prognum == req->prognum) { + err = PROG_MISMATCH; + } + + if ((program->prognum == req->prognum) && + (program->progver == req->progver)) { + found = 1; + break; + } + } + } + pthread_rwlock_unlock(&svc->rpclock); + + if (!found) { + if (err != PROG_MISMATCH) { + /* log in DEBUG when nfs clients try to see if + * ACL requests are accepted by nfs server + */ + gf_log( + GF_RPCSVC, + (req->prognum == ACL_PROGRAM) ? GF_LOG_DEBUG : GF_LOG_WARNING, + "RPC program not available (req %u %u) for %s", req->prognum, + req->progver, peername); + err = PROG_UNAVAIL; + goto err; + } + + gf_log(GF_RPCSVC, GF_LOG_WARNING, + "RPC program version not available (req %u %u) for %s", + req->prognum, req->progver, peername); + goto err; + } + req->prog = program; + if (!program->actors) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, + "RPC Actor not found for program %s %d for %s", + program->progname, program->prognum, peername); + err = SYSTEM_ERR; + goto err; + } + + if ((req->procnum < 0) || (req->procnum >= program->numactors)) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "RPC Program procedure not" + " available for procedure %d in %s for %s", + req->procnum, program->progname, peername); + err = PROC_UNAVAIL; + goto err; + } + + actor = &program->actors[req->procnum]; + if (!actor->actor) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "RPC Program procedure not" + " available for procedure %d in %s for %s", + req->procnum, program->progname, peername); + err = PROC_UNAVAIL; + actor = NULL; + goto err; + } + + if (svc->xl->ctx->measure_latency) { + timespec_now(&req->begin); + } + + req->ownthread = program->ownthread; + req->synctask = program->synctask; + + err = SUCCESS; + gf_log(GF_RPCSVC, GF_LOG_TRACE, "Actor found: %s - %s for %s", + program->progname, actor->procname, peername); +err: + if (req) + req->rpc_err = err; + + return actor; +} /* this procedure can only pass 4 arguments to registered notifyfn. To send more * arguments call wrapper->notify directly. */ -inline void -rpcsvc_program_notify (rpcsvc_listener_t *listener, rpcsvc_event_t event, - void *data) +static void +rpcsvc_program_notify(rpcsvc_listener_t *listener, rpcsvc_event_t event, + void *data) { - rpcsvc_notify_wrapper_t *wrapper = NULL; + rpcsvc_notify_wrapper_t *wrapper = NULL; - if (!listener) { - goto out; - } + if (!listener) { + goto out; + } - list_for_each_entry (wrapper, &listener->svc->notify, list) { - if (wrapper->notify) { - wrapper->notify (listener->svc, - wrapper->data, - event, data); - } + list_for_each_entry(wrapper, &listener->svc->notify, list) + { + if (wrapper->notify) { + wrapper->notify(listener->svc, wrapper->data, event, data); } + } out: - return; + return; } - -inline int -rpcsvc_accept (rpcsvc_t *svc, rpc_transport_t *listen_trans, - rpc_transport_t *new_trans) +static int +rpcsvc_accept(rpcsvc_t *svc, rpc_transport_t *listen_trans, + rpc_transport_t *new_trans) { - rpcsvc_listener_t *listener = NULL; - int32_t ret = -1; + rpcsvc_listener_t *listener = NULL; + int32_t ret = -1; - listener = rpcsvc_get_listener (svc, -1, listen_trans); - if (listener == NULL) { - goto out; - } + listener = rpcsvc_get_listener(svc, -1, listen_trans); + if (listener == NULL) { + goto out; + } - rpcsvc_program_notify (listener, RPCSVC_EVENT_ACCEPT, new_trans); - ret = 0; + rpcsvc_program_notify(listener, RPCSVC_EVENT_ACCEPT, new_trans); + ret = 0; out: - return ret; + return ret; } - void -rpcsvc_request_destroy (rpcsvc_request_t *req) +rpcsvc_request_destroy(rpcsvc_request_t *req) { - if (!req) { - goto out; - } + if (!req) { + goto out; + } - if (req->iobref) { - iobref_unref (req->iobref); - } + if (req->iobref) { + iobref_unref(req->iobref); + } + + /* This marks the "end" of an RPC request. Reply is + completely written to the socket and is on the way + to the client. It is time to decrement the + outstanding request counter by 1. + */ + if (req->prognum) // Only for initialized requests + rpcsvc_request_outstanding(req, -1); + + rpc_transport_unref(req->trans); - rpc_transport_unref (req->trans); + GF_FREE(req->auxgidlarge); - mem_put (req); + mem_put(req); out: - return; + return; } +rpcsvc_request_t * +rpcsvc_request_init(rpcsvc_t *svc, rpc_transport_t *trans, + struct rpc_msg *callmsg, struct iovec progmsg, + rpc_transport_pollin_t *msg, rpcsvc_request_t *req) +{ + int i = 0; + + if ((!trans) || (!callmsg) || (!req) || (!msg)) + return NULL; + + /* We start a RPC request as always denied. */ + req->rpc_status = MSG_DENIED; + req->xid = rpc_call_xid(callmsg); + req->prognum = rpc_call_program(callmsg); + req->progver = rpc_call_progver(callmsg); + req->procnum = rpc_call_progproc(callmsg); + req->trans = rpc_transport_ref(trans); + req->count = msg->count; + req->msg[0] = progmsg; + req->iobref = iobref_ref(msg->iobref); + if (msg->vectored) { + /* msg->vector[MAX_IOVEC] is defined in structure. prevent a + out of bound access */ + for (i = 1; i < min(msg->count, MAX_IOVEC); i++) { + req->msg[i] = msg->vector[i]; + } + } + + req->svc = svc; + req->trans_private = msg->private; + + INIT_LIST_HEAD(&req->txlist); + INIT_LIST_HEAD(&req->request_list); + req->payloadsize = 0; + + /* By this time, the data bytes for the auth scheme would have already + * been copied into the required sections of the req structure, + * we just need to fill in the meta-data about it now. + */ + rpcsvc_auth_request_init(req, callmsg); + return req; +} rpcsvc_request_t * -rpcsvc_request_init (rpcsvc_t *svc, rpc_transport_t *trans, - struct rpc_msg *callmsg, - struct iovec progmsg, rpc_transport_pollin_t *msg, - rpcsvc_request_t *req) +rpcsvc_request_create(rpcsvc_t *svc, rpc_transport_t *trans, + rpc_transport_pollin_t *msg) { - int i = 0; + char *msgbuf = NULL; + struct rpc_msg rpcmsg; + struct iovec progmsg; /* RPC Program payload */ + rpcsvc_request_t *req = NULL; + size_t msglen = 0; + int ret = -1; + + if (!svc || !trans || !svc->rxpool) + return NULL; + + /* We need to allocate the request before actually calling + * rpcsvc_request_init on the request so that we, can fill the auth + * data directly into the request structure from the message iobuf. + * This avoids a need to keep a temp buffer into which the auth data + * would've been copied otherwise. + */ + rpcsvc_alloc_request(svc, req); + if (!req) { + goto err; + } + + msgbuf = msg->vector[0].iov_base; + msglen = msg->vector[0].iov_len; + + ret = xdr_to_rpc_call(msgbuf, msglen, &rpcmsg, &progmsg, req->cred.authdata, + req->verf.authdata); + + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, "RPC call decoding failed"); + rpcsvc_request_seterr(req, GARBAGE_ARGS); + req->trans = rpc_transport_ref(trans); + req->svc = svc; + goto err; + } + + ret = -1; + rpcsvc_request_init(svc, trans, &rpcmsg, progmsg, msg, req); + + gf_log(GF_RPCSVC, GF_LOG_TRACE, + "received rpc-message " + "(XID: 0x%" GF_PRI_RPC_XID ", Ver: %" GF_PRI_RPC_VERSION + ", Program: %" GF_PRI_RPC_PROG_ID + ", " + "ProgVers: %" GF_PRI_RPC_PROG_VERS ", Proc: %" GF_PRI_RPC_PROC + ") " + "from rpc-transport (%s)", + rpc_call_xid(&rpcmsg), rpc_call_rpcvers(&rpcmsg), + rpc_call_program(&rpcmsg), rpc_call_progver(&rpcmsg), + rpc_call_progproc(&rpcmsg), trans->name); + + /* We just received a new request from the wire. Account for + it in the outsanding request counter to make sure we don't + ingest too many concurrent requests from the same client. + */ + if (req->prognum) // Only for initialized requests + ret = rpcsvc_request_outstanding(req, +1); + + if (rpc_call_rpcvers(&rpcmsg) != 2) { + /* LOG- TODO: print rpc version, also print the peerinfo + from transport */ + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "RPC version not supported " + "(XID: 0x%" GF_PRI_RPC_XID ", Ver: %" GF_PRI_RPC_VERSION + ", Program: %" GF_PRI_RPC_PROG_ID + ", " + "ProgVers: %" GF_PRI_RPC_PROG_VERS ", Proc: %" GF_PRI_RPC_PROC + ") " + "from trans (%s)", + rpc_call_xid(&rpcmsg), rpc_call_rpcvers(&rpcmsg), + rpc_call_program(&rpcmsg), rpc_call_progver(&rpcmsg), + rpc_call_progproc(&rpcmsg), trans->name); + rpcsvc_request_seterr(req, RPC_MISMATCH); + goto err; + } + + ret = rpcsvc_authenticate(req); + if (ret == RPCSVC_AUTH_REJECT) { + /* No need to set auth_err, that is the responsibility of + * the authentication handler since only that know what exact + * error happened. + */ + rpcsvc_request_seterr(req, AUTH_ERROR); + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "auth failed on request. " + "(XID: 0x%" GF_PRI_RPC_XID ", Ver: %" GF_PRI_RPC_VERSION + ", Program: %" GF_PRI_RPC_PROG_ID + ", " + "ProgVers: %" GF_PRI_RPC_PROG_VERS ", Proc: %" GF_PRI_RPC_PROC + ") " + "from trans (%s)", + rpc_call_xid(&rpcmsg), rpc_call_rpcvers(&rpcmsg), + rpc_call_program(&rpcmsg), rpc_call_progver(&rpcmsg), + rpc_call_progproc(&rpcmsg), trans->name); + ret = -1; + goto err; + } + + /* If the error is not RPC_MISMATCH, we consider the call as accepted + * since we are not handling authentication failures for now. + */ + req->rpc_status = MSG_ACCEPTED; + req->reply = NULL; + ret = 0; +err: + if (ret == -1) { + ret = rpcsvc_error_reply(req); + if (ret) + gf_log("rpcsvc", GF_LOG_WARNING, "failed to queue error reply"); + req = NULL; + } - if ((!trans) || (!callmsg)|| (!req) || (!msg)) - return NULL; + return req; +} - /* We start a RPC request as always denied. */ - req->rpc_status = MSG_DENIED; - req->xid = rpc_call_xid (callmsg); - req->prognum = rpc_call_program (callmsg); - req->progver = rpc_call_progver (callmsg); - req->procnum = rpc_call_progproc (callmsg); - req->trans = rpc_transport_ref (trans); - req->count = msg->count; - req->msg[0] = progmsg; - req->iobref = iobref_ref (msg->iobref); - if (msg->vectored) { - for (i = 1; i < msg->count; i++) { - req->msg[i] = msg->vector[i]; - } - } +int +rpcsvc_check_and_reply_error(int ret, call_frame_t *frame, void *opaque) +{ + rpcsvc_request_t *req = NULL; - req->svc = svc; - req->trans_private = msg->private; + req = opaque; - INIT_LIST_HEAD (&req->txlist); - req->payloadsize = 0; + if (ret) + gf_log("rpcsvc", GF_LOG_ERROR, + "rpc actor (%d:%d:%d) failed to complete successfully", + req->prognum, req->progver, req->procnum); - /* By this time, the data bytes for the auth scheme would have already - * been copied into the required sections of the req structure, - * we just need to fill in the meta-data about it now. - */ - req->cred.flavour = rpc_call_cred_flavour (callmsg); - req->cred.datalen = rpc_call_cred_len (callmsg); - req->verf.flavour = rpc_call_verf_flavour (callmsg); - req->verf.datalen = rpc_call_verf_len (callmsg); + if (ret == RPCSVC_ACTOR_ERROR) { + ret = rpcsvc_error_reply(req); + if (ret) + gf_log("rpcsvc", GF_LOG_WARNING, "failed to queue error reply"); + } - /* AUTH */ - rpcsvc_auth_request_init (req); - return req; + return 0; } - -rpcsvc_request_t * -rpcsvc_request_create (rpcsvc_t *svc, rpc_transport_t *trans, - rpc_transport_pollin_t *msg) +void +rpcsvc_queue_event_thread_death(rpcsvc_t *svc, rpcsvc_program_t *prog, int gen) { - char *msgbuf = NULL; - struct rpc_msg rpcmsg; - struct iovec progmsg; /* RPC Program payload */ - rpcsvc_request_t *req = NULL; - size_t msglen = 0; - int ret = -1; - - if (!svc || !trans) - return NULL; - - /* We need to allocate the request before actually calling - * rpcsvc_request_init on the request so that we, can fill the auth - * data directly into the request structure from the message iobuf. - * This avoids a need to keep a temp buffer into which the auth data - * would've been copied otherwise. - */ - rpcsvc_alloc_request (svc, req); - if (!req) { - goto err; - } + 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; + } - msgbuf = msg->vector[0].iov_base; - msglen = msg->vector[0].iov_len; + num = ((unsigned long)value) - 1; - ret = xdr_to_rpc_call (msgbuf, msglen, &rpcmsg, &progmsg, - req->cred.authdata,req->verf.authdata); + queue = &prog->request_queue[num]; - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, "RPC call decoding failed"); - rpcsvc_request_seterr (req, GARBAGE_ARGS); - req->trans = rpc_transport_ref (trans); - req->svc = svc; - goto err; - } + 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; + } - ret = -1; - rpcsvc_request_init (svc, trans, &rpcmsg, progmsg, msg, req); - - gf_log (GF_RPCSVC, GF_LOG_TRACE, "received rpc-message (XID: 0x%lx, " - "Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) from" - " rpc-transport (%s)", rpc_call_xid (&rpcmsg), - rpc_call_rpcvers (&rpcmsg), rpc_call_program (&rpcmsg), - rpc_call_progver (&rpcmsg), rpc_call_progproc (&rpcmsg), - trans->name); - - if (rpc_call_rpcvers (&rpcmsg) != 2) { - /* LOG- TODO: print rpc version, also print the peerinfo - from transport */ - gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC version not supported " - "(XID: 0x%lx, Ver: %ld, Prog: %ld, ProgVers: %ld, " - "Proc: %ld) from trans (%s)", rpc_call_xid (&rpcmsg), - rpc_call_rpcvers (&rpcmsg), rpc_call_program (&rpcmsg), - rpc_call_progver (&rpcmsg), rpc_call_progproc (&rpcmsg), - trans->name); - rpcsvc_request_seterr (req, RPC_MISMATCH); - goto err; - } + 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); - ret = rpcsvc_authenticate (req); - if (ret == RPCSVC_AUTH_REJECT) { - /* No need to set auth_err, that is the responsibility of - * the authentication handler since only that know what exact - * error happened. - */ - rpcsvc_request_seterr (req, AUTH_ERROR); - gf_log (GF_RPCSVC, GF_LOG_ERROR, "auth failed on request. " - "(XID: 0x%lx, Ver: %ld, Prog: %ld, ProgVers: %ld, " - "Proc: %ld) from trans (%s)", rpc_call_xid (&rpcmsg), - rpc_call_rpcvers (&rpcmsg), rpc_call_program (&rpcmsg), - rpc_call_progver (&rpcmsg), rpc_call_progproc (&rpcmsg), - trans->name); - ret = -1; - goto err; - } + 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 the error is not RPC_MISMATCH, we consider the call as accepted - * since we are not handling authentication failures for now. - */ - req->rpc_status = MSG_ACCEPTED; - ret = 0; -err: - if (ret == -1) { - ret = rpcsvc_error_reply (req); - if (ret) - gf_log ("rpcsvc", GF_LOG_WARNING, - "failed to queue error reply"); - req = NULL; - } + if (empty && queue->waiting) + pthread_cond_signal(&queue->queue_cond); + } + pthread_mutex_unlock(&queue->queue_lock); - return req; + return; } - int -rpcsvc_handle_rpc_call (rpcsvc_t *svc, rpc_transport_t *trans, - rpc_transport_pollin_t *msg) +rpcsvc_handle_event_thread_death(rpcsvc_t *svc, rpc_transport_t *trans, int gen) { - rpcsvc_actor_t *actor = NULL; - rpcsvc_request_t *req = NULL; - int ret = -1; - uint16_t port = 0; - gf_boolean_t is_unix = _gf_false; - gf_boolean_t unprivileged = _gf_false; + 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); - if (!trans || !svc) - return -1; + return 0; +} - switch (trans->peerinfo.sockaddr.ss_family) { +int +rpcsvc_handle_rpc_call(rpcsvc_t *svc, rpc_transport_t *trans, + rpc_transport_pollin_t *msg) +{ + rpcsvc_actor_t *actor = NULL; + rpcsvc_actor actor_fn = NULL; + rpcsvc_request_t *req = NULL; + int ret = -1; + uint16_t port = 0; + gf_boolean_t is_unix = _gf_false, empty = _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; + + switch (trans->peerinfo.sockaddr.ss_family) { case AF_INET: - port = ((struct sockaddr_in *)&trans->peerinfo.sockaddr)->sin_port; - break; + port = ((struct sockaddr_in *)&trans->peerinfo.sockaddr)->sin_port; + break; case AF_INET6: - port = ((struct sockaddr_in6 *)&trans->peerinfo.sockaddr)->sin6_port; - break; + port = ((struct sockaddr_in6 *)&trans->peerinfo.sockaddr) + ->sin6_port; + break; case AF_UNIX: - is_unix = _gf_true; - break; + is_unix = _gf_true; + break; default: - gf_log (GF_RPCSVC, GF_LOG_ERROR, - "invalid address family (%d)", - trans->peerinfo.sockaddr.ss_family); - return -1; - } + gf_log(GF_RPCSVC, GF_LOG_ERROR, "invalid address family (%d)", + trans->peerinfo.sockaddr.ss_family); + return -1; + } + if (is_unix == _gf_false) { + port = ntohs(port); + gf_log("rpcsvc", GF_LOG_TRACE, "Client port: %d", (int)port); - if (is_unix == _gf_false) { - port = ntohs (port); + if (port >= 1024) + unprivileged = _gf_true; + } - gf_log ("rpcsvc", GF_LOG_TRACE, "Client port: %d", (int)port); + req = rpcsvc_request_create(svc, trans, msg); + if (!req) + goto out; - if (port > 1024) - unprivileged = _gf_true; - } + if (!rpcsvc_request_accepted(req)) + goto err_reply; - req = rpcsvc_request_create (svc, trans, msg); - if (!req) - goto err; + actor = rpcsvc_program_actor(req); + if (!actor) + goto err_reply; - if (!rpcsvc_request_accepted (req)) - goto err_reply; + if (0 == svc->allow_insecure && unprivileged && !actor->unprivileged) { + /* Non-privileged user, fail request */ + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Request received from non-" + "privileged port. Failing request for %s.", + req->trans->peerinfo.identifier); + req->rpc_status = MSG_DENIED; + req->rpc_err = AUTH_ERROR; + req->auth_err = RPCSVC_AUTH_REJECT; + goto err_reply; + } - actor = rpcsvc_program_actor (req); - if (!actor) - goto err_reply; + /* DRC */ + if (rpcsvc_need_drc(req)) { + drc = req->svc->drc; - if (0 == svc->allow_insecure && unprivileged && !actor->unprivileged) { - /* Non-privileged user, fail request */ - gf_log ("glusterd", GF_LOG_ERROR, - "Request received from non-" - "privileged port. Failing request"); - rpcsvc_request_destroy (req); - return -1; - } + LOCK(&drc->lock); + { + reply = rpcsvc_drc_lookup(req); + + /* retransmission of completed request, send cached reply */ + if (reply && reply->state == DRC_OP_CACHED) { + gf_log(GF_RPCSVC, GF_LOG_INFO, + "duplicate request:" + " XID: 0x%x", + req->xid); + ret = rpcsvc_send_cached_reply(req, reply); + drc->cache_hits++; + UNLOCK(&drc->lock); + goto out; - if (req->rpc_err == SUCCESS) { - /* Before going to xlator code, set the THIS properly */ - THIS = svc->mydata; + } /* retransmitted request, original op in transit, drop it */ + else if (reply && reply->state == DRC_OP_IN_TRANSIT) { + gf_log(GF_RPCSVC, GF_LOG_INFO, + "op in transit," + " discarding. XID: 0x%x", + req->xid); + ret = 0; + drc->intransit_hits++; + rpcsvc_request_destroy(req); + UNLOCK(&drc->lock); + goto out; - if (req->count == 2) { - if (actor->vector_actor) { - ret = actor->vector_actor (req, &req->msg[1], 1, - req->iobref); + } /* fresh request, cache it as in-transit and proceed */ + else { + ret = rpcsvc_cache_request(req); + } + } + UNLOCK(&drc->lock); + } + + if (req->rpc_err == SUCCESS) { + /* Before going to xlator code, set the THIS properly */ + THIS = svc->xl; + + actor_fn = actor->actor; + + if (!actor_fn) { + rpcsvc_request_seterr(req, PROC_UNAVAIL); + /* LOG TODO: print more info about procnum, + prognum etc, also print transport info */ + gf_log(GF_RPCSVC, GF_LOG_ERROR, "No vectored handler present"); + ret = RPCSVC_ACTOR_ERROR; + goto err_reply; + } + + if (req->synctask) { + ret = synctask_new(THIS->ctx->env, (synctask_fn_t)actor_fn, + rpcsvc_check_and_reply_error, NULL, req); + } else if (req->ownthread) { + 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 { - rpcsvc_request_seterr (req, PROC_UNAVAIL); - /* LOG TODO: print more info about procnum, - prognum etc, also print transport info */ - gf_log (GF_RPCSVC, GF_LOG_ERROR, - "No vectored handler present"); - ret = RPCSVC_ACTOR_ERROR; + spawn_request_handler = 1; } - } else if (actor->actor) { - ret = actor->actor (req); + } } - } + 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; + } + } -err_reply: - if (ret == RPCSVC_ACTOR_ERROR) { - ret = rpcsvc_error_reply (req); + pthread_mutex_lock(&queue->queue_lock); + { + empty = list_empty(&queue->request_queue); + + list_add_tail(&req->request_list, &queue->request_queue); + + if (empty && queue->waiting) + pthread_cond_signal(&queue->queue_cond); + } + pthread_mutex_unlock(&queue->queue_lock); + + ret = 0; + } else { + noqueue: + ret = actor_fn(req); } + } - if (ret) - gf_log ("rpcsvc", GF_LOG_WARNING, "failed to queue error reply"); +err_reply: - /* No need to propagate error beyond this function since the reply - * has now been queued. */ - ret = 0; + ret = rpcsvc_check_and_reply_error(ret, NULL, req); + /* No need to propagate error beyond this function since the reply + * has now been queued. */ + ret = 0; -err: - return ret; +out: + return ret; } - int -rpcsvc_handle_disconnect (rpcsvc_t *svc, rpc_transport_t *trans) +rpcsvc_handle_disconnect(rpcsvc_t *svc, rpc_transport_t *trans) { - rpcsvc_event_t event; - rpcsvc_notify_wrapper_t *wrappers = NULL, *wrapper; - int32_t ret = -1, i = 0, wrapper_count = 0; - rpcsvc_listener_t *listener = NULL; + rpcsvc_event_t event; + rpcsvc_notify_wrapper_t *wrappers = NULL, *wrapper; + int32_t ret = -1, i = 0, wrapper_count = 0; + rpcsvc_listener_t *listener = NULL; - event = (trans->listener == NULL) ? RPCSVC_EVENT_LISTENER_DEAD - : RPCSVC_EVENT_DISCONNECT; + event = (trans->listener == NULL) ? RPCSVC_EVENT_LISTENER_DEAD + : RPCSVC_EVENT_DISCONNECT; - pthread_mutex_lock (&svc->rpclock); - { - wrappers = GF_CALLOC (svc->notify_count, sizeof (*wrapper), - gf_common_mt_rpcsvc_wrapper_t); - if (!wrappers) { - goto unlock; - } + pthread_rwlock_rdlock(&svc->rpclock); + { + if (!svc->notify_count) + goto unlock; - list_for_each_entry (wrapper, &svc->notify, list) { - if (wrapper->notify) { - wrappers[i++] = *wrapper; - } - } + wrappers = GF_CALLOC(svc->notify_count, sizeof(*wrapper), + gf_common_mt_rpcsvc_wrapper_t); + if (!wrappers) { + goto unlock; + } - wrapper_count = i; + list_for_each_entry(wrapper, &svc->notify, list) + { + if (wrapper->notify) { + wrappers[i++] = *wrapper; + } } -unlock: - pthread_mutex_unlock (&svc->rpclock); - if (wrappers) { - for (i = 0; i < wrapper_count; i++) { - wrappers[i].notify (svc, wrappers[i].data, - event, trans); - } + wrapper_count = i; + } +unlock: + pthread_rwlock_unlock(&svc->rpclock); - GF_FREE (wrappers); + if (wrappers) { + for (i = 0; i < wrapper_count; i++) { + wrappers[i].notify(svc, wrappers[i].data, event, trans); } - if (event == RPCSVC_EVENT_LISTENER_DEAD) { - listener = rpcsvc_get_listener (svc, -1, trans->listener); - rpcsvc_listener_destroy (listener); - } + GF_FREE(wrappers); + } - return ret; -} + if (event == RPCSVC_EVENT_LISTENER_DEAD) { + listener = rpcsvc_get_listener(svc, -1, trans->listener); + rpcsvc_listener_destroy(listener); + } + return ret; +} int -rpcsvc_notify (rpc_transport_t *trans, void *mydata, - rpc_transport_event_t event, void *data, ...) +rpcsvc_notify(rpc_transport_t *trans, void *mydata, rpc_transport_event_t event, + void *data, ...) { - int ret = -1; - rpc_transport_pollin_t *msg = NULL; - rpc_transport_t *new_trans = NULL; - rpcsvc_t *svc = NULL; - rpcsvc_listener_t *listener = NULL; - - svc = mydata; - if (svc == NULL) { - goto out; - } - - switch (event) { + int ret = -1; + rpc_transport_pollin_t *msg = NULL; + rpc_transport_t *new_trans = NULL; + rpcsvc_t *svc = NULL; + rpcsvc_listener_t *listener = NULL; + + svc = mydata; + if (svc == NULL) { + goto out; + } + + switch (event) { case RPC_TRANSPORT_ACCEPT: - new_trans = data; - ret = rpcsvc_accept (svc, trans, new_trans); - break; + new_trans = data; + ret = rpcsvc_accept(svc, trans, new_trans); + break; case RPC_TRANSPORT_DISCONNECT: - ret = rpcsvc_handle_disconnect (svc, trans); - break; + ret = rpcsvc_handle_disconnect(svc, trans); + break; case RPC_TRANSPORT_MSG_RECEIVED: - msg = data; - ret = rpcsvc_handle_rpc_call (svc, trans, msg); - break; + msg = data; + ret = rpcsvc_handle_rpc_call(svc, trans, msg); + break; case RPC_TRANSPORT_MSG_SENT: - ret = 0; - break; + ret = 0; + break; case RPC_TRANSPORT_CONNECT: - /* do nothing, no need for rpcsvc to handle this, client should - * handle this event - */ - /* print info about transport too : LOG TODO */ - gf_log ("rpcsvc", GF_LOG_CRITICAL, - "got CONNECT event, which should have not come"); - ret = 0; - break; + /* do nothing, no need for rpcsvc to handle this, client should + * handle this event + */ + /* print info about transport too : LOG TODO */ + gf_log("rpcsvc", GF_LOG_CRITICAL, + "got CONNECT event, which should have not come"); + ret = 0; + break; case RPC_TRANSPORT_CLEANUP: - listener = rpcsvc_get_listener (svc, -1, trans->listener); - if (listener == NULL) { - goto out; - } + listener = rpcsvc_get_listener(svc, -1, trans->listener); + if (listener == NULL) { + goto out; + } - rpcsvc_program_notify (listener, RPCSVC_EVENT_TRANSPORT_DESTROY, - trans); - ret = 0; - break; + rpcsvc_program_notify(listener, RPCSVC_EVENT_TRANSPORT_DESTROY, + trans); + ret = 0; + break; case RPC_TRANSPORT_MAP_XID_REQUEST: - /* FIXME: think about this later */ - gf_log ("rpcsvc", GF_LOG_CRITICAL, - "got MAP_XID event, which should have not come"); - ret = 0; - break; - } + /* FIXME: think about this later */ + gf_log("rpcsvc", GF_LOG_CRITICAL, + "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: - return ret; + return ret; } - /* Given the RPC reply structure and the payload handed by the RPC program, * encode the RPC record header into the buffer pointed by recordstart. */ struct iovec -rpcsvc_record_build_header (char *recordstart, size_t rlen, - struct rpc_msg reply, size_t payload) +rpcsvc_record_build_header(char *recordstart, size_t rlen, struct rpc_msg reply, + size_t payload) { - struct iovec replyhdr; - struct iovec txrecord = {0, 0}; - size_t fraglen = 0; - int ret = -1; - - /* After leaving aside the 4 bytes for the fragment header, lets - * encode the RPC reply structure into the buffer given to us. - */ - ret = rpc_reply_to_xdr (&reply, recordstart, rlen, &replyhdr); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, "Failed to create RPC reply"); - goto err; - } - - fraglen = payload + replyhdr.iov_len; - gf_log (GF_RPCSVC, GF_LOG_TRACE, "Reply fraglen %zu, payload: %zu, " - "rpc hdr: %zu", fraglen, payload, replyhdr.iov_len); - - txrecord.iov_base = recordstart; - - /* Remember, this is only the vec for the RPC header and does not - * include the payload above. We needed the payload only to calculate - * the size of the full fragment. This size is sent in the fragment - * header. - */ - txrecord.iov_len = replyhdr.iov_len; + struct iovec replyhdr; + struct iovec txrecord = {0, 0}; + size_t fraglen = 0; + int ret = -1; + + /* After leaving aside the 4 bytes for the fragment header, lets + * encode the RPC reply structure into the buffer given to us. + */ + ret = rpc_reply_to_xdr(&reply, recordstart, rlen, &replyhdr); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, "Failed to create RPC reply"); + goto err; + } + + fraglen = payload + replyhdr.iov_len; + gf_log(GF_RPCSVC, GF_LOG_TRACE, + "Reply fraglen %zu, payload: %zu, " + "rpc hdr: %zu", + fraglen, payload, replyhdr.iov_len); + + txrecord.iov_base = recordstart; + + /* Remember, this is only the vec for the RPC header and does not + * include the payload above. We needed the payload only to calculate + * the size of the full fragment. This size is sent in the fragment + * header. + */ + txrecord.iov_len = replyhdr.iov_len; err: - return txrecord; + return txrecord; } -inline int -rpcsvc_get_callid (rpcsvc_t *rpc) +static uint32_t +rpc_callback_new_callid(struct rpc_transport *trans) { - return GF_UNIVERSAL_ANSWER; + uint32_t callid = 0; + + pthread_mutex_lock(&trans->lock); + { + callid = ++trans->xid; + } + pthread_mutex_unlock(&trans->lock); + + return callid; } int -rpcsvc_fill_callback (int prognum, int progver, int procnum, int payload, - uint64_t xid, struct rpc_msg *request) +rpcsvc_fill_callback(int prognum, int progver, int procnum, int payload, + uint32_t xid, struct rpc_msg *request) { - int ret = -1; + int ret = -1; - if (!request) { - goto out; - } + if (!request) { + goto out; + } - memset (request, 0, sizeof (*request)); + memset(request, 0, sizeof(*request)); - request->rm_xid = xid; - request->rm_direction = CALL; + request->rm_xid = xid; + request->rm_direction = CALL; - request->rm_call.cb_rpcvers = 2; - request->rm_call.cb_prog = prognum; - request->rm_call.cb_vers = progver; - request->rm_call.cb_proc = procnum; + request->rm_call.cb_rpcvers = 2; + request->rm_call.cb_prog = prognum; + request->rm_call.cb_vers = progver; + request->rm_call.cb_proc = procnum; - request->rm_call.cb_cred.oa_flavor = AUTH_NONE; - request->rm_call.cb_cred.oa_base = NULL; - request->rm_call.cb_cred.oa_length = 0; + request->rm_call.cb_cred.oa_flavor = AUTH_NONE; + request->rm_call.cb_cred.oa_base = NULL; + request->rm_call.cb_cred.oa_length = 0; - request->rm_call.cb_verf.oa_flavor = AUTH_NONE; - request->rm_call.cb_verf.oa_base = NULL; - request->rm_call.cb_verf.oa_length = 0; + request->rm_call.cb_verf.oa_flavor = AUTH_NONE; + request->rm_call.cb_verf.oa_base = NULL; + request->rm_call.cb_verf.oa_length = 0; - ret = 0; + ret = 0; out: - return ret; + return ret; } - struct iovec -rpcsvc_callback_build_header (char *recordstart, size_t rlen, +rpcsvc_callback_build_header(char *recordstart, size_t rlen, struct rpc_msg *request, size_t payload) { - struct iovec requesthdr = {0, }; - struct iovec txrecord = {0, 0}; - int ret = -1; - size_t fraglen = 0; - - ret = rpc_request_to_xdr (request, recordstart, rlen, &requesthdr); - if (ret == -1) { - gf_log ("rpcsvc", GF_LOG_WARNING, - "Failed to create RPC request"); - goto out; - } - - fraglen = payload + requesthdr.iov_len; - gf_log ("rpcsvc", GF_LOG_TRACE, "Request fraglen %zu, payload: %zu, " - "rpc hdr: %zu", fraglen, payload, requesthdr.iov_len); - - txrecord.iov_base = recordstart; - - /* Remember, this is only the vec for the RPC header and does not - * include the payload above. We needed the payload only to calculate - * the size of the full fragment. This size is sent in the fragment - * header. - */ - txrecord.iov_len = requesthdr.iov_len; + struct iovec requesthdr = { + 0, + }; + struct iovec txrecord = {0, 0}; + int ret = -1; + size_t fraglen = 0; + + ret = rpc_request_to_xdr(request, recordstart, rlen, &requesthdr); + if (ret == -1) { + gf_log("rpcsvc", GF_LOG_WARNING, "Failed to create RPC request"); + goto out; + } + + fraglen = payload + requesthdr.iov_len; + gf_log("rpcsvc", GF_LOG_TRACE, + "Request fraglen %zu, payload: %zu, " + "rpc hdr: %zu", + fraglen, payload, requesthdr.iov_len); + + txrecord.iov_base = recordstart; + + /* Remember, this is only the vec for the RPC header and does not + * include the payload above. We needed the payload only to calculate + * the size of the full fragment. This size is sent in the fragment + * header. + */ + txrecord.iov_len = requesthdr.iov_len; out: - return txrecord; + return txrecord; } -struct iobuf * -rpcsvc_callback_build_record (rpcsvc_t *rpc, int prognum, int progver, - int procnum, size_t payload, uint64_t xid, - struct iovec *recbuf) -{ - struct rpc_msg request = {0, }; - struct iobuf *request_iob = NULL; - char *record = NULL; - struct iovec recordhdr = {0, }; - size_t pagesize = 0; - int ret = -1; - - if ((!rpc) || (!recbuf)) { - goto out; - } - - /* First, try to get a pointer into the buffer which the RPC - * layer can use. - */ - request_iob = iobuf_get (rpc->ctx->iobuf_pool); - if (!request_iob) { - goto out; - } +static struct iobuf * +rpcsvc_callback_build_record(rpcsvc_t *rpc, int prognum, int progver, + int procnum, size_t payload, u_long xid, + struct iovec *recbuf) +{ + struct rpc_msg request = { + 0, + }; + struct iobuf *request_iob = NULL; + char *record = NULL; + struct iovec recordhdr = { + 0, + }; + size_t pagesize = 0; + size_t xdr_size = 0; + int ret = -1; + + if ((!rpc) || (!recbuf)) { + goto out; + } + + /* Fill the rpc structure and XDR it into the buffer got above. */ + ret = rpcsvc_fill_callback(prognum, progver, procnum, payload, xid, + &request); + if (ret == -1) { + gf_log("rpcsvc", GF_LOG_WARNING, + "cannot build a rpc-request " + "xid (%lu)", + xid); + goto out; + } + + /* First, try to get a pointer into the buffer which the RPC + * layer can use. + */ + xdr_size = xdr_sizeof((xdrproc_t)xdr_callmsg, &request); + + request_iob = iobuf_get2(rpc->ctx->iobuf_pool, (xdr_size + payload)); + if (!request_iob) { + goto out; + } + + pagesize = iobuf_pagesize(request_iob); + + record = iobuf_ptr(request_iob); /* Now we have it. */ + + recordhdr = rpcsvc_callback_build_header(record, pagesize, &request, + payload); + + if (!recordhdr.iov_base) { + gf_log("rpc-clnt", GF_LOG_ERROR, + "Failed to build record " + " header"); + iobuf_unref(request_iob); + request_iob = NULL; + recbuf->iov_base = NULL; + goto out; + } + + recbuf->iov_base = recordhdr.iov_base; + recbuf->iov_len = recordhdr.iov_len; - pagesize = iobuf_pagesize (request_iob); +out: + return request_iob; +} - record = iobuf_ptr (request_iob); /* Now we have it. */ +int +rpcsvc_request_submit(rpcsvc_t *rpc, rpc_transport_t *trans, + rpcsvc_cbk_program_t *prog, int procnum, void *req, + glusterfs_ctx_t *ctx, xdrproc_t xdrproc) +{ + int ret = -1; + int count = 0; + struct iovec iov = { + 0, + }; + struct iobuf *iobuf = NULL; + ssize_t xdr_size = 0; + struct iobref *iobref = NULL; + + if (!req) + goto out; + + xdr_size = xdr_sizeof(xdrproc, req); + + iobuf = iobuf_get2(ctx->iobuf_pool, xdr_size); + if (!iobuf) + goto out; + + iov.iov_base = iobuf->ptr; + iov.iov_len = iobuf_pagesize(iobuf); + + ret = xdr_serialize_generic(iov, req, xdrproc); + if (ret == -1) { + gf_log(THIS->name, GF_LOG_WARNING, "failed to create XDR payload"); + goto out; + } + iov.iov_len = ret; + count = 1; + + iobref = iobref_new(); + if (!iobref) { + ret = -1; + gf_log("rpcsvc", GF_LOG_WARNING, "Failed to create iobref"); + goto out; + } - /* Fill the rpc structure and XDR it into the buffer got above. */ - ret = rpcsvc_fill_callback (prognum, progver, procnum, payload, xid, - &request); - if (ret == -1) { - gf_log ("rpcsvc", GF_LOG_WARNING, "cannot build a rpc-request " - "xid (%"PRIu64")", xid); - goto out; - } + iobref_add(iobref, iobuf); - recordhdr = rpcsvc_callback_build_header (record, pagesize, &request, - payload); + ret = rpcsvc_callback_submit(rpc, trans, prog, procnum, &iov, count, + iobref); - if (!recordhdr.iov_base) { - gf_log ("rpc-clnt", GF_LOG_ERROR, "Failed to build record " - " header"); - iobuf_unref (request_iob); - request_iob = NULL; - recbuf->iov_base = NULL; - goto out; - } +out: + if (iobuf) + iobuf_unref(iobuf); - recbuf->iov_base = recordhdr.iov_base; - recbuf->iov_len = recordhdr.iov_len; + if (iobref) + iobref_unref(iobref); -out: - return request_iob; + return ret; } int -rpcsvc_callback_submit (rpcsvc_t *rpc, rpc_transport_t *trans, - rpcsvc_cbk_program_t *prog, int procnum, - struct iovec *proghdr, int proghdrcount) -{ - struct iobuf *request_iob = NULL; - struct iovec rpchdr = {0,}; - rpc_transport_req_t req; - int ret = -1; - int proglen = 0; - uint64_t callid = 0; - - if (!rpc) { - goto out; - } - - memset (&req, 0, sizeof (req)); - - callid = rpcsvc_get_callid (rpc); - - if (proghdr) { - proglen += iov_length (proghdr, proghdrcount); +rpcsvc_callback_submit(rpcsvc_t *rpc, rpc_transport_t *trans, + rpcsvc_cbk_program_t *prog, int procnum, + struct iovec *proghdr, int proghdrcount, + struct iobref *iobref) +{ + struct iobuf *request_iob = NULL; + struct iovec rpchdr = { + 0, + }; + rpc_transport_req_t req; + int ret = -1; + int proglen = 0; + uint32_t xid = 0; + gf_boolean_t new_iobref = _gf_false; + + if (!rpc) { + goto out; + } + + memset(&req, 0, sizeof(req)); + + if (proghdr) { + proglen += iov_length(proghdr, proghdrcount); + } + + xid = rpc_callback_new_callid(trans); + + request_iob = rpcsvc_callback_build_record( + rpc, prog->prognum, prog->progver, procnum, proglen, xid, &rpchdr); + if (!request_iob) { + gf_log("rpcsvc", GF_LOG_WARNING, "cannot build rpc-record"); + goto out; + } + if (!iobref) { + iobref = iobref_new(); + if (!iobref) { + gf_log("rpcsvc", GF_LOG_WARNING, "Failed to create iobref"); + goto out; } + new_iobref = 1; + } - request_iob = rpcsvc_callback_build_record (rpc, prog->prognum, - prog->progver, procnum, - proglen, callid, - &rpchdr); - if (!request_iob) { - gf_log ("rpcsvc", GF_LOG_WARNING, - "cannot build rpc-record"); - goto out; - } + iobref_add(iobref, request_iob); - req.msg.rpchdr = &rpchdr; - req.msg.rpchdrcount = 1; - req.msg.proghdr = proghdr; - req.msg.proghdrcount = proghdrcount; + req.msg.rpchdr = &rpchdr; + req.msg.rpchdrcount = 1; + req.msg.proghdr = proghdr; + req.msg.proghdrcount = proghdrcount; + req.msg.iobref = iobref; - ret = rpc_transport_submit_request (trans, &req); - if (ret == -1) { - gf_log ("rpcsvc", GF_LOG_WARNING, - "transmission of rpc-request failed"); - goto out; - } + ret = rpc_transport_submit_request(trans, &req); + if (ret == -1) { + gf_log("rpcsvc", GF_LOG_WARNING, "transmission of rpc-request failed"); + goto out; + } - ret = 0; + ret = 0; out: - iobuf_unref (request_iob); + iobuf_unref(request_iob); - return ret; + if (new_iobref) + iobref_unref(iobref); + + return ret; } -inline int -rpcsvc_transport_submit (rpc_transport_t *trans, struct iovec *hdrvec, - int hdrcount, struct iovec *proghdr, int proghdrcount, - struct iovec *progpayload, int progpayloadcount, - struct iobref *iobref, void *priv) +int +rpcsvc_transport_submit(rpc_transport_t *trans, struct iovec *rpchdr, + int rpchdrcount, struct iovec *proghdr, + int proghdrcount, struct iovec *progpayload, + int progpayloadcount, struct iobref *iobref, void *priv) { - int ret = -1; - rpc_transport_reply_t reply = {{0, }}; - - if ((!trans) || (!hdrvec) || (!hdrvec->iov_base)) { - goto out; - } - - reply.msg.rpchdr = hdrvec; - reply.msg.rpchdrcount = hdrcount; - reply.msg.proghdr = proghdr; - reply.msg.proghdrcount = proghdrcount; - reply.msg.progpayload = progpayload; - reply.msg.progpayloadcount = progpayloadcount; - reply.msg.iobref = iobref; - reply.private = priv; - - ret = rpc_transport_submit_reply (trans, &reply); + int ret = -1; + rpc_transport_reply_t reply = { + 0, + }; + + if ((!trans) || (!rpchdr) || (!rpchdr->iov_base)) { + goto out; + } + + reply.msg.rpchdr = rpchdr; + reply.msg.rpchdrcount = rpchdrcount; + reply.msg.proghdr = proghdr; + reply.msg.proghdrcount = proghdrcount; + reply.msg.progpayload = progpayload; + reply.msg.progpayloadcount = progpayloadcount; + reply.msg.iobref = iobref; + reply.private = priv; + + ret = rpc_transport_submit_reply(trans, &reply); out: - return ret; + return ret; } - int -rpcsvc_fill_reply (rpcsvc_request_t *req, struct rpc_msg *reply) +rpcsvc_fill_reply(rpcsvc_request_t *req, struct rpc_msg *reply) { - int ret = -1; - rpcsvc_program_t *prog = NULL; - if ((!req) || (!reply)) - goto out; - - ret = 0; - rpc_fill_empty_reply (reply, req->xid); - if (req->rpc_status == MSG_DENIED) { - rpc_fill_denied_reply (reply, req->rpc_err, req->auth_err); - goto out; - } - - prog = rpcsvc_request_program (req); - - if (req->rpc_status == MSG_ACCEPTED) - rpc_fill_accepted_reply (reply, req->rpc_err, - (prog) ? prog->proglowvers : 0, - (prog) ? prog->proghighvers: 0, - req->verf.flavour, req->verf.datalen, - req->verf.authdata); - else - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Invalid rpc_status value"); + int ret = -1; + rpcsvc_program_t *prog = NULL; + if ((!req) || (!reply)) + goto out; + + ret = 0; + rpc_fill_empty_reply(reply, req->xid); + if (req->rpc_status == MSG_DENIED) { + rpc_fill_denied_reply(reply, req->rpc_err, req->auth_err); + goto out; + } + + prog = rpcsvc_request_program(req); + + if (req->rpc_status == MSG_ACCEPTED) + rpc_fill_accepted_reply( + reply, req->rpc_err, (prog) ? prog->proglowvers : 0, + (prog) ? prog->proghighvers : 0, req->verf.flavour, + req->verf.datalen, req->verf.authdata); + else + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Invalid rpc_status value"); out: - return ret; + return ret; } - /* Given a request and the reply payload, build a reply and encodes the reply * into a record header. This record header is encoded into the vector pointed * to be recbuf. @@ -935,52 +1400,60 @@ out: * we should account for the length of that buffer in the RPC fragment header. */ struct iobuf * -rpcsvc_record_build_record (rpcsvc_request_t *req, size_t payload, - struct iovec *recbuf) -{ - struct rpc_msg reply; - struct iobuf *replyiob = NULL; - char *record = NULL; - struct iovec recordhdr = {0, }; - size_t pagesize = 0; - rpcsvc_t *svc = NULL; - int ret = -1; - - if ((!req) || (!req->trans) || (!req->svc) || (!recbuf)) - return NULL; - - svc = req->svc; - replyiob = iobuf_get (svc->ctx->iobuf_pool); - pagesize = iobuf_pagesize (replyiob); - if (!replyiob) { - goto err_exit; - } - - record = iobuf_ptr (replyiob); /* Now we have it. */ - - /* Fill the rpc structure and XDR it into the buffer got above. */ - ret = rpcsvc_fill_reply (req, &reply); - if (ret) - goto err_exit; - - recordhdr = rpcsvc_record_build_header (record, pagesize, reply, - payload); - if (!recordhdr.iov_base) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to build record " - " header"); - iobuf_unref (replyiob); - replyiob = NULL; - recbuf->iov_base = NULL; - goto err_exit; - } - - recbuf->iov_base = recordhdr.iov_base; - recbuf->iov_len = recordhdr.iov_len; +rpcsvc_record_build_record(rpcsvc_request_t *req, size_t payload, size_t hdrlen, + struct iovec *recbuf) +{ + struct rpc_msg reply; + struct iobuf *replyiob = NULL; + char *record = NULL; + struct iovec recordhdr = { + 0, + }; + size_t pagesize = 0; + size_t xdr_size = 0; + rpcsvc_t *svc = NULL; + int ret = -1; + + if ((!req) || (!req->trans) || (!req->svc) || (!recbuf)) + return NULL; + + svc = req->svc; + + /* Fill the rpc structure and XDR it into the buffer got above. */ + ret = rpcsvc_fill_reply(req, &reply); + if (ret) + goto err_exit; + + xdr_size = xdr_sizeof((xdrproc_t)xdr_replymsg, &reply); + + /* Payload would include 'readv' size etc too, where as + that comes as another payload iobuf */ + replyiob = iobuf_get2(svc->ctx->iobuf_pool, (xdr_size + hdrlen)); + if (!replyiob) { + goto err_exit; + } + + pagesize = iobuf_pagesize(replyiob); + + record = iobuf_ptr(replyiob); /* Now we have it. */ + + recordhdr = rpcsvc_record_build_header(record, pagesize, reply, payload); + if (!recordhdr.iov_base) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Failed to build record " + " header"); + iobuf_unref(replyiob); + replyiob = NULL; + recbuf->iov_base = NULL; + goto err_exit; + } + + recbuf->iov_base = recordhdr.iov_base; + recbuf->iov_len = recordhdr.iov_len; err_exit: - return replyiob; + return replyiob; } - /* * The function to submit a program message to the RPC service. * This message is added to the transmission queue of the @@ -1008,230 +1481,344 @@ err_exit: */ int -rpcsvc_submit_generic (rpcsvc_request_t *req, struct iovec *proghdr, - int hdrcount, struct iovec *payload, int payloadcount, - struct iobref *iobref) +rpcsvc_submit_generic(rpcsvc_request_t *req, struct iovec *proghdr, + int hdrcount, struct iovec *payload, int payloadcount, + struct iobref *iobref) { - int ret = -1, i = 0; - struct iobuf *replyiob = NULL; - struct iovec recordhdr = {0, }; - rpc_transport_t *trans = NULL; - size_t msglen = 0; - char new_iobref = 0; - - if ((!req) || (!req->trans)) - return -1; - - trans = req->trans; - - for (i = 0; i < hdrcount; i++) { - msglen += proghdr[i].iov_len; - } - - for (i = 0; i < payloadcount; i++) { - msglen += payload[i].iov_len; - } - - gf_log (GF_RPCSVC, GF_LOG_TRACE, "Tx message: %zu", msglen); - - /* Build the buffer containing the encoded RPC reply. */ - replyiob = rpcsvc_record_build_record (req, msglen, &recordhdr); - if (!replyiob) { - gf_log (GF_RPCSVC, GF_LOG_ERROR,"Reply record creation failed"); - goto disconnect_exit; - } - + int ret = -1, i = 0; + struct iobuf *replyiob = NULL; + struct iovec recordhdr = { + 0, + }; + rpc_transport_t *trans = NULL; + size_t msglen = 0; + 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++) { + msglen += proghdr[i].iov_len; + } + + for (i = 0; i < payloadcount; i++) { + msglen += payload[i].iov_len; + } + + gf_log(GF_RPCSVC, GF_LOG_TRACE, "Tx message: %zu", msglen); + + /* Build the buffer containing the encoded RPC reply. */ + replyiob = rpcsvc_record_build_record(req, msglen, hdrlen, &recordhdr); + if (!replyiob) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Reply record creation failed"); + goto disconnect_exit; + } + + if (!iobref) { + iobref = iobref_new(); if (!iobref) { - iobref = iobref_new (); - if (!iobref) { - goto disconnect_exit; - } - - new_iobref = 1; + goto disconnect_exit; } - iobref_add (iobref, replyiob); + new_iobref = 1; + } - ret = rpcsvc_transport_submit (trans, &recordhdr, 1, proghdr, hdrcount, - payload, payloadcount, iobref, - req->trans_private); + iobref_add(iobref, replyiob); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "failed to submit message " - "(XID: 0x%ux, Program: %s, ProgVers: %d, Proc: %d) to " - "rpc-transport (%s)", req->xid, - req->prog ? req->prog->progname : "(not matched)", - req->prog ? req->prog->progver : 0, - req->procnum, trans->name); - } else { - gf_log (GF_RPCSVC, GF_LOG_TRACE, - "submitted reply for rpc-message (XID: 0x%ux, " - "Program: %s, ProgVers: %d, Proc: %d) to rpc-transport " - "(%s)", req->xid, req->prog ? req->prog->progname: "-", - req->prog ? req->prog->progver : 0, - req->procnum, trans->name); - } + /* cache the request in the duplicate request cache for appropriate ops */ + if ((req->reply) && (rpcsvc_need_drc(req))) { + drc = req->svc->drc; + + LOCK(&drc->lock); + ret = rpcsvc_cache_reply(req, iobref, &recordhdr, 1, proghdr, hdrcount, + payload, payloadcount); + UNLOCK(&drc->lock); + if (ret < 0) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "failed to cache reply"); + } + } + + ret = rpcsvc_transport_submit(trans, &recordhdr, 1, proghdr, hdrcount, + payload, payloadcount, iobref, + req->trans_private); + + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "failed to submit message " + "(XID: 0x%x, Program: %s, ProgVers: %d, Proc: %d) to " + "rpc-transport (%s)", + req->xid, req->prog ? req->prog->progname : "(not matched)", + req->prog ? req->prog->progver : 0, req->procnum, + trans ? trans->name : ""); + } else { + gf_log(GF_RPCSVC, GF_LOG_TRACE, + "submitted reply for rpc-message (XID: 0x%x, " + "Program: %s, ProgVers: %d, Proc: %d) to rpc-transport " + "(%s)", + req->xid, req->prog ? req->prog->progname : "-", + req->prog ? req->prog->progver : 0, req->procnum, + trans ? trans->name : ""); + } disconnect_exit: - if (replyiob) { - iobuf_unref (replyiob); - } + if (replyiob) { + iobuf_unref(replyiob); + } - if (new_iobref) { - iobref_unref (iobref); - } + if (new_iobref) { + iobref_unref(iobref); + } - rpcsvc_request_destroy (req); + rpcsvc_request_destroy(req); - return ret; + return ret; } - int -rpcsvc_error_reply (rpcsvc_request_t *req) +rpcsvc_error_reply(rpcsvc_request_t *req) { - struct iovec dummyvec = {0, }; + struct iovec dummyvec = { + 0, + }; - if (!req) - return -1; + if (!req) + return -1; - gf_log_callingfn ("", GF_LOG_WARNING, "sending a RPC error reply"); + gf_log_callingfn("", GF_LOG_DEBUG, "sending a RPC error reply"); - /* At this point the req should already have been filled with the - * appropriate RPC error numbers. - */ - return rpcsvc_submit_generic (req, &dummyvec, 0, NULL, 0, NULL); + /* At this point the req should already have been filled with the + * appropriate RPC error numbers. + */ + return rpcsvc_submit_generic(req, &dummyvec, 0, NULL, 0, NULL); } - -/* Register the program with the local portmapper service. */ -inline int -rpcsvc_program_register_portmap (rpcsvc_program_t *newprog, uint32_t port) +#ifdef IPV6_DEFAULT +int +rpcsvc_program_register_rpcbind6(rpcsvc_program_t *newprog, uint32_t port) { - int ret = 0; - - if (!newprog) { - goto out; - } + const int IP_BUF_LEN = 64; + char addr_buf[IP_BUF_LEN]; + + int err = 0; + bool_t success = 0; + struct netconfig *nc; + struct netbuf *nb; + + if (!newprog) { + goto out; + } + + nc = getnetconfigent("tcp6"); + if (!nc) { + err = -1; + goto out; + } + + err = sprintf(addr_buf, "::.%d.%d", port >> 8 & 0xff, port & 0xff); + if (err < 0) { + err = -1; + goto out; + } + + nb = uaddr2taddr(nc, addr_buf); + if (!nb) { + err = -1; + goto out; + } + + /* Force the unregistration of the program first. + * This call may fail if nothing has been registered, + * which is fine. + */ + rpcsvc_program_unregister_rpcbind6(newprog); + + success = rpcb_set(newprog->prognum, newprog->progver, nc, nb); + if (!success) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Could not register the IPv6" + " service with rpcbind"); + } + + err = 0; - if (!(pmap_set (newprog->prognum, newprog->progver, IPPROTO_TCP, - port))) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Could not register with" - " portmap"); - goto out; - } +out: + return err; +} - ret = 0; +int +rpcsvc_program_unregister_rpcbind6(rpcsvc_program_t *newprog) +{ + int err = 0; + bool_t success = 0; + struct netconfig *nc; + + if (!newprog) { + goto out; + } + + nc = getnetconfigent("tcp6"); + if (!nc) { + err = -1; + goto out; + } + + success = rpcb_unset(newprog->prognum, newprog->progver, nc); + if (!success) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Could not unregister the IPv6" + " service with rpcbind"); + } + + err = 0; out: - return ret; + return err; } +#endif +/* Register the program with the local portmapper service. */ +int +rpcsvc_program_register_portmap(rpcsvc_program_t *newprog, uint32_t port) +{ + int ret = -1; /* FAIL */ + + if (!newprog) { + goto out; + } + + /* pmap_set() returns 0 for FAIL and 1 for SUCCESS */ + if (!(pmap_set(newprog->prognum, newprog->progver, IPPROTO_TCP, port))) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Could not register with" + " portmap %d %d %u", + newprog->prognum, newprog->progver, port); + goto out; + } + + ret = 0; /* SUCCESS */ +out: + return ret; +} -inline int -rpcsvc_program_unregister_portmap (rpcsvc_program_t *prog) +int +rpcsvc_program_unregister_portmap(rpcsvc_program_t *prog) { - int ret = 0; + int ret = -1; - if (!prog) - goto out; + if (!prog) + goto out; - if (!(pmap_unset(prog->prognum, prog->progver))) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Could not unregister with" - " portmap"); - goto out; - } + if (!(pmap_unset(prog->prognum, prog->progver))) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Could not unregister with" + " portmap"); + goto out; + } - ret = 0; + ret = 0; out: - return ret; + return ret; } int -rpcsvc_register_portmap_enabled (rpcsvc_t *svc) +rpcsvc_register_portmap_enabled(rpcsvc_t *svc) { - return svc->register_portmap; + return svc->register_portmap; } int32_t -rpcsvc_get_listener_port (rpcsvc_listener_t *listener) +rpcsvc_get_listener_port(rpcsvc_listener_t *listener) { - int32_t listener_port = -1; + int32_t listener_port = -1; - if ((listener == NULL) || (listener->trans == NULL)) { - goto out; - } + if ((listener == NULL) || (listener->trans == NULL)) { + goto out; + } - switch (listener->trans->myinfo.sockaddr.ss_family) { + switch (listener->trans->myinfo.sockaddr.ss_family) { case AF_INET: - listener_port = ((struct sockaddr_in *)&listener->trans->myinfo.sockaddr)->sin_port; - break; + listener_port = ((struct sockaddr_in *)&listener->trans->myinfo + .sockaddr) + ->sin_port; + break; case AF_INET6: - listener_port = ((struct sockaddr_in6 *)&listener->trans->myinfo.sockaddr)->sin6_port; - break; + listener_port = ((struct sockaddr_in6 *)&listener->trans->myinfo + .sockaddr) + ->sin6_port; + break; default: - gf_log (GF_RPCSVC, GF_LOG_DEBUG, - "invalid address family (%d)", - listener->trans->myinfo.sockaddr.ss_family); - goto out; - } + gf_log(GF_RPCSVC, GF_LOG_DEBUG, "invalid address family (%d)", + listener->trans->myinfo.sockaddr.ss_family); + goto out; + } - listener_port = ntohs (listener_port); + listener_port = ntohs(listener_port); out: - return listener_port; + return listener_port; } - rpcsvc_listener_t * -rpcsvc_get_listener (rpcsvc_t *svc, uint16_t port, rpc_transport_t *trans) +rpcsvc_get_listener(rpcsvc_t *svc, uint16_t port, rpc_transport_t *trans) { - rpcsvc_listener_t *listener = NULL; - char found = 0; - uint32_t listener_port = 0; - - if (!svc) { - goto out; - } - - pthread_mutex_lock (&svc->rpclock); + rpcsvc_listener_t *listener = NULL; + char found = 0; + rpcsvc_listener_t *next = NULL; + uint32_t listener_port = 0; + + if (!svc) { + goto out; + } + + pthread_rwlock_rdlock(&svc->rpclock); + { + list_for_each_entry_safe(listener, next, &svc->listeners, list) { - list_for_each_entry (listener, &svc->listeners, list) { - if (trans != NULL) { - if (listener->trans == trans) { - found = 1; - break; - } - - continue; - } + if (trans != NULL) { + if (listener->trans == trans) { + found = 1; + break; + } - listener_port = rpcsvc_get_listener_port (listener); - if (listener_port == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, - "invalid port for listener %s", - listener->trans->name); - continue; - } + continue; + } - if (listener_port == port) { - found = 1; - break; - } - } - } - pthread_mutex_unlock (&svc->rpclock); + listener_port = rpcsvc_get_listener_port(listener); + if (listener_port == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "invalid port for listener %s", + listener->trans->name); + continue; + } - if (!found) { - listener = NULL; + if (listener_port == port) { + found = 1; + break; + } } + } + pthread_rwlock_unlock(&svc->rpclock); + + if (!found) { + listener = NULL; + } out: - return listener; + return listener; } - /* The only difference between the generic submit and this one is that the * generic submit is also used for submitting RPC error replies in where there * are no payloads so the msgvec and msgbuf can be NULL. @@ -1239,1160 +1826,1470 @@ out: * we must perform NULL checks before calling the generic submit. */ int -rpcsvc_submit_message (rpcsvc_request_t *req, struct iovec *proghdr, - int hdrcount, struct iovec *payload, int payloadcount, - struct iobref *iobref) +rpcsvc_submit_message(rpcsvc_request_t *req, struct iovec *proghdr, + int hdrcount, struct iovec *payload, int payloadcount, + struct iobref *iobref) { - if ((!req) || (!req->trans) || (!proghdr) || (!proghdr->iov_base)) - return -1; + if ((!req) || (!req->trans) || (!proghdr) || (!proghdr->iov_base)) + return -1; - return rpcsvc_submit_generic (req, proghdr, hdrcount, payload, - payloadcount, iobref); + return rpcsvc_submit_generic(req, proghdr, hdrcount, payload, payloadcount, + 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 *prog) +rpcsvc_program_unregister(rpcsvc_t *svc, rpcsvc_program_t *program) { - int ret = -1; - - if (!svc || !prog) { - goto out; - } - - ret = rpcsvc_program_unregister_portmap (prog); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "portmap unregistration of" - " program failed"); - goto out; - } - - gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Program unregistered: %s, Num: %d," - " Ver: %d, Port: %d", prog->progname, prog->prognum, - prog->progver, prog->progport); - - pthread_mutex_lock (&svc->rpclock); + int ret = -1; + rpcsvc_program_t *prog = NULL; + if (!svc || !program) { + goto out; + } + + pthread_rwlock_rdlock(&svc->rpclock); + { + list_for_each_entry(prog, &svc->programs, program) { - list_del (&prog->program); - } - pthread_mutex_unlock (&svc->rpclock); + 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, + "portmap unregistration of" + " program failed"); + goto out; + } +#ifdef IPV6_DEFAULT + ret = rpcsvc_program_unregister_rpcbind6(program); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "rpcbind (ipv6)" + " unregistration of program failed"); + goto out; + } +#endif - ret = 0; -out: - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Program unregistration failed" - ": %s, Num: %d, Ver: %d, Port: %d", prog->progname, - prog->prognum, prog->progver, prog->progport); - } + gf_log(GF_RPCSVC, GF_LOG_DEBUG, + "Program unregistered: %s, Num: %d," + " Ver: %d, Port: %d", + prog->progname, prog->prognum, prog->progver, prog->progport); - return ret; -} + if (prog->ownthread) { + prog->alive = _gf_false; + ret = 0; + goto out; + } + pthread_rwlock_wrlock(&svc->rpclock); + { + list_del_init(&prog->program); + } + pthread_rwlock_unlock(&svc->rpclock); -inline int -rpcsvc_transport_peername (rpc_transport_t *trans, char *hostname, int hostlen) -{ - if (!trans) { - return -1; + ret = 0; +out: + rpcsvc_program_destroy(prog); + + if (ret == -1) { + if (program) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Program " + "unregistration failed" + ": %s, Num: %d, Ver: %d, Port: %d", + program->progname, program->prognum, program->progver, + program->progport); + } else { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Program not found"); } + } - return rpc_transport_get_peername (trans, hostname, hostlen); + return ret; } - -inline int -rpcsvc_transport_peeraddr (rpc_transport_t *trans, char *addrstr, int addrlen, - struct sockaddr_storage *sa, socklen_t sasize) +int +rpcsvc_transport_peername(rpc_transport_t *trans, char *hostname, int hostlen) { - if (!trans) { - return -1; - } + if (!trans) { + return -1; + } - return rpc_transport_get_peeraddr(trans, addrstr, addrlen, sa, - sasize); + return rpc_transport_get_peername(trans, hostname, hostlen); } - -rpc_transport_t * -rpcsvc_transport_create (rpcsvc_t *svc, dict_t *options, char *name) +int +rpcsvc_transport_peeraddr(rpc_transport_t *trans, char *addrstr, int addrlen, + struct sockaddr_storage *sa, socklen_t sasize) { - int ret = -1; - rpc_transport_t *trans = NULL; - - trans = rpc_transport_load (svc->ctx, options, name); - if (!trans) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, "cannot create listener, " - "initing the transport failed"); - goto out; - } - - ret = rpc_transport_listen (trans); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, - "listening on transport failed"); - goto out; - } + if (!trans) { + return -1; + } - ret = rpc_transport_register_notify (trans, rpcsvc_notify, svc); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, "registering notify failed"); - goto out; - } - - ret = 0; -out: - if ((ret == -1) && (trans)) { - rpc_transport_disconnect (trans); - trans = NULL; - } - - return trans; + return rpc_transport_get_peeraddr(trans, addrstr, addrlen, sa, sasize); } rpcsvc_listener_t * -rpcsvc_listener_alloc (rpcsvc_t *svc, rpc_transport_t *trans) +rpcsvc_listener_alloc(rpcsvc_t *svc, rpc_transport_t *trans) { - rpcsvc_listener_t *listener = NULL; + rpcsvc_listener_t *listener = NULL; - listener = GF_CALLOC (1, sizeof (*listener), - gf_common_mt_rpcsvc_listener_t); - if (!listener) { - goto out; - } + listener = GF_CALLOC(1, sizeof(*listener), gf_common_mt_rpcsvc_listener_t); + if (!listener) { + goto out; + } - listener->trans = trans; - listener->svc = svc; + listener->trans = trans; + listener->svc = svc; - INIT_LIST_HEAD (&listener->list); + INIT_LIST_HEAD(&listener->list); - pthread_mutex_lock (&svc->rpclock); - { - list_add_tail (&listener->list, &svc->listeners); - } - pthread_mutex_unlock (&svc->rpclock); + pthread_rwlock_wrlock(&svc->rpclock); + { + list_add_tail(&listener->list, &svc->listeners); + } + pthread_rwlock_unlock(&svc->rpclock); out: - return listener; + return listener; } - int32_t -rpcsvc_create_listener (rpcsvc_t *svc, dict_t *options, char *name) +rpcsvc_create_listener(rpcsvc_t *svc, dict_t *options, char *name) { - rpc_transport_t *trans = NULL; - rpcsvc_listener_t *listener = NULL; - int32_t ret = -1; - - if (!svc || !options) { - goto out; - } - - trans = rpcsvc_transport_create (svc, options, name); - if (!trans) { - /* LOG TODO */ - goto out; - } - - listener = rpcsvc_listener_alloc (svc, trans); - if (listener == NULL) { - goto out; - } + rpc_transport_t *trans = NULL; + rpcsvc_listener_t *listener = NULL; + int32_t ret = -1; + + if (!svc || !options) { + goto out; + } + + trans = rpc_transport_load(svc->ctx, options, name); + if (!trans) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, + "cannot create listener, " + "initing the transport failed"); + goto out; + } + + ret = rpc_transport_listen(trans); + if (ret == -EADDRINUSE || ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, "listening on transport failed"); + goto out; + } + + ret = rpc_transport_register_notify(trans, rpcsvc_notify, svc); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_WARNING, "registering notify failed"); + goto out; + } + + listener = rpcsvc_listener_alloc(svc, trans); + if (listener == NULL) { + ret = -1; + goto out; + } - ret = 0; + ret = 0; out: - if (!listener && trans) { - rpc_transport_disconnect (trans); - } + if (!listener && trans) { + rpc_transport_disconnect(trans, _gf_true); + rpc_transport_cleanup(trans); + } - return ret; + return ret; } - int32_t -rpcsvc_create_listeners (rpcsvc_t *svc, dict_t *options, char *name) +rpcsvc_create_listeners(rpcsvc_t *svc, dict_t *options, char *name) { - int32_t ret = -1, count = 0; - data_t *data = NULL; - char *str = NULL, *ptr = NULL, *transport_name = NULL; - char *transport_type = NULL, *saveptr = NULL, *tmp = NULL; - - if ((svc == NULL) || (options == NULL) || (name == NULL)) { - goto out; - } - - data = dict_get (options, "transport-type"); - if (data == NULL) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, - "option transport-type not set"); - goto out; + int32_t ret = -1, count = 0; + data_t *data = NULL; + char *str = NULL, *ptr = NULL, *transport_name = NULL; + char *transport_type = NULL, *saveptr = NULL, *tmp = NULL; + + if ((svc == NULL) || (options == NULL) || (name == NULL)) { + goto out; + } + + data = dict_get(options, "transport-type"); + if (data == NULL) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "option transport-type not set"); + goto out; + } + + transport_type = data_to_str(data); + if (transport_type == NULL) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "option transport-type not set"); + goto out; + } + + /* duplicate transport_type, since following dict_set will free it */ + transport_type = gf_strdup(transport_type); + if (transport_type == NULL) { + goto out; + } + + str = gf_strdup(transport_type); + if (str == NULL) { + goto out; + } + + ptr = strtok_r(str, ",", &saveptr); + + while (ptr != NULL) { + tmp = gf_strdup(ptr); + if (tmp == NULL) { + goto out; + } + + ret = gf_asprintf(&transport_name, "%s.%s", tmp, name); + if (ret == -1) { + goto out; } - transport_type = data_to_str (data); - if (transport_type == NULL) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, - "option transport-type not set"); - goto out; + ret = dict_set_dynstr(options, "transport-type", tmp); + if (ret == -1) { + goto out; } - /* duplicate transport_type, since following dict_set will free it */ - transport_type = gf_strdup (transport_type); - if (transport_type == NULL) { - goto out; - } + tmp = NULL; + ptr = strtok_r(NULL, ",", &saveptr); - str = gf_strdup (transport_type); - if (str == NULL) { - goto out; + ret = rpcsvc_create_listener(svc, options, transport_name); + if (ret != 0) { + goto out; } - ptr = strtok_r (str, ",", &saveptr); - - while (ptr != NULL) { - tmp = gf_strdup (ptr); - if (tmp == NULL) { - goto out; - } - - ret = gf_asprintf (&transport_name, "%s.%s", tmp, name); - if (ret == -1) { - goto out; - } - - ret = dict_set_dynstr (options, "transport-type", tmp); - if (ret == -1) { - goto out; - } - - tmp = NULL; - ptr = strtok_r (NULL, ",", &saveptr); + dict_del(options, "notify-poller-death"); + GF_FREE(transport_name); + transport_name = NULL; + count++; + } - ret = rpcsvc_create_listener (svc, options, transport_name); - if (ret != 0) { - goto out; - } + ret = dict_set_dynstr(options, "transport-type", transport_type); + if (ret == -1) { + goto out; + } - GF_FREE (transport_name); - count++; - } - - ret = dict_set_dynstr (options, "transport-type", transport_type); - if (ret == -1) { - goto out; - } - - transport_type = NULL; + transport_type = NULL; out: - if (str != NULL) { - GF_FREE (str); - } + GF_FREE(str); - if (transport_type != NULL) { - GF_FREE (transport_type); - } + GF_FREE(transport_type); - if (tmp != NULL) { - GF_FREE (tmp); - } + GF_FREE(tmp); + GF_FREE(transport_name); + + if (count > 0) { return count; + } else { + return ret; + } } - int -rpcsvc_unregister_notify (rpcsvc_t *svc, rpcsvc_notify_t notify, void *mydata) +rpcsvc_unregister_notify(rpcsvc_t *svc, rpcsvc_notify_t notify, void *mydata) { - rpcsvc_notify_wrapper_t *wrapper = NULL, *tmp = NULL; - int ret = 0; + rpcsvc_notify_wrapper_t *wrapper = NULL, *tmp = NULL; + int ret = 0; - if (!svc || !notify) { - goto out; - } + if (!svc || !notify) { + goto out; + } - pthread_mutex_lock (&svc->rpclock); + pthread_rwlock_wrlock(&svc->rpclock); + { + list_for_each_entry_safe(wrapper, tmp, &svc->notify, list) { - list_for_each_entry_safe (wrapper, tmp, &svc->notify, list) { - if ((wrapper->notify == notify) - && (mydata == wrapper->data)) { - list_del_init (&wrapper->list); - GF_FREE (wrapper); - ret++; - } - } + if ((wrapper->notify == notify) && (mydata == wrapper->data)) { + list_del_init(&wrapper->list); + GF_FREE(wrapper); + ret++; + } } - pthread_mutex_unlock (&svc->rpclock); + } + pthread_rwlock_unlock(&svc->rpclock); out: - return ret; + return ret; } int -rpcsvc_register_notify (rpcsvc_t *svc, rpcsvc_notify_t notify, void *mydata) +rpcsvc_register_notify(rpcsvc_t *svc, rpcsvc_notify_t notify, void *mydata) { - rpcsvc_notify_wrapper_t *wrapper = NULL; - int ret = -1; - - wrapper = rpcsvc_notify_wrapper_alloc (); - if (!wrapper) { - goto out; - } - svc->mydata = mydata; /* this_xlator */ - wrapper->data = mydata; - wrapper->notify = notify; - - pthread_mutex_lock (&svc->rpclock); - { - list_add_tail (&wrapper->list, &svc->notify); - svc->notify_count++; - } - pthread_mutex_unlock (&svc->rpclock); - - ret = 0; + rpcsvc_notify_wrapper_t *wrapper = NULL; + int ret = -1; + + wrapper = rpcsvc_notify_wrapper_alloc(); + if (!wrapper) { + goto out; + } + svc->mydata = mydata; + wrapper->data = mydata; + wrapper->notify = notify; + + pthread_rwlock_wrlock(&svc->rpclock); + { + list_add_tail(&wrapper->list, &svc->notify); + svc->notify_count++; + } + pthread_rwlock_unlock(&svc->rpclock); + + ret = 0; out: - return ret; + return ret; } - -inline int -rpcsvc_program_register (rpcsvc_t *svc, rpcsvc_program_t *program) +void * +rpcsvc_request_handler(void *arg) { - int ret = -1; - rpcsvc_program_t *newprog = NULL; - char already_registered = 0; + 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; - if (!svc) { - goto out; - } + queue = arg; + program = queue->program; - if (program->actors == NULL) { - goto out; - } + INIT_LIST_HEAD(&tmp_list); + + if (!program) + return NULL; - pthread_mutex_lock (&svc->rpclock); + while (1) { + pthread_mutex_lock(&queue->queue_lock); { - list_for_each_entry (newprog, &svc->programs, program) { - if ((newprog->prognum == program->prognum) - && (newprog->progver == program->progver)) { - already_registered = 1; - break; - } - } - } - pthread_mutex_unlock (&svc->rpclock); + if (!program->alive && list_empty(&queue->request_queue)) { + done = 1; + goto unlock; + } - if (already_registered) { - ret = 0; - goto out; + while (list_empty(&queue->request_queue)) { + queue->waiting = _gf_true; + pthread_cond_wait(&queue->queue_cond, &queue->queue_lock); + } + + queue->waiting = _gf_false; + + if (!list_empty(&queue->request_queue)) { + INIT_LIST_HEAD(&tmp_list); + list_splice_init(&queue->request_queue, &tmp_list); + } } + unlock: + pthread_mutex_unlock(&queue->queue_lock); - newprog = GF_CALLOC (1, sizeof(*newprog),gf_common_mt_rpcsvc_program_t); - if (newprog == NULL) { - goto out; + list_for_each_entry_safe(req, tmp_req, &tmp_list, request_list) + { + if (req) { + list_del_init(&req->request_list); + + 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; + } + } } - memcpy (newprog, program, sizeof (*program)); + if (done) + break; + } - INIT_LIST_HEAD (&newprog->program); + return NULL; +} - pthread_mutex_lock (&svc->rpclock); +int +rpcsvc_program_register(rpcsvc_t *svc, rpcsvc_program_t *program, + gf_boolean_t add_to_head) +{ + 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; + } + + if (program->actors == NULL) { + goto out; + } + + pthread_rwlock_rdlock(&svc->rpclock); + { + list_for_each_entry(newprog, &svc->programs, program) { - list_add_tail (&newprog->program, &svc->programs); + if ((newprog->prognum == program->prognum) && + (newprog->progver == program->progver)) { + already_registered = 1; + break; + } } - pthread_mutex_unlock (&svc->rpclock); + } + pthread_rwlock_unlock(&svc->rpclock); + if (already_registered) { ret = 0; - gf_log (GF_RPCSVC, GF_LOG_DEBUG, "New program registered: %s, Num: %d," - " Ver: %d, Port: %d", newprog->progname, newprog->prognum, - newprog->progver, newprog->progport); + goto out; + } + + newprog = GF_CALLOC(1, sizeof(*newprog), gf_common_mt_rpcsvc_program_t); + if (newprog == NULL) { + goto out; + } + + 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); + 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) { + struct event_pool *ep = svc->ctx->event_pool; + newprog->eventthreadcount = ep->eventthreadcount; + + pthread_key_create(&newprog->req_queue_key, NULL); + newprog->thr_queue = 1; + } + + pthread_rwlock_wrlock(&svc->rpclock); + { + if (add_to_head) + list_add(&newprog->program, &svc->programs); + else + list_add_tail(&newprog->program, &svc->programs); + } + pthread_rwlock_unlock(&svc->rpclock); -out: - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Program registration failed:" - " %s, Num: %d, Ver: %d, Port: %d", program->progname, - program->prognum, program->progver, program->progport); - } + ret = 0; + gf_log(GF_RPCSVC, GF_LOG_DEBUG, + "New program registered: %s, Num: %d," + " Ver: %d, Port: %d", + newprog->progname, newprog->prognum, newprog->progver, + newprog->progport); - return ret; +out: + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Program registration failed:" + " %s, Num: %d, Ver: %d, Port: %d", + program->progname, program->prognum, program->progver, + program->progport); + } + + return ret; } static void -free_prog_details (gf_dump_rsp *rsp) +free_prog_details(gf_dump_rsp *rsp) { - gf_prog_detail *prev = NULL; - gf_prog_detail *trav = NULL; - - trav = rsp->prog; - while (trav) { - prev = trav; - trav = trav->next; - GF_FREE (prev); - } + gf_prog_detail *prev = NULL; + gf_prog_detail *trav = NULL; + + trav = rsp->prog; + while (trav) { + prev = trav; + trav = trav->next; + GF_FREE(prev); + } } static int -build_prog_details (rpcsvc_request_t *req, gf_dump_rsp *rsp) +build_prog_details(rpcsvc_request_t *req, gf_dump_rsp *rsp) { - int ret = -1; - rpcsvc_program_t *program = NULL; - gf_prog_detail *prog = NULL; - gf_prog_detail *prev = NULL; + int ret = -1; + rpcsvc_program_t *program = NULL; + gf_prog_detail *prog = NULL; + gf_prog_detail *prev = NULL; - if (!req || !req->trans || !req->svc) - goto out; + if (!req || !req->trans || !req->svc) + goto out; + + pthread_rwlock_rdlock(&req->svc->rpclock); + { + list_for_each_entry(program, &req->svc->programs, program) + { + prog = GF_CALLOC(1, sizeof(*prog), 0); + if (!prog) + goto unlock; - list_for_each_entry (program, &req->svc->programs, program) { - prog = GF_CALLOC (1, sizeof (*prog), 0); - if (!prog) - goto out; - prog->progname = program->progname; - prog->prognum = program->prognum; - prog->progver = program->progver; - if (!rsp->prog) - rsp->prog = prog; - if (prev) - prev->next = prog; - prev = prog; + prog->progname = program->progname; + prog->prognum = program->prognum; + prog->progver = program->progver; + + if (!rsp->prog) + rsp->prog = prog; + if (prev) + prev->next = prog; + prev = prog; } if (prev) - ret = 0; + ret = 0; + } +unlock: + pthread_rwlock_unlock(&req->svc->rpclock); out: - return ret; + return ret; } static int -rpcsvc_dump (rpcsvc_request_t *req) +rpcsvc_ping(rpcsvc_request_t *req) { - char rsp_buf[8 * 1024] = {0,}; - gf_dump_rsp rsp = {0,}; - struct iovec iov = {0,}; - int op_errno = EINVAL; - int ret = -1; - uint32_t dump_rsp_len = 0; + char rsp_buf[8 * 1024] = { + 0, + }; + gf_common_rsp rsp = { + 0, + }; + struct iovec iov = { + 0, + }; + int ret = -1; + uint32_t ping_rsp_len = 0; + + ping_rsp_len = xdr_sizeof((xdrproc_t)xdr_gf_common_rsp, &rsp); + + iov.iov_base = rsp_buf; + iov.iov_len = ping_rsp_len; + + ret = xdr_serialize_generic(iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + ret = RPCSVC_ACTOR_ERROR; + } else { + rsp.op_ret = 0; + rpcsvc_submit_generic(req, &iov, 1, NULL, 0, NULL); + } + + return 0; +} - if (!req) - goto fail; +static int +rpcsvc_dump(rpcsvc_request_t *req) +{ + char rsp_buf[8 * 1024] = { + 0, + }; + gf_dump_rsp rsp = { + 0, + }; + struct iovec iov = { + 0, + }; + int op_errno = EINVAL; + int ret = -1; + uint32_t dump_rsp_len = 0; + + if (!req) + goto sendrsp; + + ret = build_prog_details(req, &rsp); + if (ret < 0) { + op_errno = -ret; + goto sendrsp; + } + + op_errno = 0; + +sendrsp: + rsp.op_errno = gf_errno_to_error(op_errno); + rsp.op_ret = ret; + + dump_rsp_len = xdr_sizeof((xdrproc_t)xdr_gf_dump_rsp, &rsp); + + iov.iov_base = rsp_buf; + iov.iov_len = dump_rsp_len; + + ret = xdr_serialize_generic(iov, &rsp, (xdrproc_t)xdr_gf_dump_rsp); + if (ret < 0) { + ret = RPCSVC_ACTOR_ERROR; + } else { + rpcsvc_submit_generic(req, &iov, 1, NULL, 0, NULL); + ret = 0; + } - ret = build_prog_details (req, &rsp); - if (ret < 0) { - op_errno = -ret; - goto fail; - } + free_prog_details(&rsp); + + return ret; +} -fail: - rsp.op_errno = gf_errno_to_error (op_errno); - rsp.op_ret = ret; +int +rpcsvc_init_options(rpcsvc_t *svc, dict_t *options) +{ + char *optstr = NULL; + int ret = -1; - dump_rsp_len = xdr_sizeof ((xdrproc_t) xdr_gf_dump_rsp, - &rsp); + if ((!svc) || (!options)) + return -1; - iov.iov_base = rsp_buf; - iov.iov_len = dump_rsp_len; + svc->memfactor = RPCSVC_DEFAULT_MEMFACTOR; - ret = xdr_serialize_dump_rsp (iov, &rsp); + svc->register_portmap = _gf_true; + if (dict_get(options, "rpc.register-with-portmap")) { + ret = dict_get_str(options, "rpc.register-with-portmap", &optstr); if (ret < 0) { - if (req) - req->rpc_err = GARBAGE_ARGS; - op_errno = EINVAL; - goto fail; + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Failed to parse " + "dict"); + goto out; } - ret = rpcsvc_submit_generic (req, &iov, 1, NULL, 0, - NULL); + ret = gf_string2boolean(optstr, &svc->register_portmap); + if (ret < 0) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Failed to parse bool " + "string"); + goto out; + } + } + + if (!svc->register_portmap) + gf_log(GF_RPCSVC, GF_LOG_DEBUG, + "Portmap registration " + "disabled"); + ret = 0; +out: + return ret; +} - free_prog_details (&rsp); +int +rpcsvc_reconfigure_options(rpcsvc_t *svc, dict_t *options) +{ + xlator_t *xlator = NULL; + xlator_list_t *volentry = NULL; + char *srchkey = NULL; + char *keyval = NULL; + int ret = -1; + + if ((!svc) || (!svc->options) || (!options)) + return (-1); + + /* Fetch the xlator from svc */ + xlator = svc->xl; + if (!xlator) + return (-1); + + /* Reconfigure the volume specific rpc-auth.addr allow part */ + volentry = xlator->children; + while (volentry) { + ret = gf_asprintf(&srchkey, "rpc-auth.addr.%s.allow", + volentry->xlator->name); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); + return (-1); + } + + /* key-string: rpc-auth.addr.<volname>.allow + * + * IMP: Delete the OLD key/value pair from dict. + * And set the NEW key/value pair IFF the option is SET + * in reconfigured volfile. + * + * NB: If rpc-auth.addr.<volname>.allow is not SET explicitly, + * build_nfs_graph() sets it as "*" i.e. anonymous. + */ + dict_del(svc->options, srchkey); + if (!dict_get_str(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); + return (-1); + } + } + + GF_FREE(srchkey); + volentry = volentry->next; + } + + /* Reconfigure the volume specific rpc-auth.addr reject part */ + volentry = xlator->children; + while (volentry) { + ret = gf_asprintf(&srchkey, "rpc-auth.addr.%s.reject", + volentry->xlator->name); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); + return (-1); + } - return ret; + /* key-string: rpc-auth.addr.<volname>.reject + * + * IMP: Delete the OLD key/value pair from dict. + * And set the NEW key/value pair IFF the option is SET + * in reconfigured volfile. + * + * NB: No default value for reject key. + */ + dict_del(svc->options, srchkey); + if (!dict_get_str(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); + return (-1); + } + } + + GF_FREE(srchkey); + volentry = volentry->next; + } + + ret = rpcsvc_init_options(svc, options); + if (ret) + return (-1); + + return rpcsvc_auth_reconf(svc, options); } int -rpcsvc_init_options (rpcsvc_t *svc, dict_t *options) +rpcsvc_transport_unix_options_build(dict_t *dict, char *filepath) { - char *optstr = NULL; - int ret = -1; + char *fpath = NULL; + int ret = -1; - if ((!svc) || (!options)) - return -1; + GF_ASSERT(filepath); + GF_VALIDATE_OR_GOTO("rpcsvc", dict, out); - svc->memfactor = RPCSVC_DEFAULT_MEMFACTOR; + fpath = gf_strdup(filepath); + if (!fpath) { + ret = -1; + goto out; + } - svc->register_portmap = _gf_true; - if (dict_get (options, "rpc.register-with-portmap")) { - ret = dict_get_str (options, "rpc.register-with-portmap", - &optstr); - if (ret < 0) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to parse " - "dict"); - goto out; - } + ret = dict_set_dynstr(dict, "transport.socket.listen-path", fpath); + if (ret) + goto out; - ret = gf_string2boolean (optstr, &svc->register_portmap); - if (ret < 0) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to parse bool " - "string"); - goto out; - } - } + ret = dict_set_str(dict, "transport.address-family", "unix"); + if (ret) + goto out; - if (!svc->register_portmap) - gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Portmap registration " - "disabled"); + ret = dict_set_str(dict, "transport.socket.nodelay", "off"); + if (ret) + goto out; - ret = 0; + ret = dict_set_str(dict, "transport-type", "socket"); + if (ret) + goto out; out: - return ret; + if (ret) { + GF_FREE(fpath); + } + return ret; } +/* + * Configure() the rpc.outstanding-rpc-limit param. + * If dict_get_int32() for dict-key "rpc.outstanding-rpc-limit" FAILS, + * it would set the value as "defvalue". Otherwise it would fetch the + * value and round up to multiple-of-8. defvalue must be +ve. + * + * NB: defval or set-value "0" is special which means unlimited/65536. + */ int -rpcsvc_transport_unix_options_build (dict_t **options, char *filepath) +rpcsvc_set_outstanding_rpc_limit(rpcsvc_t *svc, dict_t *options, int defvalue) { - dict_t *dict = NULL; - char *fpath = NULL; - int ret = -1; - - GF_ASSERT (filepath); - GF_ASSERT (options); - - dict = dict_new (); - if (!dict) - goto out; + int ret = -1; /* FAILURE */ + int rpclim = 0; + static char *rpclimkey = "rpc.outstanding-rpc-limit"; + + if ((!svc) || (!options)) + return (-1); + + if ((defvalue < RPCSVC_MIN_OUTSTANDING_RPC_LIMIT) || + (defvalue > RPCSVC_MAX_OUTSTANDING_RPC_LIMIT)) { + return (-1); + } + + /* Fetch the rpc.outstanding-rpc-limit from dict. */ + ret = dict_get_int32(options, rpclimkey, &rpclim); + if (ret < 0) { + /* Fall back to default for FAILURE */ + rpclim = defvalue; + } + + /* Round up to multiple-of-8. It must not exceed + * RPCSVC_MAX_OUTSTANDING_RPC_LIMIT. + */ + rpclim = ((rpclim + 8 - 1) >> 3) * 8; + if (rpclim > RPCSVC_MAX_OUTSTANDING_RPC_LIMIT) { + rpclim = RPCSVC_MAX_OUTSTANDING_RPC_LIMIT; + } + + if (svc->outstanding_rpc_limit != rpclim) { + svc->outstanding_rpc_limit = rpclim; + gf_log(GF_RPCSVC, GF_LOG_INFO, "Configured %s with value %d", rpclimkey, + rpclim); + } + + return (0); +} - fpath = gf_strdup (filepath); - if (!fpath) { - ret = -1; - goto out; - } +/* + * Enable throttling for rpcsvc_t svc. + * Returns 0 on success, -1 otherwise. + */ +int +rpcsvc_set_throttle_on(rpcsvc_t *svc) +{ + if (!svc) + return -1; - ret = dict_set_dynstr (dict, "transport.socket.listen-path", fpath); - if (ret) - goto out; + svc->throttle = _gf_true; - ret = dict_set_str (dict, "transport.address-family", "unix"); - if (ret) - goto out; + return 0; +} - ret = dict_set_str (dict, "transport.socket.nodelay", "off"); - if (ret) - goto out; +/* + * Disable throttling for rpcsvc_t svc. + * Returns 0 on success, -1 otherwise. + */ +int +rpcsvc_set_throttle_off(rpcsvc_t *svc) +{ + if (!svc) + return -1; - ret = dict_set_str (dict, "transport-type", "socket"); - if (ret) - goto out; + svc->throttle = _gf_false; - *options = dict; -out: - if (ret) { - if (fpath) - GF_FREE (fpath); - if (dict) - dict_unref (dict); - } - return ret; + return 0; } -/* The global RPC service initializer. +/* + * Get throttle state for rpcsvc_t svc. + * Returns value of attribute throttle on success, _gf_false otherwise. */ -rpcsvc_t * -rpcsvc_init (xlator_t *xl, glusterfs_ctx_t *ctx, dict_t *options) +gf_boolean_t +rpcsvc_get_throttle(rpcsvc_t *svc) { - rpcsvc_t *svc = NULL; - int ret = -1, poolcount = 0; + if (!svc) + return _gf_false; - if ((!ctx) || (!options)) - return NULL; - - svc = GF_CALLOC (1, sizeof (*svc), gf_common_mt_rpcsvc_t); - if (!svc) - return NULL; + return svc->throttle; +} - pthread_mutex_init (&svc->rpclock, NULL); - INIT_LIST_HEAD (&svc->authschemes); - INIT_LIST_HEAD (&svc->notify); - INIT_LIST_HEAD (&svc->listeners); - INIT_LIST_HEAD (&svc->programs); +/* 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; - ret = rpcsvc_init_options (svc, options); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to init options"); - goto free_svc; - } + if (!svc) + return ret; - poolcount = RPCSVC_POOLCOUNT_MULT * svc->memfactor; + list_for_each_entry_safe(listener, next, &svc->listeners, list) + { + rpcsvc_listener_destroy(listener); + } - gf_log (GF_RPCSVC, GF_LOG_TRACE, "rx pool: %d", poolcount); - svc->rxpool = mem_pool_new (rpcsvc_request_t, poolcount); - /* TODO: leak */ - if (!svc->rxpool) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "mem pool allocation failed"); - goto free_svc; - } + list_for_each_entry_safe(auth, tmp, &svc->authschemes, authlist) + { + list_del_init(&auth->authlist); + GF_FREE(auth); + } - ret = rpcsvc_auth_init (svc, options); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to init " - "authentication"); - goto free_svc; - } + rpcsvc_program_unregister(svc, &gluster_dump_prog); + if (svc->rxpool) { + mem_pool_destroy(svc->rxpool); + svc->rxpool = NULL; + } - ret = -1; - svc->options = options; - svc->ctx = ctx; - svc->mydata = xl; - gf_log (GF_RPCSVC, GF_LOG_DEBUG, "RPC service inited."); + pthread_rwlock_destroy(&svc->rpclock); + GF_FREE(svc); - gluster_dump_prog.options = options; + return ret; +} - ret = rpcsvc_program_register (svc, &gluster_dump_prog); - if (ret) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, - "failed to register DUMP program"); - goto free_svc; - } - ret = 0; +/* The global RPC service initializer. + */ +rpcsvc_t * +rpcsvc_init(xlator_t *xl, glusterfs_ctx_t *ctx, dict_t *options, + uint32_t poolcount) +{ + rpcsvc_t *svc = NULL; + int ret = -1; + + if ((!xl) || (!ctx) || (!options)) + return NULL; + + svc = GF_CALLOC(1, sizeof(*svc), gf_common_mt_rpcsvc_t); + if (!svc) + return NULL; + + pthread_rwlock_init(&svc->rpclock, NULL); + INIT_LIST_HEAD(&svc->authschemes); + INIT_LIST_HEAD(&svc->notify); + INIT_LIST_HEAD(&svc->listeners); + INIT_LIST_HEAD(&svc->programs); + + ret = rpcsvc_init_options(svc, options); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Failed to init options"); + goto free_svc; + } + + if (!poolcount) + poolcount = RPCSVC_POOLCOUNT_MULT * svc->memfactor; + + gf_log(GF_RPCSVC, GF_LOG_TRACE, "rx pool: %d", poolcount); + svc->rxpool = mem_pool_new(rpcsvc_request_t, poolcount); + /* TODO: leak */ + if (!svc->rxpool) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "mem pool allocation failed"); + goto free_svc; + } + + ret = rpcsvc_auth_init(svc, options); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Failed to init " + "authentication"); + goto free_svc; + } + + ret = -1; + svc->options = options; + svc->ctx = ctx; + svc->xl = xl; + gf_log(GF_RPCSVC, GF_LOG_DEBUG, "RPC service inited."); + + gluster_dump_prog.options = options; + + ret = rpcsvc_program_register(svc, &gluster_dump_prog, _gf_false); + if (ret) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "failed to register DUMP program"); + goto free_svc; + } + + ret = 0; free_svc: - if (ret == -1) { - GF_FREE (svc); - svc = NULL; - } + if (ret == -1) { + GF_FREE(svc); + svc = NULL; + } - return svc; + return svc; } - int -rpcsvc_transport_peer_check_search (dict_t *options, char *pattern, char *clstr) +rpcsvc_transport_peer_check_search(dict_t *options, char *pattern, char *ip, + char *hostname) { - int ret = -1; - char *addrtok = NULL; - char *addrstr = NULL; - char *svptr = NULL; - - if ((!options) || (!clstr)) - return -1; + int ret = -1; + char *addrtok = NULL; + char *addrstr = NULL; + char *dup_addrstr = NULL; + char *svptr = NULL; - if (!dict_get (options, pattern)) - return -1; + if ((!options) || (!ip)) + return -1; - ret = dict_get_str (options, pattern, &addrstr); - if (ret < 0) { - ret = -1; - goto err; - } + ret = dict_get_str(options, pattern, &addrstr); + if (ret < 0) { + ret = -1; + goto err; + } - if (!addrstr) { - ret = -1; - goto err; - } + if (!addrstr) { + ret = -1; + goto err; + } - addrtok = strtok_r (addrstr, ",", &svptr); - while (addrtok) { + 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 */ +#ifdef FNM_CASEFOLD + ret = fnmatch(addrtok, ip, FNM_CASEFOLD); +#else + ret = fnmatch(addrtok, ip, 0); +#endif + if (ret == 0) + goto err; - /* CASEFOLD not present on Solaris */ + /* compare hostnames if applicable */ + if (hostname) { #ifdef FNM_CASEFOLD - ret = fnmatch (addrtok, clstr, FNM_CASEFOLD); + ret = fnmatch(addrtok, hostname, FNM_CASEFOLD); #else - ret = fnmatch (addrtok, clstr, 0); + ret = fnmatch(addrtok, hostname, 0); #endif - if (ret == 0) - goto err; + if (ret == 0) + goto err; + } - addrtok = strtok_r (NULL, ",", &svptr); + /* Compare IPv4 subnetwork, TODO: IPv6 subnet support */ + if (strchr(addrtok, '/')) { + ret = rpcsvc_match_subnet_v4(addrtok, ip); + if (ret == 0) + goto err; } - ret = -1; + addrtok = strtok_r(NULL, ",", &svptr); + } + + ret = -1; err: + GF_FREE(dup_addrstr); - return ret; + return ret; } - -int -rpcsvc_transport_peer_check_allow (dict_t *options, char *volname, char *clstr) +static int +rpcsvc_transport_peer_check_allow(dict_t *options, char *volname, char *ip, + char *hostname) { - int ret = RPCSVC_AUTH_DONTCARE; - char *srchstr = NULL; - char globalrule[] = "rpc-auth.addr.allow"; + int ret = RPCSVC_AUTH_DONTCARE; + char *srchstr = NULL; - if ((!options) || (!clstr)) - return ret; + if ((!options) || (!ip) || (!volname)) + return ret; - /* If volname is NULL, then we're searching for the general rule to - * determine the current address in clstr is allowed or not for all - * subvolumes. - */ - if (volname) { - ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.allow", volname); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); - ret = RPCSVC_AUTH_DONTCARE; - goto out; - } - } else - srchstr = globalrule; + ret = gf_asprintf(&srchstr, "rpc-auth.addr.%s.allow", volname); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); + ret = RPCSVC_AUTH_DONTCARE; + goto out; + } - ret = rpcsvc_transport_peer_check_search (options, srchstr, clstr); - if (volname) - GF_FREE (srchstr); + ret = rpcsvc_transport_peer_check_search(options, srchstr, ip, hostname); + GF_FREE(srchstr); - if (ret == 0) - ret = RPCSVC_AUTH_ACCEPT; - else - ret = RPCSVC_AUTH_DONTCARE; + if (ret == 0) + ret = RPCSVC_AUTH_ACCEPT; + else + ret = RPCSVC_AUTH_REJECT; out: - return ret; + return ret; } -int -rpcsvc_transport_peer_check_reject (dict_t *options, char *volname, char *clstr) -{ - int ret = RPCSVC_AUTH_DONTCARE; - char *srchstr = NULL; - char generalrule[] = "rpc-auth.addr.reject"; - - if ((!options) || (!clstr)) - return ret; - - if (volname) { - ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.reject", - volname); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); - ret = RPCSVC_AUTH_REJECT; - goto out; - } - } else - srchstr = generalrule; - - ret = rpcsvc_transport_peer_check_search (options, srchstr, clstr); - if (volname) - GF_FREE (srchstr); +static int +rpcsvc_transport_peer_check_reject(dict_t *options, char *volname, char *ip, + char *hostname) +{ + int ret = RPCSVC_AUTH_DONTCARE; + char *srchstr = NULL; - if (ret == 0) - ret = RPCSVC_AUTH_REJECT; - else - ret = RPCSVC_AUTH_DONTCARE; -out: + if ((!options) || (!ip) || (!volname)) return ret; -} - -/* This function tests the results of the allow rule and the reject rule to - * combine them into a single result that can be used to determine if the - * connection should be allowed to proceed. - * Heres the test matrix we need to follow in this function. - * - * A - Allow, the result of the allow test. Never returns R. - * R - Reject, result of the reject test. Never returns A. - * Both can return D or dont care if no rule was given. - * - * | @allow | @reject | Result | - * | A | R | R | - * | D | D | D | - * | A | D | A | - * | D | R | R | - */ -int -rpcsvc_combine_allow_reject_volume_check (int allow, int reject) -{ - int final = RPCSVC_AUTH_REJECT; + ret = gf_asprintf(&srchstr, "rpc-auth.addr.%s.reject", volname); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); + ret = RPCSVC_AUTH_REJECT; + goto out; + } - /* If allowed rule allows but reject rule rejects, we stay cautious - * and reject. */ - if ((allow == RPCSVC_AUTH_ACCEPT) && (reject == RPCSVC_AUTH_REJECT)) - final = RPCSVC_AUTH_REJECT; - /* if both are dont care, that is user did not specify for either allow - * or reject, we leave it up to the general rule to apply, in the hope - * that there is one. - */ - else if ((allow == RPCSVC_AUTH_DONTCARE) && - (reject == RPCSVC_AUTH_DONTCARE)) - final = RPCSVC_AUTH_DONTCARE; - /* If one is dont care, the other one applies. */ - else if ((allow == RPCSVC_AUTH_ACCEPT) && - (reject == RPCSVC_AUTH_DONTCARE)) - final = RPCSVC_AUTH_ACCEPT; - else if ((allow == RPCSVC_AUTH_DONTCARE) && - (reject == RPCSVC_AUTH_REJECT)) - final = RPCSVC_AUTH_REJECT; + ret = rpcsvc_transport_peer_check_search(options, srchstr, ip, hostname); + GF_FREE(srchstr); - return final; + if (ret == 0) + ret = RPCSVC_AUTH_REJECT; + else + ret = RPCSVC_AUTH_DONTCARE; +out: + return ret; } - -/* Combines the result of the general rule test against, the specific rule - * to determine final permission for the client's address. - * - * | @gen | @spec | Result | - * | A | A | A | - * | A | R | R | - * | A | D | A | - * | D | A | A | - * | D | R | R | - * | D | D | D | - * | R | A | A | - * | R | D | R | - * | R | R | R | +/* Combines rpc auth's allow and reject options. + * Order of checks is important. + * First, REJECT if either rejects. + * If neither rejects, ACCEPT if either accepts. + * If neither accepts, DONTCARE */ int -rpcsvc_combine_gen_spec_addr_checks (int gen, int spec) +rpcsvc_combine_allow_reject_volume_check(int allow, int reject) { - int final = RPCSVC_AUTH_REJECT; + if (allow == RPCSVC_AUTH_REJECT || reject == RPCSVC_AUTH_REJECT) + return RPCSVC_AUTH_REJECT; - if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_ACCEPT)) - final = RPCSVC_AUTH_ACCEPT; - else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_REJECT)) - final = RPCSVC_AUTH_REJECT; - else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_DONTCARE)) - final = RPCSVC_AUTH_ACCEPT; - else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_ACCEPT)) - final = RPCSVC_AUTH_ACCEPT; - else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_REJECT)) - final = RPCSVC_AUTH_REJECT; - else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec== RPCSVC_AUTH_DONTCARE)) - final = RPCSVC_AUTH_DONTCARE; - else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_ACCEPT)) - final = RPCSVC_AUTH_ACCEPT; - else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_DONTCARE)) - final = RPCSVC_AUTH_REJECT; - else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_REJECT)) - final = RPCSVC_AUTH_REJECT; + if (allow == RPCSVC_AUTH_ACCEPT || reject == RPCSVC_AUTH_ACCEPT) + return RPCSVC_AUTH_ACCEPT; - return final; + return RPCSVC_AUTH_DONTCARE; } - - -/* Combines the result of the general rule test against, the specific rule - * to determine final test for the connection coming in for a given volume. - * - * | @gen | @spec | Result | - * | A | A | A | - * | A | R | R | - * | A | D | A | - * | D | A | A | - * | D | R | R | - * | D | D | R |, special case, we intentionally disallow this. - * | R | A | A | - * | R | D | R | - * | R | R | R | - */ int -rpcsvc_combine_gen_spec_volume_checks (int gen, int spec) -{ - int final = RPCSVC_AUTH_REJECT; - - if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_ACCEPT)) - final = RPCSVC_AUTH_ACCEPT; - else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_REJECT)) - final = RPCSVC_AUTH_REJECT; - else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_DONTCARE)) - final = RPCSVC_AUTH_ACCEPT; - else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_ACCEPT)) - final = RPCSVC_AUTH_ACCEPT; - else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_REJECT)) - final = RPCSVC_AUTH_REJECT; - /* On no rule, we reject. */ - else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec== RPCSVC_AUTH_DONTCARE)) - final = RPCSVC_AUTH_REJECT; - else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_ACCEPT)) - final = RPCSVC_AUTH_ACCEPT; - else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_DONTCARE)) - final = RPCSVC_AUTH_REJECT; - else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_REJECT)) - final = RPCSVC_AUTH_REJECT; - - return final; -} - - -int -rpcsvc_transport_peer_check_name (dict_t *options, char *volname, - rpc_transport_t *trans) +rpcsvc_auth_check(rpcsvc_t *svc, char *volname, char *ipaddr) { - int ret = RPCSVC_AUTH_REJECT; - int aret = RPCSVC_AUTH_REJECT; - int rjret = RPCSVC_AUTH_REJECT; - char clstr[RPCSVC_PEER_STRLEN]; + int ret = RPCSVC_AUTH_REJECT; + int accept = RPCSVC_AUTH_REJECT; + int reject = RPCSVC_AUTH_REJECT; + char *hostname = NULL; + char *allow_str = NULL; + char *reject_str = NULL; + char *srchstr = NULL; + dict_t *options = NULL; + + if (!svc || !volname || !ipaddr) + return ret; - if (!trans) - return ret; + /* Fetch the options from svc struct and validate */ + options = svc->options; + if (!options) + return ret; - ret = rpcsvc_transport_peername (trans, clstr, RPCSVC_PEER_STRLEN); - if (ret != 0) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get remote addr: " - "%s", gai_strerror (ret)); - ret = RPCSVC_AUTH_REJECT; - goto err; + /* Accept if its the default case: Allow all, Reject none + * The default volfile always contains a 'allow *' rule + * for each volume. If allow rule is missing (which implies + * there is some bad volfile generating code doing this), we + * assume no one is allowed mounts, and thus, we reject mounts. + */ + ret = gf_asprintf(&srchstr, "rpc-auth.addr.%s.allow", volname); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); + return RPCSVC_AUTH_REJECT; + } + + ret = dict_get_str(options, srchstr, &allow_str); + GF_FREE(srchstr); + if (ret < 0) + return RPCSVC_AUTH_REJECT; + + ret = gf_asprintf(&srchstr, "rpc-auth.addr.%s.reject", volname); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); + return RPCSVC_AUTH_REJECT; + } + + ret = dict_get_str(options, srchstr, &reject_str); + GF_FREE(srchstr); + + /* + * If "reject_str" is being set as '*' (anonymous), then NFS-server + * would reject everything. If the "reject_str" is not set and + * "allow_str" is set as '*' (anonymous), then NFS-server would + * accept mount requests from all clients. + */ + if (reject_str != NULL) { + if (!strcmp("*", reject_str)) + return RPCSVC_AUTH_REJECT; + } else { + if (!strcmp("*", allow_str)) + return RPCSVC_AUTH_ACCEPT; + } + + /* addr-namelookup check */ + if (svc->addr_namelookup == _gf_true) { + ret = gf_get_hostname_from_ip(ipaddr, &hostname); + if (ret) { + if (hostname) + GF_FREE(hostname); + /* failed to get hostname, but hostname auth + * is enabled, so authentication will not be + * 100% correct. reject mounts + */ + return RPCSVC_AUTH_REJECT; } + } - aret = rpcsvc_transport_peer_check_allow (options, volname, clstr); - rjret = rpcsvc_transport_peer_check_reject (options, volname, clstr); + accept = rpcsvc_transport_peer_check_allow(options, volname, ipaddr, + hostname); - ret = rpcsvc_combine_allow_reject_volume_check (aret, rjret); + reject = rpcsvc_transport_peer_check_reject(options, volname, ipaddr, + hostname); -err: - return ret; + if (hostname) + GF_FREE(hostname); + return rpcsvc_combine_allow_reject_volume_check(accept, reject); } - int -rpcsvc_transport_peer_check_addr (dict_t *options, char *volname, - rpc_transport_t *trans) +rpcsvc_transport_privport_check(rpcsvc_t *svc, char *volname, uint16_t port) { - int ret = RPCSVC_AUTH_REJECT; - int aret = RPCSVC_AUTH_DONTCARE; - int rjret = RPCSVC_AUTH_REJECT; - char clstr[RPCSVC_PEER_STRLEN]; - struct sockaddr_storage sastorage = {0,}; - - if (!trans) - return ret; + int ret = RPCSVC_AUTH_REJECT; + char *srchstr = NULL; + char *valstr = NULL; + gf_boolean_t insecure = _gf_false; - ret = rpcsvc_transport_peeraddr (trans, clstr, RPCSVC_PEER_STRLEN, - &sastorage, sizeof (sastorage)); - if (ret != 0) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get remote addr: " - "%s", gai_strerror (ret)); - ret = RPCSVC_AUTH_REJECT; - goto err; - } - - aret = rpcsvc_transport_peer_check_allow (options, volname, clstr); - rjret = rpcsvc_transport_peer_check_reject (options, volname, clstr); - - ret = rpcsvc_combine_allow_reject_volume_check (aret, rjret); -err: + if ((!svc) || (!volname)) return ret; -} + gf_log(GF_RPCSVC, GF_LOG_TRACE, "Client port: %d", (int)port); + /* If the port is already a privileged one, don't bother with checking + * options. + */ + if (port <= 1024) { + ret = RPCSVC_AUTH_ACCEPT; + goto err; + } + + /* Disabled by default */ + ret = gf_asprintf(&srchstr, "rpc-auth.ports.%s.insecure", volname); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); + ret = RPCSVC_AUTH_REJECT; + goto err; + } + + ret = dict_get_str(svc->options, srchstr, &valstr); + if (ret) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Failed to" + " read rpc-auth.ports.insecure value"); + goto err; + } + + ret = gf_string2boolean(valstr, &insecure); + if (ret) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, + "Failed to" + " convert rpc-auth.ports.insecure value"); + goto err; + } + + ret = insecure ? RPCSVC_AUTH_ACCEPT : RPCSVC_AUTH_REJECT; + + if (ret == RPCSVC_AUTH_ACCEPT) + gf_log(GF_RPCSVC, GF_LOG_DEBUG, "Unprivileged port allowed"); + else + gf_log(GF_RPCSVC, GF_LOG_DEBUG, + "Unprivileged port not" + " allowed"); -int -rpcsvc_transport_check_volume_specific (dict_t *options, char *volname, - rpc_transport_t *trans) -{ - int namechk = RPCSVC_AUTH_REJECT; - int addrchk = RPCSVC_AUTH_REJECT; - gf_boolean_t namelookup = _gf_false; - char *namestr = NULL; - int ret = 0; - - if ((!options) || (!volname) || (!trans)) - return RPCSVC_AUTH_REJECT; - - /* Disabled by default */ - if ((dict_get (options, "rpc-auth.addr.namelookup"))) { - ret = dict_get_str (options, "rpc-auth.addr.namelookup" - , &namestr); - if (ret == 0) - ret = gf_string2boolean (namestr, &namelookup); - } - - /* We need two separate checks because the rules with addresses in them - * can be network addresses which can be general and names can be - * specific which will over-ride the network address rules. - */ - if (namelookup) - namechk = rpcsvc_transport_peer_check_name (options, volname, - trans); - addrchk = rpcsvc_transport_peer_check_addr (options, volname, trans); - - if (namelookup) - ret = rpcsvc_combine_gen_spec_addr_checks (addrchk, - namechk); - else - ret = addrchk; +err: + if (srchstr) + GF_FREE(srchstr); - return ret; + return ret; } +char * +rpcsvc_volume_allowed(dict_t *options, char *volname) +{ + char globalrule[] = "rpc-auth.addr.allow"; + char *srchstr = NULL; + char *addrstr = NULL; + int ret = -1; -int -rpcsvc_transport_check_volume_general (dict_t *options, rpc_transport_t *trans) -{ - int addrchk = RPCSVC_AUTH_REJECT; - int namechk = RPCSVC_AUTH_REJECT; - gf_boolean_t namelookup = _gf_false; - char *namestr = NULL; - int ret = 0; - - if ((!options) || (!trans)) - return RPCSVC_AUTH_REJECT; - - /* Disabled by default */ - if ((dict_get (options, "rpc-auth.addr.namelookup"))) { - ret = dict_get_str (options, "rpc-auth.addr.namelookup" - , &namestr); - if (ret == 0) - ret = gf_string2boolean (namestr, &namelookup); - } + if ((!options) || (!volname)) + return NULL; - /* We need two separate checks because the rules with addresses in them - * can be network addresses which can be general and names can be - * specific which will over-ride the network address rules. - */ - if (namelookup) - namechk = rpcsvc_transport_peer_check_name (options, NULL, trans); - addrchk = rpcsvc_transport_peer_check_addr (options, NULL, trans); + ret = gf_asprintf(&srchstr, "rpc-auth.addr.%s.allow", volname); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); + goto out; + } - if (namelookup) - ret = rpcsvc_combine_gen_spec_addr_checks (addrchk, - namechk); - else - ret = addrchk; + if (!dict_get(options, srchstr)) + ret = dict_get_str(options, globalrule, &addrstr); + else + ret = dict_get_str(options, srchstr, &addrstr); - return ret; +out: + GF_FREE(srchstr); + + return addrstr; } -int -rpcsvc_transport_peer_check (dict_t *options, char *volname, - rpc_transport_t *trans) +/* + * rpcsvc_match_subnet_v4() takes subnetwork address pattern and checks + * if the target IPv4 address has the same network address with the help + * of network mask. + * + * Returns 0 for SUCCESS and -1 otherwise. + * + * NB: Validation of subnetwork address pattern is not required + * as it's already being done at the time of CLI SET. + */ +static int +rpcsvc_match_subnet_v4(const char *addrtok, const char *ipaddr) { - int general_chk = RPCSVC_AUTH_REJECT; - int specific_chk = RPCSVC_AUTH_REJECT; - - if ((!options) || (!volname) || (!trans)) - return RPCSVC_AUTH_REJECT; - - general_chk = rpcsvc_transport_check_volume_general (options, trans); - specific_chk = rpcsvc_transport_check_volume_specific (options, volname, - trans); - - return rpcsvc_combine_gen_spec_volume_checks (general_chk, - specific_chk); + char *slash = NULL; + char *netaddr = NULL; + int ret = -1; + uint32_t prefixlen = 0; + uint32_t shift = 0; + struct sockaddr_in sin1 = { + 0, + }; + struct sockaddr_in sin2 = { + 0, + }; + struct sockaddr_in mask = { + 0, + }; + + /* Copy the input */ + netaddr = gf_strdup(addrtok); + if (netaddr == NULL) /* ENOMEM */ + goto out; + + /* Find the network socket addr of target */ + if (inet_pton(AF_INET, ipaddr, &sin1.sin_addr) == 0) + goto out; + + slash = strchr(netaddr, '/'); + if (slash) { + *slash = '\0'; + /* + * Find the IPv4 network mask in network byte order. + * IMP: String slash+1 is already validated, it can't have value + * more than IPv4_ADDR_SIZE (32). + */ + prefixlen = (uint32_t)atoi(slash + 1); + 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); + + if (mask_match(sin1.sin_addr.s_addr, sin2.sin_addr.s_addr, + mask.sin_addr.s_addr)) { + ret = 0; /* SUCCESS */ + } +out: + GF_FREE(netaddr); + return ret; } +void +rpcsvc_program_dump(rpcsvc_program_t *prog) +{ + char key_prefix[GF_DUMP_MAX_BUF_LEN]; + char key[GF_DUMP_MAX_BUF_LEN]; + int i; -int -rpcsvc_transport_privport_check (rpcsvc_t *svc, char *volname, - rpc_transport_t *trans) -{ - struct sockaddr_storage sastorage = {0,}; - struct sockaddr_in *sa = NULL; - int ret = RPCSVC_AUTH_REJECT; - socklen_t sasize = sizeof (sa); - char *srchstr = NULL; - char *valstr = NULL; - int globalinsecure = RPCSVC_AUTH_REJECT; - int exportinsecure = RPCSVC_AUTH_DONTCARE; - uint16_t port = 0; - gf_boolean_t insecure = _gf_false; - - if ((!svc) || (!volname) || (!trans)) - return ret; - - sa = (struct sockaddr_in*) &sastorage; - ret = rpcsvc_transport_peeraddr (trans, NULL, 0, &sastorage, - sasize); - if (ret != 0) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get peer addr: %s", - gai_strerror (ret)); - ret = RPCSVC_AUTH_REJECT; - goto err; - } + snprintf(key_prefix, GF_DUMP_MAX_BUF_LEN, "%s", prog->progname); + gf_proc_dump_add_section("%s", key_prefix); - port = ntohs (sa->sin_port); - gf_log (GF_RPCSVC, GF_LOG_TRACE, "Client port: %d", (int)port); - /* If the port is already a privileged one, dont bother with checking - * options. - */ - if (port <= 1024) { - ret = RPCSVC_AUTH_ACCEPT; - goto err; - } + gf_proc_dump_build_key(key, key_prefix, "program-number"); + gf_proc_dump_write(key, "%d", prog->prognum); - /* Disabled by default */ - if ((dict_get (svc->options, "rpc-auth.ports.insecure"))) { - ret = dict_get_str (svc->options, "rpc-auth.ports.insecure" - , &srchstr); - if (ret == 0) { - ret = gf_string2boolean (srchstr, &insecure); - if (ret == 0) { - if (insecure == _gf_true) - globalinsecure = RPCSVC_AUTH_ACCEPT; - } else - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to" - " read rpc-auth.ports.insecure value"); - } else - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to" - " read rpc-auth.ports.insecure value"); - } + gf_proc_dump_build_key(key, key_prefix, "program-version"); + gf_proc_dump_write(key, "%d", prog->progver); - /* Disabled by default */ - ret = gf_asprintf (&srchstr, "rpc-auth.ports.%s.insecure", volname); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); - ret = RPCSVC_AUTH_REJECT; - goto err; - } - - if (dict_get (svc->options, srchstr)) { - ret = dict_get_str (svc->options, srchstr, &valstr); - if (ret == 0) { - ret = gf_string2boolean (valstr, &insecure); - if (ret == 0) { - if (insecure == _gf_true) - exportinsecure = RPCSVC_AUTH_ACCEPT; - else - exportinsecure = RPCSVC_AUTH_REJECT; - } else - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to" - " read rpc-auth.ports.insecure value"); - } else - gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to" - " read rpc-auth.ports.insecure value"); - } - - ret = rpcsvc_combine_gen_spec_volume_checks (globalinsecure, - exportinsecure); - if (ret == RPCSVC_AUTH_ACCEPT) - gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Unprivileged port allowed"); - else - gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Unprivileged port not" - " allowed"); + strncat(key_prefix, ".latency", + sizeof(key_prefix) - strlen(key_prefix) - 1); -err: - return ret; + 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]); + } } - -char * -rpcsvc_volume_allowed (dict_t *options, char *volname) +void +rpcsvc_statedump(rpcsvc_t *svc) { - char globalrule[] = "rpc-auth.addr.allow"; - char *srchstr = NULL; - char *addrstr = NULL; - int ret = -1; - - if ((!options) || (!volname)) - return NULL; - - ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.allow", volname); - if (ret == -1) { - gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); - goto out; + rpcsvc_program_t *prog = NULL; + int ret = 0; + ret = pthread_rwlock_tryrdlock(&svc->rpclock); + if (ret) + return; + { + list_for_each_entry(prog, &svc->programs, program) + { + rpcsvc_program_dump(prog); } - - if (!dict_get (options, srchstr)) { - GF_FREE (srchstr); - srchstr = globalrule; - ret = dict_get_str (options, srchstr, &addrstr); - } else - ret = dict_get_str (options, srchstr, &addrstr); - -out: - return addrstr; + } + pthread_rwlock_unlock(&svc->rpclock); } - -rpcsvc_actor_t gluster_dump_actors[] = { - [GF_DUMP_NULL] = {"NULL", GF_DUMP_NULL, NULL, NULL, NULL, 0}, - [GF_DUMP_DUMP] = {"DUMP", GF_DUMP_DUMP, rpcsvc_dump, NULL, NULL, 0}, - [GF_DUMP_MAXVALUE] = {"MAXVALUE", GF_DUMP_MAXVALUE, NULL, NULL, NULL, 0}, +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 = { - .progname = "GF-DUMP", - .prognum = GLUSTER_DUMP_PROGRAM, - .progver = GLUSTER_DUMP_VERSION, - .actors = gluster_dump_actors, - .numactors = 2, +static struct rpcsvc_program gluster_dump_prog = { + .progname = "GF-DUMP", + .prognum = GLUSTER_DUMP_PROGRAM, + .progver = GLUSTER_DUMP_VERSION, + .actors = gluster_dump_actors, + .numactors = GF_DUMP_MAXVALUE, }; diff --git a/rpc/rpc-lib/src/rpcsvc.h b/rpc/rpc-lib/src/rpcsvc.h index 83aa33f8067..7b3030926c8 100644 --- a/rpc/rpc-lib/src/rpcsvc.h +++ b/rpc/rpc-lib/src/rpcsvc.h @@ -1,70 +1,67 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _RPCSVC_H #define _RPCSVC_H -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "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" - -#ifndef NGRPS -#define NGRPS 16 -#endif /* !NGRPS */ +#include <glusterfs/compat.h> +#include <glusterfs/client_t.h> #ifndef MAX_IOVEC #define MAX_IOVEC 16 #endif -#define GF_RPCSVC "rpc-service" +/* 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 */ +#define RPCSVC_MAX_OUTSTANDING_RPC_LIMIT 65536 +#define RPCSVC_MIN_OUTSTANDING_RPC_LIMIT 0 /* No limit i.e. Unlimited */ + +#define GF_RPCSVC "rpc-service" #define RPCSVC_THREAD_STACK_SIZE ((size_t)(1024 * GF_UNIT_KB)) -#define RPCSVC_FRAGHDR_SIZE 4 /* 4-byte RPC fragment header size */ -#define RPCSVC_DEFAULT_LISTEN_PORT GF_DEFAULT_BASE_PORT -#define RPCSVC_DEFAULT_MEMFACTOR 15 -#define RPCSVC_EVENTPOOL_SIZE_MULT 1024 -#define RPCSVC_POOLCOUNT_MULT 35 -#define RPCSVC_CONN_READ (128 * GF_UNIT_KB) -#define RPCSVC_PAGE_SIZE (128 * GF_UNIT_KB) +#define RPCSVC_FRAGHDR_SIZE 4 /* 4-byte RPC fragment header size */ +#define RPCSVC_DEFAULT_LISTEN_PORT GF_DEFAULT_BASE_PORT +#define RPCSVC_DEFAULT_MEMFACTOR 8 +#define RPCSVC_EVENTPOOL_SIZE_MULT 1024 +#define RPCSVC_POOLCOUNT_MULT 64 +#define RPCSVC_CONN_READ (128 * GF_UNIT_KB) +#define RPCSVC_PAGE_SIZE (128 * GF_UNIT_KB) +#define RPC_ROOT_UID 0 +#define RPC_ROOT_GID 0 +#define RPC_NOBODY_UID 65534 +#define RPC_NOBODY_GID 65534 /* RPC Record States */ -#define RPCSVC_READ_FRAGHDR 1 -#define RPCSVC_READ_FRAG 2 +#define RPCSVC_READ_FRAGHDR 1 +#define RPCSVC_READ_FRAG 2 /* The size in bytes, if crossed by a fragment will be handed over to the * vectored actor so that it can allocate its buffers the way it wants. * In our RPC layer, we assume that vectored RPC requests/records are never @@ -72,21 +69,28 @@ * whether the record should be handled in RPC layer completely or handed to * the vectored handler. */ -#define RPCSVC_VECTORED_FRAGSZ 4096 -#define RPCSVC_VECTOR_READCRED 1003 -#define RPCSVC_VECTOR_READVERFSZ 1004 -#define RPCSVC_VECTOR_READVERF 1005 -#define RPCSVC_VECTOR_IGNORE 1006 -#define RPCSVC_VECTOR_READVEC 1007 -#define RPCSVC_VECTOR_READPROCHDR 1008 - -#define rpcsvc_record_vectored_baremsg(rs) (((rs)->state == RPCSVC_READ_FRAG) && (rs)->vecstate == 0) -#define rpcsvc_record_vectored_cred(rs) ((rs)->vecstate == RPCSVC_VECTOR_READCRED) -#define rpcsvc_record_vectored_verfsz(rs) ((rs)->vecstate == RPCSVC_VECTOR_READVERFSZ) -#define rpcsvc_record_vectored_verfread(rs) ((rs)->vecstate == RPCSVC_VECTOR_READVERF) -#define rpcsvc_record_vectored_ignore(rs) ((rs)->vecstate == RPCSVC_VECTOR_IGNORE) -#define rpcsvc_record_vectored_readvec(rs) ((rs)->vecstate == RPCSVC_VECTOR_READVEC) -#define rpcsvc_record_vectored_readprochdr(rs) ((rs)->vecstate == RPCSVC_VECTOR_READPROCHDR) +#define RPCSVC_VECTORED_FRAGSZ 4096 +#define RPCSVC_VECTOR_READCRED 1003 +#define RPCSVC_VECTOR_READVERFSZ 1004 +#define RPCSVC_VECTOR_READVERF 1005 +#define RPCSVC_VECTOR_IGNORE 1006 +#define RPCSVC_VECTOR_READVEC 1007 +#define RPCSVC_VECTOR_READPROCHDR 1008 + +#define rpcsvc_record_vectored_baremsg(rs) \ + (((rs)->state == RPCSVC_READ_FRAG) && (rs)->vecstate == 0) +#define rpcsvc_record_vectored_cred(rs) \ + ((rs)->vecstate == RPCSVC_VECTOR_READCRED) +#define rpcsvc_record_vectored_verfsz(rs) \ + ((rs)->vecstate == RPCSVC_VECTOR_READVERFSZ) +#define rpcsvc_record_vectored_verfread(rs) \ + ((rs)->vecstate == RPCSVC_VECTOR_READVERF) +#define rpcsvc_record_vectored_ignore(rs) \ + ((rs)->vecstate == RPCSVC_VECTOR_IGNORE) +#define rpcsvc_record_vectored_readvec(rs) \ + ((rs)->vecstate == RPCSVC_VECTOR_READVEC) +#define rpcsvc_record_vectored_readprochdr(rs) \ + ((rs)->vecstate == RPCSVC_VECTOR_READPROCHDR) #define rpcsvc_record_vectored(rs) ((rs)->fragsize > RPCSVC_VECTORED_FRAGSZ) /* Includes bytes up to and including the credential length field. The credlen * will be followed by @credlen bytes of credential data which will have to be @@ -94,189 +98,232 @@ * verifier which will also have to be read separately including the 8 bytes of * verf flavour and verflen. */ -#define RPCSVC_BARERPC_MSGSZ 32 -#define rpcsvc_record_readfraghdr(rs) ((rs)->state == RPCSVC_READ_FRAGHDR) -#define rpcsvc_record_readfrag(rs) ((rs)->state == RPCSVC_READ_FRAG) +#define RPCSVC_BARERPC_MSGSZ 32 +#define rpcsvc_record_readfraghdr(rs) ((rs)->state == RPCSVC_READ_FRAGHDR) +#define rpcsvc_record_readfrag(rs) ((rs)->state == RPCSVC_READ_FRAG) -#define RPCSVC_LOWVERS 2 +#define RPCSVC_LOWVERS 2 #define RPCSVC_HIGHVERS 2 - #if 0 #error "defined in /usr/include/rpc/auth.h" -#define AUTH_NONE 0 /* no authentication */ -#define AUTH_NULL 0 /* backward compatibility */ -#define AUTH_SYS 1 /* unix style (uid, gids) */ -#define AUTH_UNIX AUTH_SYS -#define AUTH_SHORT 2 /* short hand unix style */ -#define AUTH_DES 3 /* des style (encrypted timestamps) */ -#define AUTH_DH AUTH_DES /* Diffie-Hellman (this is DES) */ -#define AUTH_KERB 4 /* kerberos style */ -#endif /* */ - -#define AUTH_GLUSTERFS 5 +#define AUTH_NONE 0 /* no authentication */ +#define AUTH_NULL 0 /* backward compatibility */ +#define AUTH_SYS 1 /* unix style (uid, gids) */ +#define AUTH_UNIX AUTH_SYS +#define AUTH_SHORT 2 /* short hand unix style */ +#define AUTH_DES 3 /* des style (encrypted timestamps) */ +#define AUTH_DH AUTH_DES /* Diffie-Hellman (this is DES) */ +#define AUTH_KERB 4 /* kerberos style */ +#endif /* */ typedef struct rpcsvc_program rpcsvc_program_t; struct rpcsvc_notify_wrapper { - struct list_head list; - void *data; - rpcsvc_notify_t notify; + struct list_head list; + void *data; + rpcsvc_notify_t notify; }; typedef struct rpcsvc_notify_wrapper rpcsvc_notify_wrapper_t; - typedef struct rpcsvc_request rpcsvc_request_t; typedef struct { - rpc_transport_t *trans; - rpcsvc_t *svc; - /* FIXME: remove address from this structure. Instead use get_myaddr - * interface implemented by individual transports. - */ - struct sockaddr_storage sa; - struct list_head list; + rpc_transport_t *trans; + rpcsvc_t *svc; + /* FIXME: remove address from this structure. Instead use get_myaddr + * interface implemented by individual transports. + */ + struct sockaddr_storage sa; + struct list_head list; } rpcsvc_listener_t; struct rpcsvc_config { - int max_block_size; + int max_block_size; }; -#define RPCSVC_MAX_AUTH_BYTES 400 -typedef struct rpcsvc_auth_data { - int flavour; - int datalen; - char authdata[RPCSVC_MAX_AUTH_BYTES]; -} rpcsvc_auth_data_t; +#define rpcsvc_auth_flavour(au) ((au).flavour) -#define rpcsvc_auth_flavour(au) ((au).flavour) +typedef struct drc_client drc_client_t; +typedef struct drc_cached_op drc_cached_op_t; /* The container for the RPC call handed up to an actor. * Dynamically allocated. Lives till the call reply is completely * transmitted. * */ struct rpcsvc_request { - /* connection over which this request came. */ - rpc_transport_t *trans; - - rpcsvc_t *svc; - - 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; - - int procnum; + /* connection over which this request came. */ + rpc_transport_t *trans; - int type; + rpcsvc_t *svc; + + rpcsvc_program_t *prog; - /* Uid and gid filled by the rpc-auth module during the authentication - * phase. - */ - uid_t uid; - gid_t gid; - pid_t pid; + int prognum; + + int progver; - uint64_t lk_owner; - uint64_t gfs_id; - - /* Might want to move this to AUTH_UNIX specific state since this array - * is not available for every authentication scheme. - */ - gid_t auxgids[NGRPS]; - int auxgidcount; - - - /* The RPC message payload, contains the data required - * 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 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 - * ,NFS header and the read data are brought together separately from - * different buffers, so we need to stage the buffers temporarily here - * before all of them get added to the connection's transmission list. - */ - struct list_head txlist; - - /* While the reply record is being built, this variable keeps track - * of how many bytes have been added to the record. - */ - size_t payloadsize; - - /* The credentials extracted from the rpc request */ - rpcsvc_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; - - /* Container for a RPC program wanting to store a temp - * request-specific item. - */ - void *private; - - /* Container for transport to store request-specific item */ - void *trans_private; + int procnum; + + int type; + + /* Uid and gid filled by the rpc-auth module during the authentication + * phase. + */ + uid_t uid; + gid_t gid; + pid_t pid; + + gf_lkowner_t lk_owner; + uint64_t gfs_id; + + /* Might want to move this to AUTH_UNIX specific state since this array + * is not available for every authentication scheme. + */ + gid_t *auxgids; + gid_t auxgidsmall[SMALL_GROUP_COUNT]; + gid_t *auxgidlarge; + int auxgidcount; + + /* The RPC message payload, contains the data required + * by the program actors. This is the buffer that will need to + * be de-xdred by the actor. + */ + int count; + struct iovec msg[MAX_IOVEC]; + + struct iobref *iobref; + + /* 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 + * ,NFS header and the read data are brought together separately from + * different buffers, so we need to stage the buffers temporarily here + * before all of them get added to the connection's transmission list. + */ + struct list_head txlist; + + /* While the reply record is being built, this variable keeps track + * of how many bytes have been added to the record. + */ + size_t payloadsize; + + /* The credentials extracted from the rpc request */ + 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. + */ + client_auth_data_t verf; + /* Container for a RPC program wanting to store a temp + * request-specific item. + */ + void *private; + + /* Container for transport to store request-specific item */ + void *trans_private; + + /* pointer to cached reply for use in DRC */ + drc_cached_op_t *reply; + + /* 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 + passed here instead */ + unsigned int flags; + + /* 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)) #define rpcsvc_request_procnum(req) (((req)->procnum)) -#define rpcsvc_request_program_private(req) (((rpcsvc_program_t *)((req)->prog))->private) -#define rpcsvc_request_accepted(req) ((req)->rpc_status == MSG_ACCEPTED) +#define rpcsvc_request_program_private(req) \ + (((rpcsvc_program_t *)((req)->prog))->private) +#define rpcsvc_request_accepted(req) ((req)->rpc_status == MSG_ACCEPTED) #define rpcsvc_request_accepted_success(req) ((req)->rpc_err == SUCCESS) -#define rpcsvc_request_uid(req) ((req)->uid) -#define rpcsvc_request_gid(req) ((req)->gid) #define rpcsvc_request_prog_minauth(req) (rpcsvc_request_program(req)->min_auth) #define rpcsvc_request_cred_flavour(req) (rpcsvc_auth_flavour(req->cred)) #define rpcsvc_request_verf_flavour(req) (rpcsvc_auth_flavour(req->verf)) -#define rpcsvc_request_service(req) ((req)->svc) -#define rpcsvc_request_uid(req) ((req)->uid) -#define rpcsvc_request_gid(req) ((req)->gid) -#define rpcsvc_request_private(req) ((req)->private) -#define rpcsvc_request_xid(req) ((req)->xid) -#define rpcsvc_request_set_private(req,prv) (req)->private = (void *)(prv) -#define rpcsvc_request_iobref_ref(req) (iobref_ref ((req)->iobref)) -#define rpcsvc_request_record_ref(req) (iobuf_ref ((req)->recordiob)) -#define rpcsvc_request_record_unref(req) (iobuf_unref ((req)->recordiob)) -#define rpcsvc_request_record_iob(req) ((req)->recordiob) -#define rpcsvc_request_set_vecstate(req, state) ((req)->vecstate = state) +#define rpcsvc_request_service(req) ((req)->svc) +#define rpcsvc_request_uid(req) ((req)->uid) +#define rpcsvc_request_gid(req) ((req)->gid) +#define rpcsvc_request_private(req) ((req)->private) +#define rpcsvc_request_xid(req) ((req)->xid) +#define rpcsvc_request_set_private(req, prv) (req)->private = (void *)(prv) +#define rpcsvc_request_iobref_ref(req) (iobref_ref((req)->iobref)) +#define rpcsvc_request_record_ref(req) (iobuf_ref((req)->recordiob)) +#define rpcsvc_request_record_unref(req) (iobuf_unref((req)->recordiob)) +#define rpcsvc_request_record_iob(req) ((req)->recordiob) +#define rpcsvc_request_set_vecstate(req, state) ((req)->vecstate = state) #define rpcsvc_request_vecstate(req) ((req)->vecstate) #define rpcsvc_request_transport(req) ((req)->trans) - - -#define RPCSVC_ACTOR_SUCCESS 0 -#define RPCSVC_ACTOR_ERROR (-1) -#define RPCSVC_ACTOR_IGNORE (-2) +#define rpcsvc_request_transport_ref(req) (rpc_transport_ref((req)->trans)) +#define RPC_AUTH_ROOT_SQUASH(req) \ + do { \ + int gidcount = 0; \ + if (req->svc->root_squash) { \ + if (req->uid == RPC_ROOT_UID) \ + req->uid = req->svc->anonuid; \ + if (req->gid == RPC_ROOT_GID) \ + 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 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) /* Functor for every type of protocol actor * must be defined like this. @@ -290,117 +337,146 @@ struct rpcsvc_request { * should return RPCSVC_ACTOR_ERROR. * */ -typedef int (*rpcsvc_actor) (rpcsvc_request_t *req); -typedef int (*rpcsvc_vector_actor) (rpcsvc_request_t *req, struct iovec *vec, - int count, struct iobref *iobref); -typedef int (*rpcsvc_vector_sizer) (int state, ssize_t *readsize, char *addr); +typedef int (*rpcsvc_actor)(rpcsvc_request_t *req); +typedef int (*rpcsvc_vector_sizer)(int state, ssize_t *readsize, + char *base_addr, char *curr_addr); /* Every protocol actor will also need to specify the function the RPC layer * will use to serialize or encode the message into XDR format just before * transmitting on the connection. */ -typedef void *(*rpcsvc_encode_reply) (void *msg); +typedef void *(*rpcsvc_encode_reply)(void *msg); /* Once the reply has been transmitted, the message will have to be de-allocated * , so every actor will need to provide a function that deallocates the message * it had allocated as a response. */ -typedef void (*rpcsvc_deallocate_reply) (void *msg); - +typedef void (*rpcsvc_deallocate_reply)(void *msg); -#define RPCSVC_NAME_MAX 32 +#define RPCSVC_NAME_MAX 32 /* The descriptor for each procedure/actor that runs * over the RPC service. */ 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 - * to benefit from being decoded into aligned memory addresses. While - * decoding the request in a non-vectored manner, due to the nature of - * the XDR scheme, RPC cannot guarantee memory aligned addresses for - * the resulting message-specific structures. Allowing a specialized - * handler for letting the RPC program read the data from the network - * directly into its aligned buffers. - */ - rpcsvc_vector_actor vector_actor; - rpcsvc_vector_sizer vector_sizer; - - /* Can actor be ran on behalf an unprivileged requestor? */ - gf_boolean_t unprivileged; + char procname[RPCSVC_NAME_MAX]; + rpcsvc_actor actor; + + /* Handler for cases where the RPC requests fragments are large enough + * to benefit from being decoded into aligned memory addresses. While + * decoding the request in a non-vectored manner, due to the nature of + * the XDR scheme, RPC cannot guarantee memory aligned addresses for + * the resulting message-specific structures. Allowing a specialized + * handler for letting the RPC program read the data from the network + * directly into its aligned buffers. + */ + rpcsvc_vector_sizer vector_sizer; + + int procnum; + + /* Can actor be ran on behalf an unprivileged requestor? */ + 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. */ struct rpcsvc_program { - char progname[RPCSVC_NAME_MAX]; - 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 */ + char progname[RPCSVC_NAME_MAX]; + 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. + */ #if 0 int progaddrfamily; /* AF_INET or AF_INET6 */ char *proghost; /* Bind host, can be NULL */ #endif - rpcsvc_actor_t *actors; /* All procedure handlers */ - 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; - - - /* This upcall is provided by the program during registration. - * It is used to notify the program about events like connection being - * destroyed etc. The rpc program may take appropriate actions, for eg., - * in the case of connection being destroyed, it should cleanup its - * state stored in the connection. - */ - rpcsvc_notify_t notify; - - /* 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; - - /* list member to link to list of registered services with rpcsvc */ - struct list_head program; + rpcsvc_actor_t *actors; /* All procedure handlers */ + int numactors; /* Num actors in actor array */ + int proghighvers; /* Highest ver for program + supported by the system. */ + /* 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 + * destroyed etc. The rpc program may take appropriate actions, for eg., + * in the case of connection being destroyed, it should cleanup its + * state stored in the connection. + */ + 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; + + /* list member to link to list of registered services with rpcsvc */ + struct list_head program; + 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 { - char *progname; - int prognum; - int progver; + char *progname; + int prognum; + int progver; } rpcsvc_cbk_program_t; /* All users of RPC services should use this API to register their * procedure handlers. */ extern int -rpcsvc_program_register (rpcsvc_t *svc, rpcsvc_program_t *program); +rpcsvc_program_register(rpcsvc_t *svc, rpcsvc_program_t *program, + gf_boolean_t add_to_head); extern int -rpcsvc_program_unregister (rpcsvc_t *svc, rpcsvc_program_t *program); +rpcsvc_program_unregister(rpcsvc_t *svc, rpcsvc_program_t *program); /* This will create and add a listener to listener pool. Programs can * use any of the listener in this pool. A single listener can be used by @@ -411,126 +487,150 @@ rpcsvc_program_unregister (rpcsvc_t *svc, rpcsvc_program_t *program); */ /* FIXME: can multiple programs registered on same port? */ extern int32_t -rpcsvc_create_listeners (rpcsvc_t *svc, dict_t *options, char *name); +rpcsvc_create_listeners(rpcsvc_t *svc, dict_t *options, char *name); void -rpcsvc_listener_destroy (rpcsvc_listener_t *listener); +rpcsvc_listener_destroy(rpcsvc_listener_t *listener); extern int -rpcsvc_program_register_portmap (rpcsvc_program_t *newprog, uint32_t port); +rpcsvc_program_register_portmap(rpcsvc_program_t *newprog, uint32_t port); +#ifdef IPV6_DEFAULT +extern int +rpcsvc_program_register_rpcbind6(rpcsvc_program_t *newprog, uint32_t port); extern int -rpcsvc_register_portmap_enabled (rpcsvc_t *svc); +rpcsvc_program_unregister_rpcbind6(rpcsvc_program_t *newprog); +#endif + +extern int +rpcsvc_program_unregister_portmap(rpcsvc_program_t *newprog); + +extern int +rpcsvc_register_portmap_enabled(rpcsvc_t *svc); /* Inits the global RPC service data structures. * Called in main. */ extern rpcsvc_t * -rpcsvc_init (xlator_t *xl, glusterfs_ctx_t *ctx, dict_t *options); +rpcsvc_init(xlator_t *xl, glusterfs_ctx_t *ctx, dict_t *options, + uint32_t poolcount); + +extern int +rpcsvc_reconfigure_options(rpcsvc_t *svc, dict_t *options); int -rpcsvc_register_notify (rpcsvc_t *svc, rpcsvc_notify_t notify, void *mydata); +rpcsvc_register_notify(rpcsvc_t *svc, rpcsvc_notify_t notify, void *mydata); /* unregister a notification callback @notify with data @mydata from svc. * returns the number of notification callbacks unregistered. */ int -rpcsvc_unregister_notify (rpcsvc_t *svc, rpcsvc_notify_t notify, void *mydata); +rpcsvc_unregister_notify(rpcsvc_t *svc, rpcsvc_notify_t notify, void *mydata); int -rpcsvc_submit_message (rpcsvc_request_t *req, struct iovec *proghdr, - int hdrcount, struct iovec *payload, int payloadcount, - struct iobref *iobref); +rpcsvc_transport_submit(rpc_transport_t *trans, struct iovec *rpchdr, + int rpchdrcount, struct iovec *proghdr, + int proghdrcount, struct iovec *progpayload, + int progpayloadcount, struct iobref *iobref, + void *priv); int -rpcsvc_submit_generic (rpcsvc_request_t *req, struct iovec *proghdr, - int hdrcount, struct iovec *payload, int payloadcount, - struct iobref *iobref); +rpcsvc_submit_message(rpcsvc_request_t *req, struct iovec *proghdr, + int hdrcount, struct iovec *payload, int payloadcount, + struct iobref *iobref); + +int +rpcsvc_submit_generic(rpcsvc_request_t *req, struct iovec *proghdr, + int hdrcount, struct iovec *payload, int payloadcount, + struct iobref *iobref); extern int -rpcsvc_error_reply (rpcsvc_request_t *req); +rpcsvc_error_reply(rpcsvc_request_t *req); -#define RPCSVC_PEER_STRLEN 1024 -#define RPCSVC_AUTH_ACCEPT 1 -#define RPCSVC_AUTH_REJECT 2 -#define RPCSVC_AUTH_DONTCARE 3 +#define RPCSVC_PEER_STRLEN 1024 +#define RPCSVC_AUTH_ACCEPT 1 +#define RPCSVC_AUTH_REJECT 2 +#define RPCSVC_AUTH_DONTCARE 3 extern int -rpcsvc_transport_peername (rpc_transport_t *trans, char *hostname, int hostlen); +rpcsvc_transport_peername(rpc_transport_t *trans, char *hostname, int hostlen); -extern inline int -rpcsvc_transport_peeraddr (rpc_transport_t *trans, char *addrstr, int addrlen, - struct sockaddr_storage *returnsa, socklen_t sasize); +extern int +rpcsvc_transport_peeraddr(rpc_transport_t *trans, char *addrstr, int addrlen, + struct sockaddr_storage *returnsa, socklen_t sasize); extern int -rpcsvc_transport_peer_check (dict_t *options, char *volname, - rpc_transport_t *trans); +rpcsvc_auth_check(rpcsvc_t *svc, char *volname, char *ipaddr); extern int -rpcsvc_transport_privport_check (rpcsvc_t *svc, char *volname, - rpc_transport_t *trans); -#define rpcsvc_request_seterr(req, err) (req)->rpc_err = err -#define rpcsvc_request_set_autherr(req, err) (req)->auth_err = err +rpcsvc_transport_privport_check(rpcsvc_t *svc, char *volname, uint16_t port); -extern int rpcsvc_submit_vectors (rpcsvc_request_t *req); +#define rpcsvc_request_seterr(req, err) ((req)->rpc_err = (int)(err)) +#define rpcsvc_request_set_autherr(req, err) ((req)->auth_err = (int)(err)) -extern int rpcsvc_request_attach_vector (rpcsvc_request_t *req, - struct iovec msgvec, struct iobuf *iob, - struct iobref *ioref, int finalvector); +extern int +rpcsvc_submit_vectors(rpcsvc_request_t *req); +extern int +rpcsvc_request_attach_vector(rpcsvc_request_t *req, struct iovec msgvec, + struct iobuf *iob, struct iobref *ioref, + int finalvector); -typedef int (*auth_init_trans) (rpc_transport_t *trans, void *priv); -typedef int (*auth_init_request) (rpcsvc_request_t *req, void *priv); -typedef int (*auth_request_authenticate) (rpcsvc_request_t *req, void *priv); +typedef int (*auth_init_trans)(rpc_transport_t *trans, void *priv); +typedef int (*auth_init_request)(rpcsvc_request_t *req, void *priv); +typedef int (*auth_request_authenticate)(rpcsvc_request_t *req, void *priv); /* This structure needs to be registered by every authentication scheme. * Our authentication schemes are stored per connection because * each connection will end up using a different authentication scheme. */ typedef struct rpcsvc_auth_ops { - auth_init_trans transport_init; - auth_init_request request_init; - auth_request_authenticate authenticate; + auth_init_trans transport_init; + auth_init_request request_init; + auth_request_authenticate authenticate; } rpcsvc_auth_ops_t; typedef struct rpcsvc_auth_flavour_desc { - char authname[RPCSVC_NAME_MAX]; - int authnum; - rpcsvc_auth_ops_t *authops; - void *authprivate; + char authname[RPCSVC_NAME_MAX]; + rpcsvc_auth_ops_t *authops; + void *authprivate; + int authnum; } rpcsvc_auth_t; -typedef void * (*rpcsvc_auth_initer_t) (rpcsvc_t *svc, dict_t *options); +typedef void *(*rpcsvc_auth_initer_t)(rpcsvc_t *svc, dict_t *options); struct rpcsvc_auth_list { - struct list_head authlist; - rpcsvc_auth_initer_t init; - /* Should be the name with which we identify the auth scheme given - * in the volfile options. - * This should be different from the authname in rpc_auth_t - * in way that makes it easier to specify this scheme in the volfile. - * This is because the technical names of the schemes can be a bit - * arcane. - */ - char name[RPCSVC_NAME_MAX]; - rpcsvc_auth_t *auth; - int enable; + struct list_head authlist; + rpcsvc_auth_initer_t init; + /* Should be the name with which we identify the auth scheme given + * in the volfile options. + * This should be different from the authname in rpc_auth_t + * in way that makes it easier to specify this scheme in the volfile. + * This is because the technical names of the schemes can be a bit + * arcane. + */ + char name[RPCSVC_NAME_MAX]; + rpcsvc_auth_t *auth; + int enable; }; extern int -rpcsvc_auth_request_init (rpcsvc_request_t *req); +rpcsvc_auth_request_init(rpcsvc_request_t *req, struct rpc_msg *callmsg); extern int -rpcsvc_auth_init (rpcsvc_t *svc, dict_t *options); +rpcsvc_auth_init(rpcsvc_t *svc, dict_t *options); extern int -rpcsvc_auth_transport_init (rpc_transport_t *xprt); +rpcsvc_auth_reconf(rpcsvc_t *svc, dict_t *options); extern int -rpcsvc_authenticate (rpcsvc_request_t *req); +rpcsvc_auth_transport_init(rpc_transport_t *xprt); extern int -rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen); +rpcsvc_authenticate(rpcsvc_request_t *req); + +extern int +rpcsvc_auth_array(rpcsvc_t *svc, char *volname, int *autharr, int arrlen); /* If the request has been sent using AUTH_UNIX, this function returns the * auxiliary gids as an array, otherwise, it returns NULL. @@ -538,28 +638,57 @@ rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen); * authentication code even further to support mode auth schemes. */ extern gid_t * -rpcsvc_auth_unix_auxgids (rpcsvc_request_t *req, int *arrlen); - -extern int -rpcsvc_combine_gen_spec_volume_checks (int gen, int spec); +rpcsvc_auth_unix_auxgids(rpcsvc_request_t *req, int *arrlen); extern char * -rpcsvc_volume_allowed (dict_t *options, char *volname); +rpcsvc_volume_allowed(dict_t *options, char *volname); -int rpcsvc_callback_submit (rpcsvc_t *rpc, rpc_transport_t *trans, - rpcsvc_cbk_program_t *prog, int procnum, - struct iovec *proghdr, int proghdrcount); +int +rpcsvc_request_submit(rpcsvc_t *rpc, rpc_transport_t *trans, + rpcsvc_cbk_program_t *prog, int procnum, void *req, + glusterfs_ctx_t *ctx, xdrproc_t xdrproc); + +int +rpcsvc_callback_submit(rpcsvc_t *rpc, rpc_transport_t *trans, + rpcsvc_cbk_program_t *prog, int procnum, + struct iovec *proghdr, int proghdrcount, + struct iobref *iobref); + +rpcsvc_actor_t * +rpcsvc_program_actor(rpcsvc_request_t *req); + +int +rpcsvc_transport_unix_options_build(dict_t *options, char *filepath); +int +rpcsvc_set_allow_insecure(rpcsvc_t *svc, dict_t *options); +int +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 -rpcsvc_transport_unix_options_build (dict_t **options, char *filepath); +rpcsvc_set_throttle_on(rpcsvc_t *svc); + int -rpcsvc_set_allow_insecure (rpcsvc_t *svc, dict_t *options); +rpcsvc_set_throttle_off(rpcsvc_t *svc); + +gf_boolean_t +rpcsvc_get_throttle(rpcsvc_t *svc); + int -rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen); -char * -rpcsvc_volume_allowed (dict_t *options, char *volname); +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, uint32_t procnum); +rpcsvc_get_program_vector_sizer(rpcsvc_t *svc, uint32_t prognum, + uint32_t progver, int procnum); +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 8402a62225e..752736b3d4d 100644 --- a/rpc/rpc-lib/src/xdr-common.h +++ b/rpc/rpc-lib/src/xdr-common.h @@ -1,133 +1,116 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _XDR_COMMON_H_ #define _XDR_COMMON_H_ -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include <rpc/types.h> #include <sys/types.h> #include <rpc/xdr.h> +#include <rpc/auth.h> #include <sys/uio.h> #ifdef __NetBSD__ #include <dirent.h> #endif /* __NetBSD__ */ - enum gf_dump_procnum { - GF_DUMP_NULL, - GF_DUMP_DUMP, - GF_DUMP_MAXVALUE, + GF_DUMP_NULL, + GF_DUMP_DUMP, + GF_DUMP_PING, + GF_DUMP_MAXVALUE, }; #define GLUSTER_DUMP_PROGRAM 123451501 /* Completely random */ #define GLUSTER_DUMP_VERSION 1 +/* MAX_AUTH_BYTES is restricted to 400 bytes, see + * http://tools.ietf.org/html/rfc5531#section-8.2 */ +#define GF_MAX_AUTH_BYTES MAX_AUTH_BYTES + +/* The size of an AUTH_GLUSTERFS_V2 structure: + * + * 1 | pid + * 1 | uid + * 1 | gid + * 1 | groups_len + * XX | groups_val (GF_MAX_AUX_GROUPS=65535) + * 1 | lk_owner_len + * YY | lk_owner_val (GF_MAX_LOCK_OWNER_LEN=1024) + * ----+------------------------------------------- + * 5 | total xdr-units + * + * one XDR-unit is defined as BYTES_PER_XDR_UNIT = 4 bytes + * MAX_AUTH_BYTES = 400 is the maximum, this is 100 xdr-units. + * XX + YY can be 95 to fill the 100 xdr-units. + * + * Note that the on-wire protocol has tighter requirements than the internal + * structures. It is possible for xlators to use more groups and a bigger + * lk_owner than that can be sent by a GlusterFS-client. + * + * ------- + * On v3, there are 4 more units, and hence it will be 9 xdr-units + */ +#define GF_AUTH_GLUSTERFS_MAX_GROUPS(lk_len, type) \ + ((type == AUTH_GLUSTERFS_v2) ? (95 - lk_len) : (91 - lk_len)) +#define GF_AUTH_GLUSTERFS_MAX_LKOWNER(groups_len, type) \ + ((type == AUTH_GLUSTERFS_v2) ? (95 - groups_len) : (91 - groups_len)) + +#ifdef GF_LINUX_HOST_OS +#define xdr_u_int32_t xdr_uint32_t +#define xdr_u_int64_t xdr_uint64_t +unsigned long +xdr_sizeof(xdrproc_t func, void *data); +#endif -#if GF_DARWIN_HOST_OS +#ifdef GF_DARWIN_HOST_OS #define xdr_u_quad_t xdr_u_int64_t -#define xdr_quad_t xdr_int64_t +#define xdr_quad_t xdr_int64_t #define xdr_uint32_t xdr_u_int32_t +#define xdr_uint64_t xdr_u_int64_t #define uint64_t u_int64_t +unsigned long +xdr_sizeof(xdrproc_t func, void *data); #endif #if defined(__NetBSD__) #define xdr_u_quad_t xdr_u_int64_t -#define xdr_quad_t xdr_int64_t +#define xdr_quad_t xdr_int64_t #define xdr_uint32_t xdr_u_int32_t +#define xdr_uint64_t xdr_u_int64_t #endif - -#if GF_SOLARIS_HOST_OS +#ifdef GF_SOLARIS_HOST_OS #define u_quad_t uint64_t #define quad_t int64_t #define xdr_u_quad_t xdr_uint64_t -#define xdr_quad_t xdr_int64_t -#define xdr_uint32_t xdr_uint32_t +#define xdr_quad_t xdr_int64_t #endif -struct auth_glusterfs_parms { - uint64_t lk_owner; - u_int pid; - u_int uid; - u_int gid; - u_int ngrps; - u_int groups[16]; -} __attribute__((packed)); -typedef struct auth_glusterfs_parms auth_glusterfs_parms; - -struct gf_dump_req { - uint64_t gfs_id; -} __attribute__((packed)); -typedef struct gf_dump_req gf_dump_req; - -struct gf_prog_detail { - char *progname; - uint64_t prognum; - uint64_t progver; - struct gf_prog_detail *next; -} __attribute__((packed)); -typedef struct gf_prog_detail gf_prog_detail; - -struct gf_dump_rsp { - uint64_t gfs_id; - int op_ret; - int op_errno; - struct gf_prog_detail *prog; -}__attribute__((packed)); -typedef struct gf_dump_rsp gf_dump_rsp; - -extern bool_t -xdr_auth_glusterfs_parms (XDR *xdrs, auth_glusterfs_parms *objp); -extern bool_t xdr_gf_dump_req (XDR *, gf_dump_req*); -extern bool_t xdr_gf_prog_detail (XDR *, gf_prog_detail*); -extern bool_t xdr_gf_dump_rsp (XDR *, gf_dump_rsp*); - -ssize_t -xdr_serialize_dump_rsp (struct iovec outmsg, void *rsp); -ssize_t -xdr_to_dump_req (struct iovec inmsg, void *args); -ssize_t -xdr_from_dump_req (struct iovec outmsg, void *rsp); -ssize_t -xdr_to_dump_rsp (struct iovec inmsg, void *args); - /* Returns the address of the byte that follows the * last byte used for decoding the previous xdr component. * E.g. once the RPC call for NFS has been decoded, the macro will return * the address from which the NFS header starts. */ -#define xdr_decoded_remaining_addr(xdr) ((&xdr)->x_private) +#define xdr_decoded_remaining_addr(xdr) ((&xdr)->x_private) /* Returns the length of the remaining record after the previous decode * operation completed. */ -#define xdr_decoded_remaining_len(xdr) ((&xdr)->x_handy) +#define xdr_decoded_remaining_len(xdr) ((&xdr)->x_handy) /* Returns the number of bytes used by the last encode operation. */ -#define xdr_encoded_length(xdr) (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) +#define xdr_encoded_length(xdr) \ + (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) -#define xdr_decoded_length(xdr) (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) +#define xdr_decoded_length(xdr) \ + (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) #endif diff --git a/rpc/rpc-lib/src/xdr-rpc.c b/rpc/rpc-lib/src/xdr-rpc.c index e4e5b108710..4992dc5a7ce 100644 --- a/rpc/rpc-lib/src/xdr-rpc.c +++ b/rpc/rpc-lib/src/xdr-rpc.c @@ -1,221 +1,198 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #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. */ int -xdr_to_rpc_call (char *msgbuf, size_t len, struct rpc_msg *call, - struct iovec *payload, char *credbytes, char *verfbytes) +xdr_to_rpc_call(char *msgbuf, size_t len, struct rpc_msg *call, + struct iovec *payload, char *credbytes, char *verfbytes) { - XDR xdr; - char opaquebytes[MAX_AUTH_BYTES]; - struct opaque_auth *oa = NULL; - int ret = -1; - - GF_VALIDATE_OR_GOTO ("rpc", msgbuf, out); - GF_VALIDATE_OR_GOTO ("rpc", call, out); - - memset (call, 0, sizeof (*call)); - - oa = &call->rm_call.cb_cred; - if (!credbytes) - oa->oa_base = opaquebytes; - else - oa->oa_base = credbytes; - - oa = &call->rm_call.cb_verf; - if (!verfbytes) - oa->oa_base = opaquebytes; - else - oa->oa_base = verfbytes; - - xdrmem_create (&xdr, msgbuf, len, XDR_DECODE); - if (!xdr_callmsg (&xdr, call)) { - gf_log ("rpc", GF_LOG_WARNING, "failed to decode call msg"); - goto out; - } - - if (payload) { - payload->iov_base = xdr_decoded_remaining_addr (xdr); - payload->iov_len = xdr_decoded_remaining_len (xdr); - } - - ret = 0; + XDR xdr; + char opaquebytes[GF_MAX_AUTH_BYTES]; + struct opaque_auth *oa = NULL; + int ret = -1; + + GF_VALIDATE_OR_GOTO("rpc", msgbuf, out); + GF_VALIDATE_OR_GOTO("rpc", call, out); + + memset(call, 0, sizeof(*call)); + + oa = &call->rm_call.cb_cred; + if (!credbytes) + oa->oa_base = opaquebytes; + else + oa->oa_base = credbytes; + + oa = &call->rm_call.cb_verf; + if (!verfbytes) + oa->oa_base = opaquebytes; + else + oa->oa_base = verfbytes; + + xdrmem_create(&xdr, msgbuf, len, XDR_DECODE); + if (!xdr_callmsg(&xdr, call)) { + gf_log("rpc", GF_LOG_WARNING, "failed to decode call msg"); + goto out; + } + + if (payload) { + payload->iov_base = xdr_decoded_remaining_addr(xdr); + payload->iov_len = xdr_decoded_remaining_len(xdr); + } + + ret = 0; out: - return ret; + return ret; } - bool_t -true_func (XDR *s, caddr_t *a) +true_func(XDR *s, caddr_t *a) { - return TRUE; + return TRUE; } - int -rpc_fill_empty_reply (struct rpc_msg *reply, uint32_t xid) +rpc_fill_empty_reply(struct rpc_msg *reply, uint32_t xid) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("rpc", reply, out); + GF_VALIDATE_OR_GOTO("rpc", reply, out); - /* Setting to 0 also results in reply verifier flavor to be - * set to AUTH_NULL which is what we want right now. - */ - memset (reply, 0, sizeof (*reply)); - reply->rm_xid = xid; - reply->rm_direction = REPLY; + /* Setting to 0 also results in reply verifier flavor to be + * set to AUTH_NULL which is what we want right now. + */ + memset(reply, 0, sizeof(*reply)); + reply->rm_xid = xid; + reply->rm_direction = REPLY; - ret = 0; + ret = 0; out: - return ret; + return ret; } int -rpc_fill_denied_reply (struct rpc_msg *reply, int rjstat, int auth_err) +rpc_fill_denied_reply(struct rpc_msg *reply, int rjstat, int auth_err) { - int ret = -1; - - GF_VALIDATE_OR_GOTO ("rpc", reply, out); - - reply->rm_reply.rp_stat = MSG_DENIED; - reply->rjcted_rply.rj_stat = rjstat; - if (rjstat == RPC_MISMATCH) { - /* No problem with hardcoding - * RPC version numbers. We only support - * v2 anyway. - */ - reply->rjcted_rply.rj_vers.low = 2; - reply->rjcted_rply.rj_vers.high = 2; - } else if (rjstat == AUTH_ERROR) - reply->rjcted_rply.rj_why = auth_err; - - ret = 0; + int ret = -1; + + GF_VALIDATE_OR_GOTO("rpc", reply, out); + + reply->rm_reply.rp_stat = MSG_DENIED; + reply->rjcted_rply.rj_stat = rjstat; + if (rjstat == RPC_MISMATCH) { + /* No problem with hardcoding + * RPC version numbers. We only support + * v2 anyway. + */ + reply->rjcted_rply.rj_vers.low = 2; + reply->rjcted_rply.rj_vers.high = 2; + } else if (rjstat == AUTH_ERROR) + reply->rjcted_rply.rj_why = auth_err; + + ret = 0; out: - return ret; + return ret; } - int -rpc_fill_accepted_reply (struct rpc_msg *reply, int arstat, int proglow, - int proghigh, int verf, int len, char *vdata) +rpc_fill_accepted_reply(struct rpc_msg *reply, int arstat, int proglow, + int proghigh, int verf, int len, char *vdata) { - int ret = -1; - - GF_VALIDATE_OR_GOTO ("rpc", reply, out); - - reply->rm_reply.rp_stat = MSG_ACCEPTED; - reply->acpted_rply.ar_stat = arstat; - - reply->acpted_rply.ar_verf.oa_flavor = verf; - reply->acpted_rply.ar_verf.oa_length = len; - reply->acpted_rply.ar_verf.oa_base = vdata; - if (arstat == PROG_MISMATCH) { - reply->acpted_rply.ar_vers.low = proglow; - reply->acpted_rply.ar_vers.high = proghigh; - } else if (arstat == SUCCESS) { - - /* This is a hack. I'd really like to build a custom - * XDR library because Sun RPC interface is not very flexible. - */ - reply->acpted_rply.ar_results.proc = (xdrproc_t)true_func; - reply->acpted_rply.ar_results.where = NULL; - } + int ret = -1; + + GF_VALIDATE_OR_GOTO("rpc", reply, out); + + reply->rm_reply.rp_stat = MSG_ACCEPTED; + reply->acpted_rply.ar_stat = arstat; + + reply->acpted_rply.ar_verf.oa_flavor = verf; + reply->acpted_rply.ar_verf.oa_length = len; + reply->acpted_rply.ar_verf.oa_base = vdata; + if (arstat == PROG_MISMATCH) { + reply->acpted_rply.ar_vers.low = proglow; + reply->acpted_rply.ar_vers.high = proghigh; + } else if (arstat == SUCCESS) { + /* This is a hack. I'd really like to build a custom + * XDR library because Sun RPC interface is not very flexible. + */ + reply->acpted_rply.ar_results.proc = (xdrproc_t)true_func; + reply->acpted_rply.ar_results.where = NULL; + } - ret = 0; + ret = 0; out: - return ret; + return ret; } int -rpc_reply_to_xdr (struct rpc_msg *reply, char *dest, size_t len, - struct iovec *dst) +rpc_reply_to_xdr(struct rpc_msg *reply, char *dest, size_t len, + struct iovec *dst) { - XDR xdr; - int ret = -1; + XDR xdr; + int ret = -1; - GF_VALIDATE_OR_GOTO ("rpc", reply, out); - GF_VALIDATE_OR_GOTO ("rpc", dest, out); - GF_VALIDATE_OR_GOTO ("rpc", dst, out); + GF_VALIDATE_OR_GOTO("rpc", reply, out); + GF_VALIDATE_OR_GOTO("rpc", dest, out); + GF_VALIDATE_OR_GOTO("rpc", dst, out); - xdrmem_create (&xdr, dest, len, XDR_ENCODE); - if (!xdr_replymsg(&xdr, reply)) { - gf_log ("rpc", GF_LOG_WARNING, "failed to encode reply msg"); - goto out; - } + xdrmem_create(&xdr, dest, len, XDR_ENCODE); + if (!xdr_replymsg(&xdr, reply)) { + gf_log("rpc", GF_LOG_WARNING, "failed to encode reply msg"); + goto out; + } - dst->iov_base = dest; - dst->iov_len = xdr_encoded_length (xdr); + dst->iov_base = dest; + dst->iov_len = xdr_encoded_length(xdr); - ret = 0; + ret = 0; out: - return ret; + return ret; } - int -xdr_to_auth_unix_cred (char *msgbuf, int msglen, struct authunix_parms *au, - char *machname, gid_t *gids) +xdr_to_auth_unix_cred(char *msgbuf, int msglen, struct authunix_parms *au, + char *machname, gid_t *gids) { - XDR xdr; - int ret = -1; + XDR xdr; + int ret = -1; - GF_VALIDATE_OR_GOTO ("rpc", msgbuf, out); - GF_VALIDATE_OR_GOTO ("rpc", machname, out); - GF_VALIDATE_OR_GOTO ("rpc", gids, out); - GF_VALIDATE_OR_GOTO ("rpc", au, out); + GF_VALIDATE_OR_GOTO("rpc", msgbuf, out); + GF_VALIDATE_OR_GOTO("rpc", machname, out); + GF_VALIDATE_OR_GOTO("rpc", gids, out); + GF_VALIDATE_OR_GOTO("rpc", au, out); - au->aup_machname = machname; -#ifdef GF_DARWIN_HOST_OS - au->aup_gids = (int *)gids; + au->aup_machname = machname; +#if defined(GF_DARWIN_HOST_OS) || defined(__FreeBSD__) + au->aup_gids = (int *)gids; #else - au->aup_gids = gids; + au->aup_gids = gids; #endif - xdrmem_create (&xdr, msgbuf, msglen, XDR_DECODE); + xdrmem_create(&xdr, msgbuf, msglen, XDR_DECODE); - if (!xdr_authunix_parms (&xdr, au)) { - gf_log ("rpc", GF_LOG_WARNING, "failed to decode auth unix parms"); - goto out; - } + if (!xdr_authunix_parms(&xdr, au)) { + gf_log("rpc", GF_LOG_WARNING, "failed to decode auth unix parms"); + goto out; + } - ret = 0; + ret = 0; out: - return ret; + return ret; } diff --git a/rpc/rpc-lib/src/xdr-rpc.h b/rpc/rpc-lib/src/xdr-rpc.h index 99ad888361c..7baed273846 100644 --- a/rpc/rpc-lib/src/xdr-rpc.h +++ b/rpc/rpc-lib/src/xdr-rpc.h @@ -1,30 +1,16 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _XDR_RPC_H +#ifndef _XDR_RPC_H_ #define _XDR_RPC_H_ -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #ifndef GF_SOLARIS_HOST_OS #include <rpc/rpc.h> #endif @@ -34,49 +20,76 @@ #include <rpc/auth_sys.h> #endif -//#include <rpc/pmap_clnt.h> #include <arpa/inet.h> #include <rpc/xdr.h> #include <sys/uio.h> +#include "xdr-common.h" + +typedef enum { + AUTH_GLUSTERFS = 5, + AUTH_GLUSTERFS_v2 = 390039, /* using a number from 'unused' range, + from the list available in RFC5531 */ + AUTH_GLUSTERFS_v3 = 390040, /* this too is unused */ +} gf_rpc_authtype_t; + /* Converts a given network buffer from its XDR format to a structure * that contains everything an RPC call needs to work. */ extern int -xdr_to_rpc_call (char *msgbuf, size_t len, struct rpc_msg *call, - struct iovec *payload, char *credbytes, char *verfbytes); +xdr_to_rpc_call(char *msgbuf, size_t len, struct rpc_msg *call, + struct iovec *payload, char *credbytes, char *verfbytes); extern int -rpc_fill_empty_reply (struct rpc_msg *reply, uint32_t xid); +rpc_fill_empty_reply(struct rpc_msg *reply, uint32_t xid); extern int -rpc_fill_denied_reply (struct rpc_msg *reply, int rjstat, int auth_err); +rpc_fill_denied_reply(struct rpc_msg *reply, int rjstat, int auth_err); extern int -rpc_fill_accepted_reply (struct rpc_msg *reply, int arstat, int proglow, - int proghigh, int verf, int len, char *vdata); +rpc_fill_accepted_reply(struct rpc_msg *reply, int arstat, int proglow, + int proghigh, int verf, int len, char *vdata); extern int -rpc_reply_to_xdr (struct rpc_msg *reply, char *dest, size_t len, - struct iovec *dst); +rpc_reply_to_xdr(struct rpc_msg *reply, char *dest, size_t len, + struct iovec *dst); extern int -xdr_to_auth_unix_cred (char *msgbuf, int msglen, struct authunix_parms *au, - char *machname, gid_t *gids); +xdr_to_auth_unix_cred(char *msgbuf, int msglen, struct authunix_parms *au, + char *machname, gid_t *gids); /* Macros that simplify accessing the members of an RPC call structure. */ -#define rpc_call_xid(call) ((call)->rm_xid) -#define rpc_call_direction(call) ((call)->rm_direction) -#define rpc_call_rpcvers(call) ((call)->ru.RM_cmb.cb_rpcvers) -#define rpc_call_program(call) ((call)->ru.RM_cmb.cb_prog) -#define rpc_call_progver(call) ((call)->ru.RM_cmb.cb_vers) -#define rpc_call_progproc(call) ((call)->ru.RM_cmb.cb_proc) -#define rpc_opaque_auth_flavour(oa) ((oa)->oa_flavor) -#define rpc_opaque_auth_len(oa) ((oa)->oa_length) - -#define rpc_call_cred_flavour(call) (rpc_opaque_auth_flavour ((&(call)->ru.RM_cmb.cb_cred))) -#define rpc_call_cred_len(call) (rpc_opaque_auth_len ((&(call)->ru.RM_cmb.cb_cred))) - - -#define rpc_call_verf_flavour(call) (rpc_opaque_auth_flavour ((&(call)->ru.RM_cmb.cb_verf))) -#define rpc_call_verf_len(call) (rpc_opaque_auth_len ((&(call)->ru.RM_cmb.cb_verf))) +#define rpc_call_xid(call) ((call)->rm_xid) +#define rpc_call_direction(call) ((call)->rm_direction) +#define rpc_call_rpcvers(call) ((call)->ru.RM_cmb.cb_rpcvers) +#define rpc_call_program(call) ((call)->ru.RM_cmb.cb_prog) +#define rpc_call_progver(call) ((call)->ru.RM_cmb.cb_vers) +#define rpc_call_progproc(call) ((call)->ru.RM_cmb.cb_proc) +#define rpc_opaque_auth_flavour(oa) ((oa)->oa_flavor) +#define rpc_opaque_auth_len(oa) ((oa)->oa_length) + +#define rpc_call_cred_flavour(call) \ + (rpc_opaque_auth_flavour((&(call)->ru.RM_cmb.cb_cred))) +#define rpc_call_cred_len(call) \ + (rpc_opaque_auth_len((&(call)->ru.RM_cmb.cb_cred))) + +#define rpc_call_verf_flavour(call) \ + (rpc_opaque_auth_flavour((&(call)->ru.RM_cmb.cb_verf))) +#define rpc_call_verf_len(call) \ + (rpc_opaque_auth_len((&(call)->ru.RM_cmb.cb_verf))) + +#if defined(GF_DARWIN_HOST_OS) || !defined(HAVE_RPC_RPC_H) +#define GF_PRI_RPC_XID PRIu32 +#define GF_PRI_RPC_VERSION PRIu32 +#define GF_PRI_RPC_PROG_ID PRIu32 +#define GF_PRI_RPC_PROG_VERS PRIu32 +#define GF_PRI_RPC_PROC PRIu32 +#define GF_PRI_RPC_PROC_VERSION PRIu32 +#else +#define GF_PRI_RPC_XID PRIu64 +#define GF_PRI_RPC_VERSION PRIu64 +#define GF_PRI_RPC_PROG_ID PRIu64 +#define GF_PRI_RPC_PROG_VERS PRIu64 +#define GF_PRI_RPC_PROC PRIu64 +#define GF_PRI_RPC_PROC_VERSION PRIu64 +#endif #endif diff --git a/rpc/rpc-lib/src/xdr-rpcclnt.c b/rpc/rpc-lib/src/xdr-rpcclnt.c index 69daa98cb4f..8dcdcfeda83 100644 --- a/rpc/rpc-lib/src/xdr-rpcclnt.c +++ b/rpc/rpc-lib/src/xdr-rpcclnt.c @@ -1,126 +1,105 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #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. */ int -xdr_to_rpc_reply (char *msgbuf, size_t len, struct rpc_msg *reply, - struct iovec *payload, char *verfbytes) +xdr_to_rpc_reply(char *msgbuf, size_t len, struct rpc_msg *reply, + struct iovec *payload, char *verfbytes) { - XDR xdr; - int ret = -EINVAL; - - GF_VALIDATE_OR_GOTO ("rpc", msgbuf, out); - GF_VALIDATE_OR_GOTO ("rpc", reply, out); - - memset (reply, 0, sizeof (struct rpc_msg)); - - reply->acpted_rply.ar_verf = _null_auth; - reply->acpted_rply.ar_results.where = NULL; - reply->acpted_rply.ar_results.proc = (xdrproc_t)(xdr_void); - - xdrmem_create (&xdr, msgbuf, len, XDR_DECODE); - if (!xdr_replymsg (&xdr, reply)) { - gf_log ("rpc", GF_LOG_WARNING, "failed to decode reply msg"); - ret = -errno; - goto out; - } - if (payload) { - payload->iov_base = xdr_decoded_remaining_addr (xdr); - payload->iov_len = xdr_decoded_remaining_len (xdr); - } - - ret = 0; + XDR xdr; + int ret = -EINVAL; + + GF_VALIDATE_OR_GOTO("rpc", msgbuf, out); + GF_VALIDATE_OR_GOTO("rpc", reply, out); + + memset(reply, 0, sizeof(struct rpc_msg)); + + reply->acpted_rply.ar_verf = _null_auth; + reply->acpted_rply.ar_results.where = NULL; + reply->acpted_rply.ar_results.proc = (xdrproc_t)(xdr_void); + + xdrmem_create(&xdr, msgbuf, len, XDR_DECODE); + if (!xdr_replymsg(&xdr, reply)) { + gf_log("rpc", GF_LOG_WARNING, "failed to decode reply msg"); + goto out; + } + if (payload) { + payload->iov_base = xdr_decoded_remaining_addr(xdr); + payload->iov_len = xdr_decoded_remaining_len(xdr); + } + + ret = 0; out: - return ret; + return ret; } - int -rpc_request_to_xdr (struct rpc_msg *request, char *dest, size_t len, - struct iovec *dst) +rpc_request_to_xdr(struct rpc_msg *request, char *dest, size_t len, + struct iovec *dst) { - XDR xdr; - int ret = -1; + XDR xdr; + int ret = -1; - GF_VALIDATE_OR_GOTO ("rpc", dest, out); - GF_VALIDATE_OR_GOTO ("rpc", request, out); - GF_VALIDATE_OR_GOTO ("rpc", dst, out); + GF_VALIDATE_OR_GOTO("rpc", dest, out); + GF_VALIDATE_OR_GOTO("rpc", request, out); + GF_VALIDATE_OR_GOTO("rpc", dst, out); - xdrmem_create (&xdr, dest, len, XDR_ENCODE); - if (!xdr_callmsg (&xdr, request)) { - gf_log ("rpc", GF_LOG_WARNING, "failed to encode call msg"); - goto out; - } + xdrmem_create(&xdr, dest, len, XDR_ENCODE); + if (!xdr_callmsg(&xdr, request)) { + gf_log("rpc", GF_LOG_WARNING, "failed to encode call msg"); + goto out; + } - dst->iov_base = dest; - dst->iov_len = xdr_encoded_length (xdr); + dst->iov_base = dest; + dst->iov_len = xdr_encoded_length(xdr); - ret = 0; + ret = 0; out: - return ret; + return ret; } - int -auth_unix_cred_to_xdr (struct authunix_parms *au, char *dest, size_t len, - struct iovec *iov) +auth_unix_cred_to_xdr(struct authunix_parms *au, char *dest, size_t len, + struct iovec *iov) { - XDR xdr; - int ret = -1; + XDR xdr; + int ret = -1; - GF_VALIDATE_OR_GOTO ("rpc", au, out); - GF_VALIDATE_OR_GOTO ("rpc", dest, out); - GF_VALIDATE_OR_GOTO ("rpc", iov, out); + GF_VALIDATE_OR_GOTO("rpc", au, out); + GF_VALIDATE_OR_GOTO("rpc", dest, out); + GF_VALIDATE_OR_GOTO("rpc", iov, out); - xdrmem_create (&xdr, dest, len, XDR_DECODE); + xdrmem_create(&xdr, dest, len, XDR_DECODE); - if (!xdr_authunix_parms (&xdr, au)) { - gf_log ("rpc", GF_LOG_WARNING, "failed to decode authunix parms"); - goto out; - } + if (!xdr_authunix_parms(&xdr, au)) { + gf_log("rpc", GF_LOG_WARNING, "failed to decode authunix parms"); + goto out; + } - iov->iov_base = dest; - iov->iov_len = xdr_encoded_length (xdr); + iov->iov_base = dest; + iov->iov_len = xdr_encoded_length(xdr); - ret = 0; + ret = 0; out: - return ret; + return ret; } diff --git a/rpc/rpc-lib/src/xdr-rpcclnt.h b/rpc/rpc-lib/src/xdr-rpcclnt.h index 3bcf5b54b94..58eda4892a9 100644 --- a/rpc/rpc-lib/src/xdr-rpcclnt.h +++ b/rpc/rpc-lib/src/xdr-rpcclnt.h @@ -1,32 +1,16 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _XDR_RPCCLNT_H #define _XDR_RPCCLNT_H -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -//#include <rpc/rpc.h> -//#include <rpc/pmap_clnt.h> #include <arpa/inet.h> #include <rpc/xdr.h> #include <sys/uio.h> @@ -34,18 +18,19 @@ #include <rpc/auth_unix.h> /* Macros that simplify accessing the members of an RPC call structure. */ -#define rpc_reply_xid(reply) ((reply)->rm_xid) -#define rpc_reply_status(reply) ((reply)->ru.RM_rmb.rp_stat) -#define rpc_accepted_reply_status(reply) ((reply)->acpted_rply.ar_stat) -#define rpc_reply_verf_flavour(reply) ((reply)->acpted_rply.ar_verf.oa_flavor) +#define rpc_reply_xid(reply) ((reply)->rm_xid) +#define rpc_reply_status(reply) ((reply)->ru.RM_rmb.rp_stat) +#define rpc_accepted_reply_status(reply) ((reply)->acpted_rply.ar_stat) +#define rpc_reply_verf_flavour(reply) ((reply)->acpted_rply.ar_verf.oa_flavor) -int xdr_to_rpc_reply (char *msgbuf, size_t len, struct rpc_msg *reply, - struct iovec *payload, char *verfbytes); int -rpc_request_to_xdr (struct rpc_msg *request, char *dest, size_t len, - struct iovec *dst); +xdr_to_rpc_reply(char *msgbuf, size_t len, struct rpc_msg *reply, + struct iovec *payload, char *verfbytes); +int +rpc_request_to_xdr(struct rpc_msg *request, char *dest, size_t len, + struct iovec *dst); int -auth_unix_cred_to_xdr (struct authunix_parms *au, char *dest, size_t len, - struct iovec *iov); +auth_unix_cred_to_xdr(struct authunix_parms *au, char *dest, size_t len, + struct iovec *iov); #endif 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 bc888b1750c..00000000000 --- a/rpc/rpc-transport/rdma/src/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -# TODO : need to change transportdir - -transport_LTLIBRARIES = rdma.la -transportdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/rpc-transport - -rdma_la_LDFLAGS = -module -avoidversion - -rdma_la_SOURCES = rdma.c name.c -rdma_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ - -libverbs - -noinst_HEADERS = rdma.h name.h - -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/rpc/rpc-lib/src/ \ - -I$(top_srcdir)/xlators/protocol/lib/src/ -shared -nostartfiles $(GF_CFLAGS) - -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \ - -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/rpc/rpc-lib/src/ \ - -I$(top_srcdir)/xlators/protocol/lib/src -shared -nostartfiles $(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 702c8a86a6b..00000000000 --- a/rpc/rpc-transport/rdma/src/name.c +++ /dev/null @@ -1,707 +0,0 @@ -/* - Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include <sys/types.h> -#include <sys/socket.h> -#include <errno.h> -#include <netdb.h> -#include <string.h> - -#ifdef CLIENT_PORT_CEILING -#undef CLIENT_PORT_CEILING -#endif - -#define CLIENT_PORT_CEILING 1024 - -#ifndef AF_INET_SDP -#define AF_INET_SDP 27 -#endif - -#include "rpc-transport.h" -#include "rdma.h" - -int32_t -gf_resolve_ip6 (const char *hostname, - uint16_t port, - int family, - void **dnscache, - struct addrinfo **addr_info); - -static int32_t -af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr, - socklen_t sockaddr_len, int ceiling) -{ - int32_t ret = -1; - /* struct sockaddr_in sin = {0, }; */ - uint16_t port = ceiling - 1; - - while (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; - } - - ret = bind (fd, sockaddr, sockaddr_len); - - if (ret == 0) - break; - - if (ret == -1 && errno == EACCES) - break; - - port--; - } - - return ret; -} - -static int32_t -af_unix_client_bind (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t sockaddr_len, - int sock) -{ - 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_log (this->name, GF_LOG_DEBUG, - "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_log (this->name, GF_LOG_ERROR, - "cannot bind to unix-domain socket %d (%s)", - sock, strerror (errno)); - goto err; - } - } - -err: - return ret; -} - -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_log (this->name, GF_LOG_ERROR, - "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_log (this->name, GF_LOG_DEBUG, - "address-family not specified, guessing it " - "to be inet/inet6"); - sockaddr->sa_family = AF_UNSPEC; - } else { - gf_log (this->name, GF_LOG_DEBUG, - "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 if (!strcasecmp (address_family, "inet/inet6") - || !strcasecmp (address_family, "inet6/inet")) { - sockaddr->sa_family = AF_UNSPEC; - } else { - gf_log (this->name, GF_LOG_ERROR, - "unknown address-family (%s) specified", - address_family); - 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_log (this->name, GF_LOG_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_log (this->name, GF_LOG_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_log (this->name, GF_LOG_DEBUG, - "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_log (this->name, GF_LOG_ERROR, - "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_log (this->name, GF_LOG_ERROR, - "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_log (this->name, GF_LOG_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_log (this->name, GF_LOG_ERROR, - "connect-path is null-string"); - ret = -1; - goto err; - } - - if (strlen (connect_path) > UNIX_PATH_MAX) { - gf_log (this->name, GF_LOG_ERROR, - "connect-path value length %"GF_PRI_SIZET" > " - "%d octets", strlen (connect_path), UNIX_PATH_MAX); - ret = -1; - goto err; - } - - gf_log (this->name, - GF_LOG_DEBUG, - "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_log (this->name, GF_LOG_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_log (this->name, GF_LOG_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 = -1; - 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"); - listen_host_data = dict_get (options, - "transport.rdma.bind-address"); - - if (listen_port_data) { - listen_port = data_to_uint16 (listen_port_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; - } - } - - if (listen_port == (uint16_t) -1) - listen_port = GF_DEFAULT_RDMA_LISTEN_PORT; - - - if (listen_host_data) { - listen_host = data_to_str (listen_host_data); - } - - memset (service, 0, sizeof (service)); - 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_log (this->name, GF_LOG_ERROR, - "getaddrinfo failed for host %s, service %s (%s)", - listen_host, service, gai_strerror (ret)); - 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, - int sock) -{ - 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); - - case AF_INET6: - ret = af_inet_bind_to_port_lt_ceiling (sock, sockaddr, - *sockaddr_len, - CLIENT_PORT_CEILING); - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "cannot bind inet socket (%d) to port " - "less than %d (%s)", - sock, CLIENT_PORT_CEILING, strerror (errno)); - ret = 0; - } - break; - - case AF_UNIX: - *sockaddr_len = sizeof (struct sockaddr_un); - ret = af_unix_client_bind (this, (struct sockaddr *)sockaddr, - *sockaddr_len, sock); - break; - - default: - gf_log (this->name, GF_LOG_ERROR, - "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; - - 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_log (this->name, GF_LOG_ERROR, - "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 if (!strcasecmp (address_family, "inet/inet6") - || !strcasecmp (address_family, "inet6/inet")) { - addr->sa_family = AF_UNSPEC; - } else { - gf_log (this->name, GF_LOG_ERROR, - "unknown address family (%s) specified", - address_family); - ret = -1; - goto err; - } - } else { - gf_log (this->name, GF_LOG_DEBUG, - "option address-family not specified, defaulting " - "to inet/inet6"); - addr->sa_family = AF_UNSPEC; - } - - switch (addr->sa_family) - { - case AF_INET_SDP: - is_inet_sdp = 1; - addr->sa_family = AF_INET; - - 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_log (this->name, - GF_LOG_ERROR, - "getnameinfo failed (%s)", gai_strerror (ret)); - } - - 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; - - 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_log (this->name, GF_LOG_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_log (this->name, GF_LOG_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_log (this->name, GF_LOG_ERROR, - "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 1f6fc89fd15..00000000000 --- a/rpc/rpc-transport/rdma/src/name.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _IB_VERBS_NAME_H -#define _IB_VERBS_NAME_H - -#include <sys/socket.h> -#include <sys/un.h> - -#include "compat.h" - -int32_t -gf_rdma_client_bind (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - int sock); - -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 d3a8e9c8d97..00000000000 --- a/rpc/rpc-transport/rdma/src/rdma.c +++ /dev/null @@ -1,4958 +0,0 @@ -/* - Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "dict.h" -#include "glusterfs.h" -#include "logging.h" -#include "rdma.h" -#include "name.h" -#include "byte-order.h" -#include "xlator.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); - -int32_t -gf_resolve_ip6 (const char *hostname, - uint16_t port, - int family, - void **dnscache, - struct addrinfo **addr_info); - -static uint16_t -gf_rdma_get_local_lid (struct ibv_context *context, - int32_t port) -{ - struct ibv_port_attr attr; - - if (ibv_query_port (context, port, &attr)) - return 0; - - return attr.lid; -} - -static const char * -get_port_state_str(enum ibv_port_state pstate) -{ - switch (pstate) { - case IBV_PORT_DOWN: return "PORT_DOWN"; - case IBV_PORT_INIT: return "PORT_INIT"; - case IBV_PORT_ARMED: return "PORT_ARMED"; - case IBV_PORT_ACTIVE: return "PORT_ACTIVE"; - case IBV_PORT_ACTIVE_DEFER: return "PORT_ACTIVE_DEFER"; - default: return "invalid state"; - } -} - -static int32_t -ib_check_active_port (struct ibv_context *ctx, uint8_t port) -{ - struct ibv_port_attr port_attr = {0, }; - int32_t ret = 0; - const char *state_str = NULL; - - if (!ctx) { - gf_log_callingfn (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "Error in supplied context"); - return -1; - } - - ret = ibv_query_port (ctx, port, &port_attr); - - if (ret) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "Failed to query port %u properties", port); - return -1; - } - - state_str = get_port_state_str (port_attr.state); - gf_log (GF_RDMA_LOG_NAME, GF_LOG_TRACE, - "Infiniband PORT: (%u) STATE: (%s)", - port, state_str); - - if (port_attr.state == IBV_PORT_ACTIVE) - return 0; - - return -1; -} - -static int32_t -ib_get_active_port (struct ibv_context *ib_ctx) -{ - struct ibv_device_attr ib_device_attr = {{0, }, }; - int32_t ret = -1; - uint8_t ib_port = 0; - - if (!ib_ctx) { - gf_log_callingfn (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "Error in supplied context"); - return -1; - } - if (ibv_query_device (ib_ctx, &ib_device_attr)) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "Failed to query device properties"); - return -1; - } - - for (ib_port = 1; ib_port <= ib_device_attr.phys_port_cnt; ++ib_port) { - ret = ib_check_active_port (ib_ctx, ib_port); - if (ret == 0) - return ib_port; - - gf_log (GF_RDMA_LOG_NAME, GF_LOG_TRACE, - "Port:(%u) not active", ib_port); - continue; - } - return ret; -} - - -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 (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_log_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_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "memory registration failed"); - goto out; - } - - post->device = device; - post->type = type; - - ret = 0; -out: - if (ret != 0) { - if (post->buf != NULL) { - 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 int32_t - gf_rdma_quota_get (gf_rdma_peer_t *peer) - { - int32_t ret = -1; - gf_rdma_private_t *priv = peer->trans->private; - - pthread_mutex_lock (&priv->write_mutex); - { - ret = __gf_rdma_quota_get (peer); - } - pthread_mutex_unlock (&priv->write_mutex); - - 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; - int32_t ret = 0; - - priv = this->private; - - if (priv->connected || priv->tcp_connected) { - fcntl (priv->sock, F_SETFL, O_NONBLOCK); - if (shutdown (priv->sock, SHUT_RDWR) != 0) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "shutdown () - error: %s", - strerror (errno)); - ret = -errno; - priv->tcp_connected = 0; - priv->connected = 0; - } - } - - return ret; -} - - -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, uint32_t *ptr, - gf_rdma_errcode_t err) -{ - uint32_t *startp = NULL; - struct rpc_msg *rpc_msg = NULL; - - startp = ptr; - if (reply_info != NULL) { - *ptr++ = hton32(reply_info->rm_xid); - } else { - rpc_msg = rpchdr[0].iov_base; /* assume rpchdr contains - * only one vector. - * (which is true) - */ - *ptr++ = rpc_msg->rm_xid; - } - - *ptr++ = hton32(GF_RDMA_VERSION); - *ptr++ = hton32(peer->send_count); - *ptr++ = hton32(GF_RDMA_ERROR); - *ptr++ = hton32(err); - if (err == ERR_VERS) { - *ptr++ = hton32(GF_RDMA_VERSION); - *ptr++ = hton32(GF_RDMA_VERSION); - } - - return (int)((unsigned long)ptr - (unsigned long)startp); -} - - -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, - (uint32_t *)post->buf, err); - if (len == -1) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_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_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - "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 = ibv_reg_mr (device->pd, vector[i].iov_base, - vector[i].iov_len, - IBV_ACCESS_REMOTE_READ); - if (!mr) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "memory registration failed"); - 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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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 = ibv_reg_mr (device->pd, vector[i].iov_base, - vector[i].iov_len, - IBV_ACCESS_REMOTE_WRITE - | IBV_ACCESS_LOCAL_WRITE); - if (!mr) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "memory registration failed"); - 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_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - (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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "cannot create write chunks from vector " - "entry->rpchdr"); - goto out; - } - - /* terminate reply chunklist */ - **ptr = 0; - *ptr = *ptr + 1; - } - -out: - return ret; -} - - -inline void -__gf_rdma_deregister_mr (struct ibv_mr **mr, int count) -{ - int i = 0; - - if (mr == NULL) { - goto out; - } - - for (i = 0; i < count; i++) { - 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; - int32_t ret = 0; - - if (context == NULL) { - goto out; - } - - peer = context->peer; - - __gf_rdma_deregister_mr (context->mr, context->mr_count); - - priv = peer->trans->private; - - if (priv->connected) { - ret = __gf_rdma_quota_put (peer); - if (ret < 0) { - gf_log ("rdma", GF_LOG_DEBUG, - "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_post_context_t *ctx) -{ - if (ctx == NULL) { - goto out; - } - - __gf_rdma_deregister_mr (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; -} - - -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); -} - - -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->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_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - "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; -} - - -inline 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); - 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_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - "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_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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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; -} - - -inline 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; - - if ((ctx == NULL) || (vector == NULL)) { - goto 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] = ibv_reg_mr (device->pd, - vector[i].iov_base, - vector[i].iov_len, - IBV_ACCESS_LOCAL_WRITE); - if (ctx->mr[ctx->mr_count] == NULL) { - 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_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "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) { - 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) { - 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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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_rdma_post_unref (post); - goto out; - } - - ret = gf_rdma_post_send (peer->qp, post, (buf - post->buf)); - if (ret) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - "gf_rdma_post_send 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_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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_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_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - "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; - - if ((peer == NULL) || (entry == NULL) || (post == NULL)) { - goto 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); - break; - - case gf_rdma_replych: - ret = __gf_rdma_send_reply_type_nomsg (peer, entry, post, - reply_info); - break; - - case gf_rdma_writech: - ret = __gf_rdma_send_reply_type_msg (peer, entry, post, - reply_info); - break; - - default: - gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - "invalid chunktype (%d) specified for sending reply", - type); - 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 (device, - (options->send_size + 2048), - GF_RDMA_SEND_POST); - } - - if (post == NULL) { - ret = -1; - goto out; - } - - if (entry->is_request) { - ret = __gf_rdma_ioq_churn_request (peer, entry, post); - } else { - ret = __gf_rdma_ioq_churn_reply (peer, entry, post); - } - - 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_log (this->name, GF_LOG_DEBUG, - "rdma is not connected to post a " - "send request"); - 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 (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, }; - - if (req == NULL) { - goto out; - } - - data.is_request = 1; - data.data.req = *req; - - entry = gf_rdma_ioq_new (this, &data); - if (entry == NULL) { - goto out; - } - - ret = gf_rdma_writev (this, entry); - - if (ret > 0) { - ret = 0; - } else if (ret < 0) { - rpc_transport_disconnect (this); - } - -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) { - goto out; - } - - ret = gf_rdma_writev (this, entry); - if (ret > 0) { - ret = 0; - } else if (ret < 0) { - rpc_transport_disconnect (this); - } - -out: - return ret; -} - -#if 0 -static int -gf_rdma_receive (rpc_transport_t *this, char **hdr_p, size_t *hdrlen_p, - struct iobuf **iobuf_p) -{ - gf_rdma_private_t *priv = this->private; - /* TODO: return error if !priv->connected, check with locks */ - /* TODO: boundry checks for data_ptr/offset */ - char *copy_from = NULL; - gf_rdma_header_t *header = NULL; - uint32_t size1, size2, data_len = 0; - char *hdr = NULL; - struct iobuf *iobuf = NULL; - int32_t ret = 0; - - pthread_mutex_lock (&priv->recv_mutex); - { -/* - while (!priv->data_ptr) - pthread_cond_wait (&priv->recv_cond, &priv->recv_mutex); -*/ - - copy_from = priv->data_ptr + priv->data_offset; - - priv->data_ptr = NULL; - data_len = priv->data_len; - pthread_cond_broadcast (&priv->recv_cond); - } - pthread_mutex_unlock (&priv->recv_mutex); - - header = (gf_rdma_header_t *)copy_from; - if (strcmp (header->colonO, ":O")) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "%s: corrupt header received", this->name); - ret = -1; - goto err; - } - - size1 = ntoh32 (header->size1); - size2 = ntoh32 (header->size2); - - if (data_len != (size1 + size2 + sizeof (*header))) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "%s: sizeof data read from transport is not equal " - "to the size specified in the header", - this->name); - ret = -1; - goto err; - } - - copy_from += sizeof (*header); - - if (size1) { - hdr = GF_CALLOC (1, size1, gf_common_mt_char); - if (!hdr) { - gf_log (this->name, GF_LOG_ERROR, - "unable to allocate header for peer %s", - this->peerinfo.identifier); - ret = -ENOMEM; - goto err; - } - memcpy (hdr, copy_from, size1); - copy_from += size1; - *hdr_p = hdr; - } - *hdrlen_p = size1; - - if (size2) { - iobuf = iobuf_get (this->ctx->iobuf_pool); - if (!iobuf) { - gf_log (this->name, GF_LOG_ERROR, - "unable to allocate IO buffer for peer %s", - this->peerinfo.identifier); - ret = -ENOMEM; - goto err; - } - memcpy (iobuf->ptr, copy_from, size2); - *iobuf_p = iobuf; - } - -err: - return ret; -} -#endif - - -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_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: creation of CQ for device %s failed", - this->name, device->device_name); - ret = -1; - goto out; - } else if (ibv_req_notify_cq (device->recv_cq, 0)) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: ibv_req_notify_cq on recv CQ of device %s failed", - this->name, device->device_name); - ret = -1; - goto out; - } - - do { - ret = ibv_query_device (priv->device->context, &device_attr); - if (ret != 0) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: ibv_query_device on %s returned %d (%s)", - this->name, priv->device->device_name, ret, - (ret > 0) ? strerror (ret) : ""); - ret = -1; - goto out; - } - - send_cqe = 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_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: creation of send_cq for device %s failed", - this->name, device->device_name); - ret = -1; - goto out; - } - - if (ibv_req_notify_cq (device->send_cq, 0)) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: ibv_req_notify_cq on send_cq for device %s" - " failed", this->name, device->device_name); - ret = -1; - goto out; - } - } while (0); - -out: - if (ret != 0) - gf_rdma_destroy_cq (this); - - 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) { - 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 gf_rdma_peer_t * - gf_rdma_lookup_peer (gf_rdma_device_t *device, - int32_t qp_num) - { - gf_rdma_qpreg_t *qpreg = NULL; - gf_rdma_peer_t *peer = NULL; - - qpreg = &device->qpreg; - pthread_mutex_lock (&qpreg->lock); - { - peer = __gf_rdma_lookup_peer (device, qp_num); - } - pthread_mutex_unlock (&qpreg->lock); - - 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); - ibv_destroy_qp (priv->peer.qp); - } - priv->peer.qp = NULL; - - return; -} - - -static int32_t -gf_rdma_create_qp (rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - gf_rdma_options_t *options = NULL; - gf_rdma_device_t *device = NULL; - int32_t ret = 0; - gf_rdma_peer_t *peer = NULL; - - priv = this->private; - options = &priv->options; - device = priv->device; - - peer = &priv->peer; - - 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 - }; - - struct ibv_qp_attr attr = { - .qp_state = IBV_QPS_INIT, - .pkey_index = 0, - .port_num = options->port, - .qp_access_flags - = IBV_ACCESS_REMOTE_READ | IBV_ACCESS_REMOTE_WRITE - }; - - peer->qp = ibv_create_qp (device->pd, &init_attr); - if (!peer->qp) { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_CRITICAL, - "%s: could not create QP", - this->name); - ret = -1; - goto out; - } else if (ibv_modify_qp (peer->qp, &attr, - IBV_QP_STATE | - IBV_QP_PKEY_INDEX | - IBV_QP_PORT | - IBV_QP_ACCESS_FLAGS)) { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_ERROR, - "%s: failed to modify QP to INIT state", - this->name); - ret = -1; - goto out; - } - - peer->local_lid = gf_rdma_get_local_lid (device->context, - options->port); - peer->local_qpn = peer->qp->qp_num; - peer->local_psn = lrand48 () & 0xffffff; - - ret = gf_rdma_register_peer (device, peer->qp->qp_num, peer); - -out: - if (ret == -1) - __gf_rdma_destroy_qp (this); - - return ret; -} - - -static void -gf_rdma_destroy_posts (rpc_transport_t *this) -{ - -} - - -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 (device, size + 2048, type); - if (!post) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: post creation failed", - this->name); - ret = -1; - break; - } - - gf_rdma_put_post (q, post); - } - return ret; -} - - -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 int32_t -gf_rdma_connect_qp (rpc_transport_t *this) -{ - gf_rdma_private_t *priv = this->private; - gf_rdma_options_t *options = &priv->options; - struct ibv_qp_attr attr = { - .qp_state = IBV_QPS_RTR, - .path_mtu = options->mtu, - .dest_qp_num = priv->peer.remote_qpn, - .rq_psn = priv->peer.remote_psn, - .max_dest_rd_atomic = 1, - .min_rnr_timer = 12, - .qp_access_flags - = IBV_ACCESS_REMOTE_READ | IBV_ACCESS_REMOTE_WRITE, - .ah_attr = { - .is_global = 0, - .dlid = priv->peer.remote_lid, - .sl = 0, - .src_path_bits = 0, - .port_num = options->port - } - }; - if (ibv_modify_qp (priv->peer.qp, &attr, - IBV_QP_STATE | - IBV_QP_AV | - IBV_QP_PATH_MTU | - IBV_QP_DEST_QPN | - IBV_QP_RQ_PSN | - IBV_QP_MAX_DEST_RD_ATOMIC | - IBV_QP_MIN_RNR_TIMER)) { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_CRITICAL, - "Failed to modify QP to RTR\n"); - return -1; - } - - attr.qp_state = IBV_QPS_RTS; - attr.timeout = options->attr_timeout; - attr.retry_cnt = options->attr_retry_cnt; - attr.rnr_retry = options->attr_rnr_retry; - attr.sq_psn = priv->peer.local_psn; - attr.max_rd_atomic = 1; - if (ibv_modify_qp (priv->peer.qp, &attr, - IBV_QP_STATE | - IBV_QP_TIMEOUT | - IBV_QP_RETRY_CNT | - IBV_QP_RNR_RETRY | - IBV_QP_SQ_PSN | - IBV_QP_MAX_QP_RD_ATOMIC)) { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_CRITICAL, - "Failed to modify QP to RTS\n"); - return -1; - } - - return 0; -} - -static int32_t -__gf_rdma_teardown (rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - - priv = this->private; - __gf_rdma_destroy_qp (this); - - if (!list_empty (&priv->peer.ioq)) { - __gf_rdma_ioq_flush (&priv->peer); - } - - /* TODO: decrement cq size */ - return 0; -} - -/* - * return value: - * 0 = success (completed) - * -1 = error - * > 0 = incomplete - */ - -static int -__tcp_rwv (rpc_transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count, - int write) -{ - gf_rdma_private_t *priv = NULL; - int sock = -1; - int ret = -1; - struct iovec *opvector = NULL; - int opcount = 0; - int moved = 0; - - priv = this->private; - sock = priv->sock; - opvector = vector; - opcount = count; - - while (opcount) - { - if (write) - { - ret = writev (sock, opvector, opcount); - - if (ret == 0 || (ret == -1 && errno == EAGAIN)) - { - /* done for now */ - break; - } - } - else - { - ret = readv (sock, opvector, opcount); - - if (ret == -1 && errno == EAGAIN) - { - /* done for now */ - break; - } - } - - if (ret == 0) - { - gf_log (this->name, GF_LOG_DEBUG, - "EOF from peer %s", this->peerinfo.identifier); - opcount = -1; - errno = ENOTCONN; - break; - } - - if (ret == -1) - { - if (errno == EINTR) - continue; - - gf_log (this->name, GF_LOG_DEBUG, - "%s failed (%s)", write ? "writev" : "readv", - strerror (errno)); - if (write && !priv->connected && - (errno == ECONNREFUSED)) - gf_log (this->name, GF_LOG_ERROR, - "possible mismatch of 'rpc-transport-type'" - " in protocol server and client. " - "check volume file"); - opcount = -1; - break; - } - - moved = 0; - - while (moved < ret) - { - if ((ret - moved) >= opvector[0].iov_len) - { - moved += opvector[0].iov_len; - opvector++; - opcount--; - } - else - { - opvector[0].iov_len -= (ret - moved); - opvector[0].iov_base += (ret - moved); - moved += (ret - moved); - } - while (opcount && !opvector[0].iov_len) - { - opvector++; - opcount--; - } - } - } - - if (pending_vector) - *pending_vector = opvector; - - if (pending_count) - *pending_count = opcount; - - return opcount; -} - - -static int -__tcp_readv (rpc_transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count) -{ - int ret = -1; - - ret = __tcp_rwv (this, vector, count, - pending_vector, pending_count, 0); - - return ret; -} - - -static int -__tcp_writev (rpc_transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count) -{ - int ret = -1; - gf_rdma_private_t *priv = NULL; - - priv = this->private; - - ret = __tcp_rwv (this, vector, count, pending_vector, - pending_count, 1); - - if (ret > 0) { - /* TODO: Avoid multiple calls when socket is already - registered for POLLOUT */ - priv->idx = event_select_on (this->ctx->event_pool, - priv->sock, priv->idx, -1, 1); - } else if (ret == 0) { - priv->idx = event_select_on (this->ctx->event_pool, - priv->sock, - priv->idx, -1, 0); - } - - 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; -} - - -inline 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; - - 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); - } - - iobuf = iobuf_get (peer->trans->ctx->iobuf_pool); - if (iobuf == NULL) { - ret = -1; - goto out; - } - - post->ctx.iobref = iobref = iobref_new (); - if (iobref == NULL) { - ret = -1; - goto out; - } - - iobref_add (iobref, iobuf); - iobuf_unref (iobuf); - /* - * FIXME: construct an appropriate rpc-msg here, what is being sent - * to rpc is not correct. - */ - post->ctx.vector[0].iov_base = iobuf_ptr (iobuf); - post->ctx.vector[0].iov_len = bytes_in_post; - - memcpy (post->ctx.vector[0].iov_base, (char *)post->buf, - post->ctx.vector[0].iov_len); - 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) { - goto out; - } - - /* skip terminator of read-chunklist */ - ptr = ptr + sizeof (uint32_t); - - ret = gf_rdma_get_write_chunklist (&ptr, &write_ary); - if (ret == -1) { - 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) { - 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) { - goto out; - } - - if (write_ary != NULL) { - reply_info = gf_rdma_reply_info_alloc (peer); - if (reply_info == NULL) { - 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) { - post->ctx.hdr_iobuf = iobuf_get (peer->trans->ctx->iobuf_pool); - if (post->ctx.hdr_iobuf == NULL) { - ret = -1; - goto out; - } - - header_len = (long)ptr - (long)post->buf; - post->ctx.vector[0].iov_base = iobuf_ptr (post->ctx.hdr_iobuf); - post->ctx.vector[0].iov_len = bytes_in_post - header_len; - 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 (write_ary != NULL) { - 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); - break; - - case GF_RDMA_MSGP: - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "rdma msg of msg-type GF_RDMA_MSGP should not have " - "been received"); - ret = -1; - break; - - case GF_RDMA_DONE: - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "rdma msg of msg-type GF_RDMA_DONE should not have " - "been received"); - ret = -1; - break; - - case GF_RDMA_ERROR: - /* ret = gf_rdma_decode_error_msg (peer, post, bytes_in_post); */ - break; - - default: - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "unknown rdma msg-type (%d)", header->rm_type); - } - - return ret; -} - - -int32_t -__gf_rdma_read (gf_rdma_peer_t *peer, gf_rdma_post_t *post, struct iovec *to, - gf_rdma_read_chunk_t *readch) -{ - int32_t ret = -1; - struct ibv_sge list = {0, }; - struct ibv_send_wr wr = {0, }, *bad_wr = NULL; - - ret = __gf_rdma_register_local_mr_for_rdma (peer, to, 1, &post->ctx); - if (ret == -1) { - goto out; - } - - list.addr = (unsigned long) to->iov_base; - list.length = to->iov_len; - list.lkey = post->ctx.mr[post->ctx.mr_count - 1]->lkey; - - wr.wr_id = (unsigned long) gf_rdma_post_ref (post); - wr.sg_list = &list; - wr.num_sge = 1; - wr.opcode = IBV_WR_RDMA_READ; - wr.send_flags = IBV_SEND_SIGNALED; - wr.wr.rdma.remote_addr = readch->rc_target.rs_offset; - wr.wr.rdma.rkey = readch->rc_target.rs_handle; - - ret = ibv_post_send (peer->qp, &wr, &bad_wr); - if (ret) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, "rdma read from client " - "(%s) failed with ret = %d (%s)", - peer->trans->peerinfo.identifier, - ret, (ret > 0) ? strerror (ret) : ""); - ret = -1; - gf_rdma_post_unref (post); - } -out: - 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; - - priv = peer->trans->private; - - for (i = 0; readch[i].rc_discrim != 0; i++) { - size += readch[i].rc_target.rs_length; - } - - if (i == 0) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "message type specified as rdma-read but there are no " - "rdma read-chunks present"); - goto out; - } - - post->ctx.gf_rdma_reads = i; - - if (size > peer->trans->ctx->page_size) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "total size of rdma-read (%lu) is greater than " - "page-size (%lu). This is not supported till variable " - "sized iobufs are implemented", (unsigned long)size, - (unsigned long)peer->trans->ctx->page_size); - goto out; - } - - iobuf = iobuf_get (peer->trans->ctx->iobuf_pool); - if (iobuf == NULL) { - goto out; - } - - if (post->ctx.iobref == NULL) { - post->ctx.iobref = iobref_new (); - if (post->ctx.iobref == NULL) { - iobuf_unref (iobuf); - goto out; - } - } - - iobref_add (post->ctx.iobref, iobuf); - iobuf_unref (iobuf); - - ptr = iobuf_ptr (iobuf); - iobuf = NULL; - - pthread_mutex_lock (&priv->write_mutex); - { - if (!priv->connected) { - 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_read (peer, post, - &post->ctx.vector[count], - &readch[i]); - if (ret == -1) { - goto unlock; - } - - ptr += readch[i].rc_target.rs_length; - } - - ret = 0; - } -unlock: - pthread_mutex_unlock (&priv->write_mutex); -out: - - if (ret == -1) { - if (iobuf != NULL) { - iobuf_unref (iobuf); - } - } - - 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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "cannot get request information from rpc " - "layer"); - goto out; - } - - rpc_req = request_info.rpc_req; - if (rpc_req == NULL) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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); - -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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "cannot get request information from rpc " - "layer"); - goto out; - } - - rpc_req = request_info.rpc_req; - if (rpc_req == NULL) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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); - } - - return ret; -} - - -inline 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); - } else { - ret = gf_rdma_pollin_notify (peer, post); - if (ret == -1) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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; - - post = (gf_rdma_post_t *) (long) wc->wr_id; - if (post == NULL) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "decoding of header failed"); - goto out; - } - - header = (gf_rdma_header_t *)post->buf; - - 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: - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "an error has happened while transmission of msg, " - "disconnecting the transport"); - rpc_transport_disconnect (peer->trans); - goto out; - -/* ret = gf_rdma_pollin_notify (peer, post); - if (ret == -1) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "pollin notification failed"); - } - goto out; -*/ - - default: - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "invalid rdma msg-type (%d)", header->rm_type); - break; - } - - if (msg_type == CALL) { - ret = gf_rdma_recv_request (peer, post, readch); - } else { - ret = gf_rdma_recv_reply (peer, post); - } - -out: - if (ret == -1) { - rpc_transport_disconnect (peer->trans); - } - - return; -} - - -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 = {0, }; - void *event_ctx = NULL; - int32_t ret = 0; - - chan = data; - - while (1) { - ret = ibv_get_cq_event (chan, &event_cq, &event_ctx); - if (ret) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "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 ((ret = ibv_poll_cq (event_cq, 1, &wc)) > 0) { - post = (gf_rdma_post_t *) (long) wc.wr_id; - - pthread_mutex_lock (&device->qpreg.lock); - { - peer = __gf_rdma_lookup_peer (device, - wc.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.status != IBV_WC_SUCCESS) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "recv work request on `%s' returned " - "error (%d)", device->device_name, - wc.status); - if (peer) { - rpc_transport_unref (peer->trans); - rpc_transport_disconnect (peer->trans); - } - - if (post) { - gf_rdma_post_unref (post); - } - continue; - } - - if (peer) { - gf_rdma_process_recv (peer, &wc); - rpc_transport_unref (peer->trans); - } else { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_DEBUG, - "could not lookup peer for qp_num: %d", - wc.qp_num); - } - - gf_rdma_post_unref (post); - } - - if (ret < 0) { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_ERROR, - "ibv_poll_cq on `%s' returned error " - "(ret = %d, errno = %d)", - device->device_name, ret, errno); - continue; - } - ibv_ack_cq_events (event_cq, 1); - } - - 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_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "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_log ("rdma", GF_LOG_ERROR, "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); - } - - 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; - } - - ret = gf_rdma_pollin_notify (peer, post); - if ((ret == -1) && (peer != NULL)) { - rpc_transport_disconnect (peer->trans); - } - -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 = {0, }; - char is_request = 0; - int32_t ret = 0, quota_ret = 0; - - chan = data; - while (1) { - ret = ibv_get_cq_event (chan, &event_cq, &event_ctx); - if (ret) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "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_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "ibv_req_notify_cq on %s failed, terminating " - "send thread: %d (%d)", - device->device_name, ret, errno); - continue; - } - - while ((ret = ibv_poll_cq (event_cq, 1, &wc)) > 0) { - post = (gf_rdma_post_t *) (long) wc.wr_id; - - pthread_mutex_lock (&device->qpreg.lock); - { - peer = __gf_rdma_lookup_peer (device, wc.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.status != IBV_WC_SUCCESS) { - gf_rdma_handle_failed_send_completion (peer, &wc); - } else { - gf_rdma_handle_successful_send_completion (peer, - &wc); - } - - if (post) { - is_request = post->ctx.is_request; - - ret = gf_rdma_post_unref (post); - if ((ret == 0) - && (wc.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_log ("rdma", GF_LOG_DEBUG, - "failed to send " - "message"); - } - } - } - - if (peer) { - rpc_transport_unref (peer->trans); - } else { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "could not lookup peer for qp_num: %d", - wc.qp_num); - } - } - - if (ret < 0) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "ibv_poll_cq on `%s' returned error (ret = %d," - " errno = %d)", - device->device_name, ret, errno); - continue; - } - - ibv_ack_cq_events (event_cq, 1); - } - - 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.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_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - "%s: unrecognized MTU value '%s', defaulting " - "to '2048'", this->name, - data_to_str (temp)); - else - gf_log (GF_RDMA_LOG_NAME, GF_LOG_TRACE, - "%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; -} - -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 gf_rdma_device_t * -gf_rdma_get_device (rpc_transport_t *this, struct ibv_context *ibctx) -{ - glusterfs_ctx_t *ctx = NULL; - gf_rdma_private_t *priv = NULL; - gf_rdma_options_t *options = NULL; - char *device_name = NULL; - uint32_t port = 0; - uint8_t active_port = 0; - int32_t ret = 0; - int32_t i = 0; - gf_rdma_device_t *trav = NULL; - - priv = this->private; - options = &priv->options; - device_name = priv->options.device_name; - ctx = this->ctx; - trav = ctx->ib; - port = priv->options.port; - - while (trav) { - if ((!strcmp (trav->device_name, device_name)) && - (trav->port == port)) - break; - trav = trav->next; - } - - if (!trav) { - - trav = GF_CALLOC (1, sizeof (*trav), - gf_common_mt_rdma_device_t); - if (trav == NULL) { - return NULL; - } - - priv->device = trav; - - trav->context = ibctx; - - ret = ib_get_active_port (trav->context); - - if (ret < 0) { - if (!port) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "Failed to find any active ports and " - "none specified in volume file," - " exiting"); - GF_FREE (trav); - return NULL; - } - } - - trav->request_ctx_pool = mem_pool_new (gf_rdma_request_context_t, - GF_RDMA_POOL_SIZE); - if (trav->request_ctx_pool == NULL) { - return NULL; - } - - trav->ioq_pool = mem_pool_new (gf_rdma_ioq_t, GF_RDMA_POOL_SIZE); - if (trav->ioq_pool == NULL) { - mem_pool_destroy (trav->request_ctx_pool); - return NULL; - } - - trav->reply_info_pool = mem_pool_new (gf_rdma_reply_info_t, - GF_RDMA_POOL_SIZE); - if (trav->reply_info_pool == NULL) { - mem_pool_destroy (trav->request_ctx_pool); - mem_pool_destroy (trav->ioq_pool); - return NULL; - } - - - active_port = ret; - - if (port) { - ret = ib_check_active_port (trav->context, port); - if (ret < 0) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, - "On device %s: provided port:%u is " - "found to be offline, continuing to " - "use the same port", device_name, port); - } - } else { - priv->options.port = active_port; - port = active_port; - gf_log (GF_RDMA_LOG_NAME, GF_LOG_TRACE, - "Port unspecified in volume file using active " - "port: %u", port); - } - - trav->device_name = gf_strdup (device_name); - trav->port = port; - - trav->next = ctx->ib; - ctx->ib = trav; - - trav->send_chan = ibv_create_comp_channel (trav->context); - if (!trav->send_chan) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: could not create send completion channel", - device_name); - mem_pool_destroy (trav->ioq_pool); - mem_pool_destroy (trav->request_ctx_pool); - mem_pool_destroy (trav->reply_info_pool); - GF_FREE ((char *)trav->device_name); - GF_FREE (trav); - return NULL; - } - - trav->recv_chan = ibv_create_comp_channel (trav->context); - if (!trav->recv_chan) { - mem_pool_destroy (trav->ioq_pool); - mem_pool_destroy (trav->request_ctx_pool); - mem_pool_destroy (trav->reply_info_pool); - ibv_destroy_comp_channel (trav->send_chan); - GF_FREE ((char *)trav->device_name); - GF_FREE (trav); - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "could not create recv completion channel"); - /* TODO: cleanup current mess */ - return NULL; - } - - if (gf_rdma_create_cq (this) < 0) { - mem_pool_destroy (trav->ioq_pool); - mem_pool_destroy (trav->request_ctx_pool); - mem_pool_destroy (trav->reply_info_pool); - ibv_destroy_comp_channel (trav->recv_chan); - ibv_destroy_comp_channel (trav->send_chan); - GF_FREE ((char *)trav->device_name); - GF_FREE (trav); - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: could not create CQ", - this->name); - return NULL; - } - - /* protection domain */ - trav->pd = ibv_alloc_pd (trav->context); - - if (!trav->pd) { - mem_pool_destroy (trav->ioq_pool); - mem_pool_destroy (trav->request_ctx_pool); - mem_pool_destroy (trav->reply_info_pool); - 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); - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: could not allocate protection domain", - this->name); - return NULL; - } - - struct ibv_srq_init_attr attr = { - .attr = { - .max_wr = options->recv_count, - .max_sge = 1 - } - }; - trav->srq = ibv_create_srq (trav->pd, &attr); - - if (!trav->srq) { - mem_pool_destroy (trav->ioq_pool); - mem_pool_destroy (trav->request_ctx_pool); - mem_pool_destroy (trav->reply_info_pool); - 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); - - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: could not create SRQ", - this->name); - return NULL; - } - - /* queue init */ - gf_rdma_queue_init (&trav->sendq); - gf_rdma_queue_init (&trav->recvq); - - if (gf_rdma_create_posts (this) < 0) { - mem_pool_destroy (trav->ioq_pool); - mem_pool_destroy (trav->request_ctx_pool); - mem_pool_destroy (trav->reply_info_pool); - 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); - - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: could not allocate posts", - this->name); - return NULL; - } - - /* completion threads */ - ret = pthread_create (&trav->send_thread, - NULL, - gf_rdma_send_completion_proc, - trav->send_chan); - if (ret) { - 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); - 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); - - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "could not create send completion thread"); - return NULL; - } - - ret = pthread_create (&trav->recv_thread, - NULL, - gf_rdma_recv_completion_proc, - trav->recv_chan); - if (ret) { - 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); - 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); - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "could not create recv completion 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]; - } - } - return trav; -} - -static int32_t -gf_rdma_init (rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - gf_rdma_options_t *options = NULL; - struct ibv_device **dev_list; - struct ibv_context *ib_ctx = NULL; - int32_t ret = 0; - - priv = this->private; - options = &priv->options; - - ibv_fork_init (); - gf_rdma_options_init (this); - - { - dev_list = ibv_get_device_list (NULL); - - if (!dev_list) { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_CRITICAL, - "Failed to get IB devices"); - ret = -1; - goto cleanup; - } - - if (!*dev_list) { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_CRITICAL, - "No IB devices found"); - ret = -1; - goto cleanup; - } - - if (!options->device_name) { - if (*dev_list) { - options->device_name = - gf_strdup (ibv_get_device_name (*dev_list)); - } else { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_CRITICAL, - "IB device list is empty. Check for " - "'ib_uverbs' module"); - return -1; - goto cleanup; - } - } - - while (*dev_list) { - if (!strcmp (ibv_get_device_name (*dev_list), - options->device_name)) { - ib_ctx = ibv_open_device (*dev_list); - - if (!ib_ctx) { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_ERROR, - "Failed to get infiniband" - "device context"); - ret = -1; - goto cleanup; - } - break; - } - ++dev_list; - } - - priv->device = gf_rdma_get_device (this, ib_ctx); - - if (!priv->device) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "could not create rdma device for %s", - options->device_name); - ret = -1; - goto cleanup; - } - } - - priv->peer.trans = this; - INIT_LIST_HEAD (&priv->peer.ioq); - - pthread_mutex_init (&priv->read_mutex, NULL); - pthread_mutex_init (&priv->write_mutex, NULL); - pthread_mutex_init (&priv->recv_mutex, NULL); - pthread_cond_init (&priv->recv_cond, NULL); - -cleanup: - if (-1 == ret) { - if (ib_ctx) - ibv_close_device (ib_ctx); - } - - if (dev_list) - ibv_free_device_list (dev_list); - - return ret; -} - - -static int32_t -gf_rdma_disconnect (rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - int32_t ret = 0; - - priv = this->private; - pthread_mutex_lock (&priv->write_mutex); - { - ret = __gf_rdma_disconnect (this); - } - pthread_mutex_unlock (&priv->write_mutex); - - return ret; -} - - -static int32_t -__tcp_connect_finish (int fd) -{ - int ret = -1; - int optval = 0; - socklen_t optlen = sizeof (int); - - ret = getsockopt (fd, SOL_SOCKET, SO_ERROR, - (void *)&optval, &optlen); - - if (ret == 0 && optval) - { - errno = optval; - ret = -1; - } - - return ret; -} - -static inline void -gf_rdma_fill_handshake_data (char *buf, struct gf_rdma_nbio *nbio, - gf_rdma_private_t *priv) -{ - sprintf (buf, - "QP1:RECV_BLKSIZE=%08x:SEND_BLKSIZE=%08x\n" - "QP1:LID=%04x:QPN=%06x:PSN=%06x\n", - priv->peer.recv_size, - priv->peer.send_size, - priv->peer.local_lid, - priv->peer.local_qpn, - priv->peer.local_psn); - - nbio->vector.iov_base = buf; - nbio->vector.iov_len = strlen (buf) + 1; - nbio->count = 1; - return; -} - -static inline void -gf_rdma_fill_handshake_ack (char *buf, struct gf_rdma_nbio *nbio) -{ - sprintf (buf, "DONE\n"); - nbio->vector.iov_base = buf; - nbio->vector.iov_len = strlen (buf) + 1; - nbio->count = 1; - return; -} - -static int -gf_rdma_handshake_pollin (rpc_transport_t *this) -{ - int ret = 0; - gf_rdma_private_t *priv = NULL; - char *buf = NULL; - int32_t recv_buf_size = 0, send_buf_size; - socklen_t sock_len = 0; - - priv = this->private; - buf = priv->handshake.incoming.buf; - - if (priv->handshake.incoming.state == GF_RDMA_HANDSHAKE_COMPLETE) { - return -1; - } - - pthread_mutex_lock (&priv->write_mutex); - { - while (priv->handshake.incoming.state != GF_RDMA_HANDSHAKE_COMPLETE) - { - switch (priv->handshake.incoming.state) - { - case GF_RDMA_HANDSHAKE_START: - buf = priv->handshake.incoming.buf = GF_CALLOC (1, 256, gf_common_mt_char); - gf_rdma_fill_handshake_data (buf, &priv->handshake.incoming, priv); - buf[0] = 0; - priv->handshake.incoming.state = GF_RDMA_HANDSHAKE_RECEIVING_DATA; - break; - - case GF_RDMA_HANDSHAKE_RECEIVING_DATA: - ret = __tcp_readv (this, - &priv->handshake.incoming.vector, - priv->handshake.incoming.count, - &priv->handshake.incoming.pending_vector, - &priv->handshake.incoming.pending_count); - if (ret == -1) { - goto unlock; - } - - if (ret > 0) { - gf_log (this->name, GF_LOG_TRACE, - "partial header read on NB socket. continue later"); - goto unlock; - } - - if (!ret) { - priv->handshake.incoming.state = GF_RDMA_HANDSHAKE_RECEIVED_DATA; - } - break; - - case GF_RDMA_HANDSHAKE_RECEIVED_DATA: - ret = sscanf (buf, - "QP1:RECV_BLKSIZE=%08x:SEND_BLKSIZE=%08x\n" - "QP1:LID=%04x:QPN=%06x:PSN=%06x\n", - &recv_buf_size, - &send_buf_size, - &priv->peer.remote_lid, - &priv->peer.remote_qpn, - &priv->peer.remote_psn); - - if ((ret != 5) && (strncmp (buf, "QP1:", 4))) { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_CRITICAL, - "%s: remote-host(%s)'s " - "transport type is different", - this->name, - this->peerinfo.identifier); - ret = -1; - goto unlock; - } - - if (recv_buf_size < priv->peer.recv_size) - priv->peer.recv_size = recv_buf_size; - if (send_buf_size < priv->peer.send_size) - priv->peer.send_size = send_buf_size; - - gf_log (GF_RDMA_LOG_NAME, GF_LOG_TRACE, - "%s: transacted recv_size=%d " - "send_size=%d", - this->name, priv->peer.recv_size, - priv->peer.send_size); - - priv->peer.quota = priv->peer.send_count; - - if (gf_rdma_connect_qp (this)) { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_ERROR, - "%s: failed to connect with " - "remote QP", this->name); - ret = -1; - goto unlock; - } - gf_rdma_fill_handshake_ack (buf, &priv->handshake.incoming); - buf[0] = 0; - priv->handshake.incoming.state = GF_RDMA_HANDSHAKE_RECEIVING_ACK; - break; - - case GF_RDMA_HANDSHAKE_RECEIVING_ACK: - ret = __tcp_readv (this, - &priv->handshake.incoming.vector, - priv->handshake.incoming.count, - &priv->handshake.incoming.pending_vector, - &priv->handshake.incoming.pending_count); - if (ret == -1) { - goto unlock; - } - - if (ret > 0) { - gf_log (this->name, GF_LOG_TRACE, - "partial header read on NB " - "socket. continue later"); - goto unlock; - } - - if (!ret) { - priv->handshake.incoming.state = GF_RDMA_HANDSHAKE_RECEIVED_ACK; - } - break; - - case GF_RDMA_HANDSHAKE_RECEIVED_ACK: - if (strncmp (buf, "DONE", 4)) { - gf_log (GF_RDMA_LOG_NAME, - GF_LOG_DEBUG, - "%s: handshake-3 did not " - "return 'DONE' (%s)", - this->name, buf); - ret = -1; - goto unlock; - } - ret = 0; - priv->connected = 1; - sock_len = sizeof (struct sockaddr_storage); - getpeername (priv->sock, - (struct sockaddr *) &this->peerinfo.sockaddr, - &sock_len); - - GF_FREE (priv->handshake.incoming.buf); - priv->handshake.incoming.buf = NULL; - priv->handshake.incoming.state = GF_RDMA_HANDSHAKE_COMPLETE; - } - } - } -unlock: - pthread_mutex_unlock (&priv->write_mutex); - - if (ret == -1) { - rpc_transport_disconnect (this); - } else { - ret = 0; - } - - - if (!ret && priv->connected) { - if (priv->is_server) { - ret = rpc_transport_notify (priv->listener, - RPC_TRANSPORT_ACCEPT, - this); - } else { - ret = rpc_transport_notify (this, RPC_TRANSPORT_CONNECT, - this); - } - } - - return ret; -} - -static int -gf_rdma_handshake_pollout (rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - char *buf = NULL; - int32_t ret = 0; - - priv = this->private; - buf = priv->handshake.outgoing.buf; - - if (priv->handshake.outgoing.state == GF_RDMA_HANDSHAKE_COMPLETE) { - return 0; - } - - pthread_mutex_unlock (&priv->write_mutex); - { - while (priv->handshake.outgoing.state - != GF_RDMA_HANDSHAKE_COMPLETE) - { - switch (priv->handshake.outgoing.state) - { - case GF_RDMA_HANDSHAKE_START: - buf = priv->handshake.outgoing.buf - = GF_CALLOC (1, 256, gf_common_mt_char); - gf_rdma_fill_handshake_data (buf, - &priv->handshake.outgoing, priv); - priv->handshake.outgoing.state - = GF_RDMA_HANDSHAKE_SENDING_DATA; - break; - - case GF_RDMA_HANDSHAKE_SENDING_DATA: - ret = __tcp_writev (this, - &priv->handshake.outgoing.vector, - priv->handshake.outgoing.count, - &priv->handshake.outgoing.pending_vector, - &priv->handshake.outgoing.pending_count); - if (ret == -1) { - goto unlock; - } - - if (ret > 0) { - gf_log (this->name, GF_LOG_TRACE, - "partial header read on NB " - "socket. continue later"); - goto unlock; - } - - if (!ret) { - priv->handshake.outgoing.state - = GF_RDMA_HANDSHAKE_SENT_DATA; - } - break; - - case GF_RDMA_HANDSHAKE_SENT_DATA: - gf_rdma_fill_handshake_ack (buf, - &priv->handshake.outgoing); - priv->handshake.outgoing.state - = GF_RDMA_HANDSHAKE_SENDING_ACK; - break; - - case GF_RDMA_HANDSHAKE_SENDING_ACK: - ret = __tcp_writev (this, - &priv->handshake.outgoing.vector, - priv->handshake.outgoing.count, - &priv->handshake.outgoing.pending_vector, - &priv->handshake.outgoing.pending_count); - - if (ret == -1) { - goto unlock; - } - - if (ret > 0) { - gf_log (this->name, GF_LOG_TRACE, - "partial header read on NB " - "socket. continue later"); - goto unlock; - } - - if (!ret) { - GF_FREE (priv->handshake.outgoing.buf); - priv->handshake.outgoing.buf = NULL; - priv->handshake.outgoing.state - = GF_RDMA_HANDSHAKE_COMPLETE; - } - break; - } - } - } -unlock: - pthread_mutex_unlock (&priv->write_mutex); - - if (ret == -1) { - rpc_transport_disconnect (this); - } else { - ret = 0; - } - - return ret; -} - -static int -gf_rdma_handshake_pollerr (rpc_transport_t *this) -{ - gf_rdma_private_t *priv = this->private; - char need_unref = 0, connected = 0; - - gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, - "%s: peer disconnected, cleaning up", - this->name); - - pthread_mutex_lock (&priv->write_mutex); - { - __gf_rdma_teardown (this); - - connected = priv->connected; - if (priv->sock != -1) { - event_unregister (this->ctx->event_pool, - priv->sock, priv->idx); - need_unref = 1; - - if (close (priv->sock) != 0) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "close () - error: %s", - strerror (errno)); - } - priv->tcp_connected = priv->connected = 0; - priv->sock = -1; - } - - if (priv->handshake.incoming.buf) { - GF_FREE (priv->handshake.incoming.buf); - priv->handshake.incoming.buf = NULL; - } - - priv->handshake.incoming.state = GF_RDMA_HANDSHAKE_START; - - if (priv->handshake.outgoing.buf) { - GF_FREE (priv->handshake.outgoing.buf); - priv->handshake.outgoing.buf = NULL; - } - - priv->handshake.outgoing.state = GF_RDMA_HANDSHAKE_START; - } - pthread_mutex_unlock (&priv->write_mutex); - - if (connected) { - rpc_transport_notify (this, RPC_TRANSPORT_DISCONNECT, this); - } - - if (need_unref) - rpc_transport_unref (this); - - return 0; -} - - -static int -tcp_connect_finish (rpc_transport_t *this) -{ - gf_rdma_private_t *priv = NULL; - int error = 0, ret = 0; - - priv = this->private; - pthread_mutex_lock (&priv->write_mutex); - { - ret = __tcp_connect_finish (priv->sock); - - if (!ret) { - this->myinfo.sockaddr_len = - sizeof (this->myinfo.sockaddr); - ret = getsockname (priv->sock, - (struct sockaddr *)&this->myinfo.sockaddr, - &this->myinfo.sockaddr_len); - if (ret == -1) - { - gf_log (this->name, GF_LOG_ERROR, - "getsockname on new client-socket %d " - "failed (%s)", - priv->sock, strerror (errno)); - close (priv->sock); - error = 1; - goto unlock; - } - - gf_rdma_get_transport_identifiers (this); - priv->tcp_connected = 1; - } - - if (ret == -1 && errno != EINPROGRESS) { - gf_log (this->name, GF_LOG_ERROR, - "tcp connect to %s failed (%s)", - this->peerinfo.identifier, strerror (errno)); - error = 1; - } - } -unlock: - pthread_mutex_unlock (&priv->write_mutex); - - if (error) { - rpc_transport_disconnect (this); - } - - return ret; -} - -static int -gf_rdma_event_handler (int fd, int idx, void *data, - int poll_in, int poll_out, int poll_err) -{ - rpc_transport_t *this = NULL; - gf_rdma_private_t *priv = NULL; - gf_rdma_options_t *options = NULL; - int ret = 0; - - this = data; - priv = this->private; - if (!priv->tcp_connected) { - ret = tcp_connect_finish (this); - if (priv->tcp_connected) { - 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; - - if ((ret = gf_rdma_create_qp (this)) < 0) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: could not create QP", - this->name); - rpc_transport_disconnect (this); - } - } - } - - if (!ret && poll_out && priv->tcp_connected) { - ret = gf_rdma_handshake_pollout (this); - } - - if (!ret && !poll_err && poll_in && priv->tcp_connected) { - if (priv->handshake.incoming.state - == GF_RDMA_HANDSHAKE_COMPLETE) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: pollin received on tcp socket (peer: %s) " - "after handshake is complete", - this->name, this->peerinfo.identifier); - gf_rdma_handshake_pollerr (this); - return 0; - } - ret = gf_rdma_handshake_pollin (this); - } - - if (ret < 0 || poll_err) { - ret = gf_rdma_handshake_pollerr (this); - } - - return 0; -} - -static int -__tcp_nonblock (int fd) -{ - int flags = 0; - int ret = -1; - - flags = fcntl (fd, F_GETFL); - - if (flags != -1) - ret = fcntl (fd, F_SETFL, flags | O_NONBLOCK); - - return ret; -} - -static int32_t -gf_rdma_connect (struct rpc_transport *this, int port) -{ - gf_rdma_private_t *priv = NULL; - int32_t ret = 0; - gf_boolean_t non_blocking = 1; - union gf_sock_union sock_union = {{0, }, }; - socklen_t sockaddr_len = 0; - - priv = this->private; - - ret = gf_rdma_client_get_remote_sockaddr (this, - &sock_union.sa, - &sockaddr_len, port); - if (ret != 0) { - gf_log (this->name, GF_LOG_DEBUG, - "cannot get remote address to connect"); - return ret; - } - - - pthread_mutex_lock (&priv->write_mutex); - { - if (priv->sock != -1) { - ret = 0; - goto unlock; - } - - priv->sock = socket (sock_union.sa.sa_family, SOCK_STREAM, 0); - - if (priv->sock == -1) { - gf_log (this->name, GF_LOG_ERROR, - "socket () - error: %s", strerror (errno)); - ret = -errno; - goto unlock; - } - - gf_log (this->name, GF_LOG_TRACE, - "socket fd = %d", priv->sock); - - 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; - - if (non_blocking) - { - ret = __tcp_nonblock (priv->sock); - - if (ret == -1) - { - gf_log (this->name, GF_LOG_ERROR, - "could not set socket %d to non " - "blocking mode (%s)", - priv->sock, strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - } - - ret = gf_rdma_client_bind (this, - (struct sockaddr *)&this->myinfo.sockaddr, - &this->myinfo.sockaddr_len, - priv->sock); - if (ret == -1) - { - gf_log (this->name, GF_LOG_WARNING, - "client bind failed: %s", strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - - ret = connect (priv->sock, - (struct sockaddr *)&this->peerinfo.sockaddr, - this->peerinfo.sockaddr_len); - if (ret == -1 && errno != EINPROGRESS) - { - gf_log (this->name, GF_LOG_ERROR, - "connection attempt failed (%s)", - strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - - priv->tcp_connected = priv->connected = 0; - - rpc_transport_ref (this); - - priv->handshake.incoming.state = GF_RDMA_HANDSHAKE_START; - priv->handshake.outgoing.state = GF_RDMA_HANDSHAKE_START; - - priv->idx = event_register (this->ctx->event_pool, - priv->sock, gf_rdma_event_handler, - this, 1, 1); - } -unlock: - pthread_mutex_unlock (&priv->write_mutex); - - return ret; -} - -static int -gf_rdma_server_event_handler (int fd, int idx, void *data, - int poll_in, int poll_out, int poll_err) -{ - int32_t main_sock = -1; - rpc_transport_t *this = NULL, *trans = NULL; - gf_rdma_private_t *priv = NULL; - gf_rdma_private_t *trans_priv = NULL; - gf_rdma_options_t *options = NULL; - - if (!poll_in) { - return 0; - } - - trans = data; - trans_priv = (gf_rdma_private_t *) trans->private; - - this = GF_CALLOC (1, sizeof (rpc_transport_t), - gf_common_mt_rpc_transport_t); - if (this == NULL) { - return -1; - } - - this->listener = trans; - - priv = GF_CALLOC (1, sizeof (gf_rdma_private_t), - gf_common_mt_rdma_private_t); - if (priv == NULL) { - GF_FREE (priv); - return -1; - } - this->private = priv; - /* Copy all the rdma related values in priv, from trans_priv - as other than QP, all the values remain same */ - priv->device = trans_priv->device; - priv->options = trans_priv->options; - priv->is_server = 1; - priv->listener = trans; - - options = &priv->options; - - this->ops = trans->ops; - this->init = trans->init; - this->fini = trans->fini; - this->ctx = trans->ctx; - this->name = gf_strdup (trans->name); - this->notify = trans->notify; - this->mydata = trans->mydata; - - memcpy (&this->myinfo.sockaddr, &trans->myinfo.sockaddr, - trans->myinfo.sockaddr_len); - this->myinfo.sockaddr_len = trans->myinfo.sockaddr_len; - - main_sock = (trans_priv)->sock; - this->peerinfo.sockaddr_len = sizeof (this->peerinfo.sockaddr); - priv->sock = accept (main_sock, - (struct sockaddr *)&this->peerinfo.sockaddr, - &this->peerinfo.sockaddr_len); - if (priv->sock == -1) { - gf_log ("rdma/server", GF_LOG_ERROR, - "accept() failed: %s", - strerror (errno)); - GF_FREE (this->private); - GF_FREE (this); - return -1; - } - - priv->peer.trans = this; - rpc_transport_ref (this); - - gf_rdma_get_transport_identifiers (this); - - priv->tcp_connected = 1; - priv->handshake.incoming.state = GF_RDMA_HANDSHAKE_START; - priv->handshake.outgoing.state = GF_RDMA_HANDSHAKE_START; - - 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; - INIT_LIST_HEAD (&priv->peer.ioq); - - if (gf_rdma_create_qp (this) < 0) { - gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: could not create QP", - this->name); - rpc_transport_disconnect (this); - return -1; - } - - priv->idx = event_register (this->ctx->event_pool, priv->sock, - gf_rdma_event_handler, this, 1, 1); - - pthread_mutex_init (&priv->read_mutex, NULL); - pthread_mutex_init (&priv->write_mutex, NULL); - pthread_mutex_init (&priv->recv_mutex, NULL); - /* pthread_cond_init (&priv->recv_cond, NULL); */ - return 0; -} - -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; - int opt = 1, ret = 0; - char service[NI_MAXSERV], host[NI_MAXHOST]; - - priv = this->private; - memset (&sock_union, 0, sizeof (sock_union)); - ret = gf_rdma_server_get_local_sockaddr (this, - &sock_union.sa, - &sockaddr_len); - if (ret != 0) { - gf_log (this->name, GF_LOG_DEBUG, - "cannot find network address of server to bind to"); - goto err; - } - - priv->sock = socket (sock_union.sa.sa_family, SOCK_STREAM, 0); - if (priv->sock == -1) { - gf_log ("rdma/server", GF_LOG_CRITICAL, - "init: failed to create socket, error: %s", - strerror (errno)); - GF_FREE (this->private); - ret = -1; - 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_log (this->name, GF_LOG_ERROR, - "getnameinfo failed (%s)", gai_strerror (ret)); - goto err; - } - sprintf (this->myinfo.identifier, "%s:%s", host, service); - - setsockopt (priv->sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt)); - if (bind (priv->sock, &sock_union.sa, sockaddr_len) != 0) { - ret = -1; - gf_log ("rdma/server", GF_LOG_ERROR, - "init: failed to bind to socket for %s (%s)", - this->myinfo.identifier, strerror (errno)); - goto err; - } - - if (listen (priv->sock, 10) != 0) { - gf_log ("rdma/server", GF_LOG_ERROR, - "init: listen () failed on socket for %s (%s)", - this->myinfo.identifier, strerror (errno)); - ret = -1; - goto err; - } - - /* Register the main socket */ - priv->idx = event_register (this->ctx->event_pool, priv->sock, - gf_rdma_server_event_handler, - rpc_transport_ref (this), 1, 0); - -err: - 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; - - priv = GF_CALLOC (1, sizeof (*priv), gf_common_mt_rdma_private_t); - if (!priv) - return -1; - - this->private = priv; - priv->sock = -1; - - if (gf_rdma_init (this)) { - gf_log (this->name, GF_LOG_ERROR, - "Failed to initialize IB Device"); - return -1; - } - - return 0; -} - -void -fini (struct rpc_transport *this) -{ - /* TODO: verify this function does graceful finish */ - gf_rdma_private_t *priv = NULL; - - priv = this->private; - - this->private = NULL; - - if (priv) { - pthread_mutex_destroy (&priv->recv_mutex); - pthread_mutex_destroy (&priv->write_mutex); - pthread_mutex_destroy (&priv->read_mutex); - - /* pthread_cond_destroy (&priv->recv_cond); */ - if (priv->sock != -1) { - event_unregister (this->ctx->event_pool, - priv->sock, priv->idx); - } - - gf_log (this->name, GF_LOG_TRACE, - "called fini on transport: %p", this); - GF_FREE (priv); - } - 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 34293859112..00000000000 --- a/rpc/rpc-transport/rdma/src/rdma.h +++ /dev/null @@ -1,412 +0,0 @@ -/* - Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _XPORT_RDMA_H -#define _XPORT_RDMA_H - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#ifndef MAX_IOVEC -#define MAX_IOVEC 16 -#endif /* MAX_IOVEC */ - -#include "rpc-clnt.h" -#include "rpc-transport.h" -#include "xlator.h" -#include "event.h" -#include <stdio.h> -#include <list.h> -#include <arpa/inet.h> -#include <infiniband/verbs.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; -}; -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 ibv_qp *qp; - - 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; - struct mem_pool *request_ctx_pool; - struct mem_pool *ioq_pool; - struct mem_pool *reply_info_pool; -}; -typedef struct __gf_rdma_device gf_rdma_device_t; - -typedef enum { - GF_RDMA_HANDSHAKE_START = 0, - GF_RDMA_HANDSHAKE_SENDING_DATA, - GF_RDMA_HANDSHAKE_RECEIVING_DATA, - GF_RDMA_HANDSHAKE_SENT_DATA, - GF_RDMA_HANDSHAKE_RECEIVED_DATA, - GF_RDMA_HANDSHAKE_SENDING_ACK, - GF_RDMA_HANDSHAKE_RECEIVING_ACK, - GF_RDMA_HANDSHAKE_RECEIVED_ACK, - GF_RDMA_HANDSHAKE_COMPLETE, -} gf_rdma_handshake_state_t; - -struct gf_rdma_nbio { - int state; - char *buf; - int count; - struct iovec vector; - struct iovec *pending_vector; - int pending_count; -}; - -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; - -struct __gf_rdma_private { - int32_t sock; - int32_t idx; - unsigned char connected; - unsigned char tcp_connected; - unsigned char ib_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 read_mutex; - pthread_mutex_t write_mutex; - pthread_barrier_t handshake_barrier; - char handshake_ret; - char is_server; - rpc_transport_t *listener; - - pthread_mutex_t recv_mutex; - pthread_cond_t recv_cond; - - /* used during gf_rdma_handshake */ - struct { - struct gf_rdma_nbio incoming; - struct gf_rdma_nbio outgoing; - int state; - gf_rdma_header_t header; - char *buf; - size_t size; - } handshake; -}; -typedef struct __gf_rdma_private gf_rdma_private_t; - -#endif /* _XPORT_GF_RDMA_H */ diff --git a/rpc/rpc-transport/socket/src/Makefile.am b/rpc/rpc-transport/socket/src/Makefile.am index 2c918c7e313..7b488583771 100644 --- a/rpc/rpc-transport/socket/src/Makefile.am +++ b/rpc/rpc-transport/socket/src/Makefile.am @@ -1,15 +1,22 @@ -noinst_HEADERS = socket.h name.h +noinst_HEADERS = socket.h name.h socket-mem-types.h rpctransport_LTLIBRARIES = socket.la rpctransportdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/rpc-transport -socket_la_LDFLAGS = -module -avoidversion +socket_la_LDFLAGS = -module -avoid-version socket_la_SOURCES = socket.c name.c -socket_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la +socket_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ + $(top_builddir)/rpc/xdr/src/libgfxdr.la \ + $(top_builddir)/rpc/rpc-lib/src/libgfrpc.la \ + -lssl -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ - -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/rpc/rpc-lib/src/ \ - -I$(top_srcdir)/rpc/xdr/src/ -shared -nostartfiles $(GF_CFLAGS) +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/socket/src/name.c b/rpc/rpc-transport/socket/src/name.c index bed59d58b70..9286bbb236d 100644 --- a/rpc/rpc-transport/socket/src/name.c +++ b/rpc/rpc-transport/socket/src/name.c @@ -1,20 +1,11 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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> @@ -24,727 +15,754 @@ #include <netdb.h> #include <string.h> -#ifdef CLIENT_PORT_CEILING -#undef CLIENT_PORT_CEILING -#endif - -#define CLIENT_PORT_CEILING 1024 - #ifndef AF_INET_SDP #define AF_INET_SDP 27 #endif #include "rpc-transport.h" #include "socket.h" -#include "common-utils.h" +#include <glusterfs/common-utils.h> -int32_t -gf_resolve_ip6 (const char *hostname, - uint16_t port, - int family, - void **dnscache, - struct addrinfo **addr_info); - -static int32_t -af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr, - socklen_t sockaddr_len, int ceiling) +static void +_assign_port(struct sockaddr *sockaddr, uint16_t port) { - int32_t ret = -1; - /* struct sockaddr_in sin = {0, }; */ - uint16_t port = ceiling - 1; - - while (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; - } - - ret = bind (fd, sockaddr, sockaddr_len); - - if (ret == 0) - break; - - if (ret == -1 && errno == EACCES) - break; - - port--; - } + switch (sockaddr->sa_family) { + case AF_INET6: + ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons(port); + break; - return ret; + case AF_INET_SDP: + case AF_INET: + ((struct sockaddr_in *)sockaddr)->sin_port = htons(port); + break; + } } static int32_t -af_unix_client_bind (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t sockaddr_len, - int sock) +af_inet_bind_to_port_lt_ceiling(int fd, struct sockaddr *sockaddr, + socklen_t sockaddr_len, uint32_t ceiling) { - data_t *path_data = NULL; - struct sockaddr_un *addr = NULL; - int32_t ret = 0; - - path_data = dict_get (this->options, "transport.socket.bind-path"); - if (path_data) { - char *path = data_to_str (path_data); - if (!path || strlen (path) > UNIX_PATH_MAX) { - gf_log (this->name, GF_LOG_TRACE, - "bind-path not specified for unix socket, " - "letting connect to assign default value"); - goto err; - } +#if GF_DISABLE_PRIVPORT_TRACKING + _assign_port(sockaddr, 0); + return bind(fd, sockaddr, sockaddr_len); +#else + int32_t ret = -1; + uint16_t port = ceiling - 1; + unsigned char ports[GF_PORT_ARRAY_SIZE] = { + 0, + }; + int i = 0; - addr = (struct sockaddr_un *) sockaddr; - strcpy (addr->sun_path, path); - ret = bind (sock, (struct sockaddr *)addr, sockaddr_len); - if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "cannot bind to unix-domain socket %d (%s)", - sock, strerror (errno)); - goto err; - } - } else { - gf_log (this->name, GF_LOG_TRACE, - "bind-path not specified for unix socket, " - "letting connect to assign default value"); +loop: + ret = gf_process_reserved_ports(ports, ceiling); + + while (port) { + if (port == GF_CLIENT_PORT_CEILING) { + ret = -1; + break; } -err: - return ret; -} + /* ignore the reserved ports */ + if (BIT_VALUE(ports, port)) { + port--; + continue; + } -int32_t -client_fill_address_family (rpc_transport_t *this, sa_family_t *sa_family) -{ - data_t *address_family_data = NULL; - int32_t ret = -1; + _assign_port(sockaddr, port); - if (sa_family == NULL) { - gf_log_callingfn ("", GF_LOG_WARNING, - "sa_family argument is NULL"); - goto out; - } + ret = bind(fd, sockaddr, sockaddr_len); - 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.socket.connect-path"); - - if (!(remote_host_data || connect_path_data) || - (remote_host_data && connect_path_data)) { - gf_log (this->name, GF_LOG_ERROR, - "transport.address-family not specified and " - "not able to determine the " - "same from other options (remote-host:%s and " - "transport.unix.connect-path:%s)", - data_to_str (remote_host_data), - data_to_str (connect_path_data)); - goto out; - } + if (ret == 0) + break; - if (remote_host_data) { - gf_log (this->name, GF_LOG_DEBUG, - "address-family not specified, guessing it " - "to be inet/inet6"); - *sa_family = AF_UNSPEC; - } else { - gf_log (this->name, GF_LOG_DEBUG, - "address-family not specified, guessing it " - "to be unix"); - *sa_family = AF_UNIX; - } + if (ret == -1 && errno == EACCES) + break; - } else { - char *address_family = data_to_str (address_family_data); - if (!strcasecmp (address_family, "unix")) { - *sa_family = AF_UNIX; - } else if (!strcasecmp (address_family, "inet")) { - *sa_family = AF_INET; - } else if (!strcasecmp (address_family, "inet6")) { - *sa_family = AF_INET6; - } else if (!strcasecmp (address_family, "inet-sdp")) { - *sa_family = AF_INET_SDP; - } else if (!strcasecmp (address_family, "inet/inet6") - || !strcasecmp (address_family, "inet6/inet")) { - *sa_family = AF_UNSPEC; - } else { - gf_log (this->name, GF_LOG_ERROR, - "unknown address-family (%s) specified", - address_family); - goto out; - } - } + port--; + } - ret = 0; + /* 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; + } -out: - return ret; + return ret; +#endif /* GF_DISABLE_PRIVPORT_TRACKING */ } static int32_t -af_inet_client_get_remote_sockaddr (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len) +af_unix_client_bind(rpc_transport_t *this, struct sockaddr *sockaddr, + socklen_t sockaddr_len, int sock) { - dict_t *options = this->options; - data_t *remote_host_data = NULL; - data_t *remote_port_data = NULL; - char *remote_host = NULL; - uint16_t remote_port = 0; - struct addrinfo *addr_info = NULL; - int32_t ret = 0; - - remote_host_data = dict_get (options, "remote-host"); - if (remote_host_data == NULL) - { - gf_log (this->name, GF_LOG_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_log (this->name, GF_LOG_ERROR, - "option remote-host has data NULL in volume %s", this->name); - ret = -1; - goto err; - } - - remote_port_data = dict_get (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; - } - - /* 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); + data_t *path_data = NULL; + struct sockaddr_un *addr = NULL; + int32_t ret = 0; + + path_data = dict_get_sizen(this->options, "transport.socket.bind-path"); + if (path_data) { + char *path = data_to_str(path_data); + 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"); + goto err; + } + + addr = (struct sockaddr_un *)sockaddr; + strcpy(addr->sun_path, path); + ret = bind(sock, (struct sockaddr *)addr, sockaddr_len); if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "DNS resolution failed on host %s", remote_host); - goto err; + gf_log(this->name, GF_LOG_ERROR, + "cannot bind to unix-domain socket %d (%s)", sock, + strerror(errno)); + goto err; } - - memcpy (sockaddr, addr_info->ai_addr, addr_info->ai_addrlen); - *sockaddr_len = addr_info->ai_addrlen; + } else { + gf_log(this->name, GF_LOG_TRACE, + "bind-path not specified for unix socket, " + "letting connect to assign default value"); + } err: - return ret; + return ret; } static int32_t -af_unix_client_get_remote_sockaddr (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len) +client_fill_address_family(rpc_transport_t *this, sa_family_t *sa_family) { - 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.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; + data_t *address_family_data = NULL; + int32_t ret = -1; + + if (sa_family == NULL) { + gf_log_callingfn("", GF_LOG_WARNING, "sa_family argument is NULL"); + goto out; + } + + 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_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)) { + gf_log(this->name, GF_LOG_ERROR, + "transport.address-family not specified. " + "Could not guess default value from (remote-host:%s or " + "transport.unix.connect-path:%s) options", + data_to_str(remote_host_data), + data_to_str(connect_path_data)); + *sa_family = AF_UNSPEC; + goto out; + } + + if (remote_host_data) { + gf_log(this->name, GF_LOG_DEBUG, + "address-family not specified, marking it as unspec " + "for getaddrinfo to resolve from (remote-host: %s)", + data_to_str(remote_host_data)); + *sa_family = AF_UNSPEC; + } else { + gf_log(this->name, GF_LOG_DEBUG, + "address-family not specified, guessing it " + "to be unix from (transport.unix.connect-path: %s)", + data_to_str(connect_path_data)); + *sa_family = AF_UNIX; + } + + } else { + 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")) { + *sa_family = AF_INET; + } else if (!strcasecmp(address_family, "inet6")) { + *sa_family = AF_INET6; + } else if (!strcasecmp(address_family, "inet-sdp")) { + *sa_family = AF_INET_SDP; + } else { + gf_log(this->name, GF_LOG_ERROR, + "unknown address-family (%s) specified", address_family); + *sa_family = AF_UNSPEC; + goto out; } + } - connect_path = data_to_str (connect_path_data); - if (!connect_path) { - gf_log (this->name, GF_LOG_ERROR, - "transport.unix.connect-path is null-string"); - ret = -1; - goto err; - } + ret = 0; - if (strlen (connect_path) > UNIX_PATH_MAX) { - gf_log (this->name, GF_LOG_ERROR, - "connect-path value length %"GF_PRI_SIZET" > %d octets", - strlen (connect_path), UNIX_PATH_MAX); - ret = -1; - goto err; - } +out: + return ret; +} - gf_log (this->name, GF_LOG_TRACE, - "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); +static int32_t +af_inet_client_get_remote_sockaddr(rpc_transport_t *this, + struct sockaddr *sockaddr, + socklen_t *sockaddr_len) +{ + dict_t *options = this->options; + data_t *remote_host_data = NULL; + data_t *remote_port_data = NULL; + char *remote_host = NULL; + 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_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); + ret = -1; + goto err; + } + + remote_host = data_to_str(remote_host_data); + if (remote_host == NULL) { + gf_log(this->name, GF_LOG_ERROR, + "option remote-host has data NULL in volume %s", this->name); + ret = -1; + goto err; + } + + 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); + } 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; + } + } + + /* 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 + non blocking dns techniques */ + ret = gf_resolve_ip6(remote_host, remote_port, sockaddr->sa_family, + &this->dnscache, &addr_info); + if (ret == -1) { + gf_log(this->name, GF_LOG_ERROR, "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; + return ret; } static int32_t -af_unix_server_get_local_sockaddr (rpc_transport_t *this, - struct sockaddr *addr, - socklen_t *addr_len) +af_unix_client_get_remote_sockaddr(rpc_transport_t *this, + struct sockaddr *sockaddr, + socklen_t *sockaddr_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.socket.listen-path"); - if (!listen_path_data) { - gf_log (this->name, GF_LOG_ERROR, - "missing option transport.socket.listen-path"); - ret = -1; - goto err; - } + struct sockaddr_un *sockaddr_un = NULL; + char *connect_path = NULL; + data_t *connect_path_data = NULL; + int32_t ret = -1; + + 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"); + goto err; + } + + /* 108 = sockaddr_un->sun_path length */ + if ((connect_path_data->len + 1) > 108) { + gf_log(this->name, GF_LOG_ERROR, + "connect-path value length %d > %d octets", + connect_path_data->len + 1, UNIX_PATH_MAX); + goto err; + } + + connect_path = data_to_str(connect_path_data); + if (!connect_path) { + gf_log(this->name, GF_LOG_ERROR, + "transport.unix.connect-path is null-string"); + goto err; + } + + gf_log(this->name, GF_LOG_TRACE, "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); + + ret = 0; +err: + return ret; +} - listen_path = data_to_str (listen_path_data); +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_sizen(this->options, + "transport.socket.listen-path"); + if (!listen_path_data) { + gf_log(this->name, GF_LOG_ERROR, + "missing option transport.socket.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_log (this->name, GF_LOG_ERROR, - "option transport.unix.listen-path has value length " - "%"GF_PRI_SIZET" > %d", - strlen (listen_path), UNIX_PATH_MAX); - ret = -1; - goto err; - } + 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", + 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); + sunaddr->sun_family = AF_UNIX; + strcpy(sunaddr->sun_path, listen_path); + *addr_len = sizeof(struct sockaddr_un); err: - return ret; + return ret; } static int32_t -af_inet_server_get_local_sockaddr (rpc_transport_t *this, - struct sockaddr *addr, - socklen_t *addr_len) +af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, + socklen_t *addr_len) { - struct addrinfo hints, *res = 0, *rp = NULL; - data_t *listen_port_data = NULL, *listen_host_data = NULL; - uint16_t listen_port = -1; - 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.socket.listen-port"); - listen_host_data = dict_get (options, "transport.socket.bind-address"); - - if (listen_port_data) - { - listen_port = data_to_uint16 (listen_port_data); - } - - if (listen_port == (uint16_t) -1) - listen_port = GF_DEFAULT_SOCKET_LISTEN_PORT; - - - if (listen_host_data) - { - listen_host = data_to_str (listen_host_data); + struct addrinfo hints, *res = 0, *rp = NULL; + 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; + + /* initializes addr_len */ + *addr_len = 0; + + options = this->options; + + 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_sizen(options, "transport.socket.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_PASSIVE; + + ret = getaddrinfo(listen_host, service, &hints, &res); + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, + "getaddrinfo failed for host %s, service %s (%s)", listen_host, + service, gai_strerror(ret)); + ret = -1; + goto out; + } + /* IPV6 server can handle both ipv4 and ipv6 clients */ + for (rp = res; rp != NULL; rp = rp->ai_next) { + if (rp->ai_addr == NULL) + continue; + if (rp->ai_family == AF_INET6) { + memcpy(addr, rp->ai_addr, rp->ai_addrlen); + *addr_len = rp->ai_addrlen; + } + } + + if (!(*addr_len)) { + if (res && res->ai_addr) { + memcpy(addr, res->ai_addr, res->ai_addrlen); + *addr_len = res->ai_addrlen; } 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; - } - } - - memset (service, 0, sizeof (service)); - 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_PASSIVE | AI_ADDRCONFIG; - - ret = getaddrinfo(listen_host, service, &hints, &res); - if (ret != 0) { - gf_log (this->name, GF_LOG_ERROR, - "getaddrinfo failed for host %s, service %s (%s)", - listen_host, service, gai_strerror (ret)); - ret = -1; - goto out; - } - /* IPV6 server can handle both ipv4 and ipv6 clients */ - for (rp = res; rp != NULL; rp = rp->ai_next) { - if (rp->ai_addr == NULL) - continue; - if (rp->ai_family == AF_INET6) { - memcpy (addr, rp->ai_addr, rp->ai_addrlen); - *addr_len = rp->ai_addrlen; - } - } - - if (!(*addr_len)) { - memcpy (addr, res->ai_addr, res->ai_addrlen); - *addr_len = res->ai_addrlen; + ret = -1; } + } - freeaddrinfo (res); + freeaddrinfo(res); out: - return ret; + return ret; } int32_t -client_bind (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - int sock) +client_bind(rpc_transport_t *this, struct sockaddr *sockaddr, + socklen_t *sockaddr_len, int sock) { - int ret = 0; + int ret = 0; - *sockaddr_len = sizeof (struct sockaddr_in6); - switch (sockaddr->sa_family) - { + *sockaddr_len = sizeof(struct sockaddr_in6); + switch (sockaddr->sa_family) { case AF_INET_SDP: case AF_INET: - *sockaddr_len = sizeof (struct sockaddr_in); - + *sockaddr_len = sizeof(struct sockaddr_in); + /* Fall through */ case AF_INET6: - if (!this->bind_insecure) { - ret = af_inet_bind_to_port_lt_ceiling (sock, sockaddr, - *sockaddr_len, CLIENT_PORT_CEILING); + if (!this->bind_insecure) { + ret = af_inet_bind_to_port_lt_ceiling( + sock, sockaddr, *sockaddr_len, GF_CLIENT_PORT_CEILING); + if (ret == -1) { + gf_log(this->name, GF_LOG_DEBUG, + "cannot bind inet socket (%d) " + "to port less than %d (%s)", + sock, GF_CLIENT_PORT_CEILING, strerror(errno)); + ret = 0; } + } else { + ret = af_inet_bind_to_port_lt_ceiling( + sock, sockaddr, *sockaddr_len, GF_IANA_PRIV_PORTS_START); if (ret == -1) { - gf_log (this->name, GF_LOG_DEBUG, - "cannot bind inet socket (%d) to port less than %d (%s)", - sock, CLIENT_PORT_CEILING, strerror (errno)); - ret = 0; + gf_log(this->name, GF_LOG_DEBUG, + "failed while binding to less than " + "%d (%s)", + GF_IANA_PRIV_PORTS_START, strerror(errno)); + ret = 0; } - break; + } + break; case AF_UNIX: - *sockaddr_len = sizeof (struct sockaddr_un); - ret = af_unix_client_bind (this, (struct sockaddr *)sockaddr, - *sockaddr_len, sock); - break; + *sockaddr_len = sizeof(struct sockaddr_un); + ret = af_unix_client_bind(this, (struct sockaddr *)sockaddr, + *sockaddr_len, sock); + break; default: - gf_log (this->name, GF_LOG_ERROR, - "unknown address family %d", sockaddr->sa_family); - ret = -1; - break; - } + gf_log(this->name, GF_LOG_ERROR, "unknown address family %d", + sockaddr->sa_family); + ret = -1; + break; + } - return ret; + return ret; } int32_t -socket_client_get_remote_sockaddr (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - sa_family_t *sa_family) +socket_client_get_remote_sockaddr(rpc_transport_t *this, + struct sockaddr *sockaddr, + socklen_t *sockaddr_len, + sa_family_t *sa_family) { - int32_t ret = 0; + int32_t ret = 0; - GF_VALIDATE_OR_GOTO ("socket", sockaddr, err); - GF_VALIDATE_OR_GOTO ("socket", sockaddr_len, err); - GF_VALIDATE_OR_GOTO ("socket", sa_family, err); + GF_VALIDATE_OR_GOTO("socket", sockaddr, err); + GF_VALIDATE_OR_GOTO("socket", sockaddr_len, err); + GF_VALIDATE_OR_GOTO("socket", sa_family, err); - ret = client_fill_address_family (this, &sockaddr->sa_family); - if (ret) { - ret = -1; - goto err; - } + ret = client_fill_address_family(this, &sockaddr->sa_family); + if (ret) { + ret = -1; + goto err; + } - *sa_family = sockaddr->sa_family; + *sa_family = sockaddr->sa_family; - switch (sockaddr->sa_family) - { + switch (sockaddr->sa_family) { case AF_INET_SDP: - sockaddr->sa_family = AF_INET; - + sockaddr->sa_family = AF_INET; + /* Fall through */ case AF_INET: case AF_INET6: case AF_UNSPEC: - ret = af_inet_client_get_remote_sockaddr (this, sockaddr, - sockaddr_len); - break; + ret = af_inet_client_get_remote_sockaddr(this, sockaddr, + sockaddr_len); + break; case AF_UNIX: - ret = af_unix_client_get_remote_sockaddr (this, sockaddr, - sockaddr_len); - break; + ret = af_unix_client_get_remote_sockaddr(this, sockaddr, + sockaddr_len); + break; default: - gf_log (this->name, GF_LOG_ERROR, - "unknown address-family %d", sockaddr->sa_family); - ret = -1; - } - - if (*sa_family == AF_UNSPEC) { - *sa_family = sockaddr->sa_family; - } + gf_log(this->name, GF_LOG_ERROR, "unknown address-family %d", + sockaddr->sa_family); + ret = -1; + } + + /* 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; + } err: - return ret; + return ret; } - -int32_t -server_fill_address_family (rpc_transport_t *this, sa_family_t *sa_family) +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; - - GF_VALIDATE_OR_GOTO ("socket", sa_family, out); - - 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")) { - *sa_family = AF_INET; - } else if (!strcasecmp (address_family, "inet6")) { - *sa_family = AF_INET6; - } else if (!strcasecmp (address_family, "inet-sdp")) { - *sa_family = AF_INET_SDP; - } else if (!strcasecmp (address_family, "unix")) { - *sa_family = AF_UNIX; - } else if (!strcasecmp (address_family, "inet/inet6") - || !strcasecmp (address_family, "inet6/inet")) { - *sa_family = AF_UNSPEC; - } else { - gf_log (this->name, GF_LOG_ERROR, - "unknown address family (%s) specified", address_family); - goto out; - } - } else { - gf_log (this->name, GF_LOG_DEBUG, - "option address-family not specified, defaulting to inet/inet6"); - *sa_family = AF_UNSPEC; - } + data_t *address_family_data = NULL; + int32_t ret = -1; - ret = 0; +#ifdef IPV6_DEFAULT + const char *addr_family = "inet6"; + sa_family_t default_family = AF_INET6; +#else + 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_sizen(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")) { + *sa_family = AF_INET; + } else if (!strcasecmp(address_family, "inet6")) { + *sa_family = AF_INET6; + } else if (!strcasecmp(address_family, "inet-sdp")) { + *sa_family = AF_INET_SDP; + } else if (!strcasecmp(address_family, "unix")) { + *sa_family = AF_UNIX; + } else { + gf_log(this->name, GF_LOG_ERROR, + "unknown address family (%s) specified", address_family); + *sa_family = AF_UNSPEC; + goto out; + } + } else { + gf_log(this->name, GF_LOG_DEBUG, + "option address-family not specified, " + "defaulting to %s", + addr_family); + *sa_family = default_family; + } + + ret = 0; out: - return ret; + return ret; } - int32_t -socket_server_get_local_sockaddr (rpc_transport_t *this, struct sockaddr *addr, - socklen_t *addr_len, sa_family_t *sa_family) +socket_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, + socklen_t *addr_len, sa_family_t *sa_family) { - int32_t ret = -1; + int32_t ret = -1; - GF_VALIDATE_OR_GOTO ("socket", sa_family, err); - GF_VALIDATE_OR_GOTO ("socket", addr, err); - GF_VALIDATE_OR_GOTO ("socket", addr_len, err); + GF_VALIDATE_OR_GOTO("socket", sa_family, err); + GF_VALIDATE_OR_GOTO("socket", addr, err); + GF_VALIDATE_OR_GOTO("socket", addr_len, err); - ret = server_fill_address_family (this, &addr->sa_family); - if (ret == -1) { - goto err; - } + ret = server_fill_address_family(this, &addr->sa_family); + if (ret == -1) { + goto err; + } - *sa_family = addr->sa_family; + *sa_family = addr->sa_family; - switch (addr->sa_family) - { + switch (addr->sa_family) { case AF_INET_SDP: - addr->sa_family = AF_INET; - + 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); - break; + ret = af_inet_server_get_local_sockaddr(this, addr, addr_len); + break; case AF_UNIX: - ret = af_unix_server_get_local_sockaddr (this, addr, addr_len); - break; - } + ret = af_unix_server_get_local_sockaddr(this, addr, addr_len); + break; + } - if (*sa_family == AF_UNSPEC) { - *sa_family = addr->sa_family; - } + if (*sa_family == AF_UNSPEC) { + *sa_family = addr->sa_family; + } err: - return ret; + return ret; } -int32_t -fill_inet6_inet_identifiers (rpc_transport_t *this, struct sockaddr_storage *addr, - int32_t addr_len, char *identifier) +static int32_t +fill_inet6_inet_identifiers(rpc_transport_t *this, + struct sockaddr_storage *addr, int32_t addr_len, + char *identifier) { - union gf_sock_union sock_union; - - char service[NI_MAXSERV] = {0,}; - char host[NI_MAXHOST] = {0,}; - int32_t ret = 0; - int32_t tmpaddr_len = 0; - int32_t one_to_four = 0; - int32_t four_to_eight = 0; - int32_t twelve_to_sixteen = 0; - int16_t eight_to_ten = 0; - int16_t ten_to_twelve = 0; - - memset (&sock_union, 0, sizeof (sock_union)); - sock_union.storage = *addr; - tmpaddr_len = addr_len; - - if (sock_union.sa.sa_family == AF_INET6) { - one_to_four = sock_union.sin6.sin6_addr.s6_addr32[0]; - four_to_eight = sock_union.sin6.sin6_addr.s6_addr32[1]; + union gf_sock_union sock_union; + + char service[NI_MAXSERV] = { + 0, + }; + char host[NI_MAXHOST] = { + 0, + }; + int32_t ret = 0; + int32_t tmpaddr_len = 0; + int32_t one_to_four = 0; + int32_t four_to_eight = 0; + int32_t twelve_to_sixteen = 0; + int16_t eight_to_ten = 0; + int16_t ten_to_twelve = 0; + + memset(&sock_union, 0, sizeof(sock_union)); + sock_union.storage = *addr; + tmpaddr_len = addr_len; + + if (sock_union.sa.sa_family == AF_INET6) { + 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]; + eight_to_ten = S6_ADDR16(sock_union.sin6.sin6_addr)[4]; #else - eight_to_ten = sock_union.sin6.sin6_addr.s6_addr16[4]; + 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]; + ten_to_twelve = S6_ADDR16(sock_union.sin6.sin6_addr)[5]; #else - ten_to_twelve = sock_union.sin6.sin6_addr.s6_addr16[5]; + 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); - } - } + twelve_to_sixteen = sock_union.sin6.sin6_addr.s6_addr32[3]; - ret = getnameinfo (&sock_union.sa, - tmpaddr_len, - host, sizeof (host), - service, sizeof (service), - NI_NUMERICHOST | NI_NUMERICSERV); - if (ret != 0) { - gf_log (this->name, GF_LOG_ERROR, - "getnameinfo failed (%s)", gai_strerror (ret)); + /* 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_log(this->name, GF_LOG_ERROR, "getnameinfo failed (%s)", + gai_strerror(ret)); + } - sprintf (identifier, "%s:%s", host, service); + sprintf(identifier, "%s:%s", host, service); - return ret; + return ret; } int32_t -get_transport_identifiers (rpc_transport_t *this) +get_transport_identifiers(rpc_transport_t *this) { - int32_t ret = 0; - char is_inet_sdp = 0; + int32_t ret = 0; + char is_inet_sdp = 0; - switch (((struct sockaddr *) &this->myinfo.sockaddr)->sa_family) - { + 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; - + 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_log (this->name, GF_LOG_ERROR, - "cannot 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_log (this->name, GF_LOG_ERROR, - "cannot fill inet/inet6 identifier for client"); - goto err; - } + case AF_INET6: { + ret = fill_inet6_inet_identifiers(this, &this->myinfo.sockaddr, + this->myinfo.sockaddr_len, + this->myinfo.identifier); + if (ret == -1) { + gf_log(this->name, GF_LOG_ERROR, + "cannot 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_log(this->name, GF_LOG_ERROR, + "cannot 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; + 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; + 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->myinfo.sockaddr; + strcpy(this->myinfo.identifier, sunaddr->sun_path); - sunaddr = (struct sockaddr_un *) &this->peerinfo.sockaddr; - strcpy (this->peerinfo.identifier, sunaddr->sun_path); - } - break; + sunaddr = (struct sockaddr_un *)&this->peerinfo.sockaddr; + strcpy(this->peerinfo.identifier, sunaddr->sun_path); + } break; default: - gf_log (this->name, GF_LOG_ERROR, - "unknown address family (%d)", - ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family); - ret = -1; - break; - } + gf_log(this->name, GF_LOG_ERROR, "unknown address family (%d)", + ((struct sockaddr *)&this->myinfo.sockaddr)->sa_family); + ret = -1; + break; + } err: - return ret; + return ret; } diff --git a/rpc/rpc-transport/socket/src/name.h b/rpc/rpc-transport/socket/src/name.h index 0ca67d2e4fe..080c7588f5a 100644 --- a/rpc/rpc-transport/socket/src/name.h +++ b/rpc/rpc-transport/socket/src/name.h @@ -1,44 +1,33 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _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, - socklen_t *sockaddr_len, - int sock); +client_bind(rpc_transport_t *this, struct sockaddr *sockaddr, + socklen_t *sockaddr_len, int sock); int32_t -socket_client_get_remote_sockaddr (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - sa_family_t *sa_family); +socket_client_get_remote_sockaddr(rpc_transport_t *this, + struct sockaddr *sockaddr, + socklen_t *sockaddr_len, + sa_family_t *sa_family); int32_t -socket_server_get_local_sockaddr (rpc_transport_t *this, struct sockaddr *addr, - socklen_t *addr_len, sa_family_t *sa_family); +socket_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr, + socklen_t *addr_len, sa_family_t *sa_family); int32_t -get_transport_identifiers (rpc_transport_t *this); +get_transport_identifiers(rpc_transport_t *this); #endif /* _SOCKET_NAME_H */ diff --git a/rpc/rpc-transport/socket/src/socket-mem-types.h b/rpc/rpc-transport/socket/src/socket-mem-types.h new file mode 100644 index 00000000000..241ce67f670 --- /dev/null +++ b/rpc/rpc-transport/socket/src/socket-mem-types.h @@ -0,0 +1,22 @@ +/* + Copyright (c) 2008-2014 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 __SOCKET_MEM_TYPES_H__ +#define __SOCKET_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_end +} gf_sock_mem_types_t; + +#endif diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c index 3b2d05c450b..ed8b473be23 100644 --- a/rpc/rpc-transport/socket/src/socket.c +++ b/rpc/rpc-transport/socket/src/socket.c @@ -1,808 +1,1470 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include "socket.h" #include "name.h" -#include "dict.h" -#include "rpc-transport.h" -#include "logging.h" -#include "xlator.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" /* ugly #includes below */ #include "protocol-common.h" #include "glusterfs3-xdr.h" -#include "xdr-nfs3.h" +#include "glusterfs4-xdr.h" #include "rpcsvc.h" -#include <fcntl.h> -#include <errno.h> +/* for TCP_USER_TIMEOUT */ +#if !defined(TCP_USER_TIMEOUT) && defined(GF_LINUX_HOST_OS) +#include <linux/tcp.h> +#else #include <netinet/tcp.h> +#endif + +#include <errno.h> #include <rpc/xdr.h> +#include <sys/ioctl.h> #define GF_LOG_ERRNO(errno) ((errno == ENOTCONN) ? GF_LOG_DEBUG : GF_LOG_ERROR) #define SA(ptr) ((struct sockaddr *)ptr) +#define SSL_ENABLED_OPT "transport.socket.ssl-enabled" +#define SSL_OWN_CERT_OPT "transport.socket.ssl-own-cert" +#define SSL_PRIVATE_KEY_OPT "transport.socket.ssl-private-key" +#define SSL_CA_LIST_OPT "transport.socket.ssl-ca-list" +#define SSL_CERT_DEPTH_OPT "transport.socket.ssl-cert-depth" +#define SSL_CIPHER_LIST_OPT "transport.socket.ssl-cipher-list" +#define SSL_DH_PARAM_OPT "transport.socket.ssl-dh-param" +#define SSL_EC_CURVE_OPT "transport.socket.ssl-ec-curve" +#define SSL_CRL_PATH_OPT "transport.socket.ssl-crl-path" +#define OWN_THREAD_OPT "transport.socket.own-thread" + +/* TBD: do automake substitutions etc. (ick) to set these. */ +#if !defined(DEFAULT_ETC_SSL) +#ifdef GF_LINUX_HOST_OS +#define DEFAULT_ETC_SSL "/etc/ssl" +#endif +#ifdef GF_BSD_HOST_OS +#define DEFAULT_ETC_SSL "/etc/openssl" +#endif +#ifdef GF_DARWIN_HOST_OS +#define DEFAULT_ETC_SSL "/usr/local/etc/openssl" +#endif +#if !defined(DEFAULT_ETC_SSL) +#define DEFAULT_ETC_SSL "/etc/ssl" +#endif +#endif -#define __socket_proto_reset_pending(priv) do { \ - memset (&priv->incoming.frag.vector, 0, \ - sizeof (priv->incoming.frag.vector)); \ - priv->incoming.frag.pending_vector = \ - &priv->incoming.frag.vector; \ - priv->incoming.frag.pending_vector->iov_base = \ - priv->incoming.frag.fragcurrent; \ - priv->incoming.pending_vector = \ - priv->incoming.frag.pending_vector; \ - } while (0); - - -#define __socket_proto_update_pending(priv) \ - do { \ - uint32_t remaining_fragsize = 0; \ - if (priv->incoming.frag.pending_vector->iov_len == 0) { \ - remaining_fragsize = RPC_FRAGSIZE (priv->incoming.fraghdr) \ - - priv->incoming.frag.bytes_read; \ - \ - priv->incoming.frag.pending_vector->iov_len = \ - remaining_fragsize > priv->incoming.frag.remaining_size \ - ? priv->incoming.frag.remaining_size : remaining_fragsize; \ - \ - priv->incoming.frag.remaining_size -= \ - priv->incoming.frag.pending_vector->iov_len; \ - } \ - } while (0); - -#define __socket_proto_update_priv_after_read(priv, ret, bytes_read) \ - { \ - priv->incoming.frag.fragcurrent += bytes_read; \ - priv->incoming.frag.bytes_read += bytes_read; \ - \ - if ((ret > 0) || (priv->incoming.frag.remaining_size != 0)) { \ - if (priv->incoming.frag.remaining_size != 0 && ret == 0) { \ - __socket_proto_reset_pending (priv); \ - } \ - \ - gf_log (this->name, GF_LOG_TRACE, "partial read on non-blocking socket"); \ - \ - break; \ - } \ - } - -#define __socket_proto_init_pending(priv, size) \ - do { \ - uint32_t remaining_fragsize = 0; \ - remaining_fragsize = RPC_FRAGSIZE (priv->incoming.fraghdr) \ - - priv->incoming.frag.bytes_read; \ - \ - __socket_proto_reset_pending (priv); \ - \ - priv->incoming.frag.pending_vector->iov_len = \ - remaining_fragsize > size ? size : remaining_fragsize; \ - \ - priv->incoming.frag.remaining_size = \ - size - priv->incoming.frag.pending_vector->iov_len; \ - \ - } while (0); - +#if !defined(DEFAULT_CERT_PATH) +#define DEFAULT_CERT_PATH DEFAULT_ETC_SSL "/glusterfs.pem" +#endif +#if !defined(DEFAULT_KEY_PATH) +#define DEFAULT_KEY_PATH DEFAULT_ETC_SSL "/glusterfs.key" +#endif +#if !defined(DEFAULT_CA_PATH) +#define DEFAULT_CA_PATH DEFAULT_ETC_SSL "/glusterfs.ca" +#endif +#if !defined(DEFAULT_VERIFY_DEPTH) +#define DEFAULT_VERIFY_DEPTH 1 +#endif +#define DEFAULT_CIPHER_LIST "EECDH:EDH:HIGH:!3DES:!RC4:!DES:!MD5:!aNULL:!eNULL" +#define DEFAULT_DH_PARAM DEFAULT_ETC_SSL "/dhparam.pem" +#define DEFAULT_EC_CURVE "prime256v1" + +#define POLL_MASK_INPUT (POLLIN | POLLPRI) +#define POLL_MASK_OUTPUT (POLLOUT) +#define POLL_MASK_ERROR (POLLERR | POLLHUP | POLLNVAL) + +typedef int +SSL_unary_func(SSL *); +typedef int +SSL_trinary_func(SSL *, void *, int); +static int +ssl_setup_connection_params(rpc_transport_t *this); + +#define __socket_proto_reset_pending(priv) \ + do { \ + struct gf_sock_incoming_frag *frag; \ + frag = &priv->incoming.frag; \ + \ + memset(&frag->vector, 0, sizeof(frag->vector)); \ + frag->pending_vector = &frag->vector; \ + frag->pending_vector->iov_base = frag->fragcurrent; \ + priv->incoming.pending_vector = frag->pending_vector; \ + } while (0) + +#define __socket_proto_update_pending(priv) \ + do { \ + uint32_t remaining; \ + struct gf_sock_incoming_frag *frag; \ + frag = &priv->incoming.frag; \ + if (frag->pending_vector->iov_len == 0) { \ + remaining = (RPC_FRAGSIZE(priv->incoming.fraghdr) - \ + frag->bytes_read); \ + \ + frag->pending_vector->iov_len = (remaining > frag->remaining_size) \ + ? frag->remaining_size \ + : remaining; \ + \ + frag->remaining_size -= frag->pending_vector->iov_len; \ + } \ + } while (0) + +#define __socket_proto_update_priv_after_read(priv, ret, bytes_read) \ + { \ + struct gf_sock_incoming_frag *frag; \ + frag = &priv->incoming.frag; \ + \ + frag->fragcurrent += bytes_read; \ + frag->bytes_read += bytes_read; \ + \ + if ((ret > 0) || (frag->remaining_size != 0)) { \ + if (frag->remaining_size != 0 && ret == 0) { \ + __socket_proto_reset_pending(priv); \ + } \ + \ + gf_log(this->name, GF_LOG_TRACE, \ + "partial read on non-blocking socket"); \ + ret = 0; \ + break; \ + } \ + } + +#define __socket_proto_init_pending(priv, size) \ + do { \ + uint32_t remaining = 0; \ + struct gf_sock_incoming_frag *frag; \ + frag = &priv->incoming.frag; \ + \ + remaining = (RPC_FRAGSIZE(priv->incoming.fraghdr) - frag->bytes_read); \ + \ + __socket_proto_reset_pending(priv); \ + \ + frag->pending_vector->iov_len = (remaining > size) ? size : remaining; \ + \ + frag->remaining_size = (size - frag->pending_vector->iov_len); \ + \ + } while (0) /* This will be used in a switch case and breaks from the switch case if all * the pending data is not read. */ -#define __socket_proto_read(priv, ret) \ - { \ - size_t bytes_read = 0; \ - \ - __socket_proto_update_pending (priv); \ - \ - ret = __socket_readv (this, \ - priv->incoming.pending_vector, 1, \ - &priv->incoming.pending_vector, \ - &priv->incoming.pending_count, \ - &bytes_read); \ - if (ret == -1) { \ - gf_log (this->name, GF_LOG_WARNING, \ - "reading from socket failed. Error (%s), " \ - "peer (%s)", strerror (errno), \ - this->peerinfo.identifier); \ - break; \ - } \ - __socket_proto_update_priv_after_read (priv, ret, bytes_read); \ - } - - -int socket_init (rpc_transport_t *this); +#define __socket_proto_read(priv, ret) \ + { \ + size_t bytes_read = 0; \ + struct gf_sock_incoming *in; \ + in = &priv->incoming; \ + \ + __socket_proto_update_pending(priv); \ + \ + ret = __socket_readv(this, in->pending_vector, 1, &in->pending_vector, \ + &in->pending_count, &bytes_read); \ + if (ret < 0) \ + break; \ + __socket_proto_update_priv_after_read(priv, ret, bytes_read); \ + } + +struct socket_connect_error_state_ { + xlator_t *this; + rpc_transport_t *trans; + gf_boolean_t refd; +}; +typedef struct socket_connect_error_state_ socket_connect_error_state_t; -/* - * return value: - * 0 = success (completed) - * -1 = error - * > 0 = incomplete - */ +static int +socket_init(rpc_transport_t *this); +static int +__socket_nonblock(int fd); -int -__socket_rwv (rpc_transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count, size_t *bytes, - int write) +static void +socket_dump_info(struct sockaddr *sa, int is_server, int is_ssl, int sock, + char *log_domain, char *log_label) { - socket_private_t *priv = NULL; - int sock = -1; - int ret = -1; - struct iovec *opvector = NULL; - int opcount = 0; - int moved = 0; + char addr_buf[INET6_ADDRSTRLEN + 1] = { + 0, + }; + char *addr = NULL; + const char *peer_type = NULL; + int af = sa->sa_family; + int so_error = -1; + socklen_t slen = sizeof(so_error); + + if (af == AF_UNIX) { + addr = ((struct sockaddr_un *)(sa))->sun_path; + } else { + if (af == AF_INET6) { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)(sa); + + inet_ntop(af, &sin6->sin6_addr, addr_buf, sizeof(addr_buf)); + addr = addr_buf; + } else { + struct sockaddr_in *sin = (struct sockaddr_in *)(sa); + + inet_ntop(af, &sin->sin_addr, addr_buf, sizeof(addr_buf)); + addr = addr_buf; + } + } + if (is_server) + peer_type = "server"; + else + peer_type = "client"; + + (void)getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &slen); + + gf_log(log_domain, GF_LOG_TRACE, + "$$$ %s: %s (af:%d,sock:%d) %s %s (errno:%d:%s)", peer_type, + log_label, af, sock, addr, (is_ssl ? "SSL" : "non-SSL"), so_error, + strerror(so_error)); +} - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); +static void +ssl_dump_error_stack(const char *caller) +{ + unsigned long errnum = 0; + char errbuf[120] = { + 0, + }; - priv = this->private; - sock = priv->sock; + /* OpenSSL docs explicitly give 120 as the error-string length. */ - opvector = vector; - opcount = count; + while ((errnum = ERR_get_error())) { + ERR_error_string(errnum, errbuf); + gf_log(caller, GF_LOG_ERROR, " %s", errbuf); + } +} - if (bytes != NULL) { - *bytes = 0; +static int +ssl_do(rpc_transport_t *this, void *buf, size_t len, SSL_trinary_func *func) +{ + int r = (-1); + socket_private_t *priv = NULL; + + priv = this->private; + + if (buf) { + if (priv->connected == -1) { + /* + * Fields in the SSL structure (especially + * the BIO pointers) are not valid at this + * point, so we'll segfault if we pass them + * to SSL_read/SSL_write. + */ + gf_log(this->name, GF_LOG_INFO, "lost connection in %s", __func__); + return -1; } + r = func(priv->ssl_ssl, buf, len); + } else { + /* 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: + /* fall through */ + case SSL_ERROR_WANT_READ: + /* fall through */ + case SSL_ERROR_WANT_WRITE: + errno = EAGAIN; + return r; + + case SSL_ERROR_SYSCALL: + /* Sometimes SSL_ERROR_SYSCALL returns errno as + * EAGAIN. In such a case we should reattempt operation + * So, for now, just return the return value and the + * errno as is. + */ + gf_log(this->name, GF_LOG_DEBUG, + "syscall error (probably remote disconnect) " + "errno:%d:%s", + errno, strerror(errno)); + return r; + default: + errno = EIO; + goto out; /* "break" would just loop again */ + } +out: + return -1; +} - while (opcount) { - if (write) { - ret = writev (sock, opvector, opcount); +#define ssl_read_one(t, b, l) \ + ssl_do((t), (b), (l), (SSL_trinary_func *)SSL_read) +#define ssl_write_one(t, b, l) \ + ssl_do((t), (b), (l), (SSL_trinary_func *)SSL_write) + +/* 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; +} - if (ret == 0 || (ret == -1 && errno == EAGAIN)) { - /* done for now */ - break; - } - this->total_bytes_write += ret; - } else { - ret = readv (sock, opvector, opcount); - if (ret == -1 && errno == EAGAIN) { - /* done for now */ - break; - } - this->total_bytes_read += ret; - } +/* 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; - if (ret == 0) { - /* Mostly due to 'umount' in client */ + 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 +} - gf_log (this->name, GF_LOG_DEBUG, - "EOF from peer %s", this->peerinfo.identifier); - opcount = -1; - errno = ENOTCONN; - break; - } - if (ret == -1) { - if (errno == EINTR) - continue; - - gf_log (this->name, GF_LOG_WARNING, - "%s failed (%s)", write ? "writev" : "readv", - strerror (errno)); - opcount = -1; - break; - } +static int +ssl_setup_connection_prefix(rpc_transport_t *this, gf_boolean_t server) +{ + int ret = -1; + socket_private_t *priv = NULL; + + priv = this->private; + + if (ssl_setup_connection_params(this) < 0) { + gf_log(this->name, GF_LOG_TRACE, + "+ ssl_setup_connection_params() failed!"); + goto done; + } else { + gf_log(this->name, GF_LOG_TRACE, + "+ ssl_setup_connection_params() done!"); + } + + priv->ssl_error_required = SSL_ERROR_NONE; + priv->ssl_connected = _gf_false; + 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"); + ssl_dump_error_stack(this->name); + goto done; + } + + priv->ssl_sbio = BIO_new_socket(priv->sock, BIO_NOCLOSE); + if (!priv->ssl_sbio) { + gf_log(this->name, GF_LOG_ERROR, "BIO_new_socket failed"); + ssl_dump_error_stack(this->name); + goto free_ssl; + } + + SSL_set_bio(priv->ssl_ssl, priv->ssl_sbio, priv->ssl_sbio); + ret = 0; + goto done; + +free_ssl: + SSL_free(priv->ssl_ssl); + priv->ssl_ssl = NULL; +done: + return ret; +} - if (bytes != NULL) { - *bytes += ret; - } +static char * +ssl_setup_connection_postfix(rpc_transport_t *this) +{ + X509 *peer = NULL; + char peer_CN[256] = ""; + socket_private_t *priv = NULL; + + priv = this->private; + + /* Make sure _SSL verification_ succeeded, yielding an identity. */ + if (SSL_get_verify_result(priv->ssl_ssl) != X509_V_OK) { + goto ssl_error; + } + peer = SSL_get_peer_certificate(priv->ssl_ssl); + if (!peer) { + goto ssl_error; + } + + SSL_set_mode(priv->ssl_ssl, SSL_MODE_ENABLE_PARTIAL_WRITE); + + /* Finally, everything seems OK. */ + X509_NAME_get_text_by_NID(X509_get_subject_name(peer), NID_commonName, + peer_CN, sizeof(peer_CN) - 1); + peer_CN[sizeof(peer_CN) - 1] = '\0'; + gf_log(this->name, GF_LOG_DEBUG, "peer CN = %s", peer_CN); + 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. */ +ssl_error: + gf_log(this->name, GF_LOG_ERROR, + "SSL connect error (client: %s) (server: %s)", + this->peerinfo.identifier, this->myinfo.identifier); + ssl_dump_error_stack(this->name); + + SSL_free(priv->ssl_ssl); + priv->ssl_ssl = NULL; + return NULL; +} - moved = 0; - - while (moved < ret) { - if ((ret - moved) >= opvector[0].iov_len) { - moved += opvector[0].iov_len; - opvector++; - opcount--; - } else { - opvector[0].iov_len -= (ret - moved); - opvector[0].iov_base += (ret - moved); - moved += (ret - moved); - } - while (opcount && !opvector[0].iov_len) { - opvector++; - opcount--; - } +static int +ssl_complete_connection(rpc_transport_t *this) +{ + int ret = -1; /* 1 : implies go back to epoll_wait() + * 0 : implies successful ssl connection + * -1: implies continue processing current event + * as if EPOLLERR has been encountered + */ + char *cname = NULL; + int r = -1; + int ssl_error = -1; + socket_private_t *priv = NULL; + + priv = this->private; + + if (priv->is_server) { + r = SSL_accept(priv->ssl_ssl); + } else { + r = SSL_connect(priv->ssl_ssl); + } + + ssl_error = SSL_get_error(priv->ssl_ssl, r); + priv->ssl_error_required = ssl_error; + + switch (ssl_error) { + case SSL_ERROR_NONE: + cname = ssl_setup_connection_postfix(this); + if (!cname) { + /* we've failed to get the cname so + * we must close the connection + * + * treat this as EPOLLERR + */ + gf_log(this->name, GF_LOG_TRACE, "error getting cname"); + errno = ECONNRESET; + ret = -1; + } else { + this->ssl_name = cname; + if (priv->is_server) { + priv->ssl_accepted = _gf_true; + gf_log(this->name, GF_LOG_TRACE, "ssl_accepted!"); + } else { + priv->ssl_connected = _gf_true; + gf_log(this->name, GF_LOG_TRACE, "ssl_connected!"); } - } - - if (pending_vector) - *pending_vector = opvector; - - if (pending_count) - *pending_count = opcount; + ret = 0; + } + break; + + case SSL_ERROR_WANT_READ: + /* fall through */ + case SSL_ERROR_WANT_WRITE: + errno = EAGAIN; + break; + + case SSL_ERROR_SYSCALL: + /* Sometimes SSL_ERROR_SYSCALL returns with errno as EAGAIN + * So, we should retry the operation. + * So, for now, we just return the return value and errno as is. + */ + break; + + case SSL_ERROR_SSL: + /* treat this as EPOLLERR */ + ret = -1; + break; + + default: + /* treat this as EPOLLERR */ + errno = EIO; + ret = -1; + break; + } + return ret; +} -out: - return opcount; +static void +ssl_teardown_connection(socket_private_t *priv) +{ + if (priv->ssl_ssl) { + SSL_shutdown(priv->ssl_ssl); + SSL_clear(priv->ssl_ssl); + SSL_free(priv->ssl_ssl); + SSL_CTX_free(priv->ssl_ctx); + priv->ssl_ssl = NULL; + priv->ssl_ctx = NULL; + if (priv->ssl_private_key) { + GF_FREE(priv->ssl_private_key); + priv->ssl_private_key = NULL; + } + if (priv->ssl_own_cert) { + GF_FREE(priv->ssl_own_cert); + priv->ssl_own_cert = NULL; + } + if (priv->ssl_ca_list) { + GF_FREE(priv->ssl_ca_list); + priv->ssl_ca_list = NULL; + } + } + priv->use_ssl = _gf_false; } +static ssize_t +__socket_ssl_readv(rpc_transport_t *this, struct iovec *opvector, int opcount) +{ + socket_private_t *priv = NULL; + int sock = -1; + int ret = -1; + + priv = this->private; + sock = priv->sock; + + if (priv->use_ssl) { + gf_log(this->name, GF_LOG_TRACE, "***** reading over SSL"); + ret = ssl_read_one(this, opvector->iov_base, opvector->iov_len); + } else { + gf_log(this->name, GF_LOG_TRACE, "***** reading over non-SSL"); + ret = sys_readv(sock, opvector, IOV_MIN(opcount)); + } + + return ret; +} -int -__socket_readv (rpc_transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count, - size_t *bytes) +static ssize_t +__socket_ssl_read(rpc_transport_t *this, void *buf, size_t count) { - int ret = -1; + struct iovec iov = { + 0, + }; + int ret = -1; - ret = __socket_rwv (this, vector, count, - pending_vector, pending_count, bytes, 0); + iov.iov_base = buf; + iov.iov_len = count; - return ret; + ret = __socket_ssl_readv(this, &iov, 1); + + return ret; } +static int +__socket_cached_read(rpc_transport_t *this, struct iovec *opvector, int opcount) +{ + socket_private_t *priv = NULL; + struct gf_sock_incoming *in = NULL; + int req_len = -1; + int ret = -1; + + priv = this->private; + in = &priv->incoming; + req_len = iov_length(opvector, opcount); + + if (in->record_state == SP_STATE_READING_FRAGHDR) { + in->ra_read = 0; + in->ra_served = 0; + in->ra_max = 0; + in->ra_buf = NULL; + goto uncached; + } + + if (!in->ra_max) { + /* first call after passing SP_STATE_READING_FRAGHDR */ + in->ra_max = min(RPC_FRAGSIZE(in->fraghdr), GF_SOCKET_RA_MAX); + /* Note that the in->iobuf is the primary iobuf into which + headers are read into, and in->frag.fragcurrent points to + some position in the buffer. By using this itself as our + read-ahead cache, we can avoid memory copies in iov_load + */ + in->ra_buf = in->frag.fragcurrent; + } + + /* fill read-ahead */ + if (in->ra_read < in->ra_max) { + ret = __socket_ssl_read(this, &in->ra_buf[in->ra_read], + (in->ra_max - in->ra_read)); + if (ret > 0) + in->ra_read += ret; + + /* we proceed to test if there is still cached data to + be served even if readahead could not progress */ + } + + /* serve cached */ + if (in->ra_served < in->ra_read) { + ret = iov_load(opvector, opcount, &in->ra_buf[in->ra_served], + min(req_len, (in->ra_read - in->ra_served))); + + in->ra_served += ret; + /* Do not read uncached and cached in the same call */ + goto out; + } + + if (in->ra_read < in->ra_max) + /* If there was no cached data to be served, (and we are + guaranteed to have already performed an attempt to progress + readahead above), and we have not yet read out the full + readahead capacity, then bail out for now without doing + the uncached read below (as that will overtake future cached + read) + */ + goto out; +uncached: + ret = __socket_ssl_readv(this, opvector, opcount); +out: + return ret; +} -int -__socket_writev (rpc_transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count) +static gf_boolean_t +__does_socket_rwv_error_need_logging(socket_private_t *priv, int write) { - int ret = -1; + int read = !write; - ret = __socket_rwv (this, vector, count, - pending_vector, pending_count, NULL, 1); + if (priv->connected == -1) /* Didn't even connect, of course it fails */ + return _gf_false; - return ret; + if (read && (priv->read_fail_log == _gf_false)) + return _gf_false; + + return _gf_true; } +/* + * return value: + * 0 = success (completed) + * -1 = error + * > 0 = incomplete + */ -int -__socket_disconnect (rpc_transport_t *this) +static int +__socket_rwv(rpc_transport_t *this, struct iovec *vector, int count, + struct iovec **pending_vector, int *pending_count, size_t *bytes, + int write) { - socket_private_t *priv = NULL; - int ret = -1; + socket_private_t *priv = NULL; + int sock = -1; + int ret = -1; + struct iovec *opvector = NULL; + int opcount = 0; + int moved = 0; + + GF_VALIDATE_OR_GOTO("socket", this->private, out); + + priv = this->private; + sock = priv->sock; + + opvector = vector; + opcount = count; + + if (bytes != NULL) { + *bytes = 0; + } + + while (opcount > 0) { + if (opvector->iov_len == 0) { + gf_log(this->name, GF_LOG_DEBUG, + "would have passed zero length to read/write"); + ++opvector; + --opcount; + continue; + } + if (priv->use_ssl && !priv->ssl_ssl) { + /* + * We could end up here with priv->ssl_ssl still NULL + * if (a) the connection failed and (b) some fool + * called other socket functions anyway. Demoting to + * non-SSL might be insecure, so just fail it outright. + */ + ret = -1; + gf_log(this->name, GF_LOG_TRACE, + "### no priv->ssl_ssl yet; ret = -1;"); + } else if (write) { + if (priv->use_ssl) { + ret = ssl_write_one(this, opvector->iov_base, + opvector->iov_len); + } else { + ret = sys_writev(sock, opvector, IOV_MIN(opcount)); + } + + if ((ret == 0) || ((ret < 0) && (errno == EAGAIN))) { + /* done for now */ + break; + } 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_DEBUG, + "EOF on socket %d (errno:%d:%s); returning ENODATA", + sock, errno, strerror(errno)); - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); + errno = ENODATA; + ret = -1; + } + if ((ret < 0) && (errno == EAGAIN)) { + /* done for now */ + break; + } else if (ret > 0) + this->total_bytes_read += ret; + } - priv = this->private; + if (ret == 0) { + /* Mostly due to 'umount' in client */ - if (priv->sock != -1) { - priv->connected = -1; - ret = shutdown (priv->sock, SHUT_RDWR); - if (ret) { - /* its already disconnected.. no need to understand - why it failed to shutdown in normal cases */ - gf_log (this->name, GF_LOG_DEBUG, - "shutdown() returned %d. %s", - ret, strerror (errno)); - } + gf_log(this->name, GF_LOG_DEBUG, "EOF from peer %s", + this->peerinfo.identifier); + opcount = -1; + errno = ENOTCONN; + break; + } + if (ret < 0) { + if (errno == EINTR) + continue; + + if (__does_socket_rwv_error_need_logging(priv, write)) { + GF_LOG_OCCASIONALLY(priv->log_ctr, this->name, GF_LOG_WARNING, + "%s on %s failed (%s)", + write ? "writev" : "readv", + this->peerinfo.identifier, strerror(errno)); + } + + if (priv->use_ssl && priv->ssl_ssl) { + ssl_dump_error_stack(this->name); + } + opcount = -1; + break; } + if (bytes != NULL) { + *bytes += ret; + } + + moved = 0; + + while (moved < ret) { + if (!opcount) { + gf_log(this->name, GF_LOG_DEBUG, "ran out of iov, moved %d/%d", + moved, ret); + goto ran_out; + } + if (!opvector[0].iov_len) { + opvector++; + opcount--; + continue; + } + if ((ret - moved) >= opvector[0].iov_len) { + moved += opvector[0].iov_len; + opvector++; + opcount--; + } else { + opvector[0].iov_len -= (ret - moved); + opvector[0].iov_base += (ret - moved); + moved += (ret - moved); + } + } + } + +ran_out: + + if (pending_vector) + *pending_vector = opvector; + + if (pending_count) + *pending_count = opcount; + out: - return ret; + return opcount; } +static int +__socket_readv(rpc_transport_t *this, struct iovec *vector, int count, + struct iovec **pending_vector, int *pending_count, size_t *bytes) +{ + return __socket_rwv(this, vector, count, pending_vector, pending_count, + bytes, 0); +} -int -__socket_server_bind (rpc_transport_t *this) -{ - socket_private_t *priv = NULL; - int ret = -1; - int opt = 1; - int reuse_check_sock = -1; - struct sockaddr_storage unix_addr = {0}; - - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); - - priv = this->private; - - ret = setsockopt (priv->sock, SOL_SOCKET, SO_REUSEADDR, - &opt, sizeof (opt)); - - if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "setsockopt() for SO_REUSEADDR failed (%s)", - strerror (errno)); - } - - /* reuse-address doesn't work for unix type sockets */ - if (AF_UNIX == SA (&this->myinfo.sockaddr)->sa_family) { - memcpy (&unix_addr, SA (&this->myinfo.sockaddr), - this->myinfo.sockaddr_len); - reuse_check_sock = socket (AF_UNIX, SOCK_STREAM, 0); - if (reuse_check_sock > 0) { - ret = connect (reuse_check_sock, SA (&unix_addr), - this->myinfo.sockaddr_len); - if ((ret == -1) && (ECONNREFUSED == errno)) { - unlink (((struct sockaddr_un*)&unix_addr)->sun_path); - } - close (reuse_check_sock); - } +static int +__socket_writev(rpc_transport_t *this, struct iovec *vector, int count, + struct iovec **pending_vector, int *pending_count) +{ + return __socket_rwv(this, vector, count, pending_vector, pending_count, + NULL, 1); +} + +static int +__socket_shutdown(rpc_transport_t *this) +{ + int ret = -1; + socket_private_t *priv = this->private; + + priv->connected = -1; + ret = shutdown(priv->sock, SHUT_RDWR); + if (ret) { + /* its already disconnected.. no need to understand + why it failed to shutdown in normal cases */ + gf_log(this->name, GF_LOG_DEBUG, "shutdown() returned %d. %s", ret, + strerror(errno)); + } else { + GF_LOG_OCCASIONALLY(priv->shutdown_log_ctr, this->name, GF_LOG_INFO, + "intentional socket shutdown(%d)", priv->sock); + } + + return ret; +} + +static int +__socket_teardown_connection(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + + priv = this->private; + + if (priv->use_ssl) + ssl_teardown_connection(priv); + + return __socket_shutdown(this); +} + +static int +__socket_disconnect(rpc_transport_t *this) +{ + int ret = -1; + socket_private_t *priv = NULL; + + priv = this->private; + + gf_log(this->name, GF_LOG_TRACE, "disconnecting %p, sock=%d", this, + priv->sock); + + if (priv->sock >= 0) { + gf_log_callingfn(this->name, GF_LOG_TRACE, + "tearing down socket connection"); + ret = __socket_teardown_connection(this); + if (ret) { + gf_log(this->name, GF_LOG_DEBUG, + "__socket_teardown_connection () failed: %s", + strerror(errno)); } + } - ret = bind (priv->sock, (struct sockaddr *)&this->myinfo.sockaddr, - this->myinfo.sockaddr_len); + return ret; +} - if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "binding to %s failed: %s", - this->myinfo.identifier, strerror (errno)); +static int +__socket_server_bind(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + glusterfs_ctx_t *ctx = NULL; + cmd_args_t *cmd_args = NULL; + struct sockaddr_storage unix_addr = {0}; + int ret = -1; + int opt = 1; + int reuse_check_sock = -1; + uint16_t sin_port = 0; + int retries = 0; + + priv = this->private; + ctx = this->ctx; + cmd_args = &ctx->cmd_args; + + ret = setsockopt(priv->sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, + "setsockopt() for SO_REUSEADDR failed (%s)", strerror(errno)); + } + + /* reuse-address doesn't work for unix type sockets */ + if (AF_UNIX == SA(&this->myinfo.sockaddr)->sa_family) { + memcpy(&unix_addr, SA(&this->myinfo.sockaddr), + this->myinfo.sockaddr_len); + reuse_check_sock = sys_socket(AF_UNIX, SOCK_STREAM, 0); + if (reuse_check_sock >= 0) { + ret = connect(reuse_check_sock, SA(&unix_addr), + this->myinfo.sockaddr_len); + if ((ret != 0) && (ECONNREFUSED == errno)) { + sys_unlink(((struct sockaddr_un *)&unix_addr)->sun_path); + } + gf_log(this->name, GF_LOG_INFO, + "closing (AF_UNIX) reuse check socket %d", reuse_check_sock); + sys_close(reuse_check_sock); + } + } + + 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"); + 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 != 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) != 0) { + gf_log(this->name, GF_LOG_WARNING, + "getsockname on (%d) failed (%s)", priv->sock, + strerror(errno)); + ret = -1; + goto out; + } + if (!cmd_args->brick_port) { + cmd_args->brick_port = (int)ntohs( + ((struct sockaddr_in *)&this->myinfo.sockaddr)->sin_port); + gf_log(this->name, GF_LOG_INFO, + "process started listening on port (%d)", + cmd_args->brick_port); } + } out: - return ret; + return ret; } - -int -__socket_nonblock (int fd) +static int +__socket_nonblock(int fd) { - int flags = 0; - int ret = -1; + int flags = 0; + int ret = -1; - flags = fcntl (fd, F_GETFL); + flags = fcntl(fd, F_GETFL); - if (flags != -1) - ret = fcntl (fd, F_SETFL, flags | O_NONBLOCK); + if (flags >= 0) + ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK); - return ret; + return ret; } - -int -__socket_nodelay (int fd) +static int +__socket_nodelay(int fd) { - int on = 1; - int ret = -1; + int on = 1; + int ret = -1; - ret = setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, - &on, sizeof (on)); - if (!ret) - gf_log (THIS->name, GF_LOG_TRACE, - "NODELAY enabled for socket %d", fd); + ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); + if (!ret) + gf_log(THIS->name, GF_LOG_TRACE, "NODELAY enabled for socket %d", fd); - return ret; + return ret; } - static int -__socket_keepalive (int fd, int keepalive_intvl, int keepalive_idle) +__socket_keepalive(int fd, int family, int keepaliveintvl, int keepaliveidle, + int keepalivecnt, int timeout) { - int on = 1; - int ret = -1; + int on = 1; + int ret = -1; +#if defined(TCP_USER_TIMEOUT) + int timeout_ms = timeout * 1000; +#endif - ret = setsockopt (fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)); - if (ret == -1) { - gf_log ("socket", GF_LOG_WARNING, - "failed to set keep alive option on socket %d", fd); - goto err; - } + ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)); + if (ret != 0) { + gf_log("socket", GF_LOG_WARNING, + "failed to set keep alive option on socket %d", fd); + goto err; + } - if (keepalive_intvl == GF_USE_DEFAULT_KEEPALIVE) - goto done; + if (keepaliveintvl == GF_USE_DEFAULT_KEEPALIVE) + goto done; #if !defined(GF_LINUX_HOST_OS) && !defined(__NetBSD__) -#ifdef GF_SOLARIS_HOST_OS - ret = setsockopt (fd, SOL_SOCKET, SO_KEEPALIVE, &keepalive_intvl, - sizeof (keepalive_intvl)); +#if defined(GF_SOLARIS_HOST_OS) || defined(__FreeBSD__) + ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keepaliveintvl, + sizeof(keepaliveintvl)); #else - ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPALIVE, &keepalive_intvl, - sizeof (keepalive_intvl)); + ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &keepaliveintvl, + sizeof(keepaliveintvl)); #endif - if (ret == -1) { - gf_log ("socket", GF_LOG_WARNING, - "failed to set keep alive interval on socket %d", fd); - goto err; - } + if (ret != 0) { + gf_log("socket", GF_LOG_WARNING, + "failed to set keep alive interval on socket %d", fd); + goto err; + } #else - ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepalive_idle, - sizeof (keepalive_intvl)); - if (ret == -1) { - gf_log ("socket", GF_LOG_WARNING, - "failed to set keep idle on socket %d", fd); - goto err; - } - ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPINTVL, &keepalive_intvl, - sizeof (keepalive_intvl)); - if (ret == -1) { - gf_log ("socket", GF_LOG_WARNING, - "failed to set keep alive interval on socket %d", fd); - goto err; - } + if (family != AF_INET && family != AF_INET6) + goto done; + + ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepaliveidle, + sizeof(keepaliveidle)); + if (ret != 0) { + gf_log("socket", GF_LOG_WARNING, + "failed to set keep idle %d on socket %d, %s", keepaliveidle, fd, + strerror(errno)); + goto err; + } + ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &keepaliveintvl, + sizeof(keepaliveintvl)); + if (ret != 0) { + gf_log("socket", GF_LOG_WARNING, + "failed to set keep interval %d on socket %d, %s", + keepaliveintvl, fd, strerror(errno)); + goto err; + } + +#if defined(TCP_USER_TIMEOUT) + if (timeout_ms < 0) + goto done; + ret = setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout_ms, + sizeof(timeout_ms)); + if (ret != 0) { + gf_log("socket", GF_LOG_WARNING, + "failed to set " + "TCP_USER_TIMEOUT %d on socket %d, %s", + timeout_ms, fd, strerror(errno)); + goto err; + } +#endif +#if defined(TCP_KEEPCNT) + ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &keepalivecnt, + sizeof(keepalivecnt)); + if (ret != 0) { + gf_log("socket", GF_LOG_WARNING, + "failed to set " + "TCP_KEEPCNT %d on socket %d, %s", + keepalivecnt, fd, strerror(errno)); + goto err; + } +#endif #endif done: - gf_log (THIS->name, GF_LOG_TRACE, "Keep-alive enabled for socket %d, interval " - "%d, idle: %d", fd, keepalive_intvl, keepalive_idle); + gf_log(THIS->name, GF_LOG_TRACE, + "Keep-alive enabled for socket: %d, " + "(idle: %d, interval: %d, max-probes: %d, timeout: %d)", + fd, keepaliveidle, keepaliveintvl, keepalivecnt, timeout); err: - return ret; + return ret; } - -int -__socket_connect_finish (int fd) +static int +__socket_connect_finish(int fd) { - int ret = -1; - int optval = 0; - socklen_t optlen = sizeof (int); + int ret = -1; + int optval = 0; + socklen_t optlen = sizeof(int); - ret = getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&optval, &optlen); + ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&optval, &optlen); - if (ret == 0 && optval) { - errno = optval; - ret = -1; - } + if (ret == 0 && optval) { + errno = optval; + ret = -1; + } - return ret; + return ret; } - -void -__socket_reset (rpc_transport_t *this) +static void +__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 */ + socket_private_t *priv = NULL; - if (priv->incoming.iobref) { - iobref_unref (priv->incoming.iobref); - priv->incoming.iobref = NULL; - } - - if (priv->incoming.iobuf) { - iobuf_unref (priv->incoming.iobuf); - } + priv = this->private; - if (priv->incoming.request_info != NULL) { - GF_FREE (priv->incoming.request_info); - } + /* TODO: use mem-pool on incoming data */ - memset (&priv->incoming, 0, sizeof (priv->incoming)); + if (priv->incoming.iobref) { + iobref_unref(priv->incoming.iobref); + priv->incoming.iobref = NULL; + } - event_unregister (this->ctx->event_pool, priv->sock, priv->idx); - - close (priv->sock); - priv->sock = -1; - priv->idx = -1; - priv->connected = -1; - -out: - return; + if (priv->incoming.iobuf) { + iobuf_unref(priv->incoming.iobuf); + priv->incoming.iobuf = NULL; + } + + GF_FREE(priv->incoming.request_info); + + memset(&priv->incoming, 0, sizeof(priv->incoming)); + + 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; + priv->ssl_connected = _gf_false; + priv->ssl_accepted = _gf_false; + priv->ssl_context_created = _gf_false; + + if (priv->ssl_private_key) { + GF_FREE(priv->ssl_private_key); + priv->ssl_private_key = NULL; + } + if (priv->ssl_own_cert) { + GF_FREE(priv->ssl_own_cert); + priv->ssl_own_cert = NULL; + } + if (priv->ssl_ca_list) { + GF_FREE(priv->ssl_ca_list); + priv->ssl_ca_list = NULL; + } } - -void -socket_set_lastfrag (uint32_t *fragsize) { - (*fragsize) |= 0x80000000U; +static void +socket_set_lastfrag(uint32_t *fragsize) +{ + (*fragsize) |= 0x80000000U; } - -void -socket_set_frag_header_size (uint32_t size, char *haddr) +static void +socket_set_frag_header_size(uint32_t size, char *haddr) { - size = htonl (size); - memcpy (haddr, &size, sizeof (size)); + size = htonl(size); + memcpy(haddr, &size, sizeof(size)); } - -void -socket_set_last_frag_header_size (uint32_t size, char *haddr) +static void +socket_set_last_frag_header_size(uint32_t size, char *haddr) { - socket_set_lastfrag (&size); - socket_set_frag_header_size (size, haddr); + socket_set_lastfrag(&size); + socket_set_frag_header_size(size, haddr); } -struct ioq * -__socket_ioq_new (rpc_transport_t *this, rpc_transport_msg_t *msg) +static struct ioq * +__socket_ioq_new(rpc_transport_t *this, rpc_transport_msg_t *msg) { - struct ioq *entry = NULL; - int count = 0; - uint32_t size = 0; + struct ioq *entry = NULL; + 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) + return NULL; - /* TODO: use mem-pool */ - entry = GF_CALLOC (1, sizeof (*entry), gf_common_mt_ioq); - if (!entry) - return NULL; + count = msg->rpchdrcount + msg->proghdrcount + msg->progpayloadcount; - count = msg->rpchdrcount + msg->proghdrcount + msg->progpayloadcount; + GF_ASSERT(count <= (MAX_IOVEC - 1)); - GF_ASSERT (count <= (MAX_IOVEC - 1)); + size = iov_length(msg->rpchdr, msg->rpchdrcount) + + iov_length(msg->proghdr, msg->proghdrcount) + + iov_length(msg->progpayload, msg->progpayloadcount); - size = iov_length (msg->rpchdr, msg->rpchdrcount) - + iov_length (msg->proghdr, msg->proghdrcount) - + iov_length (msg->progpayload, msg->progpayloadcount); + if (size > RPC_MAX_FRAGMENT_SIZE) { + gf_log(this->name, GF_LOG_ERROR, + "msg size (%u) bigger than the maximum allowed size on " + "sockets (%u)", + size, RPC_MAX_FRAGMENT_SIZE); + GF_FREE(entry); + return NULL; + } - if (size > RPC_MAX_FRAGMENT_SIZE) { - gf_log (this->name, GF_LOG_ERROR, - "msg size (%u) bigger than the maximum allowed size on " - "sockets (%u)", size, RPC_MAX_FRAGMENT_SIZE); - GF_FREE (entry); - return NULL; - } + socket_set_last_frag_header_size(size, (char *)&entry->fraghdr); - socket_set_last_frag_header_size (size, (char *)&entry->fraghdr); + entry->vector[0].iov_base = (char *)&entry->fraghdr; + entry->vector[0].iov_len = sizeof(entry->fraghdr); + entry->count = 1; - entry->vector[0].iov_base = (char *)&entry->fraghdr; - entry->vector[0].iov_len = sizeof (entry->fraghdr); - entry->count = 1; + if (msg->rpchdr != NULL) { + memcpy(&entry->vector[1], msg->rpchdr, + sizeof(struct iovec) * msg->rpchdrcount); + entry->count += msg->rpchdrcount; + } - if (msg->rpchdr != NULL) { - memcpy (&entry->vector[1], msg->rpchdr, - sizeof (struct iovec) * msg->rpchdrcount); - entry->count += msg->rpchdrcount; - } - - if (msg->proghdr != NULL) { - memcpy (&entry->vector[entry->count], msg->proghdr, - sizeof (struct iovec) * msg->proghdrcount); - entry->count += msg->proghdrcount; - } + if (msg->proghdr != NULL) { + memcpy(&entry->vector[entry->count], msg->proghdr, + sizeof(struct iovec) * msg->proghdrcount); + entry->count += msg->proghdrcount; + } - if (msg->progpayload != NULL) { - memcpy (&entry->vector[entry->count], msg->progpayload, - sizeof (struct iovec) * msg->progpayloadcount); - entry->count += msg->progpayloadcount; - } + if (msg->progpayload != NULL) { + memcpy(&entry->vector[entry->count], msg->progpayload, + sizeof(struct iovec) * msg->progpayloadcount); + entry->count += msg->progpayloadcount; + } - entry->pending_vector = entry->vector; - entry->pending_count = entry->count; + entry->pending_vector = entry->vector; + entry->pending_count = entry->count; - if (msg->iobref != NULL) - entry->iobref = iobref_ref (msg->iobref); + if (msg->iobref != NULL) + entry->iobref = iobref_ref(msg->iobref); - INIT_LIST_HEAD (&entry->list); + INIT_LIST_HEAD(&entry->list); -out: - return entry; + return entry; } - -void -__socket_ioq_entry_free (struct ioq *entry) +static void +__socket_ioq_entry_free(struct ioq *entry) { - GF_VALIDATE_OR_GOTO ("socket", entry, out); + GF_VALIDATE_OR_GOTO("socket", entry, out); - list_del_init (&entry->list); - if (entry->iobref) - iobref_unref (entry->iobref); + list_del_init(&entry->list); + if (entry->iobref) + iobref_unref(entry->iobref); - /* TODO: use mem-pool */ - GF_FREE (entry); + /* TODO: use mem-pool */ + GF_FREE(entry); out: - return; + return; } - -void -__socket_ioq_flush (rpc_transport_t *this) +static void +__socket_ioq_flush(socket_private_t *priv) { - socket_private_t *priv = NULL; - struct ioq *entry = 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; + while (!list_empty(&priv->ioq)) { + entry = priv->ioq_next; + __socket_ioq_entry_free(entry); + } } - -int -__socket_ioq_churn_entry (rpc_transport_t *this, struct ioq *entry) +static int +__socket_ioq_churn_entry(rpc_transport_t *this, struct ioq *entry) { - int ret = -1; + int ret = -1; - ret = __socket_writev (this, entry->pending_vector, - entry->pending_count, - &entry->pending_vector, - &entry->pending_count); + ret = __socket_writev(this, entry->pending_vector, entry->pending_count, + &entry->pending_vector, &entry->pending_count); - if (ret == 0) { - /* current entry was completely written */ - GF_ASSERT (entry->pending_count == 0); - __socket_ioq_entry_free (entry); - } + if (ret == 0) { + /* current entry was completely written */ + GF_ASSERT(entry->pending_count == 0); + __socket_ioq_entry_free(entry); + } - return ret; + return ret; } - -int -__socket_ioq_churn (rpc_transport_t *this) +static int +__socket_ioq_churn(rpc_transport_t *this) { - socket_private_t *priv = NULL; - int ret = 0; - struct ioq *entry = NULL; + socket_private_t *priv = NULL; + 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; - priv = this->private; + while (!list_empty(&priv->ioq)) { + /* pick next entry */ + entry = priv->ioq_next; - while (!list_empty (&priv->ioq)) { - /* pick next entry */ - entry = priv->ioq_next; + ret = __socket_ioq_churn_entry(this, entry); - ret = __socket_ioq_churn_entry (this, entry); + if (ret != 0) + break; + } - if (ret != 0) - break; - } + if (list_empty(&priv->ioq)) { + /* all pending writes done, not interested in POLLOUT */ + priv->idx = gf_event_select_on(this->ctx->event_pool, priv->sock, + priv->idx, -1, 0); + } - 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); - } - -out: - return ret; + return ret; } - -int -socket_event_poll_err (rpc_transport_t *this) +static gf_boolean_t +socket_event_poll_err(rpc_transport_t *this, int gen, int idx) { - socket_private_t *priv = NULL; - int ret = -1; + 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; - priv = this->private; + pthread_mutex_lock(&priv->out_lock); + { + 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_lock (&priv->lock); + if (socket_closed) { + pthread_mutex_lock(&priv->notify.lock); { - __socket_ioq_flush (this); - __socket_reset (this); + while (priv->notify.in_progress) + pthread_cond_wait(&priv->notify.cond, &priv->notify.lock); } - pthread_mutex_unlock (&priv->lock); + pthread_mutex_unlock(&priv->notify.lock); - rpc_transport_notify (this, RPC_TRANSPORT_DISCONNECT, this); + rpc_transport_notify(this, RPC_TRANSPORT_DISCONNECT, this); + } -out: - return ret; + return socket_closed; } - -int -socket_event_poll_out (rpc_transport_t *this) +static int +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->lock); - { - if (priv->connected == 1) { - ret = __socket_ioq_churn (this); - - if (ret == -1) { - __socket_disconnect (this); - } - } + socket_private_t *priv = NULL; + int ret = -1; + + priv = this->private; + + pthread_mutex_lock(&priv->out_lock); + { + if (priv->connected == 1) { + ret = __socket_ioq_churn(this); + + if (ret < 0) { + gf_log(this->name, GF_LOG_TRACE, + "__socket_ioq_churn returned -1; " + "disconnecting socket"); + __socket_disconnect(this); + } } - pthread_mutex_unlock (&priv->lock); + } + pthread_mutex_unlock(&priv->out_lock); - ret = rpc_transport_notify (this, RPC_TRANSPORT_MSG_SENT, NULL); + if (ret == 0) + rpc_transport_notify(this, RPC_TRANSPORT_MSG_SENT, NULL); -out: - return ret; -} + if (ret > 0) + ret = 0; + return ret; +} -inline int -__socket_read_simple_msg (rpc_transport_t *this) +static int +__socket_read_simple_msg(rpc_transport_t *this) { - socket_private_t *priv = NULL; - int ret = 0; - uint32_t remaining_size = 0; - size_t bytes_read = 0; + int ret = 0; + uint32_t remaining_size = 0; + size_t bytes_read = 0; + socket_private_t *priv = NULL; + 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); + GF_VALIDATE_OR_GOTO("socket", this, out); + GF_VALIDATE_OR_GOTO("socket", this->private, out); - priv = this->private; + priv = this->private; - switch (priv->incoming.frag.simple_state) { + in = &priv->incoming; + frag = &in->frag; + switch (frag->simple_state) { case SP_STATE_SIMPLE_MSG_INIT: - remaining_size = RPC_FRAGSIZE (priv->incoming.fraghdr) - - priv->incoming.frag.bytes_read; + remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; - __socket_proto_init_pending (priv, remaining_size); + __socket_proto_init_pending(priv, remaining_size); - priv->incoming.frag.simple_state = - SP_STATE_READING_SIMPLE_MSG; + frag->simple_state = SP_STATE_READING_SIMPLE_MSG; - /* fall through */ + /* fall through */ case SP_STATE_READING_SIMPLE_MSG: - ret = 0; + ret = 0; - remaining_size = RPC_FRAGSIZE (priv->incoming.fraghdr) - - priv->incoming.frag.bytes_read; + remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; - if (remaining_size > 0) { - ret = __socket_readv (this, - priv->incoming.pending_vector, 1, - &priv->incoming.pending_vector, - &priv->incoming.pending_count, - &bytes_read); - } + if (remaining_size > 0) { + ret = __socket_readv(this, in->pending_vector, 1, + &in->pending_vector, &in->pending_count, + &bytes_read); + } - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "reading from socket failed. Error (%s), " - "peer (%s)", strerror (errno), - this->peerinfo.identifier); - break; - } + if (ret < 0) { + gf_log(this->name, GF_LOG_WARNING, + "reading from socket failed. Error (%s), " + "peer (%s)", + strerror(errno), this->peerinfo.identifier); + break; + } - priv->incoming.frag.bytes_read += bytes_read; - priv->incoming.frag.fragcurrent += bytes_read; + frag->bytes_read += bytes_read; + frag->fragcurrent += bytes_read; - if (ret > 0) { - gf_log (this->name, GF_LOG_TRACE, - "partial read on non-blocking socket."); - break; - } + if (ret > 0) { + gf_log(this->name, GF_LOG_TRACE, + "partial read on non-blocking socket."); + ret = 0; + break; + } - if (ret == 0) { - priv->incoming.frag.simple_state - = SP_STATE_SIMPLE_MSG_INIT; - } - } + if (ret == 0) { + frag->simple_state = SP_STATE_SIMPLE_MSG_INIT; + } + } out: - return ret; + return ret; } - -inline 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) @@ -813,1973 +1475,3327 @@ __socket_read_simple_request (rpc_transport_t *this) #define rpc_progver_addr(buf) (buf + RPC_MSGTYPE_SIZE + 8) #define rpc_procnum_addr(buf) (buf + RPC_MSGTYPE_SIZE + 12) -inline int -__socket_read_vectored_request (rpc_transport_t *this, rpcsvc_vector_sizer vector_sizer) +static int +__socket_read_vectored_request(rpc_transport_t *this, + rpcsvc_vector_sizer vector_sizer) { - socket_private_t *priv = NULL; - int ret = 0; - uint32_t credlen = 0, verflen = 0; - char *addr = NULL; - struct iobuf *iobuf = NULL; - uint32_t remaining_size = 0; - ssize_t readsize = 0; - - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); - - priv = this->private; - - switch (priv->incoming.frag.call_body.request.vector_state) { + socket_private_t *priv = NULL; + int ret = 0; + uint32_t credlen = 0, verflen = 0; + char *addr = NULL; + struct iobuf *iobuf = NULL; + uint32_t remaining_size = 0; + ssize_t readsize = 0; + size_t size = 0; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; + sp_rpcfrag_request_state_t *request = NULL; + + priv = this->private; + + /* used to reduce the indirection */ + in = &priv->incoming; + frag = &in->frag; + request = &frag->call_body.request; + + switch (request->vector_state) { case SP_STATE_VECTORED_REQUEST_INIT: - priv->incoming.frag.call_body.request.vector_sizer_state = 0; - addr = rpc_cred_addr (iobuf_ptr (priv->incoming.iobuf)); + request->vector_sizer_state = 0; - /* also read verf flavour and verflen */ - credlen = ntoh32 (*((uint32_t *)addr)) - + RPC_AUTH_FLAVOUR_N_LENGTH_SIZE; + addr = rpc_cred_addr(iobuf_ptr(in->iobuf)); - __socket_proto_init_pending (priv, credlen); + /* also read verf flavour and verflen */ + credlen = ntoh32(*((uint32_t *)addr)) + + RPC_AUTH_FLAVOUR_N_LENGTH_SIZE; - priv->incoming.frag.call_body.request.vector_state = - SP_STATE_READING_CREDBYTES; + __socket_proto_init_pending(priv, credlen); - /* fall through */ + request->vector_state = SP_STATE_READING_CREDBYTES; + + /* fall through */ case SP_STATE_READING_CREDBYTES: - __socket_proto_read (priv, ret); + __socket_proto_read(priv, ret); - priv->incoming.frag.call_body.request.vector_state = - SP_STATE_READ_CREDBYTES; + request->vector_state = SP_STATE_READ_CREDBYTES; - /* fall through */ + /* fall through */ case SP_STATE_READ_CREDBYTES: - addr = rpc_verf_addr (priv->incoming.frag.fragcurrent); - verflen = ntoh32 (*((uint32_t *)addr)); + addr = rpc_verf_addr(frag->fragcurrent); + verflen = ntoh32(*((uint32_t *)addr)); - if (verflen == 0) { - priv->incoming.frag.call_body.request.vector_state - = SP_STATE_READ_VERFBYTES; - goto sp_state_read_verfbytes; - } - __socket_proto_init_pending (priv, verflen); + if (verflen == 0) { + request->vector_state = SP_STATE_READ_VERFBYTES; + goto sp_state_read_verfbytes; + } + __socket_proto_init_pending(priv, verflen); - priv->incoming.frag.call_body.request.vector_state - = SP_STATE_READING_VERFBYTES; + request->vector_state = SP_STATE_READING_VERFBYTES; - /* fall through */ + /* fall through */ case SP_STATE_READING_VERFBYTES: - __socket_proto_read (priv, ret); + __socket_proto_read(priv, ret); - priv->incoming.frag.call_body.request.vector_state = - SP_STATE_READ_VERFBYTES; + request->vector_state = SP_STATE_READ_VERFBYTES; - /* fall through */ + /* fall through */ case SP_STATE_READ_VERFBYTES: -sp_state_read_verfbytes: - priv->incoming.frag.call_body.request.vector_sizer_state = - vector_sizer (priv->incoming.frag.call_body.request.vector_sizer_state, - &readsize, - priv->incoming.frag.fragcurrent); - __socket_proto_init_pending (priv, readsize); - priv->incoming.frag.call_body.request.vector_state - = SP_STATE_READING_PROGHDR; + sp_state_read_verfbytes: + /* set the base_addr 'persistently' across multiple calls + into the state machine */ + in->proghdr_base_addr = frag->fragcurrent; - /* fall through */ + request->vector_sizer_state = vector_sizer( + request->vector_sizer_state, &readsize, in->proghdr_base_addr, + frag->fragcurrent); + __socket_proto_init_pending(priv, readsize); - case SP_STATE_READING_PROGHDR: - __socket_proto_read (priv, ret); -sp_state_reading_proghdr: - priv->incoming.frag.call_body.request.vector_sizer_state = - vector_sizer (priv->incoming.frag.call_body.request.vector_sizer_state, - &readsize, - priv->incoming.frag.fragcurrent); - if (readsize == 0) { - priv->incoming.frag.call_body.request.vector_state = - SP_STATE_READ_PROGHDR; - } else { - __socket_proto_init_pending (priv, readsize); - __socket_proto_read (priv, ret); - goto sp_state_reading_proghdr; - } + request->vector_state = SP_STATE_READING_PROGHDR; - case SP_STATE_READ_PROGHDR: - if (priv->incoming.payload_vector.iov_base == NULL) { - iobuf = iobuf_get (this->ctx->iobuf_pool); - if (!iobuf) { - ret = -1; - break; - } + /* fall through */ - if (priv->incoming.iobref == NULL) { - priv->incoming.iobref = iobref_new (); - if (priv->incoming.iobref == NULL) { - ret = -1; - iobuf_unref (iobuf); - break; - } - } + case SP_STATE_READING_PROGHDR: + __socket_proto_read(priv, ret); - iobref_add (priv->incoming.iobref, iobuf); - iobuf_unref (iobuf); + request->vector_state = SP_STATE_READ_PROGHDR; - priv->incoming.payload_vector.iov_base - = iobuf_ptr (iobuf); + /* fall through */ - priv->incoming.frag.fragcurrent = iobuf_ptr (iobuf); + case SP_STATE_READ_PROGHDR: + sp_state_read_proghdr: + request->vector_sizer_state = vector_sizer( + request->vector_sizer_state, &readsize, in->proghdr_base_addr, + frag->fragcurrent); + if (readsize == 0) { + request->vector_state = SP_STATE_READ_PROGHDR_XDATA; + goto sp_state_read_proghdr_xdata; + } + + __socket_proto_init_pending(priv, readsize); + + request->vector_state = SP_STATE_READING_PROGHDR_XDATA; + + /* fall through */ + + case SP_STATE_READING_PROGHDR_XDATA: + __socket_proto_read(priv, ret); + + request->vector_state = SP_STATE_READ_PROGHDR; + /* check if the vector_sizer() has more to say */ + goto sp_state_read_proghdr; + + case SP_STATE_READ_PROGHDR_XDATA: + sp_state_read_proghdr_xdata: + if (in->payload_vector.iov_base == NULL) { + size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; + iobuf = iobuf_get2(this->ctx->iobuf_pool, size); + if (!iobuf) { + ret = -1; + break; } - priv->incoming.frag.call_body.request.vector_state = - SP_STATE_READING_PROG; + if (in->iobref == NULL) { + in->iobref = iobref_new(); + if (in->iobref == NULL) { + ret = -1; + iobuf_unref(iobuf); + break; + } + } - /* fall through */ + iobref_add(in->iobref, iobuf); - case SP_STATE_READING_PROG: - /* now read the remaining rpc msg into buffer pointed by - * fragcurrent - */ + in->payload_vector.iov_base = iobuf_ptr(iobuf); + frag->fragcurrent = iobuf_ptr(iobuf); - ret = __socket_read_simple_msg (this); - - remaining_size = RPC_FRAGSIZE (priv->incoming.fraghdr) - - priv->incoming.frag.bytes_read; - - if ((ret == -1) - || ((ret == 0) - && (remaining_size == 0) - && RPC_LASTFRAG (priv->incoming.fraghdr))) { - priv->incoming.frag.call_body.request.vector_state - = SP_STATE_VECTORED_REQUEST_INIT; - priv->incoming.payload_vector.iov_len - = (unsigned long)priv->incoming.frag.fragcurrent - - (unsigned long) - priv->incoming.payload_vector.iov_base; - } - break; - } + iobuf_unref(iobuf); + } -out: - return ret; -} + request->vector_state = SP_STATE_READING_PROG; -inline int -__socket_read_request (rpc_transport_t *this) -{ - socket_private_t *priv = NULL; - uint32_t prognum = 0, procnum = 0, progver = 0; - uint32_t remaining_size = 0; - int ret = -1; - char *buf = NULL; - rpcsvc_vector_sizer vector_sizer = NULL; + /* fall through */ + + case SP_STATE_READING_PROG: + /* now read the remaining rpc msg into buffer pointed by + * fragcurrent + */ - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); + ret = __socket_read_simple_msg(this); - priv = this->private; + remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; - switch (priv->incoming.frag.call_body.request.header_state) { + 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) + in->payload_vector.iov_base); + } + break; + } + return ret; +} + +static int +__socket_read_request(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + uint32_t prognum = 0, procnum = 0, progver = 0; + uint32_t remaining_size = 0; + int ret = -1; + char *buf = NULL; + rpcsvc_vector_sizer vector_sizer = NULL; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; + sp_rpcfrag_request_state_t *request = NULL; + + priv = this->private; + + /* used to reduce the indirection */ + in = &priv->incoming; + frag = &in->frag; + request = &frag->call_body.request; + + switch (request->header_state) { case SP_STATE_REQUEST_HEADER_INIT: - __socket_proto_init_pending (priv, RPC_CALL_BODY_SIZE); + __socket_proto_init_pending(priv, RPC_CALL_BODY_SIZE); - priv->incoming.frag.call_body.request.header_state - = SP_STATE_READING_RPCHDR1; + request->header_state = SP_STATE_READING_RPCHDR1; - /* fall through */ + /* fall through */ case SP_STATE_READING_RPCHDR1: - __socket_proto_read (priv, ret); + __socket_proto_read(priv, ret); - priv->incoming.frag.call_body.request.header_state = - SP_STATE_READ_RPCHDR1; + request->header_state = SP_STATE_READ_RPCHDR1; - /* fall through */ + /* fall through */ case SP_STATE_READ_RPCHDR1: - buf = rpc_prognum_addr (iobuf_ptr (priv->incoming.iobuf)); - prognum = ntoh32 (*((uint32_t *)buf)); + buf = rpc_prognum_addr(iobuf_ptr(in->iobuf)); + prognum = ntoh32(*((uint32_t *)buf)); - buf = rpc_progver_addr (iobuf_ptr (priv->incoming.iobuf)); - progver = ntoh32 (*((uint32_t *)buf)); + buf = rpc_progver_addr(iobuf_ptr(in->iobuf)); + progver = ntoh32(*((uint32_t *)buf)); - buf = rpc_procnum_addr (iobuf_ptr (priv->incoming.iobuf)); - procnum = ntoh32 (*((uint32_t *)buf)); + buf = rpc_procnum_addr(iobuf_ptr(in->iobuf)); + procnum = ntoh32(*((uint32_t *)buf)); - if (this->listener) { - /* this check is needed as rpcsvc and rpc-clnt actor structures are - * not same */ - vector_sizer = rpcsvc_get_program_vector_sizer ((rpcsvc_t *)this->mydata, - prognum, progver, procnum); - } + if (priv->is_server) { + /* this check is needed as rpcsvc and rpc-clnt + * actor structures are not same */ + vector_sizer = rpcsvc_get_program_vector_sizer( + (rpcsvc_t *)this->mydata, prognum, progver, procnum); + } - if (vector_sizer) { - ret = __socket_read_vectored_request (this, vector_sizer); - } else { - ret = __socket_read_simple_request (this); - } + if (vector_sizer) { + ret = __socket_read_vectored_request(this, vector_sizer); + } else { + ret = __socket_read_simple_msg(this); + } - remaining_size = RPC_FRAGSIZE (priv->incoming.fraghdr) - - priv->incoming.frag.bytes_read; + remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; - if ((ret == -1) - || ((ret == 0) - && (remaining_size == 0) - && (RPC_LASTFRAG (priv->incoming.fraghdr)))) { - priv->incoming.frag.call_body.request.header_state = - SP_STATE_REQUEST_HEADER_INIT; - } + if ((ret < 0) || ((ret == 0) && (remaining_size == 0) && + (RPC_LASTFRAG(in->fraghdr)))) { + request->header_state = SP_STATE_REQUEST_HEADER_INIT; + } - break; - } + break; + } -out: - return ret; + return ret; } - -inline int -__socket_read_accepted_successful_reply (rpc_transport_t *this) +static int +__socket_read_accepted_successful_reply(rpc_transport_t *this) { - socket_private_t *priv = NULL; - int ret = 0; - struct iobuf *iobuf = NULL; - uint32_t gluster_read_rsp_hdr_len = 0; - gfs3_read_rsp read_rsp = {0, }; + socket_private_t *priv = NULL; + int ret = 0; + struct iobuf *iobuf = NULL; + gfs3_read_rsp read_rsp = { + 0, + }; + ssize_t size = 0; + ssize_t default_read_size = 0; + XDR xdr; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; + uint32_t remaining_size = 0; + + priv = this->private; + + /* used to reduce the indirection */ + in = &priv->incoming; + frag = &in->frag; + + switch (frag->call_body.reply.accepted_success_state) { + case SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT: + default_read_size = xdr_sizeof((xdrproc_t)xdr_gfs3_read_rsp, + &read_rsp); - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); + /* We need to store the current base address because we will + * need it after a partial read. */ + in->proghdr_base_addr = frag->fragcurrent; - priv = this->private; + __socket_proto_init_pending(priv, default_read_size); - switch (priv->incoming.frag.call_body.reply.accepted_success_state) { + frag->call_body.reply + .accepted_success_state = SP_STATE_READING_PROC_HEADER; - case SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT: - gluster_read_rsp_hdr_len = xdr_sizeof ((xdrproc_t) xdr_gfs3_read_rsp, - &read_rsp); + /* fall through */ + + case SP_STATE_READING_PROC_HEADER: + __socket_proto_read(priv, ret); + + /* there can be 'xdata' in read response, figure it out */ + default_read_size = frag->fragcurrent - in->proghdr_base_addr; + xdrmem_create(&xdr, in->proghdr_base_addr, default_read_size, + XDR_DECODE); - if (gluster_read_rsp_hdr_len == 0) { - gf_log (this->name, GF_LOG_ERROR, - "xdr_sizeof on gfs3_read_rsp failed"); + /* This will fail if there is xdata sent from server, if not, + well and good, we don't need to worry about */ + xdr_gfs3_read_rsp(&xdr, &read_rsp); + + free(read_rsp.xdata.xdata_val); + + /* need to round off to proper gf_roof (%4), as XDR packing pads + the end of opaque object with '0' */ + size = gf_roof(read_rsp.xdata.xdata_len, 4); + + if (!size) { + frag->call_body.reply + .accepted_success_state = SP_STATE_READ_PROC_OPAQUE; + goto read_proc_opaque; + } + + __socket_proto_init_pending(priv, size); + + frag->call_body.reply + .accepted_success_state = SP_STATE_READING_PROC_OPAQUE; + /* fall through */ + + case SP_STATE_READING_PROC_OPAQUE: + __socket_proto_read(priv, ret); + + frag->call_body.reply + .accepted_success_state = SP_STATE_READ_PROC_OPAQUE; + /* fall through */ + + case SP_STATE_READ_PROC_OPAQUE: + read_proc_opaque: + if (in->payload_vector.iov_base == NULL) { + size = (RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read); + + iobuf = iobuf_get2(this->ctx->iobuf_pool, size); + if (iobuf == NULL) { + ret = -1; + goto out; + } + + if (in->iobref == NULL) { + in->iobref = iobref_new(); + if (in->iobref == NULL) { ret = -1; + iobuf_unref(iobuf); goto out; + } } - __socket_proto_init_pending (priv, gluster_read_rsp_hdr_len); - priv->incoming.frag.call_body.reply.accepted_success_state - = SP_STATE_READING_PROC_HEADER; + ret = iobref_add(in->iobref, iobuf); + iobuf_unref(iobuf); + if (ret < 0) { + goto out; + } - /* fall through */ + in->payload_vector.iov_base = iobuf_ptr(iobuf); + in->payload_vector.iov_len = size; + } + + frag->fragcurrent = in->payload_vector.iov_base; + + frag->call_body.reply + .accepted_success_state = SP_STATE_READ_PROC_HEADER; + + /* fall through */ + + case SP_STATE_READ_PROC_HEADER: + /* now read the entire remaining msg into new iobuf */ + ret = __socket_read_simple_msg(this); + 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; + } + + break; + } + +out: + return ret; +} + +static int +__socket_read_accepted_successful_reply_v2(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + int ret = 0; + struct iobuf *iobuf = NULL; + gfx_read_rsp read_rsp = { + 0, + }; + ssize_t size = 0; + ssize_t default_read_size = 0; + XDR xdr; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; + uint32_t remaining_size = 0; + + priv = this->private; + + /* used to reduce the indirection */ + in = &priv->incoming; + frag = &in->frag; + + switch (frag->call_body.reply.accepted_success_state) { + case SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT: + default_read_size = xdr_sizeof((xdrproc_t)xdr_gfx_read_rsp, + &read_rsp); + + /* We need to store the current base address because we will + * need it after a partial read. */ + in->proghdr_base_addr = frag->fragcurrent; + + __socket_proto_init_pending(priv, default_read_size); + + frag->call_body.reply + .accepted_success_state = SP_STATE_READING_PROC_HEADER; + + /* fall through */ case SP_STATE_READING_PROC_HEADER: - __socket_proto_read (priv, ret); + __socket_proto_read(priv, ret); - priv->incoming.frag.call_body.reply.accepted_success_state - = SP_STATE_READ_PROC_HEADER; + /* there can be 'xdata' in read response, figure it out */ + default_read_size = frag->fragcurrent - in->proghdr_base_addr; - if (priv->incoming.payload_vector.iov_base == NULL) { - iobuf = iobuf_get (this->ctx->iobuf_pool); - if (iobuf == NULL) { - ret = -1; - goto out; - } + xdrmem_create(&xdr, in->proghdr_base_addr, default_read_size, + XDR_DECODE); - if (priv->incoming.iobref == NULL) { - priv->incoming.iobref = iobref_new (); - if (priv->incoming.iobref == NULL) { - ret = -1; - iobuf_unref (iobuf); - goto out; - } - } + /* This will fail if there is xdata sent from server, if not, + well and good, we don't need to worry about */ + xdr_gfx_read_rsp(&xdr, &read_rsp); - iobref_add (priv->incoming.iobref, iobuf); - iobuf_unref (iobuf); + free(read_rsp.xdata.pairs.pairs_val); - priv->incoming.payload_vector.iov_base - = iobuf_ptr (iobuf); - } + /* need to round off to proper gf_roof (%4), as XDR packing pads + the end of opaque object with '0' */ + size = gf_roof(read_rsp.xdata.xdr_size, 4); - priv->incoming.frag.fragcurrent - = priv->incoming.payload_vector.iov_base; + if (!size) { + frag->call_body.reply + .accepted_success_state = SP_STATE_READ_PROC_OPAQUE; + goto read_proc_opaque; + } - /* fall through */ + __socket_proto_init_pending(priv, size); - 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 (priv->incoming.fraghdr))) { - priv->incoming.frag.call_body.reply.accepted_success_state - = SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT; + frag->call_body.reply + .accepted_success_state = SP_STATE_READING_PROC_OPAQUE; + /* fall through */ + + case SP_STATE_READING_PROC_OPAQUE: + __socket_proto_read(priv, ret); + + frag->call_body.reply + .accepted_success_state = SP_STATE_READ_PROC_OPAQUE; + /* fall through */ + + case SP_STATE_READ_PROC_OPAQUE: + read_proc_opaque: + if (in->payload_vector.iov_base == NULL) { + size = (RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read); + + iobuf = iobuf_get2(this->ctx->iobuf_pool, size); + if (iobuf == NULL) { + ret = -1; + goto out; } - break; - } + if (in->iobref == NULL) { + in->iobref = iobref_new(); + if (in->iobref == NULL) { + ret = -1; + iobuf_unref(iobuf); + goto out; + } + } + + ret = iobref_add(in->iobref, iobuf); + iobuf_unref(iobuf); + if (ret < 0) { + goto out; + } + + in->payload_vector.iov_base = iobuf_ptr(iobuf); + in->payload_vector.iov_len = size; + } + + frag->fragcurrent = in->payload_vector.iov_base; + + frag->call_body.reply + .accepted_success_state = SP_STATE_READ_PROC_HEADER; + + /* fall through */ + + case SP_STATE_READ_PROC_HEADER: + /* now read the entire remaining msg into new iobuf */ + ret = __socket_read_simple_msg(this); + 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; + } + + break; + } out: - return ret; + return ret; } #define rpc_reply_verflen_addr(fragcurrent) ((char *)fragcurrent - 4) #define rpc_reply_accept_status_addr(fragcurrent) ((char *)fragcurrent - 4) -inline int -__socket_read_accepted_reply (rpc_transport_t *this) +static int +__socket_read_accepted_reply(rpc_transport_t *this) { - socket_private_t *priv = NULL; - int ret = -1; - char *buf = NULL; - uint32_t verflen = 0, len = 0; - uint32_t remaining_size = 0; - - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); - - priv = this->private; - - switch (priv->incoming.frag.call_body.reply.accepted_state) { - + socket_private_t *priv = NULL; + int ret = -1; + char *buf = NULL; + uint32_t verflen = 0, len = 0; + uint32_t remaining_size = 0; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; + + priv = this->private; + /* used to reduce the indirection */ + in = &priv->incoming; + frag = &in->frag; + + switch (frag->call_body.reply.accepted_state) { case SP_STATE_ACCEPTED_REPLY_INIT: - __socket_proto_init_pending (priv, - RPC_AUTH_FLAVOUR_N_LENGTH_SIZE); + __socket_proto_init_pending(priv, RPC_AUTH_FLAVOUR_N_LENGTH_SIZE); - priv->incoming.frag.call_body.reply.accepted_state - = SP_STATE_READING_REPLY_VERFLEN; + frag->call_body.reply + .accepted_state = SP_STATE_READING_REPLY_VERFLEN; - /* fall through */ + /* fall through */ case SP_STATE_READING_REPLY_VERFLEN: - __socket_proto_read (priv, ret); + __socket_proto_read(priv, ret); - priv->incoming.frag.call_body.reply.accepted_state - = SP_STATE_READ_REPLY_VERFLEN; + frag->call_body.reply.accepted_state = SP_STATE_READ_REPLY_VERFLEN; - /* fall through */ + /* fall through */ case SP_STATE_READ_REPLY_VERFLEN: - buf = rpc_reply_verflen_addr (priv->incoming.frag.fragcurrent); + buf = rpc_reply_verflen_addr(frag->fragcurrent); - verflen = ntoh32 (*((uint32_t *) buf)); + verflen = ntoh32(*((uint32_t *)buf)); - /* also read accept status along with verf data */ - len = verflen + RPC_ACCEPT_STATUS_LEN; + /* also read accept status along with verf data */ + len = verflen + RPC_ACCEPT_STATUS_LEN; - __socket_proto_init_pending (priv, len); + __socket_proto_init_pending(priv, len); - priv->incoming.frag.call_body.reply.accepted_state - = SP_STATE_READING_REPLY_VERFBYTES; + frag->call_body.reply + .accepted_state = SP_STATE_READING_REPLY_VERFBYTES; - /* fall through */ + /* fall through */ case SP_STATE_READING_REPLY_VERFBYTES: - __socket_proto_read (priv, ret); + __socket_proto_read(priv, ret); - priv->incoming.frag.call_body.reply.accepted_state - = SP_STATE_READ_REPLY_VERFBYTES; + frag->call_body.reply + .accepted_state = SP_STATE_READ_REPLY_VERFBYTES; - buf = rpc_reply_accept_status_addr (priv->incoming.frag.fragcurrent); + buf = rpc_reply_accept_status_addr(frag->fragcurrent); - priv->incoming.frag.call_body.reply.accept_status - = ntoh32 (*(uint32_t *) buf); + frag->call_body.reply.accept_status = ntoh32(*(uint32_t *)buf); - /* fall through */ + /* fall through */ case SP_STATE_READ_REPLY_VERFBYTES: - if (priv->incoming.frag.call_body.reply.accept_status - == SUCCESS) { - ret = __socket_read_accepted_successful_reply (this); + if (frag->call_body.reply.accept_status == SUCCESS) { + /* Need two different methods here for different protocols + Mainly because the exact XDR is used to calculate the + size of response */ + if ((in->request_info->procnum == GFS3_OP_READ) && + (in->request_info->prognum == GLUSTER_FOP_PROGRAM) && + (in->request_info->progver == GLUSTER_FOP_VERSION_v2)) { + ret = __socket_read_accepted_successful_reply_v2(this); } else { - /* read entire remaining msg into buffer pointed to by - * fragcurrent - */ - ret = __socket_read_simple_msg (this); + ret = __socket_read_accepted_successful_reply(this); } + } else { + /* read entire remaining msg into buffer pointed to by + * fragcurrent + */ + ret = __socket_read_simple_msg(this); + } - remaining_size = RPC_FRAGSIZE (priv->incoming.fraghdr) - - priv->incoming.frag.bytes_read; + remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; - if ((ret == -1) - || ((ret == 0) - && (remaining_size == 0) - && (RPC_LASTFRAG (priv->incoming.fraghdr)))) { - priv->incoming.frag.call_body.reply.accepted_state - = SP_STATE_ACCEPTED_REPLY_INIT; - } + if ((ret < 0) || ((ret == 0) && (remaining_size == 0) && + (RPC_LASTFRAG(in->fraghdr)))) { + frag->call_body.reply + .accepted_state = SP_STATE_ACCEPTED_REPLY_INIT; + } - break; - } + break; + } -out: - return ret; + return ret; } - -inline int -__socket_read_denied_reply (rpc_transport_t *this) +static int +__socket_read_denied_reply(rpc_transport_t *this) { - return __socket_read_simple_msg (this); + return __socket_read_simple_msg(this); } - #define rpc_reply_status_addr(fragcurrent) ((char *)fragcurrent - 4) - -inline int -__socket_read_vectored_reply (rpc_transport_t *this) +static int +__socket_read_vectored_reply(rpc_transport_t *this) { - socket_private_t *priv = NULL; - int ret = 0; - char *buf = NULL; - uint32_t remaining_size = 0; - - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); - - priv = this->private; - - switch (priv->incoming.frag.call_body.reply.status_state) { - + socket_private_t *priv = NULL; + int ret = 0; + char *buf = NULL; + uint32_t remaining_size = 0; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; + + priv = this->private; + in = &priv->incoming; + frag = &in->frag; + + switch (frag->call_body.reply.status_state) { case SP_STATE_ACCEPTED_REPLY_INIT: - __socket_proto_init_pending (priv, RPC_REPLY_STATUS_SIZE); + __socket_proto_init_pending(priv, RPC_REPLY_STATUS_SIZE); - priv->incoming.frag.call_body.reply.status_state - = SP_STATE_READING_REPLY_STATUS; + frag->call_body.reply.status_state = SP_STATE_READING_REPLY_STATUS; - /* fall through */ + /* fall through */ case SP_STATE_READING_REPLY_STATUS: - __socket_proto_read (priv, ret); + __socket_proto_read(priv, ret); - buf = rpc_reply_status_addr (priv->incoming.frag.fragcurrent); + buf = rpc_reply_status_addr(frag->fragcurrent); - priv->incoming.frag.call_body.reply.accept_status - = ntoh32 (*((uint32_t *) buf)); + frag->call_body.reply.accept_status = ntoh32(*((uint32_t *)buf)); - priv->incoming.frag.call_body.reply.status_state - = SP_STATE_READ_REPLY_STATUS; + frag->call_body.reply.status_state = SP_STATE_READ_REPLY_STATUS; - /* fall through */ + /* fall through */ case SP_STATE_READ_REPLY_STATUS: - if (priv->incoming.frag.call_body.reply.accept_status - == MSG_ACCEPTED) { - ret = __socket_read_accepted_reply (this); - } else { - ret = __socket_read_denied_reply (this); - } - - remaining_size = RPC_FRAGSIZE (priv->incoming.fraghdr) - - priv->incoming.frag.bytes_read; - - if ((ret == -1) - || ((ret == 0) - && (remaining_size == 0) - && (RPC_LASTFRAG (priv->incoming.fraghdr)))) { - priv->incoming.frag.call_body.reply.status_state - = SP_STATE_ACCEPTED_REPLY_INIT; - priv->incoming.payload_vector.iov_len - = (unsigned long)priv->incoming.frag.fragcurrent - - (unsigned long) - priv->incoming.payload_vector.iov_base; - } - break; - } - -out: - return ret; + if (frag->call_body.reply.accept_status == MSG_ACCEPTED) { + ret = __socket_read_accepted_reply(this); + } else { + ret = __socket_read_denied_reply(this); + } + + 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 + .status_state = SP_STATE_VECTORED_REPLY_STATUS_INIT; + in->payload_vector.iov_len = (unsigned long)frag->fragcurrent - + (unsigned long) + in->payload_vector.iov_base; + } + break; + } + + return ret; } - -inline int -__socket_read_simple_reply (rpc_transport_t *this) +static int +__socket_read_simple_reply(rpc_transport_t *this) { - return __socket_read_simple_msg (this); + return __socket_read_simple_msg(this); } #define rpc_xid_addr(buf) (buf) -inline int -__socket_read_reply (rpc_transport_t *this) +static int +__socket_read_reply(rpc_transport_t *this) { - socket_private_t *priv = NULL; - char *buf = NULL; - int32_t ret = -1; - rpc_request_info_t *request_info = NULL; - char map_xid = 0; - - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); - - priv = this->private; + socket_private_t *priv = NULL; + char *buf = NULL; + int32_t ret = -1; + rpc_request_info_t *request_info = NULL; + char map_xid = 0; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; + + priv = this->private; + in = &priv->incoming; + frag = &in->frag; + + buf = rpc_xid_addr(iobuf_ptr(in->iobuf)); + + if (in->request_info == NULL) { + in->request_info = GF_CALLOC(1, sizeof(*request_info), + gf_common_mt_rpc_trans_reqinfo_t); + if (in->request_info == NULL) { + goto out; + } - buf = rpc_xid_addr (iobuf_ptr (priv->incoming.iobuf)); + map_xid = 1; + } - if (priv->incoming.request_info == NULL) { - priv->incoming.request_info = GF_CALLOC (1, - sizeof (*request_info), - gf_common_mt_rpc_trans_reqinfo_t); - if (priv->incoming.request_info == NULL) { - goto out; - } - - map_xid = 1; - } + request_info = in->request_info; - request_info = priv->incoming.request_info; + if (map_xid) { + request_info->xid = ntoh32(*((uint32_t *)buf)); - if (map_xid) { - request_info->xid = ntoh32 (*((uint32_t *) buf)); + /* release priv->lock, so as to avoid deadlock b/w conn->lock + * and priv->lock, since we are doing an upcall here. + */ + frag->state = SP_STATE_NOTIFYING_XID; + ret = rpc_transport_notify(this, RPC_TRANSPORT_MAP_XID_REQUEST, + in->request_info); - /* release priv->lock, so as to avoid deadlock b/w conn->lock - * and priv->lock, since we are doing an upcall here. - */ - pthread_mutex_unlock (&priv->lock); - { - ret = rpc_transport_notify (this, - RPC_TRANSPORT_MAP_XID_REQUEST, - priv->incoming.request_info); - } - pthread_mutex_lock (&priv->lock); + /* Transition back to externally visible state. */ + frag->state = SP_STATE_READ_MSGTYPE; - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "notify for event MAP_XID failed"); - goto out; - } + if (ret < 0) { + gf_log(this->name, GF_LOG_WARNING, + "notify for event MAP_XID failed for %s", + this->peerinfo.identifier); + goto out; } + } - if ((request_info->prognum == GLUSTER3_1_FOP_PROGRAM) - && (request_info->procnum == GF_FOP_READ)) { - if (map_xid && request_info->rsp.rsp_payload_count != 0) { - priv->incoming.iobref - = iobref_ref (request_info->rsp.rsp_iobref); - priv->incoming.payload_vector - = *request_info->rsp.rsp_payload; - } - - ret = __socket_read_vectored_reply (this); - } else { - ret = __socket_read_simple_reply (this); + if ((request_info->prognum == GLUSTER_FOP_PROGRAM) && + (request_info->procnum == GF_FOP_READ)) { + if (map_xid && request_info->rsp.rsp_payload_count != 0) { + in->iobref = iobref_ref(request_info->rsp.rsp_iobref); + in->payload_vector = *request_info->rsp.rsp_payload; } + + ret = __socket_read_vectored_reply(this); + } else { + ret = __socket_read_simple_reply(this); + } out: - return ret; + return ret; } - /* returns the number of bytes yet to be read in a fragment */ -inline int -__socket_read_frag (rpc_transport_t *this) +static int +__socket_read_frag(rpc_transport_t *this) { - socket_private_t *priv = NULL; - int32_t ret = 0; - char *buf = NULL; - uint32_t remaining_size = 0; - - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); - - priv = this->private; - - switch (priv->incoming.frag.state) { + socket_private_t *priv = NULL; + int32_t ret = 0; + char *buf = NULL; + uint32_t remaining_size = 0; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; + + priv = this->private; + /* used to reduce the indirection */ + in = &priv->incoming; + frag = &in->frag; + + switch (frag->state) { case SP_STATE_NADA: - __socket_proto_init_pending (priv, RPC_MSGTYPE_SIZE); + __socket_proto_init_pending(priv, RPC_MSGTYPE_SIZE); - priv->incoming.frag.state = SP_STATE_READING_MSGTYPE; + frag->state = SP_STATE_READING_MSGTYPE; - /* fall through */ + /* fall through */ case SP_STATE_READING_MSGTYPE: - __socket_proto_read (priv, ret); + __socket_proto_read(priv, ret); - priv->incoming.frag.state = SP_STATE_READ_MSGTYPE; - /* fall through */ + frag->state = SP_STATE_READ_MSGTYPE; + /* fall through */ case SP_STATE_READ_MSGTYPE: - buf = rpc_msgtype_addr (iobuf_ptr (priv->incoming.iobuf)); - priv->incoming.msg_type = ntoh32 (*((uint32_t *)buf)); - - if (priv->incoming.msg_type == CALL) { - ret = __socket_read_request (this); - } else if (priv->incoming.msg_type == REPLY) { - ret = __socket_read_reply (this); - } else if (priv->incoming.msg_type == GF_UNIVERSAL_ANSWER) { - gf_log ("rpc", GF_LOG_ERROR, - "older version of protocol/process trying to " - "connect from %s. use newer version on that node", - this->peerinfo.identifier); - } else { - gf_log ("rpc", GF_LOG_ERROR, - "wrong MSG-TYPE (%d) received from %s", - priv->incoming.msg_type, - this->peerinfo.identifier); - ret = -1; - } + buf = rpc_msgtype_addr(iobuf_ptr(in->iobuf)); + in->msg_type = ntoh32(*((uint32_t *)buf)); + + if (in->msg_type == CALL) { + ret = __socket_read_request(this); + } else if (in->msg_type == REPLY) { + ret = __socket_read_reply(this); + } else if (in->msg_type == (msg_type_t)GF_UNIVERSAL_ANSWER) { + gf_log("rpc", GF_LOG_ERROR, + "older version of protocol/process trying to " + "connect from %s. use newer version on that node", + this->peerinfo.identifier); + } else { + gf_log("rpc", GF_LOG_ERROR, + "wrong MSG-TYPE (%d) received from %s", in->msg_type, + this->peerinfo.identifier); + ret = -1; + } - remaining_size = RPC_FRAGSIZE (priv->incoming.fraghdr) - - priv->incoming.frag.bytes_read; + remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read; - if ((ret == -1) - || ((ret == 0) - && (remaining_size == 0) - && (RPC_LASTFRAG (priv->incoming.fraghdr)))) { - priv->incoming.frag.state = SP_STATE_NADA; - } + if ((ret < 0) || ((ret == 0) && (remaining_size == 0) && + (RPC_LASTFRAG(in->fraghdr)))) { + /* frag->state = SP_STATE_NADA; */ + frag->state = SP_STATE_RPCFRAG_INIT; + } - break; - } + break; -out: - return ret; -} + case SP_STATE_NOTIFYING_XID: + /* Another epoll thread is notifying higher layers + *of reply's xid. */ + errno = EAGAIN; + return -1; + break; + } + return ret; +} -inline -void __socket_reset_priv (socket_private_t *priv) +static void +__socket_reset_priv(socket_private_t *priv) { - if (priv->incoming.iobref) { - iobref_unref (priv->incoming.iobref); - priv->incoming.iobref = NULL; - } + struct gf_sock_incoming *in = NULL; - if (priv->incoming.iobuf) { - iobuf_unref (priv->incoming.iobuf); - } + /* used to reduce the indirection */ + in = &priv->incoming; - if (priv->incoming.request_info != NULL) { - GF_FREE (priv->incoming.request_info); - priv->incoming.request_info = NULL; - } + if (in->iobref) { + iobref_unref(in->iobref); + in->iobref = NULL; + } - memset (&priv->incoming.payload_vector, 0, - sizeof (priv->incoming.payload_vector)); + if (in->iobuf) { + iobuf_unref(in->iobuf); + in->iobuf = NULL; + } - priv->incoming.iobuf = NULL; + if (in->request_info != NULL) { + GF_FREE(in->request_info); + in->request_info = NULL; + } + + memset(&in->payload_vector, 0, sizeof(in->payload_vector)); } +static int +__socket_proto_state_machine(rpc_transport_t *this, + rpc_transport_pollin_t **pollin) +{ + int ret = -1; + socket_private_t *priv = NULL; + struct iobuf *iobuf = NULL; + struct iobref *iobref = NULL; + struct iovec vector[2]; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; -int -__socket_proto_state_machine (rpc_transport_t *this, - rpc_transport_pollin_t **pollin) -{ - int ret = -1; - socket_private_t *priv = NULL; - struct iobuf *iobuf = NULL; - struct iobref *iobref = NULL; - struct iovec vector[2]; - - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); - - priv = this->private; - while (priv->incoming.record_state != SP_STATE_COMPLETE) { - switch (priv->incoming.record_state) { - - case SP_STATE_NADA: - priv->incoming.total_bytes_read = 0; - priv->incoming.payload_vector.iov_len = 0; - - priv->incoming.pending_vector = priv->incoming.vector; - priv->incoming.pending_vector->iov_base = - &priv->incoming.fraghdr; - - priv->incoming.pending_vector->iov_len = - sizeof (priv->incoming.fraghdr); - - priv->incoming.record_state = SP_STATE_READING_FRAGHDR; - - /* fall through */ - - case SP_STATE_READING_FRAGHDR: - ret = __socket_readv (this, - priv->incoming.pending_vector, 1, - &priv->incoming.pending_vector, - &priv->incoming.pending_count, - NULL); - if (ret == -1) { - if (priv->read_fail_log == 1) { - gf_log (this->name, - ((priv->connected == 1) ? - GF_LOG_WARNING : GF_LOG_DEBUG), - "reading from socket failed. Error (%s)" - ", peer (%s)", strerror (errno), - this->peerinfo.identifier); - } - goto out; - } + GF_VALIDATE_OR_GOTO("socket", this, out); + GF_VALIDATE_OR_GOTO("socket", this->private, out); - if (ret > 0) { - gf_log (this->name, GF_LOG_TRACE, "partial " - "fragment header read"); - goto out; - } + priv = this->private; + /* used to reduce the indirection */ + in = &priv->incoming; + frag = &in->frag; - if (ret == 0) { - priv->incoming.record_state = - SP_STATE_READ_FRAGHDR; - } - /* fall through */ - - case SP_STATE_READ_FRAGHDR: - - priv->incoming.fraghdr = ntoh32 (priv->incoming.fraghdr); - priv->incoming.record_state = SP_STATE_READING_FRAG; - priv->incoming.total_bytes_read - += RPC_FRAGSIZE(priv->incoming.fraghdr); - iobuf = iobuf_get2 (this->ctx->iobuf_pool, - priv->incoming.total_bytes_read + - sizeof (priv->incoming.fraghdr)); - if (!iobuf) { - ret = -ENOMEM; - goto out; - } + while (in->record_state != SP_STATE_COMPLETE) { + switch (in->record_state) { + case SP_STATE_NADA: + in->total_bytes_read = 0; + in->payload_vector.iov_len = 0; - priv->incoming.iobuf = iobuf; - priv->incoming.iobuf_size = 0; - priv->incoming.frag.fragcurrent = iobuf_ptr (iobuf); - /* fall through */ + in->pending_vector = in->vector; + in->pending_vector->iov_base = &in->fraghdr; - case SP_STATE_READING_FRAG: - ret = __socket_read_frag (this); + in->pending_vector->iov_len = sizeof(in->fraghdr); - if ((ret == -1) - || (priv->incoming.frag.bytes_read != - RPC_FRAGSIZE (priv->incoming.fraghdr))) { - goto out; - } + in->record_state = SP_STATE_READING_FRAGHDR; - priv->incoming.frag.bytes_read = 0; + /* fall through */ - if (!RPC_LASTFRAG (priv->incoming.fraghdr)) { - priv->incoming.record_state = - SP_STATE_READING_FRAGHDR; - break; - } + case SP_STATE_READING_FRAGHDR: + ret = __socket_readv(this, in->pending_vector, 1, + &in->pending_vector, &in->pending_count, + NULL); + if (ret < 0) + goto out; - /* we've read the entire rpc record, notify the - * upper layers. - */ - if (pollin != NULL) { - int count = 0; - priv->incoming.iobuf_size - = priv->incoming.total_bytes_read - - priv->incoming.payload_vector.iov_len; - - memset (vector, 0, sizeof (vector)); - - if (priv->incoming.iobref == NULL) { - priv->incoming.iobref = iobref_new (); - if (priv->incoming.iobref == NULL) { - ret = -1; - goto out; - } - } - - vector[count].iov_base - = iobuf_ptr (priv->incoming.iobuf); - vector[count].iov_len - = priv->incoming.iobuf_size; - - iobref = priv->incoming.iobref; - - count++; - - if (priv->incoming.payload_vector.iov_base - != NULL) { - vector[count] - = priv->incoming.payload_vector; - count++; - } - - *pollin = rpc_transport_pollin_alloc (this, - vector, - count, - priv->incoming.iobuf, - iobref, - priv->incoming.request_info); - iobuf_unref (priv->incoming.iobuf); - priv->incoming.iobuf = NULL; - - if (*pollin == NULL) { - gf_log (this->name, GF_LOG_WARNING, - "transport pollin allocation failed"); - ret = -1; - goto out; - } - if (priv->incoming.msg_type == REPLY) - (*pollin)->is_reply = 1; - - priv->incoming.request_info = NULL; - } - priv->incoming.record_state = SP_STATE_COMPLETE; - break; + if (ret > 0) { + gf_log(this->name, GF_LOG_TRACE, + "partial " + "fragment header read"); + ret = 0; + goto out; + } - case SP_STATE_COMPLETE: - /* control should not reach here */ - gf_log (this->name, GF_LOG_WARNING, "control reached to " - "SP_STATE_COMPLETE, which should not have " - "happened"); - break; + if (ret == 0) { + in->record_state = SP_STATE_READ_FRAGHDR; } - } + /* fall through */ - if (priv->incoming.record_state == SP_STATE_COMPLETE) { - priv->incoming.record_state = SP_STATE_NADA; - __socket_reset_priv (priv); - } + case SP_STATE_READ_FRAGHDR: -out: - if ((ret == -1) && (errno == EAGAIN)) { - ret = 0; - } - return ret; -} + in->fraghdr = ntoh32(in->fraghdr); + in->total_bytes_read += RPC_FRAGSIZE(in->fraghdr); + if (in->total_bytes_read >= GF_UNIT_GB) { + ret = -1; + goto out; + } -int -socket_proto_state_machine (rpc_transport_t *this, - rpc_transport_pollin_t **pollin) -{ - socket_private_t *priv = NULL; - int ret = 0; + iobuf = iobuf_get2( + this->ctx->iobuf_pool, + (in->total_bytes_read + sizeof(in->fraghdr))); + if (!iobuf) { + ret = -1; + goto out; + } + + if (in->iobuf == NULL) { + /* first fragment */ + frag->fragcurrent = iobuf_ptr(iobuf); + } else { + /* second or further fragment */ + memcpy(iobuf_ptr(iobuf), iobuf_ptr(in->iobuf), + in->total_bytes_read - RPC_FRAGSIZE(in->fraghdr)); + iobuf_unref(in->iobuf); + frag->fragcurrent = (char *)iobuf_ptr(iobuf) + + in->total_bytes_read - + RPC_FRAGSIZE(in->fraghdr); + frag->pending_vector->iov_base = frag->fragcurrent; + in->pending_vector = frag->pending_vector; + } - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); + in->iobuf = iobuf; + in->iobuf_size = 0; + in->record_state = SP_STATE_READING_FRAG; + /* fall through */ - priv = this->private; + case SP_STATE_READING_FRAG: + ret = __socket_read_frag(this); - pthread_mutex_lock (&priv->lock); - { - ret = __socket_proto_state_machine (this, pollin); + if ((ret < 0) || + (frag->bytes_read != RPC_FRAGSIZE(in->fraghdr))) { + goto out; + } + + frag->bytes_read = 0; + + if (!RPC_LASTFRAG(in->fraghdr)) { + in->pending_vector = in->vector; + in->pending_vector->iov_base = &in->fraghdr; + in->pending_vector->iov_len = sizeof(in->fraghdr); + in->record_state = SP_STATE_READING_FRAGHDR; + break; + } + + /* we've read the entire rpc record, notify the + * upper layers. + */ + if (pollin != NULL) { + int count = 0; + in->iobuf_size = (in->total_bytes_read - + in->payload_vector.iov_len); + + memset(vector, 0, sizeof(vector)); + + if (in->iobref == NULL) { + in->iobref = iobref_new(); + if (in->iobref == NULL) { + ret = -1; + goto out; + } + } + + vector[count].iov_base = iobuf_ptr(in->iobuf); + vector[count].iov_len = in->iobuf_size; + + iobref = in->iobref; + + count++; + + if (in->payload_vector.iov_base != NULL) { + vector[count] = in->payload_vector; + count++; + } + + *pollin = rpc_transport_pollin_alloc(this, vector, count, + in->iobuf, iobref, + in->request_info); + iobuf_unref(in->iobuf); + in->iobuf = NULL; + + if (*pollin == NULL) { + gf_log(this->name, GF_LOG_WARNING, + "transport pollin allocation failed"); + ret = -1; + goto out; + } + if (in->msg_type == REPLY) + (*pollin)->is_reply = 1; + + in->request_info = NULL; + } + in->record_state = SP_STATE_COMPLETE; + break; + + case SP_STATE_COMPLETE: + /* control should not reach here */ + gf_log(this->name, GF_LOG_WARNING, + "control reached to " + "SP_STATE_COMPLETE, which should not have " + "happened"); + break; } - pthread_mutex_unlock (&priv->lock); + } + + if (in->record_state == SP_STATE_COMPLETE) { + in->record_state = SP_STATE_NADA; + __socket_reset_priv(priv); + } out: - return ret; + return ret; } +static int +socket_proto_state_machine(rpc_transport_t *this, + rpc_transport_pollin_t **pollin) +{ + return __socket_proto_state_machine(this, pollin); +} -int -socket_event_poll_in (rpc_transport_t *this) +static void +socket_event_poll_in_async(xlator_t *xl, gf_async_t *async) { - int ret = -1; - rpc_transport_pollin_t *pollin = NULL; + rpc_transport_pollin_t *pollin; + rpc_transport_t *this; + socket_private_t *priv; - ret = socket_proto_state_machine (this, &pollin); + pollin = caa_container_of(async, rpc_transport_pollin_t, async); + this = pollin->trans; + priv = this->private; - if (pollin != NULL) { - ret = rpc_transport_notify (this, RPC_TRANSPORT_MSG_RECEIVED, - pollin); + rpc_transport_notify(this, RPC_TRANSPORT_MSG_RECEIVED, pollin); - rpc_transport_pollin_destroy (pollin); - } + rpc_transport_unref(this); - return ret; -} + rpc_transport_pollin_destroy(pollin); + pthread_mutex_lock(&priv->notify.lock); + { + --priv->notify.in_progress; -int -socket_connect_finish (rpc_transport_t *this) + if (!priv->notify.in_progress) + pthread_cond_signal(&priv->notify.cond); + } + pthread_mutex_unlock(&priv->notify.lock); +} + +static int +socket_event_poll_in(rpc_transport_t *this, gf_boolean_t notify_handled) { - int ret = -1; - socket_private_t *priv = NULL; - rpc_transport_event_t event = 0; - char notify_rpc = 0; + int ret = -1; + rpc_transport_pollin_t *pollin = NULL; + socket_private_t *priv = this->private; + glusterfs_ctx_t *ctx = NULL; - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); + ctx = this->ctx; - priv = this->private; + ret = socket_proto_state_machine(this, &pollin); - pthread_mutex_lock (&priv->lock); + if (pollin) { + pthread_mutex_lock(&priv->notify.lock); { - if (priv->connected) - goto unlock; + priv->notify.in_progress++; + } + pthread_mutex_unlock(&priv->notify.lock); + } - ret = __socket_connect_finish (priv->sock); + if (notify_handled && (ret >= 0)) + gf_event_handled(ctx->event_pool, priv->sock, priv->idx, priv->gen); - if (ret == -1 && errno == EINPROGRESS) - ret = 1; + if (pollin) { + rpc_transport_ref(this); + gf_async(&pollin->async, THIS, socket_event_poll_in_async); + } - if (ret == -1 && errno != EINPROGRESS) { - if (!priv->connect_finish_log) { - gf_log (this->name, GF_LOG_ERROR, - "connection to %s failed (%s)", - this->peerinfo.identifier, - strerror (errno)); - priv->connect_finish_log = 1; - } - __socket_disconnect (this); - notify_rpc = 1; - event = RPC_TRANSPORT_DISCONNECT; - goto unlock; - } + return ret; +} - if (ret == 0) { - notify_rpc = 1; - - this->myinfo.sockaddr_len = - sizeof (this->myinfo.sockaddr); - - ret = getsockname (priv->sock, - SA (&this->myinfo.sockaddr), - &this->myinfo.sockaddr_len); - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "getsockname on (%d) failed (%s)", - priv->sock, strerror (errno)); - __socket_disconnect (this); - event = GF_EVENT_POLLERR; - goto unlock; - } +static int +socket_connect_finish(rpc_transport_t *this) +{ + int ret = -1; + socket_private_t *priv = NULL; + rpc_transport_event_t event = 0; + char notify_rpc = 0; + + priv = this->private; + + pthread_mutex_lock(&priv->out_lock); + { + if (priv->connected != 0) + goto unlock; + + get_transport_identifiers(this); + + ret = __socket_connect_finish(priv->sock); + + if ((ret < 0) && (errno == EINPROGRESS)) + ret = 1; + + if ((ret < 0) && (errno != EINPROGRESS)) { + if (!priv->connect_finish_log) { + gf_log(this->name, GF_LOG_ERROR, + "connection to %s failed (%s); " + "disconnecting socket", + this->peerinfo.identifier, strerror(errno)); + priv->connect_finish_log = 1; + } + __socket_disconnect(this); + goto unlock; + } - priv->connected = 1; - priv->connect_finish_log = 0; - event = RPC_TRANSPORT_CONNECT; - get_transport_identifiers (this); - } + if (ret == 0) { + notify_rpc = 1; + + this->myinfo.sockaddr_len = sizeof(this->myinfo.sockaddr); + + ret = getsockname(priv->sock, SA(&this->myinfo.sockaddr), + &this->myinfo.sockaddr_len); + if (ret != 0) { + gf_log(this->name, GF_LOG_WARNING, + "getsockname on (%d) failed (%s) - " + "disconnecting socket", + priv->sock, strerror(errno)); + __socket_disconnect(this); + event = RPC_TRANSPORT_DISCONNECT; + goto unlock; + } + + priv->connected = 1; + priv->connect_finish_log = 0; + event = RPC_TRANSPORT_CONNECT; } + } unlock: - pthread_mutex_unlock (&priv->lock); + pthread_mutex_unlock(&priv->out_lock); - if (notify_rpc) { - rpc_transport_notify (this, event, this); - } -out: - return 0; + if (notify_rpc) { + rpc_transport_notify(this, event, this); + } + + return ret; } +static int +socket_disconnect(rpc_transport_t *this, gf_boolean_t wait); -/* reads rpc_requests during pollin */ -int -socket_event_handler (int fd, int idx, void *data, - int poll_in, int poll_out, int poll_err) +/* socket_is_connected() is for use only in socket_event_handler() */ +static inline gf_boolean_t +socket_is_connected(socket_private_t *priv) { - rpc_transport_t *this = NULL; - socket_private_t *priv = NULL; - int ret = 0; - - this = data; - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); - GF_VALIDATE_OR_GOTO ("socket", this->xl, out); - - THIS = this->xl; - priv = this->private; - + if (priv->use_ssl) { + return priv->is_server ? priv->ssl_accepted : priv->ssl_connected; + } else { + return priv->is_server ? priv->accepted : priv->connected; + } +} - pthread_mutex_lock (&priv->lock); - { - priv->idx = idx; - } - pthread_mutex_unlock (&priv->lock); +static void +ssl_rearm_event_fd(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + glusterfs_ctx_t *ctx = NULL; + int idx = -1; + int gen = -1; + int fd = -1; + + priv = this->private; + ctx = this->ctx; + + idx = priv->idx; + gen = priv->gen; + fd = priv->sock; + + if (priv->ssl_error_required == SSL_ERROR_WANT_READ) + gf_event_select_on(ctx->event_pool, fd, idx, 1, -1); + if (priv->ssl_error_required == SSL_ERROR_WANT_WRITE) + gf_event_select_on(ctx->event_pool, fd, idx, -1, 1); + gf_event_handled(ctx->event_pool, fd, idx, gen); +} - if (!priv->connected) { - ret = socket_connect_finish (this); +static int +ssl_handle_server_connection_attempt(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + glusterfs_ctx_t *ctx = NULL; + int idx = -1; + int gen = -1; + int ret = -1; + int fd = -1; + + priv = this->private; + ctx = this->ctx; + + idx = priv->idx; + gen = priv->gen; + fd = priv->sock; + + if (!priv->ssl_context_created) { + ret = ssl_setup_connection_prefix(this, _gf_true); + if (ret < 0) { + gf_log(this->name, GF_LOG_TRACE, + "> ssl_setup_connection_prefix() failed!"); + ret = -1; + goto out; + } else { + priv->ssl_context_created = _gf_true; } - - if (!ret && poll_out) { - ret = socket_event_poll_out (this); + } + ret = ssl_complete_connection(this); + if (ret == 0) { + /* nothing to do */ + 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) { + ssl_rearm_event_fd(this); + ret = 1; + } else { + ret = -1; + gf_log(this->name, GF_LOG_TRACE, + "ssl_complete_connection returned error"); } + } +out: + return ret; +} - if (!ret && poll_in) { - ret = socket_event_poll_in (this); +static int +ssl_handle_client_connection_attempt(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + glusterfs_ctx_t *ctx = NULL; + int idx = -1; + int ret = -1; + int fd = -1; + + priv = this->private; + ctx = this->ctx; + + idx = priv->idx; + fd = priv->sock; + + /* SSL client */ + if (priv->connect_failed) { + gf_log(this->name, GF_LOG_TRACE, ">>> disconnecting SSL socket"); + (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, _gf_false); + if (ret < 0) { + gf_log(this->name, GF_LOG_TRACE, + "> ssl_setup_connection_prefix() " + "failed!"); + ret = -1; + goto out; + } else { + priv->ssl_context_created = _gf_true; + } } - - if ((ret < 0) || poll_err) { - /* Logging has happened already in earlier cases */ - gf_log ("transport", ((ret >= 0) ? GF_LOG_INFO : GF_LOG_DEBUG), - "disconnecting now"); - socket_event_poll_err (this); - rpc_transport_unref (this); + ret = ssl_complete_connection(this); + if (ret == 0) { + ret = socket_connect_finish(this); + 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) { + gf_log(this->name, GF_LOG_TRACE, + ">>> retrying client connect 2"); + ssl_rearm_event_fd(this); + ret = 1; + } else { + /* this is a connection failure */ + (void)socket_connect_finish(this); + gf_log(this->name, GF_LOG_TRACE, + "ssl_complete_connection " + "returned error"); + ret = -1; + } } - + } out: - return 0; + return ret; } +static int +socket_handle_client_connection_attempt(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + glusterfs_ctx_t *ctx = NULL; + int idx = -1; + int gen = -1; + int ret = -1; + int fd = -1; + + priv = this->private; + ctx = this->ctx; + + idx = priv->idx; + gen = priv->gen; + fd = priv->sock; + + /* non-SSL client */ + if (priv->connect_failed) { + /* connect failed with some other error than + EINPROGRESS or ENOENT, so nothing more to + do, fail reading/writing anything even if + poll_in or poll_out + is set + */ + gf_log("transport", GF_LOG_DEBUG, + "connect failed with some other error " + "than EINPROGRESS or ENOENT, so " + "nothing more to do; disconnecting " + "socket"); + (void)socket_disconnect(this, _gf_false); + + /* Force ret to be -1, as we are officially + * done with this socket + */ + ret = -1; + } else { + ret = socket_connect_finish(this); + gf_log(this->name, GF_LOG_TRACE, "socket_connect_finish() returned %d", + ret); + if (ret == 0 || ret == 1) { + /* we don't want to do any reads or + * writes on the connection yet in + * socket_event_handler, so just + * return 1 + */ + ret = 1; + gf_event_handled(ctx->event_pool, fd, idx, gen); + } + } + return ret; +} -int -socket_server_event_handler (int fd, int idx, void *data, - int poll_in, int poll_out, int poll_err) -{ - rpc_transport_t *this = NULL; - socket_private_t *priv = NULL; - int ret = 0; - int new_sock = -1; - rpc_transport_t *new_trans = NULL; - struct sockaddr_storage new_sockaddr = {0, }; - socklen_t addrlen = sizeof (new_sockaddr); - socket_private_t *new_priv = NULL; - glusterfs_ctx_t *ctx = NULL; - - this = data; - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); - GF_VALIDATE_OR_GOTO ("socket", this->xl, out); - - THIS = this->xl; - priv = this->private; - ctx = this->ctx; - - pthread_mutex_lock (&priv->lock); - { - priv->idx = idx; +static int +socket_complete_connection(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + glusterfs_ctx_t *ctx = NULL; + int idx = -1; + int gen = -1; + int ret = -1; + int fd = -1; + + priv = this->private; + ctx = this->ctx; + + idx = priv->idx; + gen = priv->gen; + fd = priv->sock; + + if (priv->use_ssl) { + if (priv->is_server) { + ret = ssl_handle_server_connection_attempt(this); + } else { + ret = ssl_handle_client_connection_attempt(this); + } + } else { + if (priv->is_server) { + /* non-SSL server: nothing much to do + * connection has already been accepted in + * socket_server_event_handler() + */ + priv->accepted = _gf_true; + gf_event_handled(ctx->event_pool, fd, idx, gen); + ret = 1; + } else { + ret = socket_handle_client_connection_attempt(this); + } + } + return ret; +} - if (poll_in) { - new_sock = accept (priv->sock, SA (&new_sockaddr), - &addrlen); +/* reads rpc_requests during pollin */ +static void +socket_event_handler(int fd, int idx, int gen, void *data, int poll_in, + int poll_out, int poll_err, char event_thread_died) +{ + rpc_transport_t *this = NULL; + socket_private_t *priv = NULL; + int ret = -1; + glusterfs_ctx_t *ctx = NULL; + gf_boolean_t socket_closed = _gf_false, notify_handled = _gf_false; - if (new_sock == -1) { - gf_log (this->name, GF_LOG_WARNING, - "accept on %d failed (%s)", - priv->sock, strerror (errno)); - goto unlock; - } + this = data; - if (!priv->bio) { - ret = __socket_nonblock (new_sock); + 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); + + THIS = this->xl; + priv = this->private; + ctx = this->ctx; + + pthread_mutex_lock(&priv->out_lock); + { + priv->idx = idx; + priv->gen = gen; + } + pthread_mutex_unlock(&priv->out_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(priv)) { + gf_log(this->name, GF_LOG_TRACE, + "%s (sock:%d) socket is not connected, " + "completing connection", + (priv->is_server ? "server" : "client"), priv->sock); + + ret = socket_complete_connection(this); + + gf_log(this->name, GF_LOG_TRACE, + "(sock:%d) " + "socket_complete_connection() returned %d", + priv->sock, ret); + + if (ret > 0) { + gf_log(this->name, GF_LOG_TRACE, + "(sock:%d) returning to wait on socket", priv->sock); + goto out; + } + } else { + char *sock_type = (priv->is_server ? "Server" : "Client"); - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "NBIO on %d failed (%s)", - new_sock, strerror (errno)); + gf_log(this->name, GF_LOG_TRACE, + "%s socket (%d) is already connected", sock_type, + priv->sock); + ret = 0; + } + } + + if (!ret && poll_out) { + ret = socket_event_poll_out(this); + gf_log(this->name, GF_LOG_TRACE, + "(sock:%d) " + "socket_event_poll_out returned %d", + priv->sock, ret); + } + + if (!ret && poll_in) { + ret = socket_event_poll_in(this, !poll_err); + gf_log(this->name, GF_LOG_TRACE, + "(sock:%d) " + "socket_event_poll_in returned %d", + priv->sock, ret); + notify_handled = _gf_true; + } + + if ((ret < 0) || poll_err) { + struct sockaddr *sa = SA(&this->peerinfo.sockaddr); + + if (priv->is_server && + SA(&this->myinfo.sockaddr)->sa_family == AF_UNIX) { + sa = SA(&this->myinfo.sockaddr); + } - close (new_sock); - goto unlock; - } - } + socket_dump_info(sa, priv->is_server, priv->use_ssl, priv->sock, + this->name, "disconnecting from"); - if (priv->nodelay) { - ret = __socket_nodelay (new_sock); - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "setsockopt() failed for " - "NODELAY (%s)", - strerror (errno)); - } - } + /* 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); + } - if (priv->keepalive) { - ret = __socket_keepalive (new_sock, - priv->keepaliveintvl, - priv->keepaliveidle); - if (ret == -1) - gf_log (this->name, GF_LOG_WARNING, - "Failed to set keep-alive: %s", - strerror (errno)); - } + /* 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, + (priv->use_ssl ? "SSL" : "non-SSL")); - new_trans = GF_CALLOC (1, sizeof (*new_trans), - gf_common_mt_rpc_trans_t); - if (!new_trans) - goto unlock; - - new_trans->name = gf_strdup (this->name); - - memcpy (&new_trans->peerinfo.sockaddr, &new_sockaddr, - addrlen); - new_trans->peerinfo.sockaddr_len = addrlen; - - new_trans->myinfo.sockaddr_len = - sizeof (new_trans->myinfo.sockaddr); - - ret = getsockname (new_sock, - SA (&new_trans->myinfo.sockaddr), - &new_trans->myinfo.sockaddr_len); - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "getsockname on %d failed (%s)", - new_sock, strerror (errno)); - close (new_sock); - goto unlock; - } + socket_closed = socket_event_poll_err(this, gen, idx); - get_transport_identifiers (new_trans); - socket_init (new_trans); - new_trans->ops = this->ops; - new_trans->init = this->init; - new_trans->fini = this->fini; - new_trans->ctx = ctx; - new_trans->xl = this->xl; - new_trans->mydata = this->mydata; - new_trans->notify = this->notify; - new_trans->listener = this; - new_priv = new_trans->private; - - pthread_mutex_lock (&new_priv->lock); - { - new_priv->sock = new_sock; - new_priv->connected = 1; - rpc_transport_ref (new_trans); - - new_priv->idx = - event_register (ctx->event_pool, - new_sock, - socket_event_handler, - new_trans, 1, 0); - - if (new_priv->idx == -1) - ret = -1; - } - pthread_mutex_unlock (&new_priv->lock); - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "failed to register the socket with event"); - goto unlock; - } + if (socket_closed) + rpc_transport_unref(this); - ret = rpc_transport_notify (this, RPC_TRANSPORT_ACCEPT, - new_trans); - } - } -unlock: - pthread_mutex_unlock (&priv->lock); + } else if (!notify_handled) { + gf_event_handled(ctx->event_pool, fd, idx, gen); + } out: - return ret; + rpc_transport_unref(this); } - -int -socket_disconnect (rpc_transport_t *this) +static void +socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in, + int poll_out, int poll_err, char event_thread_died) { - socket_private_t *priv = NULL; - int ret = -1; + rpc_transport_t *this = NULL; + socket_private_t *priv = NULL; + int ret = 0; + int new_sock = -1; + rpc_transport_t *new_trans = NULL; + struct sockaddr_storage new_sockaddr = { + 0, + }; + socklen_t addrlen = sizeof(new_sockaddr); + socket_private_t *new_priv = NULL; + glusterfs_ctx_t *ctx = NULL; + + this = data; + GF_VALIDATE_OR_GOTO("socket", this, out); + GF_VALIDATE_OR_GOTO("socket", this->private, out); + GF_VALIDATE_OR_GOTO("socket", this->xl, out); + GF_VALIDATE_OR_GOTO("socket", this->ctx, out); + + THIS = this->xl; + priv = this->private; + ctx = this->ctx; + + if (event_thread_died) { + rpc_transport_notify(this, RPC_TRANSPORT_EVENT_THREAD_DIED, + (void *)(unsigned long)gen); + return; + } - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); + /* 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 + * attempts to unref the listener socket/transport from any other + * thread context while we are using it here. + */ + priv->idx = idx; + priv->gen = gen; - priv = this->private; + if (poll_err) { + socket_event_poll_err(this, gen, idx); + goto out; + } - pthread_mutex_lock (&priv->lock); - { - ret = __socket_disconnect (this); - } - pthread_mutex_unlock (&priv->lock); + if (poll_in) { + int aflags = 0; -out: - return ret; -} + if (!priv->bio) + aflags = O_NONBLOCK; + new_sock = sys_accept(priv->sock, SA(&new_sockaddr), &addrlen, aflags); -int -socket_connect (rpc_transport_t *this, int port) -{ - int ret = -1; - int sock = -1; - socket_private_t *priv = NULL; - socklen_t sockaddr_len = 0; - glusterfs_ctx_t *ctx = NULL; - sa_family_t sa_family = {0, }; - union gf_sock_union sock_union; + gf_event_handled(ctx->event_pool, fd, idx, gen); - GF_VALIDATE_OR_GOTO ("socket", this, err); - GF_VALIDATE_OR_GOTO ("socket", this->private, err); + if (new_sock < 0) { + gf_log(this->name, GF_LOG_WARNING, "accept on %d failed (%s)", + priv->sock, strerror(errno)); + goto out; + } - priv = this->private; - ctx = this->ctx; + 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) { - gf_log_callingfn (this->name, GF_LOG_WARNING, - "connect() called on uninitialized transport"); - goto err; + 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)); + } } - pthread_mutex_lock (&priv->lock); - { - sock = priv->sock; + new_trans = GF_CALLOC(1, sizeof(*new_trans), gf_common_mt_rpc_trans_t); + if (!new_trans) { + sys_close(new_sock); + gf_log(this->name, GF_LOG_WARNING, + "transport object allocation failure; " + "closed newly accepted socket %d", + new_sock); + goto out; } - pthread_mutex_unlock (&priv->lock); - if (sock != -1) { - gf_log_callingfn (this->name, GF_LOG_TRACE, - "connect () called on transport already connected"); - errno = EINPROGRESS; - ret = -1; - goto err; + ret = pthread_mutex_init(&new_trans->lock, NULL); + if (ret != 0) { + gf_log(this->name, GF_LOG_WARNING, + "pthread_mutex_init() failed: %s; closing newly accepted " + "socket %d", + strerror(errno), new_sock); + sys_close(new_sock); + GF_FREE(new_trans); + goto out; + } + INIT_LIST_HEAD(&new_trans->list); + + new_trans->name = gf_strdup(this->name); + + memcpy(&new_trans->peerinfo.sockaddr, &new_sockaddr, addrlen); + new_trans->peerinfo.sockaddr_len = addrlen; + + new_trans->myinfo.sockaddr_len = sizeof(new_trans->myinfo.sockaddr); + + ret = getsockname(new_sock, SA(&new_trans->myinfo.sockaddr), + &new_trans->myinfo.sockaddr_len); + if (ret != 0) { + gf_log(this->name, GF_LOG_WARNING, + "getsockname on socket %d " + "failed (errno:%s); closing newly accepted socket", + new_sock, strerror(errno)); + sys_close(new_sock); + GF_FREE(new_trans->name); + GF_FREE(new_trans); + goto out; } - ret = socket_client_get_remote_sockaddr (this, &sock_union.sa, - &sockaddr_len, &sa_family); - if (ret == -1) { - /* logged inside client_get_remote_sockaddr */ - goto err; + get_transport_identifiers(new_trans); + 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 (port > 0) { - sock_union.sin.sin_port = htons (port); + if (ret != 0) { + gf_log(this->name, GF_LOG_WARNING, + "initialization of new_trans " + "failed; closing newly accepted socket %d", + new_sock); + sys_close(new_sock); + GF_FREE(new_trans->name); + GF_FREE(new_trans); + goto out; + } + new_trans->ops = this->ops; + new_trans->init = this->init; + new_trans->fini = this->fini; + new_trans->ctx = ctx; + new_trans->xl = this->xl; + 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) { + new_priv->use_ssl = _gf_false; + } else { + switch (priv->srvr_ssl) { + case MGMT_SSL_ALWAYS: + /* Glusterd with secure_mgmt. */ + new_priv->use_ssl = _gf_true; + break; + case MGMT_SSL_COPY_IO: + /* Glusterfsd. */ + new_priv->use_ssl = priv->ssl_enabled; + break; + default: + new_priv->use_ssl = _gf_false; + } } - pthread_mutex_lock (&priv->lock); - { - if (priv->sock != -1) { - gf_log (this->name, GF_LOG_TRACE, - "connect() -- already connected"); - goto unlock; - } - memcpy (&this->peerinfo.sockaddr, &sock_union.storage, - sockaddr_len); - this->peerinfo.sockaddr_len = sockaddr_len; + new_priv->sock = new_sock; - priv->sock = socket (sa_family, SOCK_STREAM, 0); - if (priv->sock == -1) { - gf_log (this->name, GF_LOG_ERROR, - "socket creation failed (%s)", - strerror (errno)); - goto unlock; - } + new_priv->ssl_enabled = priv->ssl_enabled; + new_priv->connected = 1; + new_priv->is_server = _gf_true; - /* Cant help if setting socket options fails. We can continue - * working nonetheless. - */ - if (setsockopt (priv->sock, SOL_SOCKET, SO_RCVBUF, - &priv->windowsize, - sizeof (priv->windowsize)) < 0) { - gf_log (this->name, GF_LOG_ERROR, - "setting receive window size failed: %d: %d: " - "%s", priv->sock, priv->windowsize, - strerror (errno)); - } + /* + * This is the first ref on the newly accepted + * transport. + */ + rpc_transport_ref(new_trans); - if (setsockopt (priv->sock, SOL_SOCKET, SO_SNDBUF, - &priv->windowsize, - sizeof (priv->windowsize)) < 0) { - gf_log (this->name, GF_LOG_ERROR, - "setting send window size failed: %d: %d: " - "%s", priv->sock, priv->windowsize, - strerror (errno)); + { + /* Take a ref on the new_trans to avoid + * getting deleted when event_register() + * causes socket_event_handler() to race + * ahead of this path to eventually find + * a disconnect and unref the transport + */ + rpc_transport_ref(new_trans); + + /* Send a notification to RPCSVC layer + * to save the new_trans in its service + * list before we register the new_sock + * with epoll to begin receiving notifications + * for data handling. + */ + ret = rpc_transport_notify(this, RPC_TRANSPORT_ACCEPT, new_trans); + + 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, + "failed to register the socket " + "with event"); + + /* event_register() could have failed for some + * reason, implying that the new_sock cannot be + * added to the epoll set. If we won't get any + * more notifications for new_sock from epoll, + * then we better remove the corresponding + * new_trans object from the RPCSVC service list. + * Since we've notified RPC service of new_trans + * before we attempted event_register(), we better + * unlink the new_trans from the RPCSVC service list + * to cleanup the stateby sending out a DISCONNECT + * notification. + */ + rpc_transport_notify(this, RPC_TRANSPORT_DISCONNECT, + new_trans); } + } + + /* this rpc_transport_unref() is for managing race between + * 1. socket_server_event_handler and + * 2. socket_event_handler + * trying to add and remove new_trans from the rpcsvc + * service list + * now that we are done with the notifications, lets + * reduce the reference + */ + rpc_transport_unref(new_trans); + } + 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 + * the new_trans since we've failed at everything so far + */ + rpc_transport_unref(new_trans); + } + } +out: + return; +} - if (priv->nodelay) { - ret = __socket_nodelay (priv->sock); - if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "setsockopt() failed for NODELAY (%s)", - strerror (errno)); - } - } +static int +socket_disconnect(rpc_transport_t *this, gf_boolean_t wait) +{ + socket_private_t *priv = NULL; + int ret = -1; - if (!priv->bio) { - ret = __socket_nonblock (priv->sock); + priv = this->private; - if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "NBIO on %d failed (%s)", - priv->sock, strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - } + pthread_mutex_lock(&priv->out_lock); + { + ret = __socket_disconnect(this); + } + pthread_mutex_unlock(&priv->out_lock); - if (priv->keepalive) { - ret = __socket_keepalive (priv->sock, - priv->keepaliveintvl, - priv->keepaliveidle); - if (ret == -1) - gf_log (this->name, GF_LOG_ERROR, - "Failed to set keep-alive: %s", - strerror (errno)); - } + return ret; +} - SA (&this->myinfo.sockaddr)->sa_family = - SA (&this->peerinfo.sockaddr)->sa_family; - - ret = client_bind (this, SA (&this->myinfo.sockaddr), - &this->myinfo.sockaddr_len, priv->sock); - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "client bind failed: %s", strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } +void * +socket_connect_error_cbk(void *opaque) +{ + socket_connect_error_state_t *arg; - ret = connect (priv->sock, SA (&this->peerinfo.sockaddr), - this->peerinfo.sockaddr_len); + GF_ASSERT(opaque); - if (ret == -1 && ((errno != EINPROGRESS) && (errno != ENOENT))) { - gf_log (this->name, GF_LOG_ERROR, - "connection attempt failed (%s)", - strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } + arg = opaque; + THIS = arg->this; - priv->connected = 0; + rpc_transport_notify(arg->trans, RPC_TRANSPORT_DISCONNECT, arg->trans); - rpc_transport_ref (this); + if (arg->refd) + rpc_transport_unref(arg->trans); - priv->idx = event_register (ctx->event_pool, priv->sock, - socket_event_handler, this, 1, 1); - if (priv->idx == -1) { - gf_log (this->name, GF_LOG_WARNING, - "failed to register the event"); - ret = -1; - } - } -unlock: - pthread_mutex_unlock (&priv->lock); + GF_FREE(opaque); + return NULL; +} -err: - return ret; +static void +socket_fix_ssl_opts(rpc_transport_t *this, socket_private_t *priv, + uint16_t port) +{ + if (port == GF_DEFAULT_SOCKET_LISTEN_PORT) { + gf_log(this->name, GF_LOG_DEBUG, "%s SSL for portmapper connection", + priv->mgmt_ssl ? "enabling" : "disabling"); + priv->use_ssl = priv->mgmt_ssl; + } else if (priv->ssl_enabled && !priv->use_ssl) { + gf_log(this->name, GF_LOG_DEBUG, "re-enabling SSL for I/O connection"); + priv->use_ssl = _gf_true; + } } +/* + * If we might just be trying to connect prematurely, e.g. to a brick that's + * slow coming up, all we need is a simple retry. Don't worry about sleeping + * in some arbitrary thread. The connect(2) could already have the exact same + * effect, and we deal with it in that case so we can deal with it for sleep(2) + * as well. + */ +static int +connect_loop(int sockfd, const struct sockaddr *addr, socklen_t addrlen) +{ + int ret; + int connect_fails = 0; + + for (;;) { + ret = connect(sockfd, addr, addrlen); + if (ret >= 0) { + break; + } + if ((errno != ENOENT) || (++connect_fails >= 5)) { + break; + } + sleep(1); + } -int -socket_listen (rpc_transport_t *this) + return ret; +} + +static int +socket_connect(rpc_transport_t *this, int port) { - socket_private_t * priv = NULL; - int ret = -1; - int sock = -1; - struct sockaddr_storage sockaddr; - socklen_t sockaddr_len = 0; - peer_info_t *myinfo = NULL; - glusterfs_ctx_t *ctx = NULL; - sa_family_t sa_family = {0, }; + int ret = -1; + int th_ret = -1; + int sock = -1; + socket_private_t *priv = NULL; + socklen_t sockaddr_len = 0; + glusterfs_ctx_t *ctx = NULL; + sa_family_t sa_family = { + 0, + }; + char *local_addr = NULL; + union gf_sock_union sock_union; + struct sockaddr_in *addr = NULL; + gf_boolean_t refd = _gf_false; + socket_connect_error_state_t *arg = NULL; + pthread_t th_id = { + 0, + }; + gf_boolean_t ign_enoent = _gf_false; + gf_boolean_t connect_attempted = _gf_false; + + GF_VALIDATE_OR_GOTO("socket", this, err); + GF_VALIDATE_OR_GOTO("socket", this->private, err); + + priv = this->private; + ctx = this->ctx; + + if (!priv) { + gf_log_callingfn(this->name, GF_LOG_WARNING, + "connect() called on uninitialized transport"); + goto err; + } + + pthread_mutex_lock(&priv->out_lock); + { + if (priv->sock >= 0) { + gf_log_callingfn(this->name, GF_LOG_TRACE, + "connect () called on transport " + "already connected"); + errno = EINPROGRESS; + ret = -1; + goto unlock; + } - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); + gf_log(this->name, GF_LOG_TRACE, "connecting %p, sock=%d", this, + priv->sock); - priv = this->private; - myinfo = &this->myinfo; - ctx = this->ctx; + ret = socket_client_get_remote_sockaddr(this, &sock_union.sa, + &sockaddr_len, &sa_family); + if (ret < 0) { + /* logged inside client_get_remote_sockaddr */ + goto unlock; + } - pthread_mutex_lock (&priv->lock); - { - sock = priv->sock; + if (sa_family == AF_UNIX) { + priv->ssl_enabled = _gf_false; + priv->mgmt_ssl = _gf_false; + } else { + if (port > 0) { + sock_union.sin.sin_port = htons(port); + } + socket_fix_ssl_opts(this, priv, ntohs(sock_union.sin.sin_port)); + } + + memcpy(&this->peerinfo.sockaddr, &sock_union.storage, sockaddr_len); + this->peerinfo.sockaddr_len = sockaddr_len; + + priv->sock = sys_socket(sa_family, SOCK_STREAM, 0); + if (priv->sock < 0) { + gf_log(this->name, GF_LOG_ERROR, "socket creation failed (%s)", + strerror(errno)); + ret = -1; + goto unlock; } - pthread_mutex_unlock (&priv->lock); - if (sock != -1) { - gf_log_callingfn (this->name, GF_LOG_DEBUG, - "already listening"); - return ret; + /* Can't help if setting socket options fails. We can continue + * working nonetheless. + */ + if (priv->windowsize != 0) { + if (setsockopt(priv->sock, SOL_SOCKET, SO_RCVBUF, &priv->windowsize, + sizeof(priv->windowsize)) != 0) { + gf_log(this->name, GF_LOG_ERROR, + "setting receive window " + "size failed: %d: %d: %s", + priv->sock, priv->windowsize, strerror(errno)); + } + + if (setsockopt(priv->sock, SOL_SOCKET, SO_SNDBUF, &priv->windowsize, + sizeof(priv->windowsize)) != 0) { + gf_log(this->name, GF_LOG_ERROR, + "setting send window size " + "failed: %d: %d: %s", + priv->sock, priv->windowsize, strerror(errno)); + } } - ret = socket_server_get_local_sockaddr (this, SA (&sockaddr), - &sockaddr_len, &sa_family); - if (ret == -1) { - return ret; + /* Make sure we are not vulnerable to someone setting + * net.ipv6.bindv6only to 1 so that gluster services are + * available over IPv4 & IPv6. + */ +#ifdef IPV6_DEFAULT + int disable_v6only = 0; + if (setsockopt(priv->sock, IPPROTO_IPV6, IPV6_V6ONLY, + (void *)&disable_v6only, sizeof(disable_v6only)) < 0) { + gf_log(this->name, GF_LOG_WARNING, + "Error disabling sockopt IPV6_V6ONLY: \"%s\"", + strerror(errno)); } +#endif - pthread_mutex_lock (&priv->lock); - { - if (priv->sock != -1) { - gf_log (this->name, GF_LOG_DEBUG, - "already listening"); - goto unlock; + 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)); } + } - memcpy (&myinfo->sockaddr, &sockaddr, sockaddr_len); - myinfo->sockaddr_len = sockaddr_len; + 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)); + } + } - priv->sock = socket (sa_family, SOCK_STREAM, 0); + SA(&this->myinfo.sockaddr)->sa_family = SA(&this->peerinfo.sockaddr) + ->sa_family; - if (priv->sock == -1) { - gf_log (this->name, GF_LOG_ERROR, - "socket creation failed (%s)", - strerror (errno)); - goto unlock; - } + /* If a source addr is explicitly specified, use it */ + 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)); + } - /* Cant help if setting socket options fails. We can continue - * working nonetheless. - */ - if (setsockopt (priv->sock, SOL_SOCKET, SO_RCVBUF, - &priv->windowsize, - sizeof (priv->windowsize)) < 0) { - gf_log (this->name, GF_LOG_ERROR, - "setting receive window size failed: %d: %d: " - "%s", priv->sock, priv->windowsize, - strerror (errno)); - } + /* If client wants ENOENT to be ignored */ + ign_enoent = dict_get_str_boolean( + this->options, "transport.socket.ignore-enoent", _gf_false); - if (setsockopt (priv->sock, SOL_SOCKET, SO_SNDBUF, - &priv->windowsize, - sizeof (priv->windowsize)) < 0) { - gf_log (this->name, GF_LOG_ERROR, - "setting send window size failed: %d: %d: " - "%s", priv->sock, priv->windowsize, - strerror (errno)); - } + ret = client_bind(this, SA(&this->myinfo.sockaddr), + &this->myinfo.sockaddr_len, priv->sock); + if (ret < 0) { + gf_log(this->name, GF_LOG_WARNING, "client bind failed: %s", + strerror(errno)); + goto handler; + } - if (priv->nodelay) { - ret = __socket_nodelay (priv->sock); - if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "setsockopt() failed for NODELAY (%s)", - strerror (errno)); - } - } + /* make socket non-blocking for all types of sockets */ + if (!priv->bio) { + ret = __socket_nonblock(priv->sock); + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, "NBIO on %d failed (%s)", + priv->sock, strerror(errno)); + goto handler; + } else { + gf_log(this->name, GF_LOG_TRACE, + ">>> connect() with non-blocking IO for ALL"); + } + } + this->connect_failed = _gf_false; + priv->connect_failed = 0; + priv->connected = 0; - if (!priv->bio) { - ret = __socket_nonblock (priv->sock); + socket_dump_info(SA(&this->peerinfo.sockaddr), priv->is_server, + priv->use_ssl, priv->sock, this->name, + "connecting to"); - if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "NBIO on %d failed (%s)", - priv->sock, strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - } + if (ign_enoent) { + ret = connect_loop(priv->sock, SA(&this->peerinfo.sockaddr), + this->peerinfo.sockaddr_len); + } else { + ret = connect(priv->sock, SA(&this->peerinfo.sockaddr), + this->peerinfo.sockaddr_len); + } - ret = __socket_server_bind (this); + connect_attempted = _gf_true; - if (ret == -1) { - /* logged inside __socket_server_bind() */ - close (priv->sock); - priv->sock = -1; - goto unlock; - } + 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)); - if (priv->backlog) - ret = listen (priv->sock, priv->backlog); - else - ret = listen (priv->sock, 10); - - if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "could not set socket %d to listen mode (%s)", - priv->sock, strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } + /* connect failed with some other error than EINPROGRESS + so, getsockopt (... SO_ERROR ...), will not catch any + errors and return them to us, we need to remember this + state, and take actions in socket_event_handler + appropriately */ + /* TBD: What about ENOENT, we will do getsockopt there + as well, so how is that exempt from such a problem? */ + priv->connect_failed = 1; + this->connect_failed = _gf_true; - rpc_transport_ref (this); + goto handler; + } - priv->idx = event_register (ctx->event_pool, priv->sock, - socket_server_event_handler, - this, 1, 0); + 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 + */ + gf_log(this->name, + ((sa_family == AF_UNIX) ? GF_LOG_DEBUG : GF_LOG_ERROR), + "connection attempt on %s failed, (%s)", + this->peerinfo.identifier, strerror(errno)); + + /* connect failed with some other error than EINPROGRESS + so, getsockopt (... SO_ERROR ...), will not catch any + errors and return them to us, we need to remember this + state, and take actions in socket_event_handler + appropriately */ + /* TBD: What about ENOENT, we will do getsockopt there + as well, so how is that exempt from such a problem? */ + priv->connect_failed = 1; + + goto handler; + } else { + /* reset connect_failed so that any previous attempts + state is not carried forward */ + priv->connect_failed = 0; + ret = 0; + } - if (priv->idx == -1) { - gf_log (this->name, GF_LOG_WARNING, - "could not register socket %d with events", - priv->sock); - ret = -1; - close (priv->sock); - priv->sock = -1; - goto unlock; - } + handler: + if (ret < 0 && !connect_attempted) { + /* Ignore error from connect. epoll events + should be handled in the socket handler. shutdown(2) + will result in EPOLLERR, so cleanup is done in + socket_event_handler or socket_poller */ + shutdown(priv->sock, SHUT_RDWR); + ret = 0; + gf_log(this->name, GF_LOG_INFO, + "intentional client shutdown(%d, SHUT_RDWR)", priv->sock); } -unlock: - pthread_mutex_unlock (&priv->lock); -out: - return ret; -} + priv->connected = 0; + priv->is_server = _gf_false; + rpc_transport_ref(this); + refd = _gf_true; + + this->listener = this; + 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; " + "closing socket %d", + priv->sock); + sys_close(priv->sock); + priv->sock = -1; + ret = -1; + } + unlock: + sock = priv->sock; + } + pthread_mutex_unlock(&priv->out_lock); -int32_t -socket_submit_request (rpc_transport_t *this, rpc_transport_req_t *req) -{ - socket_private_t *priv = NULL; - int ret = -1; - char need_poll_out = 0; - char need_append = 1; - struct ioq *entry = NULL; - glusterfs_ctx_t *ctx = NULL; +err: + /* 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. + So transfer the ownership to separate thread for cleanup. + */ + arg = GF_CALLOC(1, sizeof(*arg), gf_sock_connect_error_state_t); + arg->this = THIS; + arg->trans = this; + arg->refd = refd; + th_ret = gf_thread_create_detached(&th_id, socket_connect_error_cbk, + arg, "scleanup"); + if (th_ret) { + /* Error will be logged by gf_thread_create_attached */ + gf_log(this->name, GF_LOG_ERROR, + "Thread creation " + "failed"); + GF_FREE(arg); + GF_ASSERT(0); + } - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); + ret = 0; + } - priv = this->private; - ctx = this->ctx; + return ret; +} - pthread_mutex_lock (&priv->lock); - { - if (priv->connected != 1) { - if (!priv->submit_log && !priv->connect_finish_log) { - gf_log (this->name, GF_LOG_INFO, - "not connected (priv->connected = %d)", - priv->connected); - priv->submit_log = 1; - } - goto unlock; - } +static int +socket_listen(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + int ret = -1; + int sock = -1; + struct sockaddr_storage sockaddr; + socklen_t sockaddr_len = 0; + peer_info_t *myinfo = NULL; + glusterfs_ctx_t *ctx = NULL; + sa_family_t sa_family = { + 0, + }; + + GF_VALIDATE_OR_GOTO("socket", this, out); + GF_VALIDATE_OR_GOTO("socket", this->private, out); + + priv = this->private; + myinfo = &this->myinfo; + ctx = this->ctx; + + pthread_mutex_lock(&priv->out_lock); + { + sock = priv->sock; + } + pthread_mutex_unlock(&priv->out_lock); - priv->submit_log = 0; - entry = __socket_ioq_new (this, &req->msg); - if (!entry) - goto unlock; + if (sock >= 0) { + gf_log_callingfn(this->name, GF_LOG_DEBUG, "already listening"); + return ret; + } - if (list_empty (&priv->ioq)) { - ret = __socket_ioq_churn_entry (this, entry); + ret = socket_server_get_local_sockaddr(this, SA(&sockaddr), &sockaddr_len, + &sa_family); + if (ret < 0) { + return ret; + } - if (ret == 0) - need_append = 0; + pthread_mutex_lock(&priv->out_lock); + { + if (priv->sock >= 0) { + gf_log(this->name, GF_LOG_DEBUG, "already listening"); + goto unlock; + } - if (ret > 0) - need_poll_out = 1; - } + memcpy(&myinfo->sockaddr, &sockaddr, sockaddr_len); + myinfo->sockaddr_len = sockaddr_len; - if (need_append) { - list_add_tail (&entry->list, &priv->ioq); - ret = 0; - } + priv->sock = sys_socket(sa_family, SOCK_STREAM, 0); - 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); - } + if (priv->sock < 0) { + gf_log(this->name, GF_LOG_ERROR, "socket creation failed (%s)", + strerror(errno)); + goto unlock; } -unlock: - pthread_mutex_unlock (&priv->lock); - -out: - return ret; -} + /* Can't help if setting socket options fails. We can continue + * working nonetheless. + */ + if (priv->windowsize != 0) { + if (setsockopt(priv->sock, SOL_SOCKET, SO_RCVBUF, &priv->windowsize, + sizeof(priv->windowsize)) != 0) { + gf_log(this->name, GF_LOG_ERROR, + "setting receive window size " + "failed: %d: %d: %s", + priv->sock, priv->windowsize, strerror(errno)); + } + + if (setsockopt(priv->sock, SOL_SOCKET, SO_SNDBUF, &priv->windowsize, + sizeof(priv->windowsize)) != 0) { + gf_log(this->name, GF_LOG_ERROR, + "setting send window size failed:" + " %d: %d: %s", + priv->sock, priv->windowsize, strerror(errno)); + } + } -int32_t -socket_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply) -{ - socket_private_t *priv = NULL; - int ret = -1; - char need_poll_out = 0; - char need_append = 1; - struct ioq *entry = NULL; - glusterfs_ctx_t *ctx = NULL; + if (priv->nodelay && (sa_family != AF_UNIX)) { + ret = __socket_nodelay(priv->sock); + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, + "setsockopt() failed for NODELAY (%s)", strerror(errno)); + } + } - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); + if (!priv->bio) { + ret = __socket_nonblock(priv->sock); + + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, + "NBIO on socket %d failed " + "(errno:%s); closing socket", + priv->sock, strerror(errno)); + sys_close(priv->sock); + priv->sock = -1; + goto unlock; + } + } - priv = this->private; - ctx = this->ctx; + /* coverity[SLEEP] */ + ret = __socket_server_bind(this); + + if (ret < 0) { + /* logged inside __socket_server_bind() */ + gf_log(this->name, GF_LOG_ERROR, + "__socket_server_bind failed;" + "closing socket %d", + priv->sock); + sys_close(priv->sock); + priv->sock = -1; + goto unlock; + } - pthread_mutex_lock (&priv->lock); - { - if (priv->connected != 1) { - if (!priv->submit_log && !priv->connect_finish_log) { - gf_log (this->name, GF_LOG_INFO, - "not connected (priv->connected = %d)", - priv->connected); - priv->submit_log = 1; - } - goto unlock; - } - priv->submit_log = 0; - entry = __socket_ioq_new (this, &reply->msg); - if (!entry) - goto unlock; - if (list_empty (&priv->ioq)) { - ret = __socket_ioq_churn_entry (this, entry); - - if (ret == 0) - need_append = 0; - - if (ret > 0) - need_poll_out = 1; - } + socket_dump_info(SA(&this->myinfo.sockaddr), priv->is_server, + priv->use_ssl, priv->sock, this->name, "listening on"); - if (need_append) { - list_add_tail (&entry->list, &priv->ioq); - ret = 0; - } + ret = listen(priv->sock, priv->backlog); - 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); - } + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, + "could not set socket %d to listen mode (errno:%s); " + "closing socket", + priv->sock, strerror(errno)); + sys_close(priv->sock); + priv->sock = -1; + goto unlock; } + rpc_transport_ref(this); + + 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, + "could not register socket %d with events; " + "closing socket", + priv->sock); + ret = -1; + sys_close(priv->sock); + priv->sock = -1; + goto unlock; + } + } unlock: - pthread_mutex_unlock (&priv->lock); + pthread_mutex_unlock(&priv->out_lock); out: - return ret; + return ret; } - -int32_t -socket_getpeername (rpc_transport_t *this, char *hostname, int hostlen) +static int32_t +socket_submit_outgoing_msg(rpc_transport_t *this, rpc_transport_msg_t *msg) { - int32_t ret = -1; + int ret = -1; + char need_poll_out = 0; + char need_append = 1; + struct ioq *entry = NULL; + glusterfs_ctx_t *ctx = NULL; + socket_private_t *priv = NULL; + + GF_VALIDATE_OR_GOTO("socket", this, out); + GF_VALIDATE_OR_GOTO("socket", this->private, out); + + priv = this->private; + ctx = this->ctx; + + pthread_mutex_lock(&priv->out_lock); + { + if (priv->connected != 1) { + if (!priv->submit_log && !priv->connect_finish_log) { + gf_log(this->name, GF_LOG_INFO, + "not connected (priv->connected = %d)", priv->connected); + priv->submit_log = 1; + } + goto unlock; + } - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", hostname, out); + priv->submit_log = 0; + entry = __socket_ioq_new(this, msg); + if (!entry) + goto unlock; - if (hostlen < (strlen (this->peerinfo.identifier) + 1)) { - goto out; + if (list_empty(&priv->ioq)) { + ret = __socket_ioq_churn_entry(this, entry); + + if (ret == 0) { + need_append = 0; + } + if (ret > 0) { + need_poll_out = 1; + } } - strcpy (hostname, this->peerinfo.identifier); - ret = 0; + if (need_append) { + list_add_tail(&entry->list, &priv->ioq); + ret = 0; + } + if (need_poll_out) { + /* first entry to wait. continue writing on POLLOUT */ + priv->idx = gf_event_select_on(ctx->event_pool, priv->sock, + priv->idx, -1, 1); + } + } +unlock: + pthread_mutex_unlock(&priv->out_lock); + out: - return ret; + return ret; } +static int32_t +socket_submit_request(rpc_transport_t *this, rpc_transport_req_t *req) +{ + return socket_submit_outgoing_msg(this, &req->msg); +} -int32_t -socket_getpeeraddr (rpc_transport_t *this, char *peeraddr, int addrlen, - struct sockaddr_storage *sa, socklen_t salen) +static int32_t +socket_submit_reply(rpc_transport_t *this, rpc_transport_reply_t *reply) { - int32_t ret = -1; + return socket_submit_outgoing_msg(this, &reply->msg); +} - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", sa, out); +static int32_t +socket_getpeername(rpc_transport_t *this, char *hostname, int hostlen) +{ + int32_t ret = -1; - *sa = this->peerinfo.sockaddr; + GF_VALIDATE_OR_GOTO("socket", this, out); + GF_VALIDATE_OR_GOTO("socket", hostname, out); - if (peeraddr != NULL) { - ret = socket_getpeername (this, peeraddr, addrlen); - } - ret = 0; + if (hostlen < (strlen(this->peerinfo.identifier) + 1)) { + goto out; + } + strcpy(hostname, this->peerinfo.identifier); + ret = 0; out: - return ret; + return ret; } - -int32_t -socket_getmyname (rpc_transport_t *this, char *hostname, int hostlen) +static int32_t +socket_getpeeraddr(rpc_transport_t *this, char *peeraddr, int addrlen, + struct sockaddr_storage *sa, socklen_t salen) { - int32_t ret = -1; + int32_t ret = -1; - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", hostname, out); + GF_VALIDATE_OR_GOTO("socket", this, out); + GF_VALIDATE_OR_GOTO("socket", sa, out); + ret = 0; - if (hostlen < (strlen (this->myinfo.identifier) + 1)) { - goto out; - } + *sa = this->peerinfo.sockaddr; - strcpy (hostname, this->myinfo.identifier); - ret = 0; + if (peeraddr != NULL) { + ret = socket_getpeername(this, peeraddr, addrlen); + } out: - return ret; + return ret; } +static int32_t +socket_getmyname(rpc_transport_t *this, char *hostname, int hostlen) +{ + int32_t ret = -1; + + GF_VALIDATE_OR_GOTO("socket", this, out); + GF_VALIDATE_OR_GOTO("socket", hostname, out); -int32_t -socket_getmyaddr (rpc_transport_t *this, char *myaddr, int addrlen, - struct sockaddr_storage *sa, socklen_t salen) + if (hostlen < (strlen(this->myinfo.identifier) + 1)) { + goto out; + } + + strcpy(hostname, this->myinfo.identifier); + ret = 0; +out: + return ret; +} + +static int32_t +socket_getmyaddr(rpc_transport_t *this, char *myaddr, int addrlen, + struct sockaddr_storage *sa, socklen_t salen) { - int32_t ret = 0; + int32_t ret = 0; - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", sa, out); + GF_VALIDATE_OR_GOTO("socket", this, out); + GF_VALIDATE_OR_GOTO("socket", sa, out); - *sa = this->myinfo.sockaddr; + *sa = this->myinfo.sockaddr; - if (myaddr != NULL) { - ret = socket_getmyname (this, myaddr, addrlen); - } + if (myaddr != NULL) { + ret = socket_getmyname(this, myaddr, addrlen); + } out: - return ret; + return ret; } +static int +socket_throttle(rpc_transport_t *this, gf_boolean_t onoff) +{ + socket_private_t *priv = NULL; + + priv = this->private; + + /* The way we implement throttling is by taking off + POLLIN event from the polled flags. This way we + never get called with the POLLIN event and therefore + will never read() any more data until throttling + is turned off. + */ + pthread_mutex_lock(&priv->out_lock); + { + /* Throttling is useless on a disconnected transport. In fact, + * it's dangerous since priv->idx and priv->sock are set to -1 + * on a disconnected transport, which breaks epoll's event to + * registered fd mapping. */ + + if (priv->connected == 1) + priv->idx = gf_event_select_on(this->ctx->event_pool, priv->sock, + priv->idx, (int)!onoff, -1); + } + pthread_mutex_unlock(&priv->out_lock); + return 0; +} struct rpc_transport_ops tops = { - .listen = socket_listen, - .connect = socket_connect, - .disconnect = socket_disconnect, - .submit_request = socket_submit_request, - .submit_reply = socket_submit_reply, - .get_peername = socket_getpeername, - .get_peeraddr = socket_getpeeraddr, - .get_myname = socket_getmyname, - .get_myaddr = socket_getmyaddr, + .listen = socket_listen, + .connect = socket_connect, + .disconnect = socket_disconnect, + .submit_request = socket_submit_request, + .submit_reply = socket_submit_reply, + .get_peername = socket_getpeername, + .get_peeraddr = socket_getpeeraddr, + .get_myname = socket_getmyname, + .get_myaddr = socket_getmyaddr, + .throttle = socket_throttle, }; int -reconfigure (rpc_transport_t *this, dict_t *options) +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; + socket_private_t *priv = NULL; + gf_boolean_t tmp_bool = _gf_false; + char *optstr = NULL; + int ret = -1; + uint32_t backlog = 0; + uint64_t windowsize = 0; + data_t *data; + + GF_VALIDATE_OR_GOTO("socket", this, out); + GF_VALIDATE_OR_GOTO("socket", this->private, out); + + priv = this->private; + + 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; + goto out; + } + gf_log(this->name, GF_LOG_DEBUG, + "Reconfigured transport.socket.keepalive"); - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); + priv->keepalive = tmp_bool; + } else + priv->keepalive = 1; - if (!this || !this->private) { - ret =-1; - goto out; + 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, + "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, + "Reconfigured transport.listen-backlog=%d", priv->backlog); + } + + 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_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_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_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); + goto out; } + } - priv = this->private; + priv->windowsize = (int)windowsize; - if (dict_get_str (this->options, "transport.socket.keepalive", - &optstr) == 0) { - if (gf_string2boolean (optstr, &tmp_bool) == -1) { - 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, "Reconfigured transport.socket.keepalive"); + data = dict_get_sizen(options, "non-blocking-io"); + if (data) { + optstr = data_to_str(data); - priv->keepalive = tmp_bool; + 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"); + tmp_bool = 1; } - else - priv->keepalive = 1; - ret = 0; + + if (!tmp_bool) { + priv->bio = 1; + gf_log(this->name, GF_LOG_WARNING, "disabling non-blocking IO"); + } + } + + if (!priv->bio) { + ret = __socket_nonblock(priv->sock); + if (ret != 0) { + gf_log(this->name, GF_LOG_WARNING, "NBIO on %d failed (%s)", + priv->sock, strerror(errno)); + goto out; + } + } + + ret = 0; out: - return ret; + return ret; +} +#if OPENSSL_VERSION_NUMBER < 0x1010000f +static pthread_mutex_t *lock_array = NULL; + +static void +locking_func(int mode, int type, const char *file, int line) +{ + if (mode & CRYPTO_UNLOCK) { + pthread_mutex_unlock(&lock_array[type]); + } else { + pthread_mutex_lock(&lock_array[type]); + } } -int -socket_init (rpc_transport_t *this) +#if OPENSSL_VERSION_NUMBER >= 0x1000000f +static void +threadid_func(CRYPTO_THREADID *id) { - socket_private_t *priv = NULL; - gf_boolean_t tmp_bool = 0; - uint64_t windowsize = GF_DEFAULT_SOCKET_WINDOW_SIZE; - char *optstr = NULL; - uint32_t keepalive = 0; - uint32_t backlog = 0; + /* + * We're not supposed to know whether a pthread_t is a number or a + * pointer, but we definitely need an unsigned long. Even though it + * happens to be an unsigned long already on Linux, do the cast just in + * case that's not so on another platform. Note that this can still + * break if any platforms are left where a pointer is larger than an + * unsigned long. In that case there's not much we can do; hopefully + * anyone porting to such a platform will be aware enough to notice the + * compile warnings about truncating the pointer value. + */ + CRYPTO_THREADID_set_numeric(id, (unsigned long)pthread_self()); +} +#else /* older openssl */ +static unsigned long +legacy_threadid_func(void) +{ + /* See comments above, it applies here too. */ + return (unsigned long)pthread_self(); +} +#endif /* OPENSSL_VERSION_NUMBER >= 0x1000000f */ +#endif /* OPENSSL_VERSION_NUMBER < 0x1010000f */ + +static void +init_openssl_mt(void) +{ + static gf_boolean_t initialized = _gf_false; + + if (initialized) { + /* this only needs to be initialized once GLOBALLY no + matter how many translators/sockets we end up with. */ + return; + } - if (this->private) { - gf_log_callingfn (this->name, GF_LOG_ERROR, - "double init attempted"); - return -1; + SSL_library_init(); + SSL_load_error_strings(); + + initialized = _gf_true; + +#if OPENSSL_VERSION_NUMBER < 0x1010000f + int num_locks = CRYPTO_num_locks(); + int i; + + lock_array = GF_CALLOC(num_locks, sizeof(pthread_mutex_t), + gf_sock_mt_lock_array); + if (lock_array) { + for (i = 0; i < num_locks; ++i) { + pthread_mutex_init(&lock_array[i], NULL); } +#if OPENSSL_VERSION_NUMBER >= 0x1000000f + CRYPTO_THREADID_set_callback(threadid_func); +#else /* older openssl */ + CRYPTO_set_id_callback(legacy_threadid_func); +#endif + CRYPTO_set_locking_callback(locking_func); + } +#endif +} + +static void __attribute__((destructor)) fini_openssl_mt(void) +{ +#if OPENSSL_VERSION_NUMBER < 0x1010000f + int i; + + if (!lock_array) { + return; + } + + CRYPTO_set_locking_callback(NULL); +#if OPENSSL_VERSION_NUMBER >= 0x1000000f + CRYPTO_THREADID_set_callback(NULL); +#else /* older openssl */ + CRYPTO_set_id_callback(NULL); +#endif + + for (i = 0; i < CRYPTO_num_locks(); ++i) { + pthread_mutex_destroy(&lock_array[i]); + } + + GF_FREE(lock_array); + lock_array = NULL; +#endif + + ERR_free_strings(); +} - priv = GF_CALLOC (1, sizeof (*priv), gf_common_mt_socket_private_t); - if (!priv) { - return -1; +/* 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; + } } + } - pthread_mutex_init (&priv->lock, NULL); + free(line); + fclose(fp); - priv->sock = -1; - priv->idx = -1; - priv->connected = -1; - priv->nodelay = 1; - priv->bio = 0; - priv->windowsize = GF_DEFAULT_SOCKET_WINDOW_SIZE; - INIT_LIST_HEAD (&priv->ioq); + return ret; +} - /* All the below section needs 'this->options' to be present */ - if (!this->options) - goto out; +static int +ssl_setup_connection_params(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + char *optstr = NULL; + static int session_id = 1; + int32_t cert_depth = DEFAULT_VERIFY_DEPTH; + char *cipher_list = DEFAULT_CIPHER_LIST; + char *dh_param = DEFAULT_DH_PARAM; + char *ec_curve = DEFAULT_EC_CURVE; + gf_boolean_t dh_flag = _gf_false; + + priv = this->private; + + if (priv->ssl_ctx != NULL) { + gf_log(this->name, GF_LOG_TRACE, "found old SSL context!"); + return 0; + } - if (dict_get (this->options, "non-blocking-io")) { - optstr = data_to_str (dict_get (this->options, - "non-blocking-io")); + 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_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, + SSL_ENABLED_OPT); + } + priv->ssl_own_cert = optstr; + } + priv->ssl_own_cert = gf_strdup(priv->ssl_own_cert); + + priv->ssl_private_key = DEFAULT_KEY_PATH; + 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, + SSL_ENABLED_OPT); + } + priv->ssl_private_key = optstr; + } + priv->ssl_private_key = gf_strdup(priv->ssl_private_key); + + priv->ssl_ca_list = DEFAULT_CA_PATH; + 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, + SSL_ENABLED_OPT); + } + priv->ssl_ca_list = optstr; + } + priv->ssl_ca_list = gf_strdup(priv->ssl_ca_list); + + 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) + priv->crl_path = NULL; + else + priv->crl_path = gf_strdup(optstr); + } - if (gf_string2boolean (optstr, &tmp_bool) == -1) { - gf_log (this->name, GF_LOG_ERROR, - "'non-blocking-io' takes only boolean options," - " not taking any action"); - tmp_bool = 1; - } + if (!priv->mgmt_ssl) { + 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, 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_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_sizen(this->options, SSL_EC_CURVE_OPT, &ec_curve)) { + gf_log(this->name, GF_LOG_INFO, "using EC curve %s", ec_curve); + } + + if (priv->ssl_enabled || priv->mgmt_ssl) { + BIO *bio = NULL; + +#if HAVE_TLS_METHOD + priv->ssl_meth = (SSL_METHOD *)TLS_method(); +#elif HAVE_TLSV1_2_METHOD + priv->ssl_meth = (SSL_METHOD *)TLSv1_2_method(); +#else +/* + * Nobody should use an OpenSSL so old it does not support TLS 1.2. + * If that is really required, build with -DUSE_INSECURE_OPENSSL + */ +#ifndef USE_INSECURE_OPENSSL +#error Old and insecure OpenSSL, use -DUSE_INSECURE_OPENSSL to use it anyway +#endif + /* SSLv23_method uses highest available protocol */ + priv->ssl_meth = SSLv23_method(); +#endif + priv->ssl_ctx = SSL_CTX_new(priv->ssl_meth); - if (!tmp_bool) { - priv->bio = 1; - gf_log (this->name, GF_LOG_WARNING, - "disabling non-blocking IO"); - } + SSL_CTX_set_options(priv->ssl_ctx, SSL_OP_NO_SSLv2); + SSL_CTX_set_options(priv->ssl_ctx, SSL_OP_NO_SSLv3); +#ifdef SSL_OP_NO_TICKET + SSL_CTX_set_options(priv->ssl_ctx, SSL_OP_NO_TICKET); +#endif +#ifdef SSL_OP_NO_COMPRESSION + SSL_CTX_set_options(priv->ssl_ctx, SSL_OP_NO_COMPRESSION); +#endif + /* 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); + } } - optstr = NULL; + if (bio != NULL) { +#ifdef HAVE_OPENSSL_DH_H + DH *dh; + unsigned long err; + + dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL); + BIO_free(bio); + if (dh != NULL) { + SSL_CTX_set_options(priv->ssl_ctx, SSL_OP_SINGLE_DH_USE); + SSL_CTX_set_tmp_dh(priv->ssl_ctx, dh); + DH_free(dh); + } else { + err = ERR_get_error(); + gf_log(this->name, GF_LOG_ERROR, + "failed to read DH param from %s: %s " + "DH ciphers are disabled.", + dh_param, ERR_error_string(err, NULL)); + } +#else /* HAVE_OPENSSL_DH_H */ + BIO_free(bio); + gf_log(this->name, GF_LOG_ERROR, "OpenSSL has no DH support"); +#endif /* HAVE_OPENSSL_DH_H */ + } - // By default, we enable NODELAY - if (dict_get (this->options, "transport.socket.nodelay")) { - optstr = data_to_str (dict_get (this->options, - "transport.socket.nodelay")); + if (ec_curve != NULL) { +#ifdef HAVE_OPENSSL_ECDH_H + EC_KEY *ecdh = NULL; + int nid; + unsigned long err; + + nid = OBJ_sn2nid(ec_curve); + if (nid != 0) + ecdh = EC_KEY_new_by_curve_name(nid); + + if (ecdh != NULL) { + SSL_CTX_set_options(priv->ssl_ctx, SSL_OP_SINGLE_ECDH_USE); + SSL_CTX_set_tmp_ecdh(priv->ssl_ctx, ecdh); + EC_KEY_free(ecdh); + } else { + err = ERR_get_error(); + gf_log(this->name, GF_LOG_ERROR, + "failed to load EC curve %s: %s. " + "ECDH ciphers are disabled.", + ec_curve, ERR_error_string(err, NULL)); + } +#else /* HAVE_OPENSSL_ECDH_H */ + gf_log(this->name, GF_LOG_ERROR, "OpenSSL has no ECDH support"); +#endif /* HAVE_OPENSSL_ECDH_H */ + } - if (gf_string2boolean (optstr, &tmp_bool) == -1) { - gf_log (this->name, GF_LOG_ERROR, - "'transport.socket.nodelay' takes only " - "boolean options, not taking any action"); - tmp_bool = 1; - } - if (!tmp_bool) { - priv->nodelay = 0; - gf_log (this->name, GF_LOG_DEBUG, - "disabling nodelay"); - } + /* This must be done after DH and ECDH setups */ + if (SSL_CTX_set_cipher_list(priv->ssl_ctx, cipher_list) == 0) { + gf_log(this->name, GF_LOG_ERROR, + "failed to find any valid ciphers"); + goto err; } + SSL_CTX_set_options(priv->ssl_ctx, SSL_OP_CIPHER_SERVER_PREFERENCE); - optstr = NULL; - if (dict_get_str (this->options, "transport.window-size", - &optstr) == 0) { - if (gf_string2bytesize (optstr, &windowsize) != 0) { - gf_log (this->name, GF_LOG_ERROR, - "invalid number format: %s", optstr); - return -1; - } + if (!SSL_CTX_use_certificate_chain_file(priv->ssl_ctx, + priv->ssl_own_cert)) { + gf_log(this->name, GF_LOG_ERROR, "could not load our cert at %s", + priv->ssl_own_cert); + ssl_dump_error_stack(this->name); + goto err; } - optstr = NULL; + if (!SSL_CTX_use_PrivateKey_file(priv->ssl_ctx, priv->ssl_private_key, + SSL_FILETYPE_PEM)) { + gf_log(this->name, GF_LOG_ERROR, "could not load private key at %s", + priv->ssl_private_key); + ssl_dump_error_stack(this->name); + goto err; + } - /* Enable Keep-alive by default. */ - priv->keepalive = 1; - priv->keepaliveintvl = 2; - priv->keepaliveidle = 20; - if (dict_get_str (this->options, "transport.socket.keepalive", - &optstr) == 0) { - if (gf_string2boolean (optstr, &tmp_bool) == -1) { - gf_log (this->name, GF_LOG_ERROR, - "'transport.socket.keepalive' takes only " - "boolean options, not taking any action"); - tmp_bool = 1; - } + if (!SSL_CTX_load_verify_locations(priv->ssl_ctx, priv->ssl_ca_list, + 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 (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, + (void *)&priv->ssl_session_id, + sizeof(priv->ssl_session_id)); + + SSL_CTX_set_verify(priv->ssl_ctx, SSL_VERIFY_PEER, 0); + + /* + * Since glusterfs shares the same settings for client-side + * and server-side of SSL, we need to ignore any certificate + * usage specification (SSL client vs SSL server), otherwise + * SSL connexions will fail with 'unsupported cerritifcate" + */ + SSL_CTX_set_purpose(priv->ssl_ctx, X509_PURPOSE_ANY); + } + return 0; + +err: + return -1; +} + +static int +socket_init(rpc_transport_t *this) +{ + socket_private_t *priv = NULL; + gf_boolean_t tmp_bool = 0; + uint64_t windowsize = GF_DEFAULT_SOCKET_WINDOW_SIZE; + char *optstr = NULL; + data_t *data; + + if (this->private) { + gf_log_callingfn(this->name, GF_LOG_ERROR, "double init attempted"); + return -1; + } + + priv = GF_CALLOC(1, sizeof(*priv), gf_common_mt_socket_private_t); + if (!priv) { + return -1; + } + + this->private = priv; + pthread_mutex_init(&priv->out_lock, NULL); + pthread_mutex_init(&priv->cond_lock, NULL); + pthread_cond_init(&priv->cond, NULL); + + /*GF_REF_INIT (priv, socket_poller_mayday);*/ + + priv->sock = -1; + priv->idx = -1; + priv->connected = -1; + priv->nodelay = 1; + priv->bio = 0; + priv->ssl_accepted = _gf_false; + priv->ssl_connected = _gf_false; + priv->windowsize = GF_DEFAULT_SOCKET_WINDOW_SIZE; + INIT_LIST_HEAD(&priv->ioq); + pthread_mutex_init(&priv->notify.lock, NULL); + pthread_cond_init(&priv->notify.cond, NULL); + + /* All the below section needs 'this->options' to be present */ + if (!this->options) + goto out; + + data = dict_get_sizen(this->options, "non-blocking-io"); + if (data) { + optstr = data_to_str(data); + + 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"); + tmp_bool = 1; + } - if (!tmp_bool) - priv->keepalive = 0; + if (!tmp_bool) { + priv->bio = 1; + gf_log(this->name, GF_LOG_WARNING, "disabling non-blocking IO"); } + } - if (dict_get_uint32 (this->options, - "transport.socket.keepalive-interval", - &keepalive) == 0) { - priv->keepaliveintvl = keepalive; + optstr = NULL; + + /* By default, we enable NODELAY */ + data = dict_get_sizen(this->options, "transport.socket.nodelay"); + if (data) { + optstr = data_to_str(data); + + 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"); + tmp_bool = 1; + } + if (!tmp_bool) { + priv->nodelay = 0; + gf_log(this->name, GF_LOG_DEBUG, "disabling nodelay"); + } + } + + optstr = NULL; + 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); + return -1; + } + } + + priv->windowsize = (int)windowsize; + + optstr = NULL; + /* Enable Keep-alive by default. */ + priv->keepalive = 1; + priv->keepaliveintvl = GF_KEEPALIVE_INTERVAL; + priv->keepaliveidle = GF_KEEPALIVE_TIME; + priv->keepalivecnt = GF_KEEPALIVE_COUNT; + 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"); + tmp_bool = 1; } - if (dict_get_uint32 (this->options, - "transport.socket.keepalive-time", - &keepalive) == 0) { - priv->keepaliveidle = keepalive; + if (!tmp_bool) + priv->keepalive = 0; + } + + 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 (priv->keepalive) { + if (dict_get_int32_sizen(this->options, + "transport.socket.keepalive-time", + &(priv->keepaliveidle)) != 0) { + priv->keepaliveidle = GF_KEEPALIVE_TIME; } - if (dict_get_uint32 (this->options, - "transport.socket.listen-backlog", - &backlog) == 0) { - priv->backlog = backlog; + if (dict_get_int32_sizen(this->options, + "transport.socket.keepalive-interval", + &(priv->keepaliveintvl)) != 0) { + priv->keepaliveintvl = GF_KEEPALIVE_INTERVAL; } - optstr = NULL; + 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", + &(priv->backlog)) != 0) { + priv->backlog = GLUSTERFS_SOCKET_LISTEN_BACKLOG; + } + + optstr = NULL; + + /* Check if socket read failures are to be logged */ + priv->read_fail_log = 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"); + } else if (tmp_bool == _gf_false) { + priv->read_fail_log = 0; + } + } - /* 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) { - gf_log (this->name, GF_LOG_WARNING, - "'transport.socket.read-fail-log' takes only " - "boolean options; logging socket read fails"); - } - else if (tmp_bool == _gf_false) { - priv->read_fail_log = 0; - } + priv->windowsize = (int)windowsize; + + priv->ssl_enabled = _gf_false; + 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"); } + } + priv->mgmt_ssl = this->ctx->secure_mgmt; + priv->srvr_ssl = this->ctx->secure_srvr; - priv->windowsize = (int)windowsize; + ssl_setup_connection_params(this); out: - this->private = priv; - - return 0; + this->private = priv; + return 0; } - void -fini (rpc_transport_t *this) +fini(rpc_transport_t *this) { - socket_private_t *priv = NULL; + socket_private_t *priv = NULL; - if (!this) - return; + if (!this) + return; - priv = this->private; - if (priv) { - if (priv->sock != -1) { - pthread_mutex_lock (&priv->lock); - { - __socket_ioq_flush (this); - __socket_reset (this); - } - pthread_mutex_unlock (&priv->lock); - } - gf_log (this->name, GF_LOG_TRACE, - "transport %p destroyed", this); + priv = this->private; + if (priv) { + if (priv->sock >= 0) { + pthread_mutex_lock(&priv->out_lock); + { + __socket_ioq_flush(priv); + __socket_reset(this); + } + pthread_mutex_unlock(&priv->out_lock); + } + gf_log(this->name, GF_LOG_TRACE, "transport %p destroyed", this); + + 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); - pthread_mutex_destroy (&priv->lock); - GF_FREE (priv); + 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; } - this->private = NULL; -} + if (priv->ssl_private_key) { + GF_FREE(priv->ssl_private_key); + } + if (priv->ssl_own_cert) { + GF_FREE(priv->ssl_own_cert); + } + if (priv->ssl_ca_list) { + GF_FREE(priv->ssl_ca_list); + } + GF_FREE(priv); + } + this->private = NULL; +} int32_t -init (rpc_transport_t *this) +init(rpc_transport_t *this) { - int ret = -1; + int ret = -1; - ret = socket_init (this); + init_openssl_mt(); - if (ret == -1) { - gf_log (this->name, GF_LOG_DEBUG, "socket_init() failed"); - } + ret = socket_init(this); - return ret; + if (ret < 0) { + gf_log(this->name, GF_LOG_DEBUG, "socket_init() failed"); + } + + return ret; } struct volume_options options[] = { - { .key = {"remote-port", - "transport.remote-port", - "transport.socket.remote-port"}, - .type = GF_OPTION_TYPE_INT - }, - { .key = {"transport.socket.listen-port", "listen-port"}, - .type = GF_OPTION_TYPE_INT - }, - { .key = {"transport.socket.bind-address", "bind-address" }, - .type = GF_OPTION_TYPE_INTERNET_ADDRESS - }, - { .key = {"transport.socket.connect-path", "connect-path"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"transport.socket.bind-path", "bind-path"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"transport.socket.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 = {"non-blocking-io"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"transport.window-size"}, - .type = GF_OPTION_TYPE_SIZET, - .min = GF_MIN_SOCKET_WINDOW_SIZE, - .max = GF_MAX_SOCKET_WINDOW_SIZE, - }, - { .key = {"transport.socket.nodelay"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"transport.socket.lowlat"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"transport.socket.keepalive"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"transport.socket.keepalive-interval"}, - .type = GF_OPTION_TYPE_INT - }, - { .key = {"transport.socket.keepalive-time"}, - .type = GF_OPTION_TYPE_INT - }, - { .key = {"transport.socket.listen-backlog"}, - .type = GF_OPTION_TYPE_INT - }, - { .key = {"transport.socket.read-fail-log"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {NULL} } -}; + {.key = {"remote-port", "transport.remote-port", + "transport.socket.remote-port"}, + .type = GF_OPTION_TYPE_INT}, + {.key = {"transport.socket.listen-port", "listen-port"}, + .type = GF_OPTION_TYPE_INT}, + {.key = {"transport.socket.bind-address", "bind-address"}, + .type = GF_OPTION_TYPE_INTERNET_ADDRESS}, + {.key = {"transport.socket.connect-path", "connect-path"}, + .type = GF_OPTION_TYPE_ANY}, + {.key = {"transport.socket.bind-path", "bind-path"}, + .type = GF_OPTION_TYPE_ANY}, + {.key = {"transport.socket.listen-path", "listen-path"}, + .type = GF_OPTION_TYPE_ANY}, + {.key = {"transport.address-family", "address-family"}, + .value = {"inet", "inet6", "unix", "inet-sdp"}, + .op_version = {GD_OP_VERSION_3_7_4}, + .type = GF_OPTION_TYPE_STR}, + {.key = {"non-blocking-io"}, .type = GF_OPTION_TYPE_BOOL}, + {.key = {"tcp-window-size"}, + .type = GF_OPTION_TYPE_SIZET, + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE, + .description = "Option to set TCP SEND/RECV BUFFER SIZE", + .min = GF_MIN_SOCKET_WINDOW_SIZE, + .max = GF_MAX_SOCKET_WINDOW_SIZE}, + { + .key = {"transport.listen-backlog"}, + .type = GF_OPTION_TYPE_SIZET, + .op_version = {GD_OP_VERSION_3_11_1}, + .flags = OPT_FLAG_SETTABLE, + .description = "This option uses the value of backlog argument that " + "defines the maximum length to which the queue of " + "pending connections for socket fd may grow.", + .default_value = "1024", + }, + {.key = {"transport.tcp-user-timeout"}, + .type = GF_OPTION_TYPE_INT, + .op_version = {GD_OP_VERSION_3_10_2}, + .default_value = TOSTRING(GF_NETWORK_TIMEOUT)}, + {.key = {"transport.socket.nodelay"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "1"}, + {.key = {"transport.socket.keepalive"}, + .type = GF_OPTION_TYPE_BOOL, + .op_version = {1}, + .default_value = "1"}, + {.key = {"transport.socket.keepalive-interval"}, + .type = GF_OPTION_TYPE_INT, + .op_version = {GD_OP_VERSION_3_10_2}, + .default_value = "2"}, + {.key = {"transport.socket.keepalive-time"}, + .type = GF_OPTION_TYPE_INT, + .op_version = {GD_OP_VERSION_3_10_2}, + .default_value = "20"}, + {.key = {"transport.socket.keepalive-count"}, + .type = GF_OPTION_TYPE_INT, + .op_version = {GD_OP_VERSION_3_10_2}, + .default_value = "9"}, + {.key = {"transport.socket.read-fail-log"}, .type = GF_OPTION_TYPE_BOOL}, + {.key = {SSL_ENABLED_OPT}, .type = GF_OPTION_TYPE_BOOL}, + {.key = {SSL_OWN_CERT_OPT}, .type = GF_OPTION_TYPE_STR}, + {.key = {SSL_PRIVATE_KEY_OPT}, .type = GF_OPTION_TYPE_STR}, + {.key = {SSL_CA_LIST_OPT}, .type = GF_OPTION_TYPE_STR}, + {.key = {SSL_CERT_DEPTH_OPT}, .type = GF_OPTION_TYPE_STR}, + {.key = {SSL_CIPHER_LIST_OPT}, .type = GF_OPTION_TYPE_STR}, + {.key = {SSL_DH_PARAM_OPT}, .type = GF_OPTION_TYPE_STR}, + {.key = {SSL_EC_CURVE_OPT}, .type = GF_OPTION_TYPE_STR}, + {.key = {SSL_CRL_PATH_OPT}, .type = GF_OPTION_TYPE_STR}, + {.key = {OWN_THREAD_OPT}, .type = GF_OPTION_TYPE_BOOL}, + {.key = {"ssl-own-cert"}, + .op_version = {GD_OP_VERSION_3_7_4}, + .flags = OPT_FLAG_SETTABLE, + .type = GF_OPTION_TYPE_STR, + .description = "SSL certificate. Ignored if SSL is not enabled."}, + {.key = {"ssl-private-key"}, + .op_version = {GD_OP_VERSION_3_7_4}, + .flags = OPT_FLAG_SETTABLE, + .type = GF_OPTION_TYPE_STR, + .description = "SSL private key. Ignored if SSL is not enabled."}, + {.key = {"ssl-ca-list"}, + .op_version = {GD_OP_VERSION_3_7_4}, + .flags = OPT_FLAG_SETTABLE, + .type = GF_OPTION_TYPE_STR, + .description = "SSL CA list. Ignored if SSL is not enabled."}, + {.key = {"ssl-cert-depth"}, + .type = GF_OPTION_TYPE_INT, + .op_version = {GD_OP_VERSION_3_6_0}, + .flags = OPT_FLAG_SETTABLE, + .description = "Maximum certificate-chain depth. If zero, the " + "peer's certificate itself must be in the local " + "certificate list. Otherwise, there may be up to N " + "signing certificates between the peer's and the " + "local list. Ignored if SSL is not enabled."}, + {.key = {"ssl-cipher-list"}, + .type = GF_OPTION_TYPE_STR, + .op_version = {GD_OP_VERSION_3_6_0}, + .flags = OPT_FLAG_SETTABLE, + .description = "Allowed SSL ciphers. Ignored if SSL is not enabled."}, + {.key = {"ssl-dh-param"}, + .type = GF_OPTION_TYPE_STR, + .op_version = {GD_OP_VERSION_3_7_4}, + .flags = OPT_FLAG_SETTABLE, + .description = "DH parameters file. Ignored if SSL is not enabled."}, + {.key = {"ssl-ec-curve"}, + .type = GF_OPTION_TYPE_STR, + .op_version = {GD_OP_VERSION_3_7_4}, + .flags = OPT_FLAG_SETTABLE, + .description = "ECDH curve name. Ignored if SSL is not enabled."}, + {.key = {"ssl-crl-path"}, + .type = GF_OPTION_TYPE_STR, + .op_version = {GD_OP_VERSION_3_7_4}, + .flags = OPT_FLAG_SETTABLE, + .description = "Path to directory containing CRL. " + "Ignored if SSL is not enabled."}, + {.key = {NULL}}}; diff --git a/rpc/rpc-transport/socket/src/socket.h b/rpc/rpc-transport/socket/src/socket.h index 7f0fb6bc356..8a2eda70605 100644 --- a/rpc/rpc-transport/socket/src/socket.h +++ b/rpc/rpc-transport/socket/src/socket.h @@ -1,203 +1,276 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _SOCKET_H #define _SOCKET_H - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" +#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 +#ifdef HAVE_OPENSSL_ECDH_H +#include <openssl/ecdh.h> #endif -#include "event.h" #include "rpc-transport.h" -#include "logging.h" -#include "dict.h" -#include "mem-pool.h" -#include "globals.h" #ifndef MAX_IOVEC #define MAX_IOVEC 16 #endif /* MAX_IOVEC */ -#define GF_DEFAULT_SOCKET_LISTEN_PORT GF_DEFAULT_BASE_PORT +#define GF_DEFAULT_SOCKET_LISTEN_PORT GF_DEFAULT_BASE_PORT #define RPC_MAX_FRAGMENT_SIZE 0x7fffffff -/* This is the size set through setsockopt for - * both the TCP receive window size and the - * send buffer size. - * Till the time iobuf size becomes configurable, this size is set to include - * two iobufs + the GlusterFS protocol headers. +/* The default window size will be 0, indicating not to set + * it to any size. Default size of Linux is found to be + * performance friendly. * Linux allows us to over-ride the max values for the system. * Should we over-ride them? Because if we set a value larger than the default * setsockopt will fail. Having larger values might be beneficial for * IB links. */ -#define GF_DEFAULT_SOCKET_WINDOW_SIZE (512 * GF_UNIT_KB) -#define GF_MAX_SOCKET_WINDOW_SIZE (1 * GF_UNIT_MB) -#define GF_MIN_SOCKET_WINDOW_SIZE (128 * GF_UNIT_KB) -#define GF_USE_DEFAULT_KEEPALIVE (-1) +#define GF_DEFAULT_SOCKET_WINDOW_SIZE (0) +#define GF_MAX_SOCKET_WINDOW_SIZE (1 * GF_UNIT_MB) +#define GF_MIN_SOCKET_WINDOW_SIZE (0) +#define GF_USE_DEFAULT_KEEPALIVE (-1) + +#define GF_KEEPALIVE_TIME (20) +#define GF_KEEPALIVE_INTERVAL (2) +#define GF_KEEPALIVE_COUNT (9) typedef enum { - SP_STATE_NADA = 0, - SP_STATE_COMPLETE, - SP_STATE_READING_FRAGHDR, - SP_STATE_READ_FRAGHDR, - SP_STATE_READING_FRAG, + SP_STATE_NADA = 0, + SP_STATE_COMPLETE, + SP_STATE_READING_FRAGHDR, + SP_STATE_READ_FRAGHDR, + SP_STATE_READING_FRAG, } sp_rpcrecord_state_t; typedef enum { - SP_STATE_RPCFRAG_INIT, - SP_STATE_READING_MSGTYPE, - SP_STATE_READ_MSGTYPE, + SP_STATE_RPCFRAG_INIT, + SP_STATE_READING_MSGTYPE, + SP_STATE_READ_MSGTYPE, + SP_STATE_NOTIFYING_XID } sp_rpcfrag_state_t; typedef enum { - SP_STATE_SIMPLE_MSG_INIT, - SP_STATE_READING_SIMPLE_MSG, + SP_STATE_SIMPLE_MSG_INIT, + SP_STATE_READING_SIMPLE_MSG, } sp_rpcfrag_simple_msg_state_t; typedef enum { - SP_STATE_VECTORED_REQUEST_INIT, - SP_STATE_READING_CREDBYTES, - SP_STATE_READ_CREDBYTES, /* read credential data. */ - SP_STATE_READING_VERFBYTES, - SP_STATE_READ_VERFBYTES, /* read verifier data */ - SP_STATE_READING_PROGHDR, - SP_STATE_READ_PROGHDR, - SP_STATE_READING_PROG, + SP_STATE_VECTORED_REQUEST_INIT, + SP_STATE_READING_CREDBYTES, + SP_STATE_READ_CREDBYTES, /* read credential data. */ + SP_STATE_READING_VERFBYTES, + SP_STATE_READ_VERFBYTES, /* read verifier data */ + SP_STATE_READING_PROGHDR, + SP_STATE_READ_PROGHDR, + SP_STATE_READING_PROGHDR_XDATA, + SP_STATE_READ_PROGHDR_XDATA, /* It's a bad "name" in the generic + RPC state machine, but greatly + aids code review (and xdata is + the only "consumer" of this state) + */ + SP_STATE_READING_PROG, } sp_rpcfrag_vectored_request_state_t; typedef enum { - SP_STATE_REQUEST_HEADER_INIT, - SP_STATE_READING_RPCHDR1, - SP_STATE_READ_RPCHDR1, /* read msg from beginning till and - * including credlen - */ + SP_STATE_REQUEST_HEADER_INIT, + SP_STATE_READING_RPCHDR1, + SP_STATE_READ_RPCHDR1, /* read msg from beginning till and + * including credlen + */ } sp_rpcfrag_request_header_state_t; struct ioq { - union { - struct list_head list; - struct { - struct ioq *next; - struct ioq *prev; - }; + union { + struct list_head list; + struct { + struct ioq *next; + struct ioq *prev; }; + }; - uint32_t fraghdr; - struct iovec vector[MAX_IOVEC]; - int count; - struct iovec *pending_vector; - int pending_count; - struct iobref *iobref; + struct iovec vector[MAX_IOVEC]; + struct iovec *pending_vector; + int count; + int pending_count; + struct iobref *iobref; + uint32_t fraghdr; + char _pad[4]; }; typedef struct { - sp_rpcfrag_request_header_state_t header_state; - sp_rpcfrag_vectored_request_state_t vector_state; - int vector_sizer_state; + sp_rpcfrag_request_header_state_t header_state; + sp_rpcfrag_vectored_request_state_t vector_state; + int vector_sizer_state; } sp_rpcfrag_request_state_t; typedef enum { - SP_STATE_VECTORED_REPLY_STATUS_INIT, - SP_STATE_READING_REPLY_STATUS, - SP_STATE_READ_REPLY_STATUS, + SP_STATE_VECTORED_REPLY_STATUS_INIT, + SP_STATE_READING_REPLY_STATUS, + SP_STATE_READ_REPLY_STATUS, } sp_rpcfrag_vectored_reply_status_state_t; typedef enum { - SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT, - SP_STATE_READING_PROC_HEADER, - SP_STATE_READ_PROC_HEADER, + SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT, + SP_STATE_READING_PROC_HEADER, + SP_STATE_READING_PROC_OPAQUE, + SP_STATE_READ_PROC_OPAQUE, + SP_STATE_READ_PROC_HEADER, } sp_rpcfrag_vectored_reply_accepted_success_state_t; typedef enum { - SP_STATE_ACCEPTED_REPLY_INIT, - SP_STATE_READING_REPLY_VERFLEN, - SP_STATE_READ_REPLY_VERFLEN, - SP_STATE_READING_REPLY_VERFBYTES, - SP_STATE_READ_REPLY_VERFBYTES, + SP_STATE_ACCEPTED_REPLY_INIT, + SP_STATE_READING_REPLY_VERFLEN, + SP_STATE_READ_REPLY_VERFLEN, + SP_STATE_READING_REPLY_VERFBYTES, + SP_STATE_READ_REPLY_VERFBYTES, } sp_rpcfrag_vectored_reply_accepted_state_t; typedef struct { - uint32_t accept_status; - sp_rpcfrag_vectored_reply_status_state_t status_state; - sp_rpcfrag_vectored_reply_accepted_state_t accepted_state; - sp_rpcfrag_vectored_reply_accepted_success_state_t accepted_success_state; + uint32_t accept_status; + sp_rpcfrag_vectored_reply_status_state_t status_state; + sp_rpcfrag_vectored_reply_accepted_state_t accepted_state; + sp_rpcfrag_vectored_reply_accepted_success_state_t accepted_success_state; } sp_rpcfrag_vectored_reply_state_t; +struct gf_sock_incoming_frag { + char *fragcurrent; + uint32_t bytes_read; + uint32_t remaining_size; + struct iovec vector; + struct iovec *pending_vector; + union { + sp_rpcfrag_request_state_t request; + sp_rpcfrag_vectored_reply_state_t reply; + } call_body; + + sp_rpcfrag_simple_msg_state_t simple_state; + sp_rpcfrag_state_t state; +}; + +#define GF_SOCKET_RA_MAX 1024 + +struct gf_sock_incoming { + char *proghdr_base_addr; + struct iobuf *iobuf; + size_t iobuf_size; + struct gf_sock_incoming_frag frag; + struct iovec vector[2]; + struct iovec payload_vector; + struct iobref *iobref; + rpc_request_info_t *request_info; + struct iovec *pending_vector; + int count; + int pending_count; + 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 struct { - int32_t sock; - int32_t idx; - unsigned char connected; // -1 = not connected. 0 = in progress. 1 = connected - char bio; - char connect_finish_log; - char submit_log; - union { - struct list_head ioq; - struct { - struct ioq *ioq_next; - struct ioq *ioq_prev; - }; - }; + union { + struct list_head ioq; struct { - sp_rpcrecord_state_t record_state; - struct { - char *fragcurrent; - uint32_t bytes_read; - uint32_t remaining_size; - struct iovec vector; - struct iovec *pending_vector; - union { - sp_rpcfrag_request_state_t request; - sp_rpcfrag_vectored_reply_state_t reply; - } call_body; - - sp_rpcfrag_simple_msg_state_t simple_state; - sp_rpcfrag_state_t state; - } frag; - struct iobuf *iobuf; - size_t iobuf_size; - struct iovec vector[2]; - int count; - struct iovec payload_vector; - struct iobref *iobref; - rpc_request_info_t *request_info; - struct iovec *pending_vector; - int pending_count; - uint32_t fraghdr; - char complete_record; - msg_type_t msg_type; - size_t total_bytes_read; - } incoming; - pthread_mutex_t lock; - int windowsize; - char lowlat; - char nodelay; - int keepalive; - int keepaliveidle; - int keepaliveintvl; - uint32_t backlog; - gf_boolean_t read_fail_log; -} socket_private_t; + struct ioq *ioq_next; + struct ioq *ioq_prev; + }; + }; + pthread_mutex_t out_lock; + pthread_mutex_t cond_lock; + pthread_cond_t cond; + int windowsize; + 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; + SSL_METHOD *ssl_meth; + SSL_CTX *ssl_ctx; + BIO *ssl_sbio; + SSL *ssl_ssl; + char *ssl_own_cert; + char *ssl_private_key; + char *ssl_ca_list; + 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; + 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. + * These are valid only when + * use_ssl is true. + */ + /* SSL_CTX is created for each transport. Since we are now using non- + * blocking mechanism for SSL_accept() and SSL_connect(), the SSL + * context is created on the first EPOLLIN event which may lead to + * SSL_ERROR_WANT_READ/SSL_ERROR_WANT_WRITE and may not complete the + * SSL connection at the first attempt. + * ssl_context_created is a flag to note that we've created the SSL + * context for the connection so that we don't blindly create any more + * while !ssl_accepted or !ssl_connected. + */ + gf_boolean_t ssl_context_created; + gf_boolean_t accepted; /* explicit flag to be set in + * socket_event_handler() for + * newly accepted socket + */ + char _pad[4]; +} socket_private_t; #endif diff --git a/rpc/xdr/src/.gitignore b/rpc/xdr/src/.gitignore new file mode 100644 index 00000000000..a0c8b7ca2b6 --- /dev/null +++ b/rpc/xdr/src/.gitignore @@ -0,0 +1,25 @@ +acl3-xdr.c +acl3-xdr.h +changelog-xdr.c +changelog-xdr.h +cli1-xdr.c +cli1-xdr.h +glusterd1-xdr.c +glusterd1-xdr.h +glusterfs3-xdr.c +glusterfs3-xdr.h +glusterfs4-xdr.c +glusterfs4-xdr.h +mount3udp.c +mount3udp.h +nlm4-xdr.c +nlm4-xdr.h +nlmcbk-xdr.c +nlmcbk-xdr.h +nsm-xdr.c +nsm-xdr.h +portmap-xdr.c +portmap-xdr.h +rpc-common-xdr.c +rpc-common-xdr.h +*-e diff --git a/rpc/xdr/src/Makefile.am b/rpc/xdr/src/Makefile.am index cabab3db62d..0e9c377ec93 100644 --- a/rpc/xdr/src/Makefile.am +++ b/rpc/xdr/src/Makefile.am @@ -1,24 +1,85 @@ +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 ${NFS_EXTRA_XDRS} + lib_LTLIBRARIES = libgfxdr.la -libgfxdr_la_CFLAGS = -fPIC -Wall -g -shared -nostartfiles $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) +libgfxdr_la_CFLAGS = -Wall $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) + +libgfxdr_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 \ + -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/rpc/rpc-lib/src \ + -I$(top_builddir)/rpc/xdr/src + +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 ${NFS_SRCS} +nodist_libgfxdr_la_SOURCES = $(XDRSOURCES) + +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) + +# 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 -libgfxdr_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 \ - -D_GNU_SOURCE -D$(GF_HOST_OS) \ - -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/rpc/rpc-lib/src +# 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 -libgfxdr_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ - $(top_builddir)/rpc/rpc-lib/src/libgfrpc.la -libgfxdr_la_SOURCES = xdr-generic.c \ - glusterfs3-xdr.c \ - cli1-xdr.c \ - glusterd1-xdr.c \ - portmap-xdr.c \ - xdr-nfs3.c msg-nfs3.c +# 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; -noinst_HEADERS = xdr-generic.h \ - glusterfs3-xdr.h glusterfs3.h \ - cli1-xdr.h \ - glusterd1-xdr.h \ - portmap-xdr.h \ - xdr-nfs3.h msg-nfs3.h +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 new file mode 100644 index 00000000000..7f7364971e6 --- /dev/null +++ b/rpc/xdr/src/acl3-xdr.x @@ -0,0 +1,52 @@ +/* + * Copyright (c) 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. + */ + +#ifdef RPC_XDR +%#include "rpc-pragmas.h" +#endif +%#include <glusterfs/compat.h> +%#include "xdr-nfs3.h" + +struct aclentry { + int type; + int uid; + int perm; +}; + +struct getaclargs { + netobj fh; + int mask; +}; + +struct getaclreply { + int status; + int attr_follows; + fattr3 attr; + int mask; + int aclcount; + aclentry aclentry<>; + int daclcount; + aclentry daclentry<>; +}; + +struct setaclargs { + netobj fh; + int mask; + int aclcount; + aclentry aclentry<>; + int daclcount; + aclentry daclentry<>; +}; + +struct setaclreply { + int status; + int attr_follows; + fattr3 attr; +}; diff --git a/rpc/xdr/src/changelog-xdr.x b/rpc/xdr/src/changelog-xdr.x new file mode 100644 index 00000000000..5956245d5ce --- /dev/null +++ b/rpc/xdr/src/changelog-xdr.x @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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. + */ + +#ifdef RPC_XDR +%#include "rpc-pragmas.h" +#endif +%#include <glusterfs/compat.h> + +/* XDR: libgfchangelog -> changelog */ + +struct changelog_probe_req { + unsigned int filter; + char sock[UNIX_PATH_MAX]; +}; + +struct changelog_probe_rsp { + int op_ret; +}; + +/* XDR: changelog -> libgfchangelog */ +struct changelog_event_req { + /* sequence number for the buffer */ + unsigned hyper seq; + + /* time of dispatch */ + unsigned hyper tv_sec; + unsigned hyper tv_usec; +}; + +struct changelog_event_rsp { + int op_ret; + + /* ack'd buffers sequence number */ + unsigned hyper seq; +}; diff --git a/rpc/xdr/src/cli1-xdr.c b/rpc/xdr/src/cli1-xdr.c deleted file mode 100644 index 56562ee3d00..00000000000 --- a/rpc/xdr/src/cli1-xdr.c +++ /dev/null @@ -1,451 +0,0 @@ -/* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include "xdr-common.h" -#include "compat.h" - -#if defined(__GNUC__) -#if __GNUC__ >= 4 -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif -#endif - -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#include "cli1-xdr.h" - -bool_t -xdr_gf_cli_defrag_type (XDR *xdrs, gf_cli_defrag_type *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_defrag_status_t (XDR *xdrs, gf_defrag_status_t *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cluster_type (XDR *xdrs, gf1_cluster_type *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_replace_op (XDR *xdrs, gf1_cli_replace_op *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_op_commands (XDR *xdrs, gf1_op_commands *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_quota_type (XDR *xdrs, gf_quota_type *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_friends_list (XDR *xdrs, gf1_cli_friends_list *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_get_volume (XDR *xdrs, gf1_cli_get_volume *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_sync_volume (XDR *xdrs, gf1_cli_sync_volume *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_op_flags (XDR *xdrs, gf1_cli_op_flags *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_gsync_set (XDR *xdrs, gf1_cli_gsync_set *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_stats_op (XDR *xdrs, gf1_cli_stats_op *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_top_op (XDR *xdrs, gf1_cli_top_op *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_cli_status_type (XDR *xdrs, gf_cli_status_type *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_cli_req (XDR *xdrs, gf_cli_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_cli_rsp (XDR *xdrs, gf_cli_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_probe_req (XDR *xdrs, gf1_cli_probe_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_probe_rsp (XDR *xdrs, gf1_cli_probe_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - - if (xdrs->x_op == XDR_ENCODE) { - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - - } else { - IXDR_PUT_LONG(buf, objp->op_ret); - IXDR_PUT_LONG(buf, objp->op_errno); - IXDR_PUT_LONG(buf, objp->port); - } - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - return TRUE; - } else if (xdrs->x_op == XDR_DECODE) { - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - - } else { - objp->op_ret = IXDR_GET_LONG(buf); - objp->op_errno = IXDR_GET_LONG(buf); - objp->port = IXDR_GET_LONG(buf); - } - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - return TRUE; - } - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_deprobe_req (XDR *xdrs, gf1_cli_deprobe_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - if (!xdr_int (xdrs, &objp->flags)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_deprobe_rsp (XDR *xdrs, gf1_cli_deprobe_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_peer_list_req (XDR *xdrs, gf1_cli_peer_list_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_peer_list_rsp (XDR *xdrs, gf1_cli_peer_list_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->friends.friends_val, (u_int *) &objp->friends.friends_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_fsm_log_req (XDR *xdrs, gf1_cli_fsm_log_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->name, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_fsm_log_rsp (XDR *xdrs, gf1_cli_fsm_log_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->fsm_log.fsm_log_val, (u_int *) &objp->fsm_log.fsm_log_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_getwd_req (XDR *xdrs, gf1_cli_getwd_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->unused)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_getwd_rsp (XDR *xdrs, gf1_cli_getwd_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_string (xdrs, &objp->wd, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_mount_req (XDR *xdrs, gf1_cli_mount_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->label, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_mount_rsp (XDR *xdrs, gf1_cli_mount_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_umount_req (XDR *xdrs, gf1_cli_umount_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->lazy)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_umount_rsp (XDR *xdrs, gf1_cli_umount_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - return TRUE; -} diff --git a/rpc/xdr/src/cli1-xdr.h b/rpc/xdr/src/cli1-xdr.h deleted file mode 100644 index d5593977d97..00000000000 --- a/rpc/xdr/src/cli1-xdr.h +++ /dev/null @@ -1,369 +0,0 @@ -/* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include "xdr-common.h" -#include "compat.h" - -#if defined(__GNUC__) -#if __GNUC__ >= 4 -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif -#endif - -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#ifndef _CLI1_XDR_H_RPCGEN -#define _CLI1_XDR_H_RPCGEN - -#include <rpc/rpc.h> - - -#ifdef __cplusplus -extern "C" { -#endif - - -enum gf_cli_defrag_type { - GF_DEFRAG_CMD_START = 1, - GF_DEFRAG_CMD_STOP = 1 + 1, - GF_DEFRAG_CMD_STATUS = 1 + 2, - GF_DEFRAG_CMD_START_LAYOUT_FIX = 1 + 3, - GF_DEFRAG_CMD_START_MIGRATE_DATA = 1 + 4, - GF_DEFRAG_CMD_START_MIGRATE_DATA_FORCE = 1 + 5, - GF_DEFRAG_CMD_START_FORCE = 1 + 6, -}; -typedef enum gf_cli_defrag_type gf_cli_defrag_type; - -enum gf_defrag_status_t { - GF_DEFRAG_STATUS_NOT_STARTED = 0, - GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED = 1, - GF_DEFRAG_STATUS_MIGRATE_DATA_STARTED = 2, - GF_DEFRAG_STATUS_STOPPED = 3, - GF_DEFRAG_STATUS_COMPLETE = 4, - GF_DEFRAG_STATUS_FAILED = 5, - GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE = 6, - GF_DEFRAG_STATUS_MIGRATE_DATA_COMPLETE = 7, - GF_DEFRAG_STATUS_PAUSED = 8, -}; -typedef enum gf_defrag_status_t gf_defrag_status_t; - -enum gf1_cluster_type { - GF_CLUSTER_TYPE_NONE = 0, - GF_CLUSTER_TYPE_STRIPE = 0 + 1, - GF_CLUSTER_TYPE_REPLICATE = 0 + 2, - GF_CLUSTER_TYPE_STRIPE_REPLICATE = 0 + 3, -}; -typedef enum gf1_cluster_type gf1_cluster_type; - -enum gf1_cli_replace_op { - GF_REPLACE_OP_NONE = 0, - GF_REPLACE_OP_START = 0 + 1, - GF_REPLACE_OP_COMMIT = 0 + 2, - GF_REPLACE_OP_PAUSE = 0 + 3, - GF_REPLACE_OP_ABORT = 0 + 4, - GF_REPLACE_OP_STATUS = 0 + 5, - GF_REPLACE_OP_COMMIT_FORCE = 0 + 6, -}; -typedef enum gf1_cli_replace_op gf1_cli_replace_op; - -enum gf1_op_commands { - GF_OP_CMD_NONE = 0, - GF_OP_CMD_START = 0 + 1, - GF_OP_CMD_COMMIT = 0 + 2, - GF_OP_CMD_PAUSE = 0 + 3, - GF_OP_CMD_ABORT = 0 + 4, - GF_OP_CMD_STATUS = 0 + 5, - GF_OP_CMD_COMMIT_FORCE = 0 + 6, -}; -typedef enum gf1_op_commands gf1_op_commands; - -enum gf_quota_type { - GF_QUOTA_OPTION_TYPE_NONE = 0, - GF_QUOTA_OPTION_TYPE_ENABLE = 0 + 1, - GF_QUOTA_OPTION_TYPE_DISABLE = 0 + 2, - GF_QUOTA_OPTION_TYPE_LIMIT_USAGE = 0 + 3, - GF_QUOTA_OPTION_TYPE_REMOVE = 0 + 4, - GF_QUOTA_OPTION_TYPE_LIST = 0 + 5, - GF_QUOTA_OPTION_TYPE_VERSION = 0 + 6, -}; -typedef enum gf_quota_type gf_quota_type; - -enum gf1_cli_friends_list { - GF_CLI_LIST_ALL = 1, -}; -typedef enum gf1_cli_friends_list gf1_cli_friends_list; - -enum gf1_cli_get_volume { - GF_CLI_GET_VOLUME_ALL = 1, - GF_CLI_GET_VOLUME = 1 + 1, - GF_CLI_GET_NEXT_VOLUME = 1 + 2, -}; -typedef enum gf1_cli_get_volume gf1_cli_get_volume; - -enum gf1_cli_sync_volume { - GF_CLI_SYNC_ALL = 1, -}; -typedef enum gf1_cli_sync_volume gf1_cli_sync_volume; - -enum gf1_cli_op_flags { - GF_CLI_FLAG_OP_FORCE = 1, -}; -typedef enum gf1_cli_op_flags gf1_cli_op_flags; - -enum gf1_cli_gsync_set { - GF_GSYNC_OPTION_TYPE_NONE = 0, - GF_GSYNC_OPTION_TYPE_START = 1, - GF_GSYNC_OPTION_TYPE_STOP = 2, - GF_GSYNC_OPTION_TYPE_CONFIG = 3, - GF_GSYNC_OPTION_TYPE_STATUS = 4, - GF_GSYNC_OPTION_TYPE_ROTATE = 5, -}; -typedef enum gf1_cli_gsync_set gf1_cli_gsync_set; - -enum gf1_cli_stats_op { - GF_CLI_STATS_NONE = 0, - GF_CLI_STATS_START = 1, - GF_CLI_STATS_STOP = 2, - GF_CLI_STATS_INFO = 3, - GF_CLI_STATS_TOP = 4, -}; -typedef enum gf1_cli_stats_op gf1_cli_stats_op; - -enum gf1_cli_top_op { - GF_CLI_TOP_NONE = 0, - GF_CLI_TOP_OPEN = 0 + 1, - GF_CLI_TOP_READ = 0 + 2, - GF_CLI_TOP_WRITE = 0 + 3, - GF_CLI_TOP_OPENDIR = 0 + 4, - GF_CLI_TOP_READDIR = 0 + 5, - GF_CLI_TOP_READ_PERF = 0 + 6, - GF_CLI_TOP_WRITE_PERF = 0 + 7, -}; -typedef enum gf1_cli_top_op gf1_cli_top_op; - -enum gf_cli_status_type { - GF_CLI_STATUS_NONE = 0x0000, - GF_CLI_STATUS_VOL = 0x0100, - GF_CLI_STATUS_ALL = 0x0200, - GF_CLI_STATUS_BRICK = 0x0400, - GF_CLI_STATUS_DETAIL = 0x0800, - GF_CLI_STATUS_VOL_DETAIL = 0x0900, - GF_CLI_STATUS_ALL_DETAIL = 0x0A00, - GF_CLI_STATUS_BRICK_DETAIL = 0x0C00, -}; -typedef enum gf_cli_status_type gf_cli_status_type; - -struct gf_cli_req { - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf_cli_req gf_cli_req; - -struct gf_cli_rsp { - int op_ret; - int op_errno; - char *op_errstr; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf_cli_rsp gf_cli_rsp; - -struct gf1_cli_probe_req { - char *hostname; - int port; -}; -typedef struct gf1_cli_probe_req gf1_cli_probe_req; - -struct gf1_cli_probe_rsp { - int op_ret; - int op_errno; - int port; - char *hostname; -}; -typedef struct gf1_cli_probe_rsp gf1_cli_probe_rsp; - -struct gf1_cli_deprobe_req { - char *hostname; - int port; - int flags; -}; -typedef struct gf1_cli_deprobe_req gf1_cli_deprobe_req; - -struct gf1_cli_deprobe_rsp { - int op_ret; - int op_errno; - char *hostname; -}; -typedef struct gf1_cli_deprobe_rsp gf1_cli_deprobe_rsp; - -struct gf1_cli_peer_list_req { - int flags; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf1_cli_peer_list_req gf1_cli_peer_list_req; - -struct gf1_cli_peer_list_rsp { - int op_ret; - int op_errno; - struct { - u_int friends_len; - char *friends_val; - } friends; -}; -typedef struct gf1_cli_peer_list_rsp gf1_cli_peer_list_rsp; - -struct gf1_cli_fsm_log_req { - char *name; -}; -typedef struct gf1_cli_fsm_log_req gf1_cli_fsm_log_req; - -struct gf1_cli_fsm_log_rsp { - int op_ret; - int op_errno; - char *op_errstr; - struct { - u_int fsm_log_len; - char *fsm_log_val; - } fsm_log; -}; -typedef struct gf1_cli_fsm_log_rsp gf1_cli_fsm_log_rsp; - -struct gf1_cli_getwd_req { - int unused; -}; -typedef struct gf1_cli_getwd_req gf1_cli_getwd_req; - -struct gf1_cli_getwd_rsp { - int op_ret; - int op_errno; - char *wd; -}; -typedef struct gf1_cli_getwd_rsp gf1_cli_getwd_rsp; - -struct gf1_cli_mount_req { - char *label; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf1_cli_mount_req gf1_cli_mount_req; - -struct gf1_cli_mount_rsp { - int op_ret; - int op_errno; - char *path; -}; -typedef struct gf1_cli_mount_rsp gf1_cli_mount_rsp; - -struct gf1_cli_umount_req { - int lazy; - char *path; -}; -typedef struct gf1_cli_umount_req gf1_cli_umount_req; - -struct gf1_cli_umount_rsp { - int op_ret; - int op_errno; -}; -typedef struct gf1_cli_umount_rsp gf1_cli_umount_rsp; - -/* the xdr functions */ - -#if defined(__STDC__) || defined(__cplusplus) -extern bool_t xdr_gf_cli_defrag_type (XDR *, gf_cli_defrag_type*); -extern bool_t xdr_gf_defrag_status_t (XDR *, gf_defrag_status_t*); -extern bool_t xdr_gf1_cluster_type (XDR *, gf1_cluster_type*); -extern bool_t xdr_gf1_cli_replace_op (XDR *, gf1_cli_replace_op*); -extern bool_t xdr_gf1_op_commands (XDR *, gf1_op_commands*); -extern bool_t xdr_gf_quota_type (XDR *, gf_quota_type*); -extern bool_t xdr_gf1_cli_friends_list (XDR *, gf1_cli_friends_list*); -extern bool_t xdr_gf1_cli_get_volume (XDR *, gf1_cli_get_volume*); -extern bool_t xdr_gf1_cli_sync_volume (XDR *, gf1_cli_sync_volume*); -extern bool_t xdr_gf1_cli_op_flags (XDR *, gf1_cli_op_flags*); -extern bool_t xdr_gf1_cli_gsync_set (XDR *, gf1_cli_gsync_set*); -extern bool_t xdr_gf1_cli_stats_op (XDR *, gf1_cli_stats_op*); -extern bool_t xdr_gf1_cli_top_op (XDR *, gf1_cli_top_op*); -extern bool_t xdr_gf_cli_status_type (XDR *, gf_cli_status_type*); -extern bool_t xdr_gf_cli_req (XDR *, gf_cli_req*); -extern bool_t xdr_gf_cli_rsp (XDR *, gf_cli_rsp*); -extern bool_t xdr_gf1_cli_probe_req (XDR *, gf1_cli_probe_req*); -extern bool_t xdr_gf1_cli_probe_rsp (XDR *, gf1_cli_probe_rsp*); -extern bool_t xdr_gf1_cli_deprobe_req (XDR *, gf1_cli_deprobe_req*); -extern bool_t xdr_gf1_cli_deprobe_rsp (XDR *, gf1_cli_deprobe_rsp*); -extern bool_t xdr_gf1_cli_peer_list_req (XDR *, gf1_cli_peer_list_req*); -extern bool_t xdr_gf1_cli_peer_list_rsp (XDR *, gf1_cli_peer_list_rsp*); -extern bool_t xdr_gf1_cli_fsm_log_req (XDR *, gf1_cli_fsm_log_req*); -extern bool_t xdr_gf1_cli_fsm_log_rsp (XDR *, gf1_cli_fsm_log_rsp*); -extern bool_t xdr_gf1_cli_getwd_req (XDR *, gf1_cli_getwd_req*); -extern bool_t xdr_gf1_cli_getwd_rsp (XDR *, gf1_cli_getwd_rsp*); -extern bool_t xdr_gf1_cli_mount_req (XDR *, gf1_cli_mount_req*); -extern bool_t xdr_gf1_cli_mount_rsp (XDR *, gf1_cli_mount_rsp*); -extern bool_t xdr_gf1_cli_umount_req (XDR *, gf1_cli_umount_req*); -extern bool_t xdr_gf1_cli_umount_rsp (XDR *, gf1_cli_umount_rsp*); - -#else /* K&R C */ -extern bool_t xdr_gf_cli_defrag_type (); -extern bool_t xdr_gf_defrag_status_t (); -extern bool_t xdr_gf1_cluster_type (); -extern bool_t xdr_gf1_cli_replace_op (); -extern bool_t xdr_gf1_op_commands (); -extern bool_t xdr_gf_quota_type (); -extern bool_t xdr_gf1_cli_friends_list (); -extern bool_t xdr_gf1_cli_get_volume (); -extern bool_t xdr_gf1_cli_sync_volume (); -extern bool_t xdr_gf1_cli_op_flags (); -extern bool_t xdr_gf1_cli_gsync_set (); -extern bool_t xdr_gf1_cli_stats_op (); -extern bool_t xdr_gf1_cli_top_op (); -extern bool_t xdr_gf_cli_status_type (); -extern bool_t xdr_gf_cli_req (); -extern bool_t xdr_gf_cli_rsp (); -extern bool_t xdr_gf1_cli_probe_req (); -extern bool_t xdr_gf1_cli_probe_rsp (); -extern bool_t xdr_gf1_cli_deprobe_req (); -extern bool_t xdr_gf1_cli_deprobe_rsp (); -extern bool_t xdr_gf1_cli_peer_list_req (); -extern bool_t xdr_gf1_cli_peer_list_rsp (); -extern bool_t xdr_gf1_cli_fsm_log_req (); -extern bool_t xdr_gf1_cli_fsm_log_rsp (); -extern bool_t xdr_gf1_cli_getwd_req (); -extern bool_t xdr_gf1_cli_getwd_rsp (); -extern bool_t xdr_gf1_cli_mount_req (); -extern bool_t xdr_gf1_cli_mount_rsp (); -extern bool_t xdr_gf1_cli_umount_req (); -extern bool_t xdr_gf1_cli_umount_rsp (); - -#endif /* K&R C */ - -#ifdef __cplusplus -} -#endif - -#endif /* !_CLI1_XDR_H_RPCGEN */ diff --git a/rpc/xdr/src/cli1-xdr.x b/rpc/xdr/src/cli1-xdr.x index 5697310ad7d..777cb0046a2 100644 --- a/rpc/xdr/src/cli1-xdr.x +++ b/rpc/xdr/src/cli1-xdr.x @@ -1,51 +1,89 @@ +/* + * Copyright (c) 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. + */ + +#ifdef RPC_XDR +%#include "rpc-pragmas.h" +#endif +%#include <glusterfs/compat.h> + enum gf_cli_defrag_type { - GF_DEFRAG_CMD_START = 1, + GF_DEFRAG_CMD_NONE = 0, + GF_DEFRAG_CMD_START, GF_DEFRAG_CMD_STOP, GF_DEFRAG_CMD_STATUS, GF_DEFRAG_CMD_START_LAYOUT_FIX, - GF_DEFRAG_CMD_START_MIGRATE_DATA, - GF_DEFRAG_CMD_START_MIGRATE_DATA_FORCE, - GF_DEFRAG_CMD_START_FORCE /* used by remove-brick data migration */ -} ; + GF_DEFRAG_CMD_START_FORCE, /* used by remove-brick data migration */ + GF_DEFRAG_CMD_START_TIER, + GF_DEFRAG_CMD_STATUS_TIER, + GF_DEFRAG_CMD_START_DETACH_TIER, + GF_DEFRAG_CMD_STOP_DETACH_TIER, + GF_DEFRAG_CMD_PAUSE_TIER, + GF_DEFRAG_CMD_RESUME_TIER, + GF_DEFRAG_CMD_DETACH_STATUS, + GF_DEFRAG_CMD_STOP_TIER, + GF_DEFRAG_CMD_DETACH_START, + GF_DEFRAG_CMD_DETACH_COMMIT, + GF_DEFRAG_CMD_DETACH_COMMIT_FORCE, + GF_DEFRAG_CMD_DETACH_STOP, + GF_DEFRAG_CMD_TYPE_MAX +}; enum gf_defrag_status_t { GF_DEFRAG_STATUS_NOT_STARTED, - GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED, - GF_DEFRAG_STATUS_MIGRATE_DATA_STARTED, + GF_DEFRAG_STATUS_STARTED, GF_DEFRAG_STATUS_STOPPED, GF_DEFRAG_STATUS_COMPLETE, GF_DEFRAG_STATUS_FAILED, + GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED, + GF_DEFRAG_STATUS_LAYOUT_FIX_STOPPED, GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE, - GF_DEFRAG_STATUS_MIGRATE_DATA_COMPLETE, - GF_DEFRAG_STATUS_PAUSED -} ; + GF_DEFRAG_STATUS_LAYOUT_FIX_FAILED, + GF_DEFRAG_STATUS_MAX +}; - enum gf1_cluster_type { +enum gf1_cluster_type { GF_CLUSTER_TYPE_NONE = 0, GF_CLUSTER_TYPE_STRIPE, GF_CLUSTER_TYPE_REPLICATE, - GF_CLUSTER_TYPE_STRIPE_REPLICATE -} ; - - enum gf1_cli_replace_op { - GF_REPLACE_OP_NONE = 0, - GF_REPLACE_OP_START, - GF_REPLACE_OP_COMMIT, - GF_REPLACE_OP_PAUSE, - GF_REPLACE_OP_ABORT, - GF_REPLACE_OP_STATUS, - GF_REPLACE_OP_COMMIT_FORCE -} ; + GF_CLUSTER_TYPE_STRIPE_REPLICATE, + GF_CLUSTER_TYPE_DISPERSE, + GF_CLUSTER_TYPE_TIER, + GF_CLUSTER_TYPE_MAX +}; + +enum gf_bitrot_type { + GF_BITROT_OPTION_TYPE_NONE = 0, + GF_BITROT_OPTION_TYPE_ENABLE, + GF_BITROT_OPTION_TYPE_DISABLE, + GF_BITROT_OPTION_TYPE_SCRUB_THROTTLE, + GF_BITROT_OPTION_TYPE_SCRUB_FREQ, + GF_BITROT_OPTION_TYPE_SCRUB, + 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 +}; enum gf1_op_commands { GF_OP_CMD_NONE = 0, GF_OP_CMD_START, GF_OP_CMD_COMMIT, - GF_OP_CMD_PAUSE, - GF_OP_CMD_ABORT, + GF_OP_CMD_STOP, GF_OP_CMD_STATUS, - GF_OP_CMD_COMMIT_FORCE -} ; + GF_OP_CMD_COMMIT_FORCE, + GF_OP_CMD_DETACH_START, + GF_OP_CMD_DETACH_COMMIT, + GF_OP_CMD_DETACH_COMMIT_FORCE, + GF_OP_CMD_STOP_DETACH_TIER +}; enum gf_quota_type { GF_QUOTA_OPTION_TYPE_NONE = 0, @@ -54,22 +92,34 @@ enum gf_quota_type { GF_QUOTA_OPTION_TYPE_LIMIT_USAGE, GF_QUOTA_OPTION_TYPE_REMOVE, GF_QUOTA_OPTION_TYPE_LIST, - GF_QUOTA_OPTION_TYPE_VERSION + GF_QUOTA_OPTION_TYPE_VERSION, + GF_QUOTA_OPTION_TYPE_ALERT_TIME, + GF_QUOTA_OPTION_TYPE_SOFT_TIMEOUT, + GF_QUOTA_OPTION_TYPE_HARD_TIMEOUT, + GF_QUOTA_OPTION_TYPE_DEFAULT_SOFT_LIMIT, + GF_QUOTA_OPTION_TYPE_VERSION_OBJECTS, + GF_QUOTA_OPTION_TYPE_LIMIT_OBJECTS, + GF_QUOTA_OPTION_TYPE_LIST_OBJECTS, + GF_QUOTA_OPTION_TYPE_REMOVE_OBJECTS, + GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS, + GF_QUOTA_OPTION_TYPE_UPGRADE, + GF_QUOTA_OPTION_TYPE_MAX }; enum gf1_cli_friends_list { - GF_CLI_LIST_ALL = 1 -} ; + GF_CLI_LIST_PEERS = 1, + GF_CLI_LIST_POOL_NODES = 2 +}; enum gf1_cli_get_volume { GF_CLI_GET_VOLUME_ALL = 1, GF_CLI_GET_VOLUME, GF_CLI_GET_NEXT_VOLUME -} ; +}; enum gf1_cli_sync_volume { GF_CLI_SYNC_ALL = 1 -} ; +}; enum gf1_cli_op_flags { GF_CLI_FLAG_OP_FORCE = 1 @@ -81,7 +131,11 @@ enum gf1_cli_gsync_set { GF_GSYNC_OPTION_TYPE_STOP, GF_GSYNC_OPTION_TYPE_CONFIG, GF_GSYNC_OPTION_TYPE_STATUS, - GF_GSYNC_OPTION_TYPE_ROTATE + GF_GSYNC_OPTION_TYPE_ROTATE, + GF_GSYNC_OPTION_TYPE_CREATE, + GF_GSYNC_OPTION_TYPE_DELETE, + GF_GSYNC_OPTION_TYPE_PAUSE, + GF_GSYNC_OPTION_TYPE_RESUME }; enum gf1_cli_stats_op { @@ -92,6 +146,19 @@ enum gf1_cli_stats_op { GF_CLI_STATS_TOP = 4 }; +enum gf1_cli_info_op { + GF_CLI_INFO_NONE = 0, + GF_CLI_INFO_ALL = 1, + GF_CLI_INFO_INCREMENTAL = 2, + GF_CLI_INFO_CUMULATIVE = 3, + GF_CLI_INFO_CLEAR = 4 +}; + +enum gf_cli_get_state_op { + GF_CLI_GET_STATE_DETAIL = 1, + GF_CLI_GET_STATE_VOLOPTS = 2 +}; + enum gf1_cli_top_op { GF_CLI_TOP_NONE = 0, GF_CLI_TOP_OPEN, @@ -106,61 +173,95 @@ enum gf1_cli_top_op { /* The unconventional hex numbers help us perform bit-wise operations which reduces complexity */ enum gf_cli_status_type { - GF_CLI_STATUS_NONE = 0x0000, - GF_CLI_STATUS_VOL = 0x0100, - GF_CLI_STATUS_ALL = 0x0200, - GF_CLI_STATUS_BRICK = 0x0400, - GF_CLI_STATUS_DETAIL = 0x0800, - GF_CLI_STATUS_VOL_DETAIL = 0x0900, - GF_CLI_STATUS_ALL_DETAIL = 0x0A00, - GF_CLI_STATUS_BRICK_DETAIL = 0x0C00 + GF_CLI_STATUS_NONE = 0x000000, + GF_CLI_STATUS_MEM = 0x000001, /*000000000000001*/ + GF_CLI_STATUS_CLIENTS = 0x000002, /*000000000000010*/ + GF_CLI_STATUS_INODE = 0x000004, /*000000000000100*/ + GF_CLI_STATUS_FD = 0x000008, /*000000000001000*/ + GF_CLI_STATUS_CALLPOOL = 0x000010, /*000000000010000*/ + GF_CLI_STATUS_DETAIL = 0x000020, /*000000000100000*/ + GF_CLI_STATUS_TASKS = 0x000040, /*00000001000000*/ + GF_CLI_STATUS_CLIENT_LIST = 0x000080, /*00000010000000*/ + GF_CLI_STATUS_MASK = 0x0000FF, /*000000011111111 Used to get the op*/ + GF_CLI_STATUS_VOL = 0x000100, /*00000000100000000*/ + GF_CLI_STATUS_ALL = 0x000200, /*00000001000000000*/ + GF_CLI_STATUS_BRICK = 0x000400, /*00000010000000000*/ + GF_CLI_STATUS_NFS = 0x000800, /*00000100000000000*/ + GF_CLI_STATUS_SHD = 0x001000, /*00001000000000000*/ + GF_CLI_STATUS_QUOTAD = 0x002000, /*00010000000000000*/ + GF_CLI_STATUS_SNAPD = 0x004000, /*00100000000000000*/ + GF_CLI_STATUS_BITD = 0x008000, /*01000000000000000*/ + GF_CLI_STATUS_SCRUB = 0x010000, /*10000000000000000*/ + GF_CLI_STATUS_TIERD = 0x020000 /*100000000000000000*/ }; - struct gf_cli_req { - opaque dict<>; -} ; +/* Identifiers for snapshot clis */ +enum gf1_cli_snapshot { + GF_SNAP_OPTION_TYPE_NONE = 0, + GF_SNAP_OPTION_TYPE_CREATE, + GF_SNAP_OPTION_TYPE_DELETE, + GF_SNAP_OPTION_TYPE_RESTORE, + GF_SNAP_OPTION_TYPE_ACTIVATE, + GF_SNAP_OPTION_TYPE_DEACTIVATE, + GF_SNAP_OPTION_TYPE_LIST, + GF_SNAP_OPTION_TYPE_STATUS, + GF_SNAP_OPTION_TYPE_CONFIG, + GF_SNAP_OPTION_TYPE_CLONE, + GF_SNAP_OPTION_TYPE_INFO +}; - struct gf_cli_rsp { - int op_ret; - int op_errno; - string op_errstr<>; - opaque dict<>; -} ; +enum gf1_cli_snapshot_info { + GF_SNAP_INFO_TYPE_ALL = 0, + GF_SNAP_INFO_TYPE_SNAP, + GF_SNAP_INFO_TYPE_VOL +}; - struct gf1_cli_probe_req { - string hostname<>; - int port; -} ; +enum gf1_cli_snapshot_config { + GF_SNAP_CONFIG_TYPE_NONE = 0, + GF_SNAP_CONFIG_TYPE_SET, + GF_SNAP_CONFIG_DISPLAY +}; - struct gf1_cli_probe_rsp { - int op_ret; - int op_errno; - int port; - string hostname<>; -} ; +enum gf1_cli_snapshot_status { + GF_SNAP_STATUS_TYPE_ALL = 0, + GF_SNAP_STATUS_TYPE_SNAP, + GF_SNAP_STATUS_TYPE_VOL, + GF_SNAP_STATUS_TYPE_ITER +}; - struct gf1_cli_deprobe_req { - string hostname<>; - int port; - int flags; -} ; +/* Changing order of GF_SNAP_DELETE_TYPE_VOL * + * and GF_SNAP_DELETE_TYPE_SNAP so that they don't * + * overlap with the enums of GF_SNAP_STATUS_TYPE_SNAP, * + * and GF_SNAP_STATUS_TYPE_VOL * + */ +enum gf1_cli_snapshot_delete { + GF_SNAP_DELETE_TYPE_ALL = 0, + GF_SNAP_DELETE_TYPE_VOL = 1, + GF_SNAP_DELETE_TYPE_SNAP = 2, + GF_SNAP_DELETE_TYPE_ITER = 3 +}; - struct gf1_cli_deprobe_rsp { +struct gf_cli_req { + opaque dict<>; +}; + + struct gf_cli_rsp { int op_ret; int op_errno; - string hostname<>; -} ; + string op_errstr<>; + opaque dict<>; +}; struct gf1_cli_peer_list_req { int flags; opaque dict<>; -} ; +}; struct gf1_cli_peer_list_rsp { int op_ret; int op_errno; opaque friends<>; -} ; +}; struct gf1_cli_fsm_log_req { string name<>; @@ -175,7 +276,7 @@ struct gf1_cli_fsm_log_rsp { struct gf1_cli_getwd_req { int unused; -} ; +}; struct gf1_cli_getwd_rsp { int op_ret; diff --git a/rpc/xdr/src/glusterd1-xdr.c b/rpc/xdr/src/glusterd1-xdr.c deleted file mode 100644 index a5438d23e3f..00000000000 --- a/rpc/xdr/src/glusterd1-xdr.c +++ /dev/null @@ -1,451 +0,0 @@ -/* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include "xdr-common.h" -#include "compat.h" - -#if defined(__GNUC__) -#if __GNUC__ >= 4 -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif -#endif - -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#include "glusterd1-xdr.h" - -bool_t -xdr_glusterd_volume_status (XDR *xdrs, glusterd_volume_status *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_probe_req (XDR *xdrs, gd1_mgmt_probe_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_probe_rsp (XDR *xdrs, gd1_mgmt_probe_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_friend_req (XDR *xdrs, gd1_mgmt_friend_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->vols.vols_val, (u_int *) &objp->vols.vols_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_friend_rsp (XDR *xdrs, gd1_mgmt_friend_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_unfriend_req (XDR *xdrs, gd1_mgmt_unfriend_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_unfriend_rsp (XDR *xdrs, gd1_mgmt_unfriend_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_cluster_lock_req (XDR *xdrs, gd1_mgmt_cluster_lock_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_cluster_lock_rsp (XDR *xdrs, gd1_mgmt_cluster_lock_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_cluster_unlock_req (XDR *xdrs, gd1_mgmt_cluster_unlock_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_cluster_unlock_rsp (XDR *xdrs, gd1_mgmt_cluster_unlock_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_stage_op_req (XDR *xdrs, gd1_mgmt_stage_op_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_int (xdrs, &objp->op)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->buf.buf_val, (u_int *) &objp->buf.buf_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_stage_op_rsp (XDR *xdrs, gd1_mgmt_stage_op_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - - if (xdrs->x_op == XDR_ENCODE) { - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - - } else { - IXDR_PUT_LONG(buf, objp->op); - IXDR_PUT_LONG(buf, objp->op_ret); - IXDR_PUT_LONG(buf, objp->op_errno); - } - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; - } else if (xdrs->x_op == XDR_DECODE) { - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - - } else { - objp->op = IXDR_GET_LONG(buf); - objp->op_ret = IXDR_GET_LONG(buf); - objp->op_errno = IXDR_GET_LONG(buf); - } - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; - } - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_int (xdrs, &objp->op)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_commit_op_req (XDR *xdrs, gd1_mgmt_commit_op_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_int (xdrs, &objp->op)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->buf.buf_val, (u_int *) &objp->buf.buf_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_commit_op_rsp (XDR *xdrs, gd1_mgmt_commit_op_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - - if (xdrs->x_op == XDR_ENCODE) { - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - - } else { - IXDR_PUT_LONG(buf, objp->op); - IXDR_PUT_LONG(buf, objp->op_ret); - IXDR_PUT_LONG(buf, objp->op_errno); - } - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; - } else if (xdrs->x_op == XDR_DECODE) { - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - - } else { - objp->op = IXDR_GET_LONG(buf); - objp->op_ret = IXDR_GET_LONG(buf); - objp->op_errno = IXDR_GET_LONG(buf); - } - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; - } - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_int (xdrs, &objp->op)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_friend_update (XDR *xdrs, gd1_mgmt_friend_update *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->friends.friends_val, (u_int *) &objp->friends.friends_len, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_friend_update_rsp (XDR *xdrs, gd1_mgmt_friend_update_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_vector (xdrs, (char *)objp->uuid, 16, - sizeof (u_char), (xdrproc_t) xdr_u_char)) - return FALSE; - if (!xdr_int (xdrs, &objp->op)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_brick_op_req (XDR *xdrs, gd1_mgmt_brick_op_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->name, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->op)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->input.input_val, (u_int *) &objp->input.input_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gd1_mgmt_brick_op_rsp (XDR *xdrs, gd1_mgmt_brick_op_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->output.output_val, (u_int *) &objp->output.output_len, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; -} diff --git a/rpc/xdr/src/glusterd1-xdr.h b/rpc/xdr/src/glusterd1-xdr.h deleted file mode 100644 index 14c41baffba..00000000000 --- a/rpc/xdr/src/glusterd1-xdr.h +++ /dev/null @@ -1,263 +0,0 @@ -/* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include "xdr-common.h" -#include "compat.h" - -#if defined(__GNUC__) -#if __GNUC__ >= 4 -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif -#endif - -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#ifndef _GLUSTERD1_XDR_H_RPCGEN -#define _GLUSTERD1_XDR_H_RPCGEN - -#include <rpc/rpc.h> - - -#ifdef __cplusplus -extern "C" { -#endif - - -enum glusterd_volume_status { - GLUSTERD_STATUS_NONE = 0, - GLUSTERD_STATUS_STARTED = 0 + 1, - GLUSTERD_STATUS_STOPPED = 0 + 2, -}; -typedef enum glusterd_volume_status glusterd_volume_status; - -struct gd1_mgmt_probe_req { - u_char uuid[16]; - char *hostname; - int port; -}; -typedef struct gd1_mgmt_probe_req gd1_mgmt_probe_req; - -struct gd1_mgmt_probe_rsp { - u_char uuid[16]; - char *hostname; - int port; - int op_ret; - int op_errno; -}; -typedef struct gd1_mgmt_probe_rsp gd1_mgmt_probe_rsp; - -struct gd1_mgmt_friend_req { - u_char uuid[16]; - char *hostname; - int port; - struct { - u_int vols_len; - char *vols_val; - } vols; -}; -typedef struct gd1_mgmt_friend_req gd1_mgmt_friend_req; - -struct gd1_mgmt_friend_rsp { - u_char uuid[16]; - char *hostname; - int op_ret; - int op_errno; - int port; -}; -typedef struct gd1_mgmt_friend_rsp gd1_mgmt_friend_rsp; - -struct gd1_mgmt_unfriend_req { - u_char uuid[16]; - char *hostname; - int port; -}; -typedef struct gd1_mgmt_unfriend_req gd1_mgmt_unfriend_req; - -struct gd1_mgmt_unfriend_rsp { - u_char uuid[16]; - char *hostname; - int op_ret; - int op_errno; - int port; -}; -typedef struct gd1_mgmt_unfriend_rsp gd1_mgmt_unfriend_rsp; - -struct gd1_mgmt_cluster_lock_req { - u_char uuid[16]; -}; -typedef struct gd1_mgmt_cluster_lock_req gd1_mgmt_cluster_lock_req; - -struct gd1_mgmt_cluster_lock_rsp { - u_char uuid[16]; - int op_ret; - int op_errno; -}; -typedef struct gd1_mgmt_cluster_lock_rsp gd1_mgmt_cluster_lock_rsp; - -struct gd1_mgmt_cluster_unlock_req { - u_char uuid[16]; -}; -typedef struct gd1_mgmt_cluster_unlock_req gd1_mgmt_cluster_unlock_req; - -struct gd1_mgmt_cluster_unlock_rsp { - u_char uuid[16]; - int op_ret; - int op_errno; -}; -typedef struct gd1_mgmt_cluster_unlock_rsp gd1_mgmt_cluster_unlock_rsp; - -struct gd1_mgmt_stage_op_req { - u_char uuid[16]; - int op; - struct { - u_int buf_len; - char *buf_val; - } buf; -}; -typedef struct gd1_mgmt_stage_op_req gd1_mgmt_stage_op_req; - -struct gd1_mgmt_stage_op_rsp { - u_char uuid[16]; - int op; - int op_ret; - int op_errno; - char *op_errstr; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gd1_mgmt_stage_op_rsp gd1_mgmt_stage_op_rsp; - -struct gd1_mgmt_commit_op_req { - u_char uuid[16]; - int op; - struct { - u_int buf_len; - char *buf_val; - } buf; -}; -typedef struct gd1_mgmt_commit_op_req gd1_mgmt_commit_op_req; - -struct gd1_mgmt_commit_op_rsp { - u_char uuid[16]; - int op; - int op_ret; - int op_errno; - struct { - u_int dict_len; - char *dict_val; - } dict; - char *op_errstr; -}; -typedef struct gd1_mgmt_commit_op_rsp gd1_mgmt_commit_op_rsp; - -struct gd1_mgmt_friend_update { - u_char uuid[16]; - struct { - u_int friends_len; - char *friends_val; - } friends; - int port; -}; -typedef struct gd1_mgmt_friend_update gd1_mgmt_friend_update; - -struct gd1_mgmt_friend_update_rsp { - u_char uuid[16]; - int op; - int op_ret; - int op_errno; -}; -typedef struct gd1_mgmt_friend_update_rsp gd1_mgmt_friend_update_rsp; - -struct gd1_mgmt_brick_op_req { - char *name; - int op; - struct { - u_int input_len; - char *input_val; - } input; -}; -typedef struct gd1_mgmt_brick_op_req gd1_mgmt_brick_op_req; - -struct gd1_mgmt_brick_op_rsp { - int op_ret; - int op_errno; - struct { - u_int output_len; - char *output_val; - } output; - char *op_errstr; -}; -typedef struct gd1_mgmt_brick_op_rsp gd1_mgmt_brick_op_rsp; - -/* the xdr functions */ - -#if defined(__STDC__) || defined(__cplusplus) -extern bool_t xdr_glusterd_volume_status (XDR *, glusterd_volume_status*); -extern bool_t xdr_gd1_mgmt_probe_req (XDR *, gd1_mgmt_probe_req*); -extern bool_t xdr_gd1_mgmt_probe_rsp (XDR *, gd1_mgmt_probe_rsp*); -extern bool_t xdr_gd1_mgmt_friend_req (XDR *, gd1_mgmt_friend_req*); -extern bool_t xdr_gd1_mgmt_friend_rsp (XDR *, gd1_mgmt_friend_rsp*); -extern bool_t xdr_gd1_mgmt_unfriend_req (XDR *, gd1_mgmt_unfriend_req*); -extern bool_t xdr_gd1_mgmt_unfriend_rsp (XDR *, gd1_mgmt_unfriend_rsp*); -extern bool_t xdr_gd1_mgmt_cluster_lock_req (XDR *, gd1_mgmt_cluster_lock_req*); -extern bool_t xdr_gd1_mgmt_cluster_lock_rsp (XDR *, gd1_mgmt_cluster_lock_rsp*); -extern bool_t xdr_gd1_mgmt_cluster_unlock_req (XDR *, gd1_mgmt_cluster_unlock_req*); -extern bool_t xdr_gd1_mgmt_cluster_unlock_rsp (XDR *, gd1_mgmt_cluster_unlock_rsp*); -extern bool_t xdr_gd1_mgmt_stage_op_req (XDR *, gd1_mgmt_stage_op_req*); -extern bool_t xdr_gd1_mgmt_stage_op_rsp (XDR *, gd1_mgmt_stage_op_rsp*); -extern bool_t xdr_gd1_mgmt_commit_op_req (XDR *, gd1_mgmt_commit_op_req*); -extern bool_t xdr_gd1_mgmt_commit_op_rsp (XDR *, gd1_mgmt_commit_op_rsp*); -extern bool_t xdr_gd1_mgmt_friend_update (XDR *, gd1_mgmt_friend_update*); -extern bool_t xdr_gd1_mgmt_friend_update_rsp (XDR *, gd1_mgmt_friend_update_rsp*); -extern bool_t xdr_gd1_mgmt_brick_op_req (XDR *, gd1_mgmt_brick_op_req*); -extern bool_t xdr_gd1_mgmt_brick_op_rsp (XDR *, gd1_mgmt_brick_op_rsp*); - -#else /* K&R C */ -extern bool_t xdr_glusterd_volume_status (); -extern bool_t xdr_gd1_mgmt_probe_req (); -extern bool_t xdr_gd1_mgmt_probe_rsp (); -extern bool_t xdr_gd1_mgmt_friend_req (); -extern bool_t xdr_gd1_mgmt_friend_rsp (); -extern bool_t xdr_gd1_mgmt_unfriend_req (); -extern bool_t xdr_gd1_mgmt_unfriend_rsp (); -extern bool_t xdr_gd1_mgmt_cluster_lock_req (); -extern bool_t xdr_gd1_mgmt_cluster_lock_rsp (); -extern bool_t xdr_gd1_mgmt_cluster_unlock_req (); -extern bool_t xdr_gd1_mgmt_cluster_unlock_rsp (); -extern bool_t xdr_gd1_mgmt_stage_op_req (); -extern bool_t xdr_gd1_mgmt_stage_op_rsp (); -extern bool_t xdr_gd1_mgmt_commit_op_req (); -extern bool_t xdr_gd1_mgmt_commit_op_rsp (); -extern bool_t xdr_gd1_mgmt_friend_update (); -extern bool_t xdr_gd1_mgmt_friend_update_rsp (); -extern bool_t xdr_gd1_mgmt_brick_op_req (); -extern bool_t xdr_gd1_mgmt_brick_op_rsp (); - -#endif /* K&R C */ - -#ifdef __cplusplus -} -#endif - -#endif /* !_GLUSTERD1_XDR_H_RPCGEN */ diff --git a/rpc/xdr/src/glusterd1-xdr.x b/rpc/xdr/src/glusterd1-xdr.x index c30c71e021a..b631dea3502 100644 --- a/rpc/xdr/src/glusterd1-xdr.x +++ b/rpc/xdr/src/glusterd1-xdr.x @@ -1,3 +1,18 @@ +/* + * Copyright (c) 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. + */ + +#ifdef RPC_XDR +%#include "rpc-pragmas.h" +#endif +%#include <glusterfs/compat.h> + enum glusterd_volume_status { GLUSTERD_STATUS_NONE = 0, GLUSTERD_STATUS_STARTED, @@ -16,6 +31,7 @@ int port; int op_ret; int op_errno; + string op_errstr<>; } ; struct gd1_mgmt_friend_req { @@ -116,6 +132,7 @@ struct gd1_mgmt_brick_op_req { string name<>; int op; opaque input<>; + opaque dict<>; } ; struct gd1_mgmt_brick_op_rsp { @@ -124,3 +141,109 @@ struct gd1_mgmt_brick_op_rsp { opaque output<>; string op_errstr<>; } ; + +struct gd1_mgmt_v3_lock_req { + unsigned char uuid[16]; + unsigned char txn_id[16]; + int op; + opaque dict<>; +} ; + +struct gd1_mgmt_v3_lock_rsp { + unsigned char uuid[16]; + unsigned char txn_id[16]; + opaque dict<>; + int op_ret; + int op_errno; +} ; + +struct gd1_mgmt_v3_pre_val_req { + unsigned char uuid[16]; + int op; + opaque dict<>; +} ; + +struct gd1_mgmt_v3_pre_val_rsp { + unsigned char uuid[16]; + int op; + int op_ret; + int op_errno; + string op_errstr<>; + opaque dict<>; +} ; + +struct gd1_mgmt_v3_brick_op_req { + unsigned char uuid[16]; + int op; + opaque dict<>; +} ; + +struct gd1_mgmt_v3_brick_op_rsp { + unsigned char uuid[16]; + int op; + int op_ret; + int op_errno; + string op_errstr<>; + opaque dict<>; +} ; + +struct gd1_mgmt_v3_commit_req { + unsigned char uuid[16]; + int op; + opaque dict<>; +} ; + +struct gd1_mgmt_v3_commit_rsp { + unsigned char uuid[16]; + int op; + int op_ret; + int op_errno; + opaque dict<>; + 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; + int op_ret; + opaque dict<>; +} ; + +struct gd1_mgmt_v3_post_val_rsp { + unsigned char uuid[16]; + int op; + int op_ret; + int op_errno; + string op_errstr<>; + opaque dict<>; +} ; + +struct gd1_mgmt_v3_unlock_req { + unsigned char uuid[16]; + unsigned char txn_id[16]; + int op; + opaque dict<>; +} ; + +struct gd1_mgmt_v3_unlock_rsp { + unsigned char uuid[16]; + unsigned char txn_id[16]; + opaque dict<>; + int op_ret; + int op_errno; +} ; diff --git a/rpc/xdr/src/glusterfs3-xdr.c b/rpc/xdr/src/glusterfs3-xdr.c deleted file mode 100644 index 64e504f46f6..00000000000 --- a/rpc/xdr/src/glusterfs3-xdr.c +++ /dev/null @@ -1,1688 +0,0 @@ -/* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include "xdr-common.h" -#include "compat.h" - -#if defined(__GNUC__) -#if __GNUC__ >= 4 -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif -#endif - -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#include "glusterfs3-xdr.h" - -bool_t -xdr_gf_statfs (XDR *xdrs, gf_statfs *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_u_quad_t (xdrs, &objp->bsize)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->frsize)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->blocks)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->bfree)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->bavail)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->files)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ffree)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->favail)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->fsid)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->flag)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->namemax)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_proto_flock (XDR *xdrs, gf_proto_flock *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_u_int (xdrs, &objp->type)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->whence)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->start)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->len)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->pid)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->owner)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_iatt (XDR *xdrs, gf_iatt *objp) -{ - register int32_t *buf; - buf = NULL; - - - if (xdrs->x_op == XDR_ENCODE) { - if (!xdr_opaque (xdrs, objp->ia_gfid, 16)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_ino)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_dev)) - return FALSE; - buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_u_int (xdrs, &objp->mode)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_nlink)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_uid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_gid)) - return FALSE; - - } else { - IXDR_PUT_U_LONG(buf, objp->mode); - IXDR_PUT_U_LONG(buf, objp->ia_nlink); - IXDR_PUT_U_LONG(buf, objp->ia_uid); - IXDR_PUT_U_LONG(buf, objp->ia_gid); - } - if (!xdr_u_quad_t (xdrs, &objp->ia_rdev)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_size)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_blksize)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_blocks)) - return FALSE; - buf = XDR_INLINE (xdrs, 6 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_u_int (xdrs, &objp->ia_atime)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_atime_nsec)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_mtime)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_mtime_nsec)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_ctime)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_ctime_nsec)) - return FALSE; - } else { - IXDR_PUT_U_LONG(buf, objp->ia_atime); - IXDR_PUT_U_LONG(buf, objp->ia_atime_nsec); - IXDR_PUT_U_LONG(buf, objp->ia_mtime); - IXDR_PUT_U_LONG(buf, objp->ia_mtime_nsec); - IXDR_PUT_U_LONG(buf, objp->ia_ctime); - IXDR_PUT_U_LONG(buf, objp->ia_ctime_nsec); - } - return TRUE; - } else if (xdrs->x_op == XDR_DECODE) { - if (!xdr_opaque (xdrs, objp->ia_gfid, 16)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_ino)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_dev)) - return FALSE; - buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_u_int (xdrs, &objp->mode)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_nlink)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_uid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_gid)) - return FALSE; - - } else { - objp->mode = IXDR_GET_U_LONG(buf); - objp->ia_nlink = IXDR_GET_U_LONG(buf); - objp->ia_uid = IXDR_GET_U_LONG(buf); - objp->ia_gid = IXDR_GET_U_LONG(buf); - } - if (!xdr_u_quad_t (xdrs, &objp->ia_rdev)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_size)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_blksize)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_blocks)) - return FALSE; - buf = XDR_INLINE (xdrs, 6 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_u_int (xdrs, &objp->ia_atime)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_atime_nsec)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_mtime)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_mtime_nsec)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_ctime)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_ctime_nsec)) - return FALSE; - } else { - objp->ia_atime = IXDR_GET_U_LONG(buf); - objp->ia_atime_nsec = IXDR_GET_U_LONG(buf); - objp->ia_mtime = IXDR_GET_U_LONG(buf); - objp->ia_mtime_nsec = IXDR_GET_U_LONG(buf); - objp->ia_ctime = IXDR_GET_U_LONG(buf); - objp->ia_ctime_nsec = IXDR_GET_U_LONG(buf); - } - return TRUE; - } - - if (!xdr_opaque (xdrs, objp->ia_gfid, 16)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_ino)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_dev)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->mode)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_nlink)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_uid)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_gid)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_rdev)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_size)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_blksize)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->ia_blocks)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_atime)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_atime_nsec)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_mtime)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_mtime_nsec)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_ctime)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->ia_ctime_nsec)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_stat_req (XDR *xdrs, gfs3_stat_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_stat_rsp (XDR *xdrs, gfs3_stat_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stat)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_readlink_req (XDR *xdrs, gfs3_readlink_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->size)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_readlink_rsp (XDR *xdrs, gfs3_readlink_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->buf)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_mknod_req (XDR *xdrs, gfs3_mknod_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->pargfid, 16)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->dev)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->mode)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->bname, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_mknod_rsp (XDR *xdrs, gfs3_mknod_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stat)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->preparent)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->postparent)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_mkdir_req (XDR *xdrs, gfs3_mkdir_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->pargfid, 16)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->mode)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->bname, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_mkdir_rsp (XDR *xdrs, gfs3_mkdir_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stat)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->preparent)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->postparent)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_unlink_req (XDR *xdrs, gfs3_unlink_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->pargfid, 16)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->bname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_unlink_rsp (XDR *xdrs, gfs3_unlink_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->preparent)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->postparent)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_rmdir_req (XDR *xdrs, gfs3_rmdir_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->pargfid, 16)) - return FALSE; - if (!xdr_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->bname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_rmdir_rsp (XDR *xdrs, gfs3_rmdir_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->preparent)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->postparent)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_symlink_req (XDR *xdrs, gfs3_symlink_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->pargfid, 16)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->bname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->linkname, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_symlink_rsp (XDR *xdrs, gfs3_symlink_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stat)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->preparent)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->postparent)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_rename_req (XDR *xdrs, gfs3_rename_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->oldgfid, 16)) - return FALSE; - if (!xdr_opaque (xdrs, objp->newgfid, 16)) - return FALSE; - if (!xdr_string (xdrs, &objp->oldpath, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->oldbname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->newpath, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->newbname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_rename_rsp (XDR *xdrs, gfs3_rename_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stat)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->preoldparent)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->postoldparent)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->prenewparent)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->postnewparent)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_link_req (XDR *xdrs, gfs3_link_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->oldgfid, 16)) - return FALSE; - if (!xdr_opaque (xdrs, objp->newgfid, 16)) - return FALSE; - if (!xdr_string (xdrs, &objp->oldpath, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->newpath, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->newbname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_link_rsp (XDR *xdrs, gfs3_link_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stat)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->preparent)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->postparent)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_truncate_req (XDR *xdrs, gfs3_truncate_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->offset)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_truncate_rsp (XDR *xdrs, gfs3_truncate_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->prestat)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->poststat)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_open_req (XDR *xdrs, gfs3_open_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->wbflags)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_open_rsp (XDR *xdrs, gfs3_open_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_read_req (XDR *xdrs, gfs3_read_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->offset)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->size)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_read_rsp (XDR *xdrs, gfs3_read_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stat)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->size)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_lookup_req (XDR *xdrs, gfs3_lookup_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_opaque (xdrs, objp->pargfid, 16)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->bname, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_lookup_rsp (XDR *xdrs, gfs3_lookup_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stat)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->postparent)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_write_req (XDR *xdrs, gfs3_write_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->offset)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->size)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_write_rsp (XDR *xdrs, gfs3_write_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->prestat)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->poststat)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_statfs_req (XDR *xdrs, gfs3_statfs_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_statfs_rsp (XDR *xdrs, gfs3_statfs_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_statfs (xdrs, &objp->statfs)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_lk_req (XDR *xdrs, gfs3_lk_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->cmd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->type)) - return FALSE; - if (!xdr_gf_proto_flock (xdrs, &objp->flock)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_lk_rsp (XDR *xdrs, gfs3_lk_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_proto_flock (xdrs, &objp->flock)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_inodelk_req (XDR *xdrs, gfs3_inodelk_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->cmd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->type)) - return FALSE; - if (!xdr_gf_proto_flock (xdrs, &objp->flock)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->volume, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_finodelk_req (XDR *xdrs, gfs3_finodelk_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->cmd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->type)) - return FALSE; - if (!xdr_gf_proto_flock (xdrs, &objp->flock)) - return FALSE; - if (!xdr_string (xdrs, &objp->volume, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_flush_req (XDR *xdrs, gfs3_flush_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fsync_req (XDR *xdrs, gfs3_fsync_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->data)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fsync_rsp (XDR *xdrs, gfs3_fsync_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->prestat)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->poststat)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_setxattr_req (XDR *xdrs, gfs3_setxattr_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fsetxattr_req (XDR *xdrs, gfs3_fsetxattr_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_xattrop_req (XDR *xdrs, gfs3_xattrop_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_xattrop_rsp (XDR *xdrs, gfs3_xattrop_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fxattrop_req (XDR *xdrs, gfs3_fxattrop_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fxattrop_rsp (XDR *xdrs, gfs3_fxattrop_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_getxattr_req (XDR *xdrs, gfs3_getxattr_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->namelen)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->name, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_getxattr_rsp (XDR *xdrs, gfs3_getxattr_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fgetxattr_req (XDR *xdrs, gfs3_fgetxattr_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->namelen)) - return FALSE; - if (!xdr_string (xdrs, &objp->name, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fgetxattr_rsp (XDR *xdrs, gfs3_fgetxattr_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_removexattr_req (XDR *xdrs, gfs3_removexattr_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->name, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_opendir_req (XDR *xdrs, gfs3_opendir_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_opendir_rsp (XDR *xdrs, gfs3_opendir_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fsyncdir_req (XDR *xdrs, gfs3_fsyncdir_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_int (xdrs, &objp->data)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_readdir_req (XDR *xdrs, gfs3_readdir_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->offset)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->size)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_readdirp_req (XDR *xdrs, gfs3_readdirp_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->offset)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->size)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_setvolume_req (XDR *xdrs, gf_setvolume_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_setvolume_rsp (XDR *xdrs, gf_setvolume_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_access_req (XDR *xdrs, gfs3_access_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->mask)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_create_req (XDR *xdrs, gfs3_create_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->pargfid, 16)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->mode)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->bname, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_create_rsp (XDR *xdrs, gfs3_create_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stat)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->preparent)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->postparent)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_ftruncate_req (XDR *xdrs, gfs3_ftruncate_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->offset)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_ftruncate_rsp (XDR *xdrs, gfs3_ftruncate_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->prestat)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->poststat)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fstat_req (XDR *xdrs, gfs3_fstat_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fstat_rsp (XDR *xdrs, gfs3_fstat_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stat)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_entrylk_req (XDR *xdrs, gfs3_entrylk_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->cmd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->type)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->namelen)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->name, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->volume, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fentrylk_req (XDR *xdrs, gfs3_fentrylk_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->cmd)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->type)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->namelen)) - return FALSE; - if (!xdr_string (xdrs, &objp->name, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->volume, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_setattr_req (XDR *xdrs, gfs3_setattr_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stbuf)) - return FALSE; - if (!xdr_int (xdrs, &objp->valid)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_setattr_rsp (XDR *xdrs, gfs3_setattr_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->statpre)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->statpost)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fsetattr_req (XDR *xdrs, gfs3_fsetattr_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stbuf)) - return FALSE; - if (!xdr_int (xdrs, &objp->valid)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_fsetattr_rsp (XDR *xdrs, gfs3_fsetattr_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->statpre)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->statpost)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_rchecksum_req (XDR *xdrs, gfs3_rchecksum_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->offset)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->len)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_rchecksum_rsp (XDR *xdrs, gfs3_rchecksum_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - - if (xdrs->x_op == XDR_ENCODE) { - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->weak_checksum)) - return FALSE; - - } else { - IXDR_PUT_LONG(buf, objp->op_ret); - IXDR_PUT_LONG(buf, objp->op_errno); - IXDR_PUT_U_LONG(buf, objp->weak_checksum); - } - if (!xdr_bytes (xdrs, (char **)&objp->strong_checksum.strong_checksum_val, (u_int *) &objp->strong_checksum.strong_checksum_len, ~0)) - return FALSE; - return TRUE; - } else if (xdrs->x_op == XDR_DECODE) { - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->weak_checksum)) - return FALSE; - - } else { - objp->op_ret = IXDR_GET_LONG(buf); - objp->op_errno = IXDR_GET_LONG(buf); - objp->weak_checksum = IXDR_GET_U_LONG(buf); - } - if (!xdr_bytes (xdrs, (char **)&objp->strong_checksum.strong_checksum_val, (u_int *) &objp->strong_checksum.strong_checksum_len, ~0)) - return FALSE; - return TRUE; - } - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->weak_checksum)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->strong_checksum.strong_checksum_val, (u_int *) &objp->strong_checksum.strong_checksum_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_getspec_req (XDR *xdrs, gf_getspec_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_string (xdrs, &objp->key, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_getspec_rsp (XDR *xdrs, gf_getspec_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_string (xdrs, &objp->spec, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_log_req (XDR *xdrs, gf_log_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_bytes (xdrs, (char **)&objp->msg.msg_val, (u_int *) &objp->msg.msg_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_notify_req (XDR *xdrs, gf_notify_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_string (xdrs, &objp->buf, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_notify_rsp (XDR *xdrs, gf_notify_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - - if (xdrs->x_op == XDR_ENCODE) { - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - - } else { - IXDR_PUT_LONG(buf, objp->op_ret); - IXDR_PUT_LONG(buf, objp->op_errno); - IXDR_PUT_U_LONG(buf, objp->flags); - } - if (!xdr_string (xdrs, &objp->buf, ~0)) - return FALSE; - return TRUE; - } else if (xdrs->x_op == XDR_DECODE) { - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - - } else { - objp->op_ret = IXDR_GET_LONG(buf); - objp->op_errno = IXDR_GET_LONG(buf); - objp->flags = IXDR_GET_U_LONG(buf); - } - if (!xdr_string (xdrs, &objp->buf, ~0)) - return FALSE; - return TRUE; - } - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_string (xdrs, &objp->buf, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_releasedir_req (XDR *xdrs, gfs3_releasedir_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_release_req (XDR *xdrs, gfs3_release_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_opaque (xdrs, objp->gfid, 16)) - return FALSE; - if (!xdr_quad_t (xdrs, &objp->fd)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf_common_rsp (XDR *xdrs, gf_common_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_dirlist (XDR *xdrs, gfs3_dirlist *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_u_quad_t (xdrs, &objp->d_ino)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->d_off)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->d_len)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->d_type)) - return FALSE; - if (!xdr_string (xdrs, &objp->name, ~0)) - return FALSE; - if (!xdr_pointer (xdrs, (char **)&objp->nextentry, sizeof (gfs3_dirlist), (xdrproc_t) xdr_gfs3_dirlist)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_readdir_rsp (XDR *xdrs, gfs3_readdir_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_pointer (xdrs, (char **)&objp->reply, sizeof (gfs3_dirlist), (xdrproc_t) xdr_gfs3_dirlist)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_dirplist (XDR *xdrs, gfs3_dirplist *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_u_quad_t (xdrs, &objp->d_ino)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->d_off)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->d_len)) - return FALSE; - if (!xdr_u_int (xdrs, &objp->d_type)) - return FALSE; - if (!xdr_string (xdrs, &objp->name, ~0)) - return FALSE; - if (!xdr_gf_iatt (xdrs, &objp->stat)) - return FALSE; - if (!xdr_pointer (xdrs, (char **)&objp->nextentry, sizeof (gfs3_dirplist), (xdrproc_t) xdr_gfs3_dirplist)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gfs3_readdirp_rsp (XDR *xdrs, gfs3_readdirp_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_pointer (xdrs, (char **)&objp->reply, sizeof (gfs3_dirplist), (xdrproc_t) xdr_gfs3_dirplist)) - return FALSE; - return TRUE; -} diff --git a/rpc/xdr/src/glusterfs3-xdr.h b/rpc/xdr/src/glusterfs3-xdr.h deleted file mode 100644 index 0c8af17d2cf..00000000000 --- a/rpc/xdr/src/glusterfs3-xdr.h +++ /dev/null @@ -1,970 +0,0 @@ -/* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include "xdr-common.h" -#include "compat.h" - -#if defined(__GNUC__) -#if __GNUC__ >= 4 -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif -#endif - -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#ifndef _GLUSTERFS3_XDR_H_RPCGEN -#define _GLUSTERFS3_XDR_H_RPCGEN - -#include <rpc/rpc.h> - - -#ifdef __cplusplus -extern "C" { -#endif - - -struct gf_statfs { - u_quad_t bsize; - u_quad_t frsize; - u_quad_t blocks; - u_quad_t bfree; - u_quad_t bavail; - u_quad_t files; - u_quad_t ffree; - u_quad_t favail; - u_quad_t fsid; - u_quad_t flag; - u_quad_t namemax; -}; -typedef struct gf_statfs gf_statfs; - -struct gf_proto_flock { - u_int type; - u_int whence; - u_quad_t start; - u_quad_t len; - u_int pid; - u_quad_t owner; -}; -typedef struct gf_proto_flock gf_proto_flock; - -struct gf_iatt { - char ia_gfid[16]; - u_quad_t ia_ino; - u_quad_t ia_dev; - u_int mode; - u_int ia_nlink; - u_int ia_uid; - u_int ia_gid; - u_quad_t ia_rdev; - u_quad_t ia_size; - u_int ia_blksize; - u_quad_t ia_blocks; - u_int ia_atime; - u_int ia_atime_nsec; - u_int ia_mtime; - u_int ia_mtime_nsec; - u_int ia_ctime; - u_int ia_ctime_nsec; -}; -typedef struct gf_iatt gf_iatt; - -struct gfs3_stat_req { - char gfid[16]; - char *path; -}; -typedef struct gfs3_stat_req gfs3_stat_req; - -struct gfs3_stat_rsp { - int op_ret; - int op_errno; - struct gf_iatt stat; -}; -typedef struct gfs3_stat_rsp gfs3_stat_rsp; - -struct gfs3_readlink_req { - char gfid[16]; - u_int size; - char *path; -}; -typedef struct gfs3_readlink_req gfs3_readlink_req; - -struct gfs3_readlink_rsp { - int op_ret; - int op_errno; - struct gf_iatt buf; - char *path; -}; -typedef struct gfs3_readlink_rsp gfs3_readlink_rsp; - -struct gfs3_mknod_req { - char pargfid[16]; - u_quad_t dev; - u_int mode; - char *path; - char *bname; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_mknod_req gfs3_mknod_req; - -struct gfs3_mknod_rsp { - int op_ret; - int op_errno; - struct gf_iatt stat; - struct gf_iatt preparent; - struct gf_iatt postparent; -}; -typedef struct gfs3_mknod_rsp gfs3_mknod_rsp; - -struct gfs3_mkdir_req { - char pargfid[16]; - u_int mode; - char *path; - char *bname; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_mkdir_req gfs3_mkdir_req; - -struct gfs3_mkdir_rsp { - int op_ret; - int op_errno; - struct gf_iatt stat; - struct gf_iatt preparent; - struct gf_iatt postparent; -}; -typedef struct gfs3_mkdir_rsp gfs3_mkdir_rsp; - -struct gfs3_unlink_req { - char pargfid[16]; - char *path; - char *bname; -}; -typedef struct gfs3_unlink_req gfs3_unlink_req; - -struct gfs3_unlink_rsp { - int op_ret; - int op_errno; - struct gf_iatt preparent; - struct gf_iatt postparent; -}; -typedef struct gfs3_unlink_rsp gfs3_unlink_rsp; - -struct gfs3_rmdir_req { - char pargfid[16]; - int flags; - char *path; - char *bname; -}; -typedef struct gfs3_rmdir_req gfs3_rmdir_req; - -struct gfs3_rmdir_rsp { - int op_ret; - int op_errno; - struct gf_iatt preparent; - struct gf_iatt postparent; -}; -typedef struct gfs3_rmdir_rsp gfs3_rmdir_rsp; - -struct gfs3_symlink_req { - char pargfid[16]; - char *path; - char *bname; - char *linkname; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_symlink_req gfs3_symlink_req; - -struct gfs3_symlink_rsp { - int op_ret; - int op_errno; - struct gf_iatt stat; - struct gf_iatt preparent; - struct gf_iatt postparent; -}; -typedef struct gfs3_symlink_rsp gfs3_symlink_rsp; - -struct gfs3_rename_req { - char oldgfid[16]; - char newgfid[16]; - char *oldpath; - char *oldbname; - char *newpath; - char *newbname; -}; -typedef struct gfs3_rename_req gfs3_rename_req; - -struct gfs3_rename_rsp { - int op_ret; - int op_errno; - struct gf_iatt stat; - struct gf_iatt preoldparent; - struct gf_iatt postoldparent; - struct gf_iatt prenewparent; - struct gf_iatt postnewparent; -}; -typedef struct gfs3_rename_rsp gfs3_rename_rsp; - -struct gfs3_link_req { - char oldgfid[16]; - char newgfid[16]; - char *oldpath; - char *newpath; - char *newbname; -}; -typedef struct gfs3_link_req gfs3_link_req; - -struct gfs3_link_rsp { - int op_ret; - int op_errno; - struct gf_iatt stat; - struct gf_iatt preparent; - struct gf_iatt postparent; -}; -typedef struct gfs3_link_rsp gfs3_link_rsp; - -struct gfs3_truncate_req { - char gfid[16]; - u_quad_t offset; - char *path; -}; -typedef struct gfs3_truncate_req gfs3_truncate_req; - -struct gfs3_truncate_rsp { - int op_ret; - int op_errno; - struct gf_iatt prestat; - struct gf_iatt poststat; -}; -typedef struct gfs3_truncate_rsp gfs3_truncate_rsp; - -struct gfs3_open_req { - char gfid[16]; - u_int flags; - u_int wbflags; - char *path; -}; -typedef struct gfs3_open_req gfs3_open_req; - -struct gfs3_open_rsp { - int op_ret; - int op_errno; - quad_t fd; -}; -typedef struct gfs3_open_rsp gfs3_open_rsp; - -struct gfs3_read_req { - char gfid[16]; - quad_t fd; - u_quad_t offset; - u_int size; -}; -typedef struct gfs3_read_req gfs3_read_req; - -struct gfs3_read_rsp { - int op_ret; - int op_errno; - struct gf_iatt stat; - u_int size; -}; -typedef struct gfs3_read_rsp gfs3_read_rsp; - -struct gfs3_lookup_req { - char gfid[16]; - char pargfid[16]; - u_int flags; - char *path; - char *bname; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_lookup_req gfs3_lookup_req; - -struct gfs3_lookup_rsp { - int op_ret; - int op_errno; - struct gf_iatt stat; - struct gf_iatt postparent; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_lookup_rsp gfs3_lookup_rsp; - -struct gfs3_write_req { - char gfid[16]; - quad_t fd; - u_quad_t offset; - u_int size; -}; -typedef struct gfs3_write_req gfs3_write_req; - -struct gfs3_write_rsp { - int op_ret; - int op_errno; - struct gf_iatt prestat; - struct gf_iatt poststat; -}; -typedef struct gfs3_write_rsp gfs3_write_rsp; - -struct gfs3_statfs_req { - char gfid[16]; - char *path; -}; -typedef struct gfs3_statfs_req gfs3_statfs_req; - -struct gfs3_statfs_rsp { - int op_ret; - int op_errno; - struct gf_statfs statfs; -}; -typedef struct gfs3_statfs_rsp gfs3_statfs_rsp; - -struct gfs3_lk_req { - char gfid[16]; - quad_t fd; - u_int cmd; - u_int type; - struct gf_proto_flock flock; -}; -typedef struct gfs3_lk_req gfs3_lk_req; - -struct gfs3_lk_rsp { - int op_ret; - int op_errno; - struct gf_proto_flock flock; -}; -typedef struct gfs3_lk_rsp gfs3_lk_rsp; - -struct gfs3_inodelk_req { - char gfid[16]; - u_int cmd; - u_int type; - struct gf_proto_flock flock; - char *path; - char *volume; -}; -typedef struct gfs3_inodelk_req gfs3_inodelk_req; - -struct gfs3_finodelk_req { - char gfid[16]; - quad_t fd; - u_int cmd; - u_int type; - struct gf_proto_flock flock; - char *volume; -}; -typedef struct gfs3_finodelk_req gfs3_finodelk_req; - -struct gfs3_flush_req { - char gfid[16]; - quad_t fd; -}; -typedef struct gfs3_flush_req gfs3_flush_req; - -struct gfs3_fsync_req { - char gfid[16]; - quad_t fd; - u_int data; -}; -typedef struct gfs3_fsync_req gfs3_fsync_req; - -struct gfs3_fsync_rsp { - int op_ret; - int op_errno; - struct gf_iatt prestat; - struct gf_iatt poststat; -}; -typedef struct gfs3_fsync_rsp gfs3_fsync_rsp; - -struct gfs3_setxattr_req { - char gfid[16]; - u_int flags; - struct { - u_int dict_len; - char *dict_val; - } dict; - char *path; -}; -typedef struct gfs3_setxattr_req gfs3_setxattr_req; - -struct gfs3_fsetxattr_req { - char gfid[16]; - quad_t fd; - u_int flags; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_fsetxattr_req gfs3_fsetxattr_req; - -struct gfs3_xattrop_req { - char gfid[16]; - u_int flags; - struct { - u_int dict_len; - char *dict_val; - } dict; - char *path; -}; -typedef struct gfs3_xattrop_req gfs3_xattrop_req; - -struct gfs3_xattrop_rsp { - int op_ret; - int op_errno; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_xattrop_rsp gfs3_xattrop_rsp; - -struct gfs3_fxattrop_req { - char gfid[16]; - quad_t fd; - u_int flags; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_fxattrop_req gfs3_fxattrop_req; - -struct gfs3_fxattrop_rsp { - int op_ret; - int op_errno; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_fxattrop_rsp gfs3_fxattrop_rsp; - -struct gfs3_getxattr_req { - char gfid[16]; - u_int namelen; - char *path; - char *name; -}; -typedef struct gfs3_getxattr_req gfs3_getxattr_req; - -struct gfs3_getxattr_rsp { - int op_ret; - int op_errno; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_getxattr_rsp gfs3_getxattr_rsp; - -struct gfs3_fgetxattr_req { - char gfid[16]; - quad_t fd; - u_int namelen; - char *name; -}; -typedef struct gfs3_fgetxattr_req gfs3_fgetxattr_req; - -struct gfs3_fgetxattr_rsp { - int op_ret; - int op_errno; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_fgetxattr_rsp gfs3_fgetxattr_rsp; - -struct gfs3_removexattr_req { - char gfid[16]; - char *path; - char *name; -}; -typedef struct gfs3_removexattr_req gfs3_removexattr_req; - -struct gfs3_opendir_req { - char gfid[16]; - char *path; -}; -typedef struct gfs3_opendir_req gfs3_opendir_req; - -struct gfs3_opendir_rsp { - int op_ret; - int op_errno; - quad_t fd; -}; -typedef struct gfs3_opendir_rsp gfs3_opendir_rsp; - -struct gfs3_fsyncdir_req { - char gfid[16]; - quad_t fd; - int data; -}; -typedef struct gfs3_fsyncdir_req gfs3_fsyncdir_req; - -struct gfs3_readdir_req { - char gfid[16]; - quad_t fd; - u_quad_t offset; - u_int size; -}; -typedef struct gfs3_readdir_req gfs3_readdir_req; - -struct gfs3_readdirp_req { - char gfid[16]; - quad_t fd; - u_quad_t offset; - u_int size; -}; -typedef struct gfs3_readdirp_req gfs3_readdirp_req; - -struct gf_setvolume_req { - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf_setvolume_req gf_setvolume_req; - -struct gf_setvolume_rsp { - int op_ret; - int op_errno; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf_setvolume_rsp gf_setvolume_rsp; - -struct gfs3_access_req { - char gfid[16]; - u_int mask; - char *path; -}; -typedef struct gfs3_access_req gfs3_access_req; - -struct gfs3_create_req { - char pargfid[16]; - u_int flags; - u_int mode; - char *path; - char *bname; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gfs3_create_req gfs3_create_req; - -struct gfs3_create_rsp { - int op_ret; - int op_errno; - struct gf_iatt stat; - u_quad_t fd; - struct gf_iatt preparent; - struct gf_iatt postparent; -}; -typedef struct gfs3_create_rsp gfs3_create_rsp; - -struct gfs3_ftruncate_req { - char gfid[16]; - quad_t fd; - u_quad_t offset; -}; -typedef struct gfs3_ftruncate_req gfs3_ftruncate_req; - -struct gfs3_ftruncate_rsp { - int op_ret; - int op_errno; - struct gf_iatt prestat; - struct gf_iatt poststat; -}; -typedef struct gfs3_ftruncate_rsp gfs3_ftruncate_rsp; - -struct gfs3_fstat_req { - char gfid[16]; - quad_t fd; -}; -typedef struct gfs3_fstat_req gfs3_fstat_req; - -struct gfs3_fstat_rsp { - int op_ret; - int op_errno; - struct gf_iatt stat; -}; -typedef struct gfs3_fstat_rsp gfs3_fstat_rsp; - -struct gfs3_entrylk_req { - char gfid[16]; - u_int cmd; - u_int type; - u_quad_t namelen; - char *path; - char *name; - char *volume; -}; -typedef struct gfs3_entrylk_req gfs3_entrylk_req; - -struct gfs3_fentrylk_req { - char gfid[16]; - quad_t fd; - u_int cmd; - u_int type; - u_quad_t namelen; - char *name; - char *volume; -}; -typedef struct gfs3_fentrylk_req gfs3_fentrylk_req; - -struct gfs3_setattr_req { - char gfid[16]; - struct gf_iatt stbuf; - int valid; - char *path; -}; -typedef struct gfs3_setattr_req gfs3_setattr_req; - -struct gfs3_setattr_rsp { - int op_ret; - int op_errno; - struct gf_iatt statpre; - struct gf_iatt statpost; -}; -typedef struct gfs3_setattr_rsp gfs3_setattr_rsp; - -struct gfs3_fsetattr_req { - quad_t fd; - struct gf_iatt stbuf; - int valid; -}; -typedef struct gfs3_fsetattr_req gfs3_fsetattr_req; - -struct gfs3_fsetattr_rsp { - int op_ret; - int op_errno; - struct gf_iatt statpre; - struct gf_iatt statpost; -}; -typedef struct gfs3_fsetattr_rsp gfs3_fsetattr_rsp; - -struct gfs3_rchecksum_req { - quad_t fd; - u_quad_t offset; - u_int len; -}; -typedef struct gfs3_rchecksum_req gfs3_rchecksum_req; - -struct gfs3_rchecksum_rsp { - int op_ret; - int op_errno; - u_int weak_checksum; - struct { - u_int strong_checksum_len; - char *strong_checksum_val; - } strong_checksum; -}; -typedef struct gfs3_rchecksum_rsp gfs3_rchecksum_rsp; - -struct gf_getspec_req { - u_int flags; - char *key; -}; -typedef struct gf_getspec_req gf_getspec_req; - -struct gf_getspec_rsp { - int op_ret; - int op_errno; - char *spec; -}; -typedef struct gf_getspec_rsp gf_getspec_rsp; - -struct gf_log_req { - struct { - u_int msg_len; - char *msg_val; - } msg; -}; -typedef struct gf_log_req gf_log_req; - -struct gf_notify_req { - u_int flags; - char *buf; -}; -typedef struct gf_notify_req gf_notify_req; - -struct gf_notify_rsp { - int op_ret; - int op_errno; - u_int flags; - char *buf; -}; -typedef struct gf_notify_rsp gf_notify_rsp; - -struct gfs3_releasedir_req { - char gfid[16]; - quad_t fd; -}; -typedef struct gfs3_releasedir_req gfs3_releasedir_req; - -struct gfs3_release_req { - char gfid[16]; - quad_t fd; -}; -typedef struct gfs3_release_req gfs3_release_req; - -struct gf_common_rsp { - int op_ret; - int op_errno; -}; -typedef struct gf_common_rsp gf_common_rsp; - -struct gfs3_dirlist { - u_quad_t d_ino; - u_quad_t d_off; - u_int d_len; - u_int d_type; - char *name; - struct gfs3_dirlist *nextentry; -}; -typedef struct gfs3_dirlist gfs3_dirlist; - -struct gfs3_readdir_rsp { - int op_ret; - int op_errno; - struct gfs3_dirlist *reply; -}; -typedef struct gfs3_readdir_rsp gfs3_readdir_rsp; - -struct gfs3_dirplist { - u_quad_t d_ino; - u_quad_t d_off; - u_int d_len; - u_int d_type; - char *name; - struct gf_iatt stat; - struct gfs3_dirplist *nextentry; -}; -typedef struct gfs3_dirplist gfs3_dirplist; - -struct gfs3_readdirp_rsp { - int op_ret; - int op_errno; - struct gfs3_dirplist *reply; -}; -typedef struct gfs3_readdirp_rsp gfs3_readdirp_rsp; - -/* the xdr functions */ - -#if defined(__STDC__) || defined(__cplusplus) -extern bool_t xdr_gf_statfs (XDR *, gf_statfs*); -extern bool_t xdr_gf_proto_flock (XDR *, gf_proto_flock*); -extern bool_t xdr_gf_iatt (XDR *, gf_iatt*); -extern bool_t xdr_gfs3_stat_req (XDR *, gfs3_stat_req*); -extern bool_t xdr_gfs3_stat_rsp (XDR *, gfs3_stat_rsp*); -extern bool_t xdr_gfs3_readlink_req (XDR *, gfs3_readlink_req*); -extern bool_t xdr_gfs3_readlink_rsp (XDR *, gfs3_readlink_rsp*); -extern bool_t xdr_gfs3_mknod_req (XDR *, gfs3_mknod_req*); -extern bool_t xdr_gfs3_mknod_rsp (XDR *, gfs3_mknod_rsp*); -extern bool_t xdr_gfs3_mkdir_req (XDR *, gfs3_mkdir_req*); -extern bool_t xdr_gfs3_mkdir_rsp (XDR *, gfs3_mkdir_rsp*); -extern bool_t xdr_gfs3_unlink_req (XDR *, gfs3_unlink_req*); -extern bool_t xdr_gfs3_unlink_rsp (XDR *, gfs3_unlink_rsp*); -extern bool_t xdr_gfs3_rmdir_req (XDR *, gfs3_rmdir_req*); -extern bool_t xdr_gfs3_rmdir_rsp (XDR *, gfs3_rmdir_rsp*); -extern bool_t xdr_gfs3_symlink_req (XDR *, gfs3_symlink_req*); -extern bool_t xdr_gfs3_symlink_rsp (XDR *, gfs3_symlink_rsp*); -extern bool_t xdr_gfs3_rename_req (XDR *, gfs3_rename_req*); -extern bool_t xdr_gfs3_rename_rsp (XDR *, gfs3_rename_rsp*); -extern bool_t xdr_gfs3_link_req (XDR *, gfs3_link_req*); -extern bool_t xdr_gfs3_link_rsp (XDR *, gfs3_link_rsp*); -extern bool_t xdr_gfs3_truncate_req (XDR *, gfs3_truncate_req*); -extern bool_t xdr_gfs3_truncate_rsp (XDR *, gfs3_truncate_rsp*); -extern bool_t xdr_gfs3_open_req (XDR *, gfs3_open_req*); -extern bool_t xdr_gfs3_open_rsp (XDR *, gfs3_open_rsp*); -extern bool_t xdr_gfs3_read_req (XDR *, gfs3_read_req*); -extern bool_t xdr_gfs3_read_rsp (XDR *, gfs3_read_rsp*); -extern bool_t xdr_gfs3_lookup_req (XDR *, gfs3_lookup_req*); -extern bool_t xdr_gfs3_lookup_rsp (XDR *, gfs3_lookup_rsp*); -extern bool_t xdr_gfs3_write_req (XDR *, gfs3_write_req*); -extern bool_t xdr_gfs3_write_rsp (XDR *, gfs3_write_rsp*); -extern bool_t xdr_gfs3_statfs_req (XDR *, gfs3_statfs_req*); -extern bool_t xdr_gfs3_statfs_rsp (XDR *, gfs3_statfs_rsp*); -extern bool_t xdr_gfs3_lk_req (XDR *, gfs3_lk_req*); -extern bool_t xdr_gfs3_lk_rsp (XDR *, gfs3_lk_rsp*); -extern bool_t xdr_gfs3_inodelk_req (XDR *, gfs3_inodelk_req*); -extern bool_t xdr_gfs3_finodelk_req (XDR *, gfs3_finodelk_req*); -extern bool_t xdr_gfs3_flush_req (XDR *, gfs3_flush_req*); -extern bool_t xdr_gfs3_fsync_req (XDR *, gfs3_fsync_req*); -extern bool_t xdr_gfs3_fsync_rsp (XDR *, gfs3_fsync_rsp*); -extern bool_t xdr_gfs3_setxattr_req (XDR *, gfs3_setxattr_req*); -extern bool_t xdr_gfs3_fsetxattr_req (XDR *, gfs3_fsetxattr_req*); -extern bool_t xdr_gfs3_xattrop_req (XDR *, gfs3_xattrop_req*); -extern bool_t xdr_gfs3_xattrop_rsp (XDR *, gfs3_xattrop_rsp*); -extern bool_t xdr_gfs3_fxattrop_req (XDR *, gfs3_fxattrop_req*); -extern bool_t xdr_gfs3_fxattrop_rsp (XDR *, gfs3_fxattrop_rsp*); -extern bool_t xdr_gfs3_getxattr_req (XDR *, gfs3_getxattr_req*); -extern bool_t xdr_gfs3_getxattr_rsp (XDR *, gfs3_getxattr_rsp*); -extern bool_t xdr_gfs3_fgetxattr_req (XDR *, gfs3_fgetxattr_req*); -extern bool_t xdr_gfs3_fgetxattr_rsp (XDR *, gfs3_fgetxattr_rsp*); -extern bool_t xdr_gfs3_removexattr_req (XDR *, gfs3_removexattr_req*); -extern bool_t xdr_gfs3_opendir_req (XDR *, gfs3_opendir_req*); -extern bool_t xdr_gfs3_opendir_rsp (XDR *, gfs3_opendir_rsp*); -extern bool_t xdr_gfs3_fsyncdir_req (XDR *, gfs3_fsyncdir_req*); -extern bool_t xdr_gfs3_readdir_req (XDR *, gfs3_readdir_req*); -extern bool_t xdr_gfs3_readdirp_req (XDR *, gfs3_readdirp_req*); -extern bool_t xdr_gf_setvolume_req (XDR *, gf_setvolume_req*); -extern bool_t xdr_gf_setvolume_rsp (XDR *, gf_setvolume_rsp*); -extern bool_t xdr_gfs3_access_req (XDR *, gfs3_access_req*); -extern bool_t xdr_gfs3_create_req (XDR *, gfs3_create_req*); -extern bool_t xdr_gfs3_create_rsp (XDR *, gfs3_create_rsp*); -extern bool_t xdr_gfs3_ftruncate_req (XDR *, gfs3_ftruncate_req*); -extern bool_t xdr_gfs3_ftruncate_rsp (XDR *, gfs3_ftruncate_rsp*); -extern bool_t xdr_gfs3_fstat_req (XDR *, gfs3_fstat_req*); -extern bool_t xdr_gfs3_fstat_rsp (XDR *, gfs3_fstat_rsp*); -extern bool_t xdr_gfs3_entrylk_req (XDR *, gfs3_entrylk_req*); -extern bool_t xdr_gfs3_fentrylk_req (XDR *, gfs3_fentrylk_req*); -extern bool_t xdr_gfs3_setattr_req (XDR *, gfs3_setattr_req*); -extern bool_t xdr_gfs3_setattr_rsp (XDR *, gfs3_setattr_rsp*); -extern bool_t xdr_gfs3_fsetattr_req (XDR *, gfs3_fsetattr_req*); -extern bool_t xdr_gfs3_fsetattr_rsp (XDR *, gfs3_fsetattr_rsp*); -extern bool_t xdr_gfs3_rchecksum_req (XDR *, gfs3_rchecksum_req*); -extern bool_t xdr_gfs3_rchecksum_rsp (XDR *, gfs3_rchecksum_rsp*); -extern bool_t xdr_gf_getspec_req (XDR *, gf_getspec_req*); -extern bool_t xdr_gf_getspec_rsp (XDR *, gf_getspec_rsp*); -extern bool_t xdr_gf_log_req (XDR *, gf_log_req*); -extern bool_t xdr_gf_notify_req (XDR *, gf_notify_req*); -extern bool_t xdr_gf_notify_rsp (XDR *, gf_notify_rsp*); -extern bool_t xdr_gfs3_releasedir_req (XDR *, gfs3_releasedir_req*); -extern bool_t xdr_gfs3_release_req (XDR *, gfs3_release_req*); -extern bool_t xdr_gf_common_rsp (XDR *, gf_common_rsp*); -extern bool_t xdr_gfs3_dirlist (XDR *, gfs3_dirlist*); -extern bool_t xdr_gfs3_readdir_rsp (XDR *, gfs3_readdir_rsp*); -extern bool_t xdr_gfs3_dirplist (XDR *, gfs3_dirplist*); -extern bool_t xdr_gfs3_readdirp_rsp (XDR *, gfs3_readdirp_rsp*); - -#else /* K&R C */ -extern bool_t xdr_gf_statfs (); -extern bool_t xdr_gf_proto_flock (); -extern bool_t xdr_gf_iatt (); -extern bool_t xdr_gfs3_stat_req (); -extern bool_t xdr_gfs3_stat_rsp (); -extern bool_t xdr_gfs3_readlink_req (); -extern bool_t xdr_gfs3_readlink_rsp (); -extern bool_t xdr_gfs3_mknod_req (); -extern bool_t xdr_gfs3_mknod_rsp (); -extern bool_t xdr_gfs3_mkdir_req (); -extern bool_t xdr_gfs3_mkdir_rsp (); -extern bool_t xdr_gfs3_unlink_req (); -extern bool_t xdr_gfs3_unlink_rsp (); -extern bool_t xdr_gfs3_rmdir_req (); -extern bool_t xdr_gfs3_rmdir_rsp (); -extern bool_t xdr_gfs3_symlink_req (); -extern bool_t xdr_gfs3_symlink_rsp (); -extern bool_t xdr_gfs3_rename_req (); -extern bool_t xdr_gfs3_rename_rsp (); -extern bool_t xdr_gfs3_link_req (); -extern bool_t xdr_gfs3_link_rsp (); -extern bool_t xdr_gfs3_truncate_req (); -extern bool_t xdr_gfs3_truncate_rsp (); -extern bool_t xdr_gfs3_open_req (); -extern bool_t xdr_gfs3_open_rsp (); -extern bool_t xdr_gfs3_read_req (); -extern bool_t xdr_gfs3_read_rsp (); -extern bool_t xdr_gfs3_lookup_req (); -extern bool_t xdr_gfs3_lookup_rsp (); -extern bool_t xdr_gfs3_write_req (); -extern bool_t xdr_gfs3_write_rsp (); -extern bool_t xdr_gfs3_statfs_req (); -extern bool_t xdr_gfs3_statfs_rsp (); -extern bool_t xdr_gfs3_lk_req (); -extern bool_t xdr_gfs3_lk_rsp (); -extern bool_t xdr_gfs3_inodelk_req (); -extern bool_t xdr_gfs3_finodelk_req (); -extern bool_t xdr_gfs3_flush_req (); -extern bool_t xdr_gfs3_fsync_req (); -extern bool_t xdr_gfs3_fsync_rsp (); -extern bool_t xdr_gfs3_setxattr_req (); -extern bool_t xdr_gfs3_fsetxattr_req (); -extern bool_t xdr_gfs3_xattrop_req (); -extern bool_t xdr_gfs3_xattrop_rsp (); -extern bool_t xdr_gfs3_fxattrop_req (); -extern bool_t xdr_gfs3_fxattrop_rsp (); -extern bool_t xdr_gfs3_getxattr_req (); -extern bool_t xdr_gfs3_getxattr_rsp (); -extern bool_t xdr_gfs3_fgetxattr_req (); -extern bool_t xdr_gfs3_fgetxattr_rsp (); -extern bool_t xdr_gfs3_removexattr_req (); -extern bool_t xdr_gfs3_opendir_req (); -extern bool_t xdr_gfs3_opendir_rsp (); -extern bool_t xdr_gfs3_fsyncdir_req (); -extern bool_t xdr_gfs3_readdir_req (); -extern bool_t xdr_gfs3_readdirp_req (); -extern bool_t xdr_gf_setvolume_req (); -extern bool_t xdr_gf_setvolume_rsp (); -extern bool_t xdr_gfs3_access_req (); -extern bool_t xdr_gfs3_create_req (); -extern bool_t xdr_gfs3_create_rsp (); -extern bool_t xdr_gfs3_ftruncate_req (); -extern bool_t xdr_gfs3_ftruncate_rsp (); -extern bool_t xdr_gfs3_fstat_req (); -extern bool_t xdr_gfs3_fstat_rsp (); -extern bool_t xdr_gfs3_entrylk_req (); -extern bool_t xdr_gfs3_fentrylk_req (); -extern bool_t xdr_gfs3_setattr_req (); -extern bool_t xdr_gfs3_setattr_rsp (); -extern bool_t xdr_gfs3_fsetattr_req (); -extern bool_t xdr_gfs3_fsetattr_rsp (); -extern bool_t xdr_gfs3_rchecksum_req (); -extern bool_t xdr_gfs3_rchecksum_rsp (); -extern bool_t xdr_gf_getspec_req (); -extern bool_t xdr_gf_getspec_rsp (); -extern bool_t xdr_gf_log_req (); -extern bool_t xdr_gf_notify_req (); -extern bool_t xdr_gf_notify_rsp (); -extern bool_t xdr_gfs3_releasedir_req (); -extern bool_t xdr_gfs3_release_req (); -extern bool_t xdr_gf_common_rsp (); -extern bool_t xdr_gfs3_dirlist (); -extern bool_t xdr_gfs3_readdir_rsp (); -extern bool_t xdr_gfs3_dirplist (); -extern bool_t xdr_gfs3_readdirp_rsp (); - -#endif /* K&R C */ - -#ifdef __cplusplus -} -#endif - -#endif /* !_GLUSTERFS3_XDR_H_RPCGEN */ diff --git a/rpc/xdr/src/glusterfs3-xdr.x b/rpc/xdr/src/glusterfs3-xdr.x index 592f7ed70c4..1c99099a721 100644 --- a/rpc/xdr/src/glusterfs3-xdr.x +++ b/rpc/xdr/src/glusterfs3-xdr.x @@ -1,40 +1,63 @@ +/* + * Copyright (c) 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. + */ + +#ifdef RPC_XDR +%#include "rpc-pragmas.h" +#endif +%#include <glusterfs/glusterfs-fops.h> +%#include "rpc-common-xdr.h" + #define GF_REQUEST_MAXGROUPS 16 struct gf_statfs { - unsigned hyper bsize; - unsigned hyper frsize; - unsigned hyper blocks; - unsigned hyper bfree; - unsigned hyper bavail; - unsigned hyper files; - unsigned hyper ffree; - unsigned hyper favail; - unsigned hyper fsid; - unsigned hyper flag; - unsigned hyper namemax; + u_quad_t bsize; + u_quad_t frsize; + u_quad_t blocks; + u_quad_t bfree; + u_quad_t bavail; + u_quad_t files; + u_quad_t ffree; + u_quad_t favail; + u_quad_t fsid; + u_quad_t flag; + u_quad_t namemax; }; + struct gf_proto_flock { unsigned int type; unsigned int whence; - unsigned hyper start; - unsigned hyper len; + u_quad_t start; + u_quad_t len; unsigned int pid; - unsigned hyper owner; + opaque lk_owner<>; } ; +struct gf_proto_lease { + unsigned int cmd; + unsigned int lease_type; + opaque lease_id[16]; + unsigned int lease_flags; +} ; struct gf_iatt { opaque ia_gfid[16]; - unsigned hyper ia_ino; /* inode number */ - unsigned hyper ia_dev; /* backing device ID */ + u_quad_t ia_ino; /* inode number */ + u_quad_t ia_dev; /* backing device ID */ unsigned int mode; /* mode (type + protection )*/ unsigned int ia_nlink; /* Link count */ unsigned int ia_uid; /* user ID of owner */ unsigned int ia_gid; /* group ID of owner */ - unsigned hyper ia_rdev; /* device ID (if special file) */ - unsigned hyper ia_size; /* file size in bytes */ + u_quad_t ia_rdev; /* device ID (if special file) */ + u_quad_t ia_size; /* file size in bytes */ unsigned int ia_blksize; /* blocksize for filesystem I/O */ - unsigned hyper ia_blocks; /* number of 512B blocks allocated */ + u_quad_t ia_blocks; /* number of 512B blocks allocated */ unsigned int ia_atime; /* last access time */ unsigned int ia_atime_nsec; unsigned int ia_mtime; /* last modification time */ @@ -43,270 +66,326 @@ struct gf_iatt { unsigned int ia_ctime_nsec; }; + +struct gfs3_cbk_cache_invalidation_req { + string gfid<>; + unsigned int event_type; /* Upcall event type */ + unsigned int flags; /* or mask of events incase of inotify */ + unsigned int expire_time_attr; /* the amount of time which client + * can cache this entry */ + gf_iatt stat; /* Updated/current stat of the file/dir */ + gf_iatt parent_stat; /* Updated stat of the parent dir + * needed in case of create, mkdir, + * unlink, rmdir, rename fops */ + gf_iatt oldparent_stat; /* Updated stat of the oldparent dir + needed in case of rename fop */ + opaque xdata<>; /* Extra data */ +}; + struct gfs3_stat_req { opaque gfid[16]; - string path<>; /* NULL terminated */ - + opaque xdata<>; /* Extra data */ }; struct gfs3_stat_rsp { int op_ret; int op_errno; - struct gf_iatt stat; + gf_iatt stat; + opaque xdata<>; /* Extra data */ } ; struct gfs3_readlink_req { opaque gfid[16]; unsigned int size; - string path<>; /* NULL terminated */ + opaque xdata<>; /* Extra data */ } ; struct gfs3_readlink_rsp { int op_ret; int op_errno; - struct gf_iatt buf; + gf_iatt buf; string path<>; /* NULL terminated */ + opaque xdata<>; /* Extra data */ } ; struct gfs3_mknod_req { opaque pargfid[16]; - unsigned hyper dev; + u_quad_t dev; unsigned int mode; - string path<>; /* NULL terminated */ + unsigned int umask; string bname<>; /* NULL terminated */ - opaque dict<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_mknod_rsp { int op_ret; int op_errno; - struct gf_iatt stat; - struct gf_iatt preparent; - struct gf_iatt postparent; + gf_iatt stat; + gf_iatt preparent; + gf_iatt postparent; + opaque xdata<>; /* Extra data */ }; struct gfs3_mkdir_req { opaque pargfid[16]; unsigned int mode; - string path<>; /* NULL terminated */ + unsigned int umask; string bname<>; /* NULL terminated */ - opaque dict<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_mkdir_rsp { int op_ret; int op_errno; - struct gf_iatt stat; - struct gf_iatt preparent; - struct gf_iatt postparent; + gf_iatt stat; + gf_iatt preparent; + gf_iatt postparent; + opaque xdata<>; /* Extra data */ } ; struct gfs3_unlink_req { opaque pargfid[16]; - string path<>; /* NULL terminated */ string bname<>; /* NULL terminated */ + unsigned int xflags; + opaque xdata<>; /* Extra data */ }; struct gfs3_unlink_rsp { int op_ret; int op_errno; - struct gf_iatt preparent; - struct gf_iatt postparent; + gf_iatt preparent; + gf_iatt postparent; + opaque xdata<>; /* Extra data */ }; struct gfs3_rmdir_req { opaque pargfid[16]; - int flags; - string path<>; + int xflags; string bname<>; /* NULL terminated */ + opaque xdata<>; /* Extra data */ }; struct gfs3_rmdir_rsp { int op_ret; int op_errno; - struct gf_iatt preparent; - struct gf_iatt postparent; + gf_iatt preparent; + gf_iatt postparent; + opaque xdata<>; /* Extra data */ }; struct gfs3_symlink_req { opaque pargfid[16]; - string path<>; string bname<>; + unsigned int umask; string linkname<>; - opaque dict<>; + opaque xdata<>; /* Extra data */ }; struct gfs3_symlink_rsp { int op_ret; int op_errno; - struct gf_iatt stat; - struct gf_iatt preparent; - struct gf_iatt postparent; + gf_iatt stat; + gf_iatt preparent; + gf_iatt postparent; + opaque xdata<>; /* Extra data */ }; struct gfs3_rename_req { opaque oldgfid[16]; opaque newgfid[16]; - string oldpath<>; string oldbname<>; /* NULL terminated */ - string newpath<>; string newbname<>; /* NULL terminated */ + opaque xdata<>; /* Extra data */ }; struct gfs3_rename_rsp { int op_ret; int op_errno; - struct gf_iatt stat; - struct gf_iatt preoldparent; - struct gf_iatt postoldparent; - struct gf_iatt prenewparent; - struct gf_iatt postnewparent; + gf_iatt stat; + gf_iatt preoldparent; + gf_iatt postoldparent; + gf_iatt prenewparent; + gf_iatt postnewparent; + opaque xdata<>; /* Extra data */ }; struct gfs3_link_req { opaque oldgfid[16]; opaque newgfid[16]; - string oldpath<>; - string newpath<>; string newbname<>; + opaque xdata<>; /* Extra data */ }; struct gfs3_link_rsp { int op_ret; int op_errno; - struct gf_iatt stat; - struct gf_iatt preparent; - struct gf_iatt postparent; + gf_iatt stat; + gf_iatt preparent; + gf_iatt postparent; + opaque xdata<>; /* Extra data */ }; struct gfs3_truncate_req { opaque gfid[16]; - unsigned hyper offset; - string path<>; + u_quad_t offset; + opaque xdata<>; /* Extra data */ }; struct gfs3_truncate_rsp { int op_ret; int op_errno; - struct gf_iatt prestat; - struct gf_iatt poststat; + gf_iatt prestat; + gf_iatt poststat; + opaque xdata<>; /* Extra data */ }; struct gfs3_open_req { opaque gfid[16]; unsigned int flags; - unsigned int wbflags; - string path<>; + opaque xdata<>; /* Extra data */ }; struct gfs3_open_rsp { int op_ret; int op_errno; - hyper fd; + quad_t fd; + opaque xdata<>; /* Extra data */ }; struct gfs3_read_req { opaque gfid[16]; - hyper fd; - unsigned hyper offset; + quad_t fd; + u_quad_t offset; unsigned int size; + unsigned int flag; + opaque xdata<>; /* Extra data */ }; struct gfs3_read_rsp { int op_ret; int op_errno; - struct gf_iatt stat; + gf_iatt stat; unsigned int size; + opaque xdata<>; /* Extra data */ } ; struct gfs3_lookup_req { opaque gfid[16]; opaque pargfid[16]; unsigned int flags; - string path<>; string bname<>; - opaque dict<>; + opaque xdata<>; /* Extra data */ }; struct gfs3_lookup_rsp { int op_ret; int op_errno; - struct gf_iatt stat; - struct gf_iatt postparent; - opaque dict<>; + gf_iatt stat; + gf_iatt postparent; + opaque xdata<>; /* Extra data */ } ; struct gfs3_write_req { opaque gfid[16]; - hyper fd; - unsigned hyper offset; + quad_t fd; + u_quad_t offset; unsigned int size; + unsigned int flag; + opaque xdata<>; /* Extra data */ }; struct gfs3_write_rsp { int op_ret; int op_errno; - struct gf_iatt prestat; - struct gf_iatt poststat; + gf_iatt prestat; + gf_iatt poststat; + opaque xdata<>; /* Extra data */ } ; struct gfs3_statfs_req { opaque gfid[16]; - string path<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_statfs_rsp { int op_ret; int op_errno; - struct gf_statfs statfs; + gf_statfs statfs; + opaque xdata<>; /* Extra data */ } ; struct gfs3_lk_req { opaque gfid[16]; - hyper fd; + int64_t fd; unsigned int cmd; unsigned int type; - struct gf_proto_flock flock; + gf_proto_flock flock; + opaque xdata<>; /* Extra data */ } ; struct gfs3_lk_rsp { int op_ret; int op_errno; - struct gf_proto_flock flock; + gf_proto_flock flock; + opaque xdata<>; /* Extra data */ +} ; + +struct gfs3_lease_req { + opaque gfid[16]; + gf_proto_lease lease; + opaque xdata<>; /* Extra data */ +} ; + +struct gfs3_lease_rsp { + int op_ret; + int op_errno; + gf_proto_lease lease; + opaque xdata<>; /* Extra data */ +} ; + +struct gfs3_recall_lease_req { + opaque gfid[16]; + unsigned int lease_type; + opaque tid[16]; + opaque xdata<>; /* Extra data */ } ; struct gfs3_inodelk_req { opaque gfid[16]; unsigned int cmd; unsigned int type; - struct gf_proto_flock flock; - string path<>; + gf_proto_flock flock; string volume<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_finodelk_req { opaque gfid[16]; - hyper fd; + quad_t fd; unsigned int cmd; unsigned int type; - struct gf_proto_flock flock; + gf_proto_flock flock; string volume<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_flush_req { opaque gfid[16]; - hyper fd; + quad_t fd; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fsync_req { opaque gfid[16]; - hyper fd; + quad_t fd; unsigned int data; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fsync_rsp { int op_ret; int op_errno; - struct gf_iatt prestat; - struct gf_iatt poststat; + gf_iatt prestat; + gf_iatt poststat; + opaque xdata<>; /* Extra data */ } ; @@ -314,16 +393,17 @@ struct gfs3_finodelk_req { opaque gfid[16]; unsigned int flags; opaque dict<>; - string path<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fsetxattr_req { opaque gfid[16]; - hyper fd; + int64_t fd; unsigned int flags; opaque dict<>; + opaque xdata<>; /* Extra data */ } ; @@ -332,109 +412,117 @@ struct gfs3_finodelk_req { opaque gfid[16]; unsigned int flags; opaque dict<>; - string path<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_xattrop_rsp { int op_ret; int op_errno; opaque dict<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fxattrop_req { opaque gfid[16]; - hyper fd; + quad_t fd; unsigned int flags; opaque dict<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fxattrop_rsp { int op_ret; int op_errno; opaque dict<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_getxattr_req { opaque gfid[16]; unsigned int namelen; - string path<>; string name<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_getxattr_rsp { int op_ret; int op_errno; opaque dict<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fgetxattr_req { opaque gfid[16]; - hyper fd; + quad_t fd; unsigned int namelen; string name<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fgetxattr_rsp { int op_ret; int op_errno; opaque dict<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_removexattr_req { opaque gfid[16]; - string path<>; string name<>; + opaque xdata<>; /* Extra data */ +} ; + + struct gfs3_fremovexattr_req { + opaque gfid[16]; + quad_t fd; + string name<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_opendir_req { opaque gfid[16]; - string path<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_opendir_rsp { int op_ret; int op_errno; - hyper fd; + quad_t fd; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fsyncdir_req { opaque gfid[16]; - hyper fd; + quad_t fd; int data; + opaque xdata<>; /* Extra data */ } ; struct gfs3_readdir_req { opaque gfid[16]; - hyper fd; - unsigned hyper offset; + quad_t fd; + u_quad_t offset; unsigned int size; + opaque xdata<>; /* Extra data */ }; struct gfs3_readdirp_req { opaque gfid[16]; - hyper fd; - unsigned hyper offset; + quad_t fd; + u_quad_t offset; unsigned int size; -} ; - - - struct gf_setvolume_req { opaque dict<>; } ; - struct gf_setvolume_rsp { - int op_ret; - int op_errno; - opaque dict<>; -} ; + struct gfs3_access_req { opaque gfid[16]; unsigned int mask; - string path<>; + opaque xdata<>; /* Extra data */ } ; @@ -442,42 +530,47 @@ struct gfs3_create_req { opaque pargfid[16]; unsigned int flags; unsigned int mode; - string path<>; + unsigned int umask; string bname<>; - opaque dict<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_create_rsp { int op_ret; int op_errno; - struct gf_iatt stat; - unsigned hyper fd; - struct gf_iatt preparent; - struct gf_iatt postparent; + gf_iatt stat; + u_quad_t fd; + gf_iatt preparent; + gf_iatt postparent; + opaque xdata<>; /* Extra data */ } ; struct gfs3_ftruncate_req { opaque gfid[16]; - hyper fd; - unsigned hyper offset; + quad_t fd; + u_quad_t offset; + opaque xdata<>; /* Extra data */ } ; struct gfs3_ftruncate_rsp { int op_ret; int op_errno; - struct gf_iatt prestat; - struct gf_iatt poststat; + gf_iatt prestat; + gf_iatt poststat; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fstat_req { opaque gfid[16]; - hyper fd; + quad_t fd; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fstat_rsp { int op_ret; int op_errno; - struct gf_iatt stat; + gf_iatt stat; + opaque xdata<>; /* Extra data */ } ; @@ -486,131 +579,312 @@ struct gfs3_fstat_req { opaque gfid[16]; unsigned int cmd; unsigned int type; - unsigned hyper namelen; - string path<>; + u_quad_t namelen; string name<>; string volume<>; + opaque xdata<>; /* Extra data */ }; struct gfs3_fentrylk_req { opaque gfid[16]; - hyper fd; + quad_t fd; unsigned int cmd; unsigned int type; - unsigned hyper namelen; + u_quad_t namelen; string name<>; string volume<>; + opaque xdata<>; /* Extra data */ }; struct gfs3_setattr_req { opaque gfid[16]; - struct gf_iatt stbuf; + gf_iatt stbuf; int valid; - string path<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_setattr_rsp { int op_ret; int op_errno; - struct gf_iatt statpre; - struct gf_iatt statpost; + gf_iatt statpre; + gf_iatt statpost; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fsetattr_req { - hyper fd; - struct gf_iatt stbuf; + quad_t fd; + gf_iatt stbuf; int valid; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fsetattr_rsp { int op_ret; int op_errno; - struct gf_iatt statpre; - struct gf_iatt statpost; + gf_iatt statpre; + gf_iatt statpost; + opaque xdata<>; /* Extra data */ +} ; + + struct gfs3_fallocate_req { + opaque gfid[16]; + quad_t fd; + unsigned int flags; + u_quad_t offset; + u_quad_t size; + opaque xdata<>; /* Extra data */ } ; + struct gfs3_fallocate_rsp { + int op_ret; + int op_errno; + gf_iatt statpre; + gf_iatt statpost; + opaque xdata<>; /* Extra data */ +} ; + + struct gfs3_discard_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + u_quad_t size; + opaque xdata<>; /* Extra data */ +} ; + + struct gfs3_discard_rsp { + int op_ret; + int op_errno; + gf_iatt statpre; + gf_iatt statpost; + opaque xdata<>; /* Extra data */ +} ; + + struct gfs3_zerofill_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + u_quad_t size; + opaque xdata<>; +} ; + + struct gfs3_zerofill_rsp { + int op_ret; + int op_errno; + gf_iatt statpre; + gf_iatt statpost; + opaque xdata<>; +} ; + + struct gfs3_rchecksum_req { - hyper fd; - unsigned hyper offset; + quad_t fd; + u_quad_t offset; unsigned int len; + opaque xdata<>; /* Extra data */ } ; struct gfs3_rchecksum_rsp { int op_ret; int op_errno; unsigned int weak_checksum; opaque strong_checksum<>; + opaque xdata<>; /* Extra data */ +} ; + + +struct gfs3_ipc_req { + int op; + opaque xdata<>; +}; + +struct gfs3_ipc_rsp { + int op_ret; + int op_errno; + opaque xdata<>; +}; + + +struct gfs3_seek_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + int what; + opaque xdata<>; +}; + +struct gfs3_seek_rsp { + int op_ret; + int op_errno; + u_quad_t offset; + opaque xdata<>; +}; + + + struct gf_setvolume_req { + opaque dict<>; } ; + struct gf_setvolume_rsp { + int op_ret; + int op_errno; + opaque dict<>; +} ; struct gf_getspec_req { unsigned int flags; string key<>; + opaque xdata<>; /* Extra data */ } ; struct gf_getspec_rsp { int op_ret; int op_errno; string spec<>; + opaque xdata<>; /* Extra data */ } ; + struct gf_get_volume_info_req { + opaque dict<>; /* Extra data */ +} ; + struct gf_get_volume_info_rsp { + int op_ret; + int op_errno; + string op_errstr<>; + opaque dict<>; /* Extra data */ +} ; + + struct gf_mgmt_hndsk_req { + opaque hndsk<>; +} ; + + struct gf_mgmt_hndsk_rsp { + int op_ret; + int op_errno; + opaque hndsk<>; +} ; struct gf_log_req { - opaque msg<>; -}; + opaque msg<>; +} ; struct gf_notify_req { unsigned int flags; string buf<>; + opaque xdata<>; /* Extra data */ } ; struct gf_notify_rsp { int op_ret; int op_errno; unsigned int flags; string buf<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_releasedir_req { opaque gfid[16]; - hyper fd; + quad_t fd; + opaque xdata<>; /* Extra data */ } ; struct gfs3_release_req { opaque gfid[16]; - hyper fd; + quad_t fd; + opaque xdata<>; /* Extra data */ } ; -struct gf_common_rsp { - int op_ret; - int op_errno; -} ; - struct gfs3_dirlist { - unsigned hyper d_ino; - unsigned hyper d_off; + u_quad_t d_ino; + u_quad_t d_off; unsigned int d_len; unsigned int d_type; string name<>; - struct gfs3_dirlist *nextentry; + gfs3_dirlist *nextentry; }; struct gfs3_readdir_rsp { int op_ret; int op_errno; - struct gfs3_dirlist *reply; + gfs3_dirlist *reply; + opaque xdata<>; /* Extra data */ }; struct gfs3_dirplist { - unsigned hyper d_ino; - unsigned hyper d_off; + u_quad_t d_ino; + u_quad_t d_off; unsigned int d_len; unsigned int d_type; string name<>; - struct gf_iatt stat; - struct gfs3_dirplist *nextentry; + gf_iatt stat; + opaque dict<>; + gfs3_dirplist *nextentry; }; struct gfs3_readdirp_rsp { int op_ret; int op_errno; - struct gfs3_dirplist *reply; + gfs3_dirplist *reply; + opaque xdata<>; /* Extra data */ }; +struct gf_set_lk_ver_rsp { + int op_ret; + int op_errno; + int lk_ver; +}; + +struct gf_set_lk_ver_req { + string uid<>; + int lk_ver; +}; + +struct gf_event_notify_req { + int op; + opaque dict<>; +}; + +struct gf_event_notify_rsp { + int op_ret; + int op_errno; + opaque dict<>; +}; + + +struct gf_getsnap_name_uuid_req { + opaque dict<>; +}; + +struct gf_getsnap_name_uuid_rsp { + int op_ret; + int op_errno; + string op_errstr<>; + opaque dict<>; +}; + +struct gfs3_locklist { + gf_proto_flock flock; + string client_uid<>; + unsigned int lk_flags; + gfs3_locklist *nextentry; +}; + +struct gfs3_getactivelk_rsp { + int op_ret; + int op_errno; + gfs3_locklist *reply; + opaque xdata<>; +}; + +struct gfs3_getactivelk_req { + opaque gfid[16]; + opaque xdata<>; +}; + +struct gfs3_setactivelk_rsp { + int op_ret; + int op_errno; + opaque xdata<>; +}; + +struct gfs3_setactivelk_req { + opaque gfid[16]; + gfs3_locklist *request; + opaque xdata<>; +}; diff --git a/rpc/xdr/src/glusterfs3.h b/rpc/xdr/src/glusterfs3.h index ba64a0b4508..86b3a4c0e5d 100644 --- a/rpc/xdr/src/glusterfs3.h +++ b/rpc/xdr/src/glusterfs3.h @@ -1,23 +1,13 @@ /* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _GLUSTERFS3_H #define _GLUSTERFS3_H @@ -25,246 +15,943 @@ #include "xdr-generic.h" #include "glusterfs3-xdr.h" -#include "iatt.h" - -#define xdr_decoded_remaining_addr(xdr) ((&xdr)->x_private) -#define xdr_decoded_remaining_len(xdr) ((&xdr)->x_handy) -#define xdr_encoded_length(xdr) (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) -#define xdr_decoded_length(xdr) (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) - - -#define GF_O_ACCMODE 003 -#define GF_O_RDONLY 00 -#define GF_O_WRONLY 01 -#define GF_O_RDWR 02 -#define GF_O_CREAT 0100 -#define GF_O_EXCL 0200 -#define GF_O_NOCTTY 0400 -#define GF_O_TRUNC 01000 -#define GF_O_APPEND 02000 -#define GF_O_NONBLOCK 04000 -#define GF_O_SYNC 010000 -#define GF_O_ASYNC 020000 - -#define GF_O_DIRECT 040000 -#define GF_O_DIRECTORY 0200000 -#define GF_O_NOFOLLOW 0400000 -#define GF_O_NOATIME 01000000 -#define GF_O_CLOEXEC 02000000 - -#define GF_O_LARGEFILE 0100000 - -#define XLATE_BIT(from, to, bit) do { \ - if (from & bit) \ - to = to | GF_##bit; \ - } while (0) - -#define UNXLATE_BIT(from, to, bit) do { \ - if (from & GF_##bit) \ - to = to | bit; \ - } while (0) - -#define XLATE_ACCESSMODE(from, to) do { \ - switch (from & O_ACCMODE) { \ - case O_RDONLY: to |= GF_O_RDONLY; \ - break; \ - case O_WRONLY: to |= GF_O_WRONLY; \ - break; \ - case O_RDWR: to |= GF_O_RDWR; \ - break; \ - } \ - } while (0) - -#define UNXLATE_ACCESSMODE(from, to) do { \ - switch (from & GF_O_ACCMODE) { \ - case GF_O_RDONLY: to |= O_RDONLY; \ - break; \ - case GF_O_WRONLY: to |= O_WRONLY; \ - break; \ - case GF_O_RDWR: to |= O_RDWR; \ - break; \ - } \ - } while (0) +#include "glusterfs4-xdr.h" +#include <glusterfs/iatt.h> +#include "protocol-common.h" +#include <glusterfs/upcall-utils.h> + +#define xdr_decoded_remaining_addr(xdr) ((&xdr)->x_private) +#define xdr_decoded_remaining_len(xdr) ((&xdr)->x_handy) +#define xdr_encoded_length(xdr) \ + (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) +#define xdr_decoded_length(xdr) \ + (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) + +#define GF_O_ACCMODE 003 +#define GF_O_RDONLY 00 +#define GF_O_WRONLY 01 +#define GF_O_RDWR 02 +#define GF_O_CREAT 0100 +#define GF_O_EXCL 0200 +#define GF_O_NOCTTY 0400 +#define GF_O_TRUNC 01000 +#define GF_O_APPEND 02000 +#define GF_O_NONBLOCK 04000 +#define GF_O_SYNC 010000 +#define GF_O_ASYNC 020000 + +#define GF_O_DIRECT 040000 +#define GF_O_DIRECTORY 0200000 +#define GF_O_NOFOLLOW 0400000 +#define GF_O_NOATIME 01000000 +#define GF_O_CLOEXEC 02000000 + +#define GF_O_LARGEFILE 0100000 + +#define GF_O_FMODE_EXEC 040 + +#define XLATE_BIT(from, to, bit) \ + do { \ + if (from & bit) \ + to = to | GF_##bit; \ + } while (0) + +#define UNXLATE_BIT(from, to, bit) \ + do { \ + if (from & GF_##bit) \ + to = to | bit; \ + } while (0) + +#define XLATE_ACCESSMODE(from, to) \ + do { \ + switch (from & O_ACCMODE) { \ + case O_RDONLY: \ + to |= GF_O_RDONLY; \ + break; \ + case O_WRONLY: \ + to |= GF_O_WRONLY; \ + break; \ + case O_RDWR: \ + to |= GF_O_RDWR; \ + break; \ + } \ + } while (0) + +#define UNXLATE_ACCESSMODE(from, to) \ + do { \ + switch (from & GF_O_ACCMODE) { \ + case GF_O_RDONLY: \ + to |= O_RDONLY; \ + break; \ + case GF_O_WRONLY: \ + to |= O_WRONLY; \ + break; \ + case GF_O_RDWR: \ + to |= O_RDWR; \ + break; \ + } \ + } while (0) static inline uint32_t -gf_flags_from_flags (uint32_t flags) +gf_flags_from_flags(uint32_t flags) { - uint32_t gf_flags = 0; - - XLATE_ACCESSMODE (flags, gf_flags); - - XLATE_BIT (flags, gf_flags, O_CREAT); - XLATE_BIT (flags, gf_flags, O_EXCL); - XLATE_BIT (flags, gf_flags, O_NOCTTY); - XLATE_BIT (flags, gf_flags, O_TRUNC); - XLATE_BIT (flags, gf_flags, O_APPEND); - XLATE_BIT (flags, gf_flags, O_NONBLOCK); - XLATE_BIT (flags, gf_flags, O_SYNC); - XLATE_BIT (flags, gf_flags, O_ASYNC); - - XLATE_BIT (flags, gf_flags, O_DIRECT); - XLATE_BIT (flags, gf_flags, O_DIRECTORY); - XLATE_BIT (flags, gf_flags, O_NOFOLLOW); + uint32_t gf_flags = 0; + + XLATE_ACCESSMODE(flags, gf_flags); + + XLATE_BIT(flags, gf_flags, O_CREAT); + XLATE_BIT(flags, gf_flags, O_EXCL); + XLATE_BIT(flags, gf_flags, O_NOCTTY); + XLATE_BIT(flags, gf_flags, O_TRUNC); + XLATE_BIT(flags, gf_flags, O_APPEND); + XLATE_BIT(flags, gf_flags, O_NONBLOCK); + XLATE_BIT(flags, gf_flags, O_SYNC); + XLATE_BIT(flags, gf_flags, O_ASYNC); + + XLATE_BIT(flags, gf_flags, O_DIRECT); + XLATE_BIT(flags, gf_flags, O_DIRECTORY); + XLATE_BIT(flags, gf_flags, O_NOFOLLOW); #ifdef O_NOATIME - XLATE_BIT (flags, gf_flags, O_NOATIME); + XLATE_BIT(flags, gf_flags, O_NOATIME); #endif #ifdef O_CLOEXEC - XLATE_BIT (flags, gf_flags, O_CLOEXEC); + XLATE_BIT(flags, gf_flags, O_CLOEXEC); #endif - XLATE_BIT (flags, gf_flags, O_LARGEFILE); + XLATE_BIT(flags, gf_flags, O_LARGEFILE); + XLATE_BIT(flags, gf_flags, O_FMODE_EXEC); - return gf_flags; + return gf_flags; } static inline uint32_t -gf_flags_to_flags (uint32_t gf_flags) +gf_flags_to_flags(uint32_t gf_flags) { - uint32_t flags = 0; - - UNXLATE_ACCESSMODE (gf_flags, flags); - - UNXLATE_BIT (gf_flags, flags, O_CREAT); - UNXLATE_BIT (gf_flags, flags, O_EXCL); - UNXLATE_BIT (gf_flags, flags, O_NOCTTY); - UNXLATE_BIT (gf_flags, flags, O_TRUNC); - UNXLATE_BIT (gf_flags, flags, O_APPEND); - UNXLATE_BIT (gf_flags, flags, O_NONBLOCK); - UNXLATE_BIT (gf_flags, flags, O_SYNC); - UNXLATE_BIT (gf_flags, flags, O_ASYNC); - - UNXLATE_BIT (gf_flags, flags, O_DIRECT); - UNXLATE_BIT (gf_flags, flags, O_DIRECTORY); - UNXLATE_BIT (gf_flags, flags, O_NOFOLLOW); + uint32_t flags = 0; + + UNXLATE_ACCESSMODE(gf_flags, flags); + + UNXLATE_BIT(gf_flags, flags, O_CREAT); + UNXLATE_BIT(gf_flags, flags, O_EXCL); + UNXLATE_BIT(gf_flags, flags, O_NOCTTY); + UNXLATE_BIT(gf_flags, flags, O_TRUNC); + UNXLATE_BIT(gf_flags, flags, O_APPEND); + UNXLATE_BIT(gf_flags, flags, O_NONBLOCK); + UNXLATE_BIT(gf_flags, flags, O_SYNC); + UNXLATE_BIT(gf_flags, flags, O_ASYNC); + + UNXLATE_BIT(gf_flags, flags, O_DIRECT); + UNXLATE_BIT(gf_flags, flags, O_DIRECTORY); + UNXLATE_BIT(gf_flags, flags, O_NOFOLLOW); #ifdef O_NOATIME - UNXLATE_BIT (gf_flags, flags, O_NOATIME); + UNXLATE_BIT(gf_flags, flags, O_NOATIME); #endif #ifdef O_CLOEXEC - UNXLATE_BIT (gf_flags, flags, O_CLOEXEC); + UNXLATE_BIT(gf_flags, flags, O_CLOEXEC); #endif - UNXLATE_BIT (gf_flags, flags, O_LARGEFILE); + UNXLATE_BIT(gf_flags, flags, O_LARGEFILE); + UNXLATE_BIT(gf_flags, flags, O_FMODE_EXEC); - return flags; + return flags; } +static inline void +gf_statfs_to_statfs(struct gf_statfs *gf_stat, struct statvfs *stat) +{ + if (!stat || !gf_stat) + return; + + stat->f_bsize = (gf_stat->bsize); + stat->f_frsize = (gf_stat->frsize); + stat->f_blocks = (gf_stat->blocks); + stat->f_bfree = (gf_stat->bfree); + stat->f_bavail = (gf_stat->bavail); + stat->f_files = (gf_stat->files); + stat->f_ffree = (gf_stat->ffree); + stat->f_favail = (gf_stat->favail); + stat->f_fsid = (gf_stat->fsid); + stat->f_flag = (gf_stat->flag); + stat->f_namemax = (gf_stat->namemax); +} static inline void -gf_statfs_to_statfs (struct gf_statfs *gf_stat, struct statvfs *stat) +gf_statfs_from_statfs(struct gf_statfs *gf_stat, struct statvfs *stat) { - if (!stat || !gf_stat) - return; - - stat->f_bsize = (gf_stat->bsize); - stat->f_frsize = (gf_stat->frsize); - stat->f_blocks = (gf_stat->blocks); - stat->f_bfree = (gf_stat->bfree); - stat->f_bavail = (gf_stat->bavail); - stat->f_files = (gf_stat->files); - stat->f_ffree = (gf_stat->ffree); - stat->f_favail = (gf_stat->favail); - stat->f_fsid = (gf_stat->fsid); - stat->f_flag = (gf_stat->flag); - stat->f_namemax = (gf_stat->namemax); + if (!stat || !gf_stat) + return; + + gf_stat->bsize = stat->f_bsize; + gf_stat->frsize = stat->f_frsize; + gf_stat->blocks = stat->f_blocks; + gf_stat->bfree = stat->f_bfree; + gf_stat->bavail = stat->f_bavail; + gf_stat->files = stat->f_files; + gf_stat->ffree = stat->f_ffree; + gf_stat->favail = stat->f_favail; + gf_stat->fsid = stat->f_fsid; + gf_stat->flag = stat->f_flag; + gf_stat->namemax = stat->f_namemax; } +static inline void +gf_proto_lease_to_lease(struct gf_proto_lease *gf_proto_lease, + struct gf_lease *gf_lease) +{ + if (!gf_lease || !gf_proto_lease) + return; + + gf_lease->cmd = gf_proto_lease->cmd; + gf_lease->lease_type = gf_proto_lease->lease_type; + memcpy(gf_lease->lease_id, gf_proto_lease->lease_id, LEASE_ID_SIZE); +} static inline void -gf_statfs_from_statfs (struct gf_statfs *gf_stat, struct statvfs *stat) +gf_proto_lease_from_lease(struct gf_proto_lease *gf_proto_lease, + struct gf_lease *gf_lease) { - if (!stat || !gf_stat) - return; - - gf_stat->bsize = stat->f_bsize; - gf_stat->frsize = stat->f_frsize; - gf_stat->blocks = stat->f_blocks; - gf_stat->bfree = stat->f_bfree; - gf_stat->bavail = stat->f_bavail; - gf_stat->files = stat->f_files; - gf_stat->ffree = stat->f_ffree; - gf_stat->favail = stat->f_favail; - gf_stat->fsid = stat->f_fsid; - gf_stat->flag = stat->f_flag; - gf_stat->namemax = stat->f_namemax; + if (!gf_lease || !gf_proto_lease) + return; + + gf_proto_lease->cmd = gf_lease->cmd; + gf_proto_lease->lease_type = gf_lease->lease_type; + memcpy(gf_proto_lease->lease_id, gf_lease->lease_id, LEASE_ID_SIZE); +} + +static inline int +gf_proto_recall_lease_to_upcall(struct gfs3_recall_lease_req *recall_lease, + struct gf_upcall *gf_up_data) +{ + struct gf_upcall_recall_lease *tmp = NULL; + int ret = 0; + + GF_VALIDATE_OR_GOTO(THIS->name, recall_lease, out); + GF_VALIDATE_OR_GOTO(THIS->name, gf_up_data, out); + + tmp = (struct gf_upcall_recall_lease *)gf_up_data->data; + tmp->lease_type = recall_lease->lease_type; + memcpy(gf_up_data->gfid, recall_lease->gfid, 16); + memcpy(tmp->tid, recall_lease->tid, 16); + + GF_PROTOCOL_DICT_UNSERIALIZE( + THIS, tmp->dict, (recall_lease->xdata).xdata_val, + (recall_lease->xdata).xdata_len, ret, errno, out); +out: + return ret; +} + +static inline int +gf_proto_recall_lease_from_upcall(xlator_t *this, + struct gfs3_recall_lease_req *recall_lease, + struct gf_upcall *gf_up_data) +{ + struct gf_upcall_recall_lease *tmp = NULL; + int ret = 0; + + GF_VALIDATE_OR_GOTO(this->name, recall_lease, out); + GF_VALIDATE_OR_GOTO(this->name, gf_up_data, out); + + tmp = (struct gf_upcall_recall_lease *)gf_up_data->data; + recall_lease->lease_type = tmp->lease_type; + memcpy(recall_lease->gfid, gf_up_data->gfid, 16); + memcpy(recall_lease->tid, tmp->tid, 16); + + GF_PROTOCOL_DICT_SERIALIZE(this, tmp->dict, + &(recall_lease->xdata).xdata_val, + (recall_lease->xdata).xdata_len, ret, out); +out: + return ret; } static inline void -gf_proto_flock_to_flock (struct gf_proto_flock *gf_proto_flock, struct gf_flock *gf_flock) +gf_proto_flock_to_flock(struct gf_proto_flock *gf_proto_flock, + struct gf_flock *gf_flock) { - if (!gf_flock || !gf_proto_flock) - return; - - gf_flock->l_type = gf_proto_flock->type; - gf_flock->l_whence = gf_proto_flock->whence; - gf_flock->l_start = gf_proto_flock->start; - gf_flock->l_len = gf_proto_flock->len; - gf_flock->l_pid = gf_proto_flock->pid; - gf_flock->l_owner = gf_proto_flock->owner; + if (!gf_flock || !gf_proto_flock) + return; + + gf_flock->l_type = gf_proto_flock->type; + gf_flock->l_whence = gf_proto_flock->whence; + gf_flock->l_start = gf_proto_flock->start; + gf_flock->l_len = gf_proto_flock->len; + gf_flock->l_pid = gf_proto_flock->pid; + gf_flock->l_owner.len = gf_proto_flock->lk_owner.lk_owner_len; + if (gf_flock->l_owner.len && + (gf_flock->l_owner.len < GF_MAX_LOCK_OWNER_LEN)) + memcpy(gf_flock->l_owner.data, gf_proto_flock->lk_owner.lk_owner_val, + gf_flock->l_owner.len); } +static inline void +gf_proto_flock_from_flock(struct gf_proto_flock *gf_proto_flock, + struct gf_flock *gf_flock) +{ + if (!gf_flock || !gf_proto_flock) + return; + + gf_proto_flock->type = (gf_flock->l_type); + gf_proto_flock->whence = (gf_flock->l_whence); + gf_proto_flock->start = (gf_flock->l_start); + gf_proto_flock->len = (gf_flock->l_len); + gf_proto_flock->pid = (gf_flock->l_pid); + gf_proto_flock->lk_owner.lk_owner_len = gf_flock->l_owner.len; + if (gf_flock->l_owner.len) + gf_proto_flock->lk_owner.lk_owner_val = gf_flock->l_owner.data; +} static inline void -gf_proto_flock_from_flock (struct gf_proto_flock *gf_proto_flock, struct gf_flock *gf_flock) +gf_stat_to_iatt(struct gf_iatt *gf_stat, struct iatt *iatt) { - if (!gf_flock || !gf_proto_flock) - return; - - gf_proto_flock->type = (gf_flock->l_type); - gf_proto_flock->whence = (gf_flock->l_whence); - gf_proto_flock->start = (gf_flock->l_start); - gf_proto_flock->len = (gf_flock->l_len); - gf_proto_flock->pid = (gf_flock->l_pid); - gf_proto_flock->owner = (gf_flock->l_owner); + if (!iatt || !gf_stat) + return; + + memcpy(iatt->ia_gfid, gf_stat->ia_gfid, 16); + iatt->ia_ino = gf_stat->ia_ino; + iatt->ia_dev = gf_stat->ia_dev; + iatt->ia_type = ia_type_from_st_mode(gf_stat->mode); + iatt->ia_prot = ia_prot_from_st_mode(gf_stat->mode); + iatt->ia_nlink = gf_stat->ia_nlink; + iatt->ia_uid = gf_stat->ia_uid; + iatt->ia_gid = gf_stat->ia_gid; + iatt->ia_rdev = gf_stat->ia_rdev; + iatt->ia_size = gf_stat->ia_size; + iatt->ia_blksize = gf_stat->ia_blksize; + iatt->ia_blocks = gf_stat->ia_blocks; + iatt->ia_atime = gf_stat->ia_atime; + iatt->ia_atime_nsec = gf_stat->ia_atime_nsec; + iatt->ia_mtime = gf_stat->ia_mtime; + iatt->ia_mtime_nsec = gf_stat->ia_mtime_nsec; + iatt->ia_ctime = gf_stat->ia_ctime; + iatt->ia_ctime_nsec = gf_stat->ia_ctime_nsec; } static inline void -gf_stat_to_iatt (struct gf_iatt *gf_stat, struct iatt *iatt) +gf_stat_from_iatt(struct gf_iatt *gf_stat, struct iatt *iatt) +{ + if (!iatt || !gf_stat) + return; + + memcpy(gf_stat->ia_gfid, iatt->ia_gfid, 16); + gf_stat->ia_ino = iatt->ia_ino; + gf_stat->ia_dev = iatt->ia_dev; + gf_stat->mode = st_mode_from_ia(iatt->ia_prot, iatt->ia_type); + gf_stat->ia_nlink = iatt->ia_nlink; + gf_stat->ia_uid = iatt->ia_uid; + gf_stat->ia_gid = iatt->ia_gid; + gf_stat->ia_rdev = iatt->ia_rdev; + gf_stat->ia_size = iatt->ia_size; + gf_stat->ia_blksize = iatt->ia_blksize; + gf_stat->ia_blocks = iatt->ia_blocks; + gf_stat->ia_atime = iatt->ia_atime; + gf_stat->ia_atime_nsec = iatt->ia_atime_nsec; + gf_stat->ia_mtime = iatt->ia_mtime; + gf_stat->ia_mtime_nsec = iatt->ia_mtime_nsec; + gf_stat->ia_ctime = iatt->ia_ctime; + gf_stat->ia_ctime_nsec = iatt->ia_ctime_nsec; +} + +static inline int +gf_proto_cache_invalidation_from_upcall( + xlator_t *this, gfs3_cbk_cache_invalidation_req *gf_c_req, + struct gf_upcall *gf_up_data) { - if (!iatt || !gf_stat) - return; - - memcpy (iatt->ia_gfid, gf_stat->ia_gfid, 16); - iatt->ia_ino = gf_stat->ia_ino ; - iatt->ia_dev = gf_stat->ia_dev ; - iatt->ia_type = ia_type_from_st_mode (gf_stat->mode) ; - iatt->ia_prot = ia_prot_from_st_mode (gf_stat->mode) ; - iatt->ia_nlink = gf_stat->ia_nlink ; - iatt->ia_uid = gf_stat->ia_uid ; - iatt->ia_gid = gf_stat->ia_gid ; - iatt->ia_rdev = gf_stat->ia_rdev ; - iatt->ia_size = gf_stat->ia_size ; - iatt->ia_blksize = gf_stat->ia_blksize ; - iatt->ia_blocks = gf_stat->ia_blocks ; - iatt->ia_atime = gf_stat->ia_atime ; - iatt->ia_atime_nsec = gf_stat->ia_atime_nsec ; - iatt->ia_mtime = gf_stat->ia_mtime ; - iatt->ia_mtime_nsec = gf_stat->ia_mtime_nsec ; - iatt->ia_ctime = gf_stat->ia_ctime ; - iatt->ia_ctime_nsec = gf_stat->ia_ctime_nsec ; + struct gf_upcall_cache_invalidation *gf_c_data = NULL; + int is_cache_inval = 0; + int ret = -1; + + GF_VALIDATE_OR_GOTO(this->name, gf_c_req, out); + GF_VALIDATE_OR_GOTO(this->name, gf_up_data, out); + + is_cache_inval = ((gf_up_data->event_type == GF_UPCALL_CACHE_INVALIDATION) + ? 1 + : 0); + GF_VALIDATE_OR_GOTO(this->name, is_cache_inval, out); + + gf_c_data = (struct gf_upcall_cache_invalidation *)gf_up_data->data; + GF_VALIDATE_OR_GOTO(this->name, gf_c_data, out); + + gf_c_req->gfid = uuid_utoa(gf_up_data->gfid); + gf_c_req->event_type = gf_up_data->event_type; + gf_c_req->flags = gf_c_data->flags; + gf_c_req->expire_time_attr = gf_c_data->expire_time_attr; + gf_stat_from_iatt(&gf_c_req->stat, &gf_c_data->stat); + gf_stat_from_iatt(&gf_c_req->parent_stat, &gf_c_data->p_stat); + gf_stat_from_iatt(&gf_c_req->oldparent_stat, &gf_c_data->oldp_stat); + + ret = 0; + GF_PROTOCOL_DICT_SERIALIZE(this, gf_c_data->dict, + &(gf_c_req->xdata).xdata_val, + (gf_c_req->xdata).xdata_len, ret, out); +out: + return ret; } +static inline int +gf_proto_cache_invalidation_to_upcall(xlator_t *this, + gfs3_cbk_cache_invalidation_req *gf_c_req, + struct gf_upcall *gf_up_data) +{ + struct gf_upcall_cache_invalidation *gf_c_data = NULL; + int ret = -1; + + GF_VALIDATE_OR_GOTO(this->name, gf_c_req, out); + GF_VALIDATE_OR_GOTO(this->name, gf_up_data, out); + + gf_c_data = (struct gf_upcall_cache_invalidation *)gf_up_data->data; + GF_VALIDATE_OR_GOTO(this->name, gf_c_data, out); + + ret = gf_uuid_parse(gf_c_req->gfid, gf_up_data->gfid); + if (ret) { + gf_log(this->name, GF_LOG_WARNING, "gf_uuid_parse(%s) failed", + gf_c_req->gfid); + gf_up_data->event_type = GF_UPCALL_EVENT_NULL; + goto out; + } + + gf_up_data->event_type = gf_c_req->event_type; + + gf_c_data->flags = gf_c_req->flags; + gf_c_data->expire_time_attr = gf_c_req->expire_time_attr; + gf_stat_to_iatt(&gf_c_req->stat, &gf_c_data->stat); + gf_stat_to_iatt(&gf_c_req->parent_stat, &gf_c_data->p_stat); + gf_stat_to_iatt(&gf_c_req->oldparent_stat, &gf_c_data->oldp_stat); + + ret = 0; + GF_PROTOCOL_DICT_UNSERIALIZE(this, gf_c_data->dict, + (gf_c_req->xdata).xdata_val, + (gf_c_req->xdata).xdata_len, ret, ret, out); + + /* If no dict was sent, create an empty dict, so that each xlator + * need not check if empty then create new dict. Will be unref'd by the + * caller */ + if (!gf_c_data->dict) + gf_c_data->dict = dict_new(); +out: + return ret; +} + +static inline int +gf_proto_inodelk_contention_to_upcall(struct gfs4_inodelk_contention_req *lc, + struct gf_upcall *gf_up_data) +{ + struct gf_upcall_inodelk_contention *tmp = NULL; + xlator_t *this = NULL; + int ret = -1; + int op_errno = EINVAL; + + this = THIS; + + GF_VALIDATE_OR_GOTO(this->name, lc, out); + GF_VALIDATE_OR_GOTO(this->name, gf_up_data, out); + + tmp = (struct gf_upcall_inodelk_contention *)gf_up_data->data; + + gf_uuid_copy(gf_up_data->gfid, (unsigned char *)lc->gfid); + + gf_proto_flock_to_flock(&lc->flock, &tmp->flock); + tmp->pid = lc->pid; + tmp->domain = lc->domain; + if ((tmp->domain != NULL) && (*tmp->domain == 0)) { + tmp->domain = NULL; + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, tmp->xdata, lc->xdata.xdata_val, + lc->xdata.xdata_len, ret, op_errno, out); + + ret = 0; + +out: + if (ret < 0) { + ret = -op_errno; + } + + return ret; +} + +static inline int +gf_proto_inodelk_contention_from_upcall(xlator_t *this, + struct gfs4_inodelk_contention_req *lc, + struct gf_upcall *gf_up_data) +{ + struct gf_upcall_inodelk_contention *tmp = NULL; + int ret = -1; + int op_errno = EINVAL; + + GF_VALIDATE_OR_GOTO(this->name, lc, out); + GF_VALIDATE_OR_GOTO(this->name, gf_up_data, out); + + tmp = (struct gf_upcall_inodelk_contention *)gf_up_data->data; + + gf_uuid_copy((unsigned char *)lc->gfid, gf_up_data->gfid); + + gf_proto_flock_from_flock(&lc->flock, &tmp->flock); + lc->pid = tmp->pid; + lc->domain = (char *)tmp->domain; + if (lc->domain == NULL) { + lc->domain = ""; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, tmp->xdata, &lc->xdata.xdata_val, + lc->xdata.xdata_len, op_errno, out); + + ret = 0; + +out: + if (ret < 0) { + ret = -op_errno; + } + + return ret; +} + +static inline int +gf_proto_entrylk_contention_to_upcall(struct gfs4_entrylk_contention_req *lc, + struct gf_upcall *gf_up_data) +{ + struct gf_upcall_entrylk_contention *tmp = NULL; + xlator_t *this = NULL; + int ret = -1; + int op_errno = EINVAL; + + this = THIS; + + GF_VALIDATE_OR_GOTO(this->name, lc, out); + GF_VALIDATE_OR_GOTO(this->name, gf_up_data, out); + + tmp = (struct gf_upcall_entrylk_contention *)gf_up_data->data; + + gf_uuid_copy(gf_up_data->gfid, (unsigned char *)lc->gfid); + + tmp->type = lc->type; + tmp->name = lc->name; + if ((tmp->name != NULL) && (*tmp->name == 0)) { + tmp->name = NULL; + } + tmp->pid = lc->pid; + tmp->domain = lc->domain; + if ((tmp->domain != NULL) && (*tmp->domain == 0)) { + tmp->domain = NULL; + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, tmp->xdata, lc->xdata.xdata_val, + lc->xdata.xdata_len, ret, op_errno, out); + + ret = 0; + +out: + if (ret < 0) { + ret = -op_errno; + } + + return ret; +} + +static inline int +gf_proto_entrylk_contention_from_upcall(xlator_t *this, + struct gfs4_entrylk_contention_req *lc, + struct gf_upcall *gf_up_data) +{ + struct gf_upcall_entrylk_contention *tmp = NULL; + int ret = -1; + int op_errno = EINVAL; + + GF_VALIDATE_OR_GOTO(this->name, lc, out); + GF_VALIDATE_OR_GOTO(this->name, gf_up_data, out); + + tmp = (struct gf_upcall_entrylk_contention *)gf_up_data->data; + + gf_uuid_copy((unsigned char *)lc->gfid, gf_up_data->gfid); + + lc->type = tmp->type; + lc->name = (char *)tmp->name; + if (lc->name == NULL) { + lc->name = ""; + } + lc->pid = tmp->pid; + lc->domain = (char *)tmp->domain; + if (lc->domain == NULL) { + lc->domain = ""; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, tmp->xdata, &lc->xdata.xdata_val, + lc->xdata.xdata_len, op_errno, out); + + ret = 0; + +out: + if (ret < 0) { + ret = -op_errno; + } + + return ret; +} + +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) + return; + + memcpy(iatt->ia_gfid, gf_stat->ia_gfid, 16); + + iatt->ia_flags = gf_stat->ia_flags; + iatt->ia_ino = gf_stat->ia_ino; + iatt->ia_dev = gf_stat->ia_dev; + iatt->ia_rdev = gf_stat->ia_rdev; + iatt->ia_size = gf_stat->ia_size; + iatt->ia_nlink = gf_stat->ia_nlink; + iatt->ia_uid = gf_stat->ia_uid; + iatt->ia_gid = gf_stat->ia_gid; + iatt->ia_blksize = gf_stat->ia_blksize; + iatt->ia_blocks = gf_stat->ia_blocks; + iatt->ia_atime = gf_stat->ia_atime; + iatt->ia_atime_nsec = gf_stat->ia_atime_nsec; + iatt->ia_mtime = gf_stat->ia_mtime; + iatt->ia_mtime_nsec = gf_stat->ia_mtime_nsec; + iatt->ia_ctime = gf_stat->ia_ctime; + iatt->ia_ctime_nsec = gf_stat->ia_ctime_nsec; + iatt->ia_btime = gf_stat->ia_btime; + iatt->ia_btime_nsec = gf_stat->ia_btime_nsec; + iatt->ia_attributes = gf_stat->ia_attributes; + iatt->ia_attributes_mask = gf_stat->ia_attributes_mask; + + iatt->ia_type = ia_type_from_st_mode(gf_stat->mode); + iatt->ia_prot = ia_prot_from_st_mode(gf_stat->mode); +} static inline void -gf_stat_from_iatt (struct gf_iatt *gf_stat, struct iatt *iatt) +gfx_stat_from_iattx(struct gfx_iattx *gf_stat, struct iatt *iatt) +{ + if (!iatt || !gf_stat) + return; + + memcpy(gf_stat->ia_gfid, iatt->ia_gfid, 16); + gf_stat->ia_ino = iatt->ia_ino; + gf_stat->ia_dev = iatt->ia_dev; + + gf_stat->ia_nlink = iatt->ia_nlink; + gf_stat->ia_uid = iatt->ia_uid; + gf_stat->ia_gid = iatt->ia_gid; + gf_stat->ia_rdev = iatt->ia_rdev; + gf_stat->ia_size = iatt->ia_size; + gf_stat->ia_blksize = iatt->ia_blksize; + gf_stat->ia_blocks = iatt->ia_blocks; + gf_stat->ia_atime = iatt->ia_atime; + gf_stat->ia_atime_nsec = iatt->ia_atime_nsec; + gf_stat->ia_mtime = iatt->ia_mtime; + gf_stat->ia_mtime_nsec = iatt->ia_mtime_nsec; + gf_stat->ia_ctime = iatt->ia_ctime; + gf_stat->ia_ctime_nsec = iatt->ia_ctime_nsec; + + gf_stat->ia_flags = iatt->ia_flags; + gf_stat->ia_btime = iatt->ia_btime; + gf_stat->ia_btime_nsec = iatt->ia_btime_nsec; + gf_stat->ia_attributes = iatt->ia_attributes; + gf_stat->ia_attributes_mask = iatt->ia_attributes_mask; + + gf_stat->mode = st_mode_from_ia(iatt->ia_prot, iatt->ia_type); +} + +/* dict_to_xdr () */ +static inline int +dict_to_xdr(dict_t *this, gfx_dict *dict) +{ + int ret = -1; + int i = 0; + int index = 0; + data_pair_t *dpair = NULL; + gfx_dict_pair *xpair = NULL; + ssize_t size = 0; + + /* This is a failure as we expect destination to be valid */ + if (!dict) + goto out; + + /* This is OK as dictionary can be null, in which case, destination + should also know that it is NULL. */ + if (!this) { + /* encode special meaning data here, + while decoding, you know it is NULL dict */ + dict->count = -1; + /* everything else is normal */ + dict->pairs.pairs_len = 0; + ret = 0; + goto out; + } + + /* Do the whole operation in locked region */ + LOCK(&this->lock); + + dict->pairs.pairs_val = GF_CALLOC(1, (this->count * sizeof(gfx_dict_pair)), + gf_common_mt_char); + if (!dict->pairs.pairs_val) + goto out; + + dpair = this->members_list; + for (i = 0; i < this->count; i++) { + xpair = &dict->pairs.pairs_val[index]; + + xpair->key.key_val = dpair->key; + xpair->key.key_len = strlen(dpair->key) + 1; + xpair->value.type = dpair->value->data_type; + switch (dpair->value->data_type) { + /* Add more type here */ + case GF_DATA_TYPE_INT: + index++; + xpair->value.gfx_value_u.value_int = strtoll(dpair->value->data, + NULL, 0); + break; + case GF_DATA_TYPE_UINT: + index++; + xpair->value.gfx_value_u.value_uint = strtoull( + dpair->value->data, NULL, 0); + break; + case GF_DATA_TYPE_DOUBLE: + index++; + xpair->value.gfx_value_u.value_dbl = strtod(dpair->value->data, + NULL); + break; + case GF_DATA_TYPE_STR: + index++; + xpair->value.gfx_value_u.val_string + .val_string_val = dpair->value->data; + xpair->value.gfx_value_u.val_string + .val_string_len = dpair->value->len; + break; + case GF_DATA_TYPE_IATT: + index++; + 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, + sizeof(uuid_t)); + 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 + sent on wire */ + + /* This is done for backward compatibility as dict is + heavily used for transporting data over wire. + Ideally, wherever there is an issue, fix and + move on */ + xpair->value.gfx_value_u.other.other_val = dpair->value->data; + 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_DEBUG, EINVAL, LG_MSG_DICT_SERIAL_FAILED, + "key '%s' would not be sent on wire in the future", + dpair->key); + break; + default: + /* Unknown type and ptr type is not sent on wire */ + gf_msg("dict", GF_LOG_WARNING, EINVAL, + LG_MSG_DICT_SERIAL_FAILED, + "key '%s' is not sent on wire", dpair->key); + break; + } + dpair = dpair->next; + } + + dict->pairs.pairs_len = index; + dict->count = index; + + /* This is required mainly in the RPC layer to understand the + boundary for proper payload. Hence only send the size of + variable XDR size. ie, the formula should be: + xdr_size = total size - (xdr_size + count + pairs.pairs_len)) */ + size = xdr_sizeof((xdrproc_t)xdr_gfx_dict, dict); + + dict->xdr_size = (size > 12) ? (size - 12) : 0; + + ret = 0; +out: + /* this can be null here, so unlock only if its not null */ + if (this) + UNLOCK(&this->lock); + + return ret; +} + +static inline int +xdr_to_dict(gfx_dict *dict, dict_t **to) { - if (!iatt || !gf_stat) - return; - - memcpy (gf_stat->ia_gfid, iatt->ia_gfid, 16); - gf_stat->ia_ino = iatt->ia_ino ; - gf_stat->ia_dev = iatt->ia_dev ; - gf_stat->mode = st_mode_from_ia (iatt->ia_prot, iatt->ia_type); - gf_stat->ia_nlink = iatt->ia_nlink ; - gf_stat->ia_uid = iatt->ia_uid ; - gf_stat->ia_gid = iatt->ia_gid ; - gf_stat->ia_rdev = iatt->ia_rdev ; - gf_stat->ia_size = iatt->ia_size ; - gf_stat->ia_blksize = iatt->ia_blksize ; - gf_stat->ia_blocks = iatt->ia_blocks ; - gf_stat->ia_atime = iatt->ia_atime ; - gf_stat->ia_atime_nsec = iatt->ia_atime_nsec ; - gf_stat->ia_mtime = iatt->ia_mtime ; - gf_stat->ia_mtime_nsec = iatt->ia_mtime_nsec ; - gf_stat->ia_ctime = iatt->ia_ctime ; - gf_stat->ia_ctime_nsec = iatt->ia_ctime_nsec ; + int ret = -1; + int index = 0; + char *key = NULL; + char *value = NULL; + gfx_dict_pair *xpair = NULL; + dict_t *this = NULL; + unsigned char *uuid = NULL; + struct iatt *iatt = NULL; + struct mdata_iatt *mdata_iatt = NULL; + + if (!to || !dict) + goto out; + + if (dict->count < 0) { + /* indicates NULL dict was passed for encoding */ + ret = 0; + goto out; + } + + this = dict_new(); + if (!this) + goto out; + + for (index = 0; index < dict->pairs.pairs_len; index++) { + ret = -1; + xpair = &dict->pairs.pairs_val[index]; + + key = xpair->key.key_val; + switch (xpair->value.type) { + /* Add more type here */ + case GF_DATA_TYPE_INT: + ret = dict_set_int64(this, key, + xpair->value.gfx_value_u.value_int); + break; + case GF_DATA_TYPE_UINT: + ret = dict_set_uint64(this, key, + xpair->value.gfx_value_u.value_uint); + break; + case GF_DATA_TYPE_DOUBLE: + ret = dict_set_double(this, key, + xpair->value.gfx_value_u.value_dbl); + break; + case GF_DATA_TYPE_STR: + value = GF_MALLOC( + xpair->value.gfx_value_u.val_string.val_string_len + 1, + gf_common_mt_char); + if (!value) { + errno = ENOMEM; + goto out; + } + memcpy(value, + xpair->value.gfx_value_u.val_string.val_string_val, + xpair->value.gfx_value_u.val_string.val_string_len); + value[xpair->value.gfx_value_u.val_string.val_string_len] = + '\0'; + free(xpair->value.gfx_value_u.val_string.val_string_val); + ret = dict_set_dynstr(this, key, value); + break; + case GF_DATA_TYPE_GFUUID: + uuid = GF_MALLOC(sizeof(uuid_t), gf_common_mt_uuid_t); + if (!uuid) { + errno = ENOMEM; + goto out; + } + memcpy(uuid, xpair->value.gfx_value_u.uuid, sizeof(uuid_t)); + ret = dict_set_gfuuid(this, key, uuid, false); + break; + case GF_DATA_TYPE_IATT: + iatt = GF_CALLOC(1, sizeof(struct iatt), gf_common_mt_char); + if (!iatt) { + errno = ENOMEM; + goto out; + } + 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) { + errno = ENOMEM; + goto out; + } + memcpy(value, xpair->value.gfx_value_u.other.other_val, + xpair->value.gfx_value_u.other.other_len); + value[xpair->value.gfx_value_u.other.other_len] = '\0'; + free(xpair->value.gfx_value_u.other.other_val); + ret = dict_set_dynptr(this, key, value, + xpair->value.gfx_value_u.other.other_len); + break; + default: + ret = 0; + /* Unknown type and ptr type is not sent on wire */ + break; + } + if (ret) { + gf_msg_debug(THIS->name, ENOMEM, + "failed to set the key (%s) into dict", key); + } + free(xpair->key.key_val); + } + + free(dict->pairs.pairs_val); + ret = 0; + + /* If everything is fine, assign the dictionary to target */ + *to = this; + this = NULL; + +out: + if (this) + dict_unref(this); + + return ret; } #endif /* !_GLUSTERFS3_H */ diff --git a/rpc/xdr/src/glusterfs4-xdr.x b/rpc/xdr/src/glusterfs4-xdr.x new file mode 100644 index 00000000000..d3b1d0dfaf0 --- /dev/null +++ b/rpc/xdr/src/glusterfs4-xdr.x @@ -0,0 +1,797 @@ +/* + * Copyright (c) 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. + */ + +#ifdef RPC_XDR +%#include "rpc-pragmas.h" +#endif +%#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]; + + unsigned hyper ia_flags; + unsigned hyper ia_ino; /* inode number */ + unsigned hyper ia_dev; /* backing device ID */ + unsigned hyper ia_rdev; /* device ID (if special file) */ + unsigned hyper ia_size; /* file size in bytes */ + unsigned hyper ia_blocks; /* number of 512B blocks allocated */ + unsigned hyper ia_attributes; /* chattr related:compressed, immutable, + * append only, encrypted etc.*/ + unsigned hyper ia_attributes_mask; /* Mask for the attributes */ + + hyper ia_atime; /* last access time */ + hyper ia_mtime; /* last modification time */ + hyper ia_ctime; /* last status change time */ + hyper ia_btime; /* creation time. Fill using statx */ + + unsigned int ia_atime_nsec; + unsigned int ia_mtime_nsec; + unsigned int ia_ctime_nsec; + unsigned int ia_btime_nsec; + unsigned int ia_nlink; /* Link count */ + unsigned int ia_uid; /* user ID of owner */ + unsigned int ia_gid; /* group ID of owner */ + unsigned int ia_blksize; /* blocksize for filesystem I/O */ + unsigned int mode; /* type of file and rwx mode */ +}; + +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: + unsigned hyper value_uint; + case GF_DATA_TYPE_DOUBLE: + double value_dbl; + case GF_DATA_TYPE_STR: + opaque val_string<>; + case GF_DATA_TYPE_IATT: + gfx_iattx iatt; + 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 */ +/* This is used in the rpc header part itself, And not program payload. + Avoid sending large data load here. Allowed maximum is 400 bytes. + Ref: http://tools.ietf.org/html/rfc5531#section-8.2 + this is also handled in xdr-common.h +*/ +struct auth_glusterfs_params_v3 { + int pid; + unsigned int uid; + unsigned int gid; + + /* flags */ + /* Makes sense to use it for each bits */ + /* 0x1 == IS_INTERNAL? */ + /* Another 31 bits are reserved */ + unsigned int flags; + + /* birth time of the frame / call */ + unsigned int ctime_nsec; /* good to have 32bit for this */ + unsigned hyper ctime_sec; + + unsigned int groups<>; + opaque lk_owner<>; +}; + +struct gfx_dict_pair { + opaque key<>; + gfx_value value; +}; + +struct gfx_dict { + unsigned int xdr_size; + int count; + gfx_dict_pair pairs<>; +}; + +/* FOPS */ +struct gfx_common_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_common_iatt_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; + gfx_iattx stat; +}; + +struct gfx_common_2iatt_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; + gfx_iattx prestat; + gfx_iattx poststat; +}; + +struct gfx_common_3iatt_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_iattx stat; + gfx_iattx preparent; + gfx_iattx postparent; +}; + +struct gfx_fsetattr_req { + opaque gfid[16]; + hyper fd; + gfx_iattx stbuf; + int valid; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_rchecksum_req { + opaque gfid[16]; + hyper fd; + unsigned hyper offset; + unsigned int len; + unsigned int flags; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_icreate_req { + opaque gfid[16]; + unsigned int mode; + gfx_dict xdata; +}; + +struct gfx_put_req { + opaque pargfid[16]; + string bname<>; + unsigned int mode; + unsigned int umask; + unsigned int flag; + u_quad_t offset; + unsigned int size; + gfx_dict xattr; + gfx_dict xdata; +}; + +struct gfx_namelink_req { + opaque pargfid[16]; + string bname<>; + gfx_dict xdata; +}; + +/* Define every fops */ +/* Changes from Version 3: + 1. Dict has its own type instead of being opaque + 2. Iattx instead of iatt on wire + 3. gfid has 4 extra bytes so it can be used for future +*/ +struct gfx_stat_req { + opaque gfid[16]; + gfx_dict xdata; +}; + +struct gfx_readlink_req { + opaque gfid[16]; + unsigned int size; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_readlink_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_iattx buf; + string path<>; /* NULL terminated */ +}; + +struct gfx_mknod_req { + opaque pargfid[16]; + u_quad_t dev; + unsigned int mode; + unsigned int umask; + string bname<>; /* NULL terminated */ + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_mkdir_req { + opaque pargfid[16]; + unsigned int mode; + unsigned int umask; + string bname<>; /* NULL terminated */ + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_unlink_req { + opaque pargfid[16]; + string bname<>; /* NULL terminated */ + unsigned int xflags; + gfx_dict xdata; /* Extra data */ +}; + + +struct gfx_rmdir_req { + opaque pargfid[16]; + int xflags; + string bname<>; /* NULL terminated */ + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_symlink_req { + opaque pargfid[16]; + string bname<>; + unsigned int umask; + string linkname<>; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_rename_req { + opaque oldgfid[16]; + opaque newgfid[16]; + string oldbname<>; /* NULL terminated */ + string newbname<>; /* NULL terminated */ + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_rename_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_iattx stat; + gfx_iattx preoldparent; + gfx_iattx postoldparent; + gfx_iattx prenewparent; + gfx_iattx postnewparent; +}; + + + struct gfx_link_req { + opaque oldgfid[16]; + opaque newgfid[16]; + string newbname<>; + gfx_dict xdata; /* Extra data */ +}; + + struct gfx_truncate_req { + opaque gfid[16]; + u_quad_t offset; + gfx_dict xdata; /* Extra data */ +}; + + struct gfx_open_req { + opaque gfid[16]; + unsigned int flags; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_open_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + quad_t fd; +}; + +struct gfx_opendir_req { + opaque gfid[16]; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_read_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + unsigned int size; + unsigned int flag; + gfx_dict xdata; /* Extra data */ +}; + struct gfx_read_rsp { + int op_ret; + int op_errno; + gfx_iattx stat; + unsigned int size; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_lookup_req { + opaque gfid[16]; + opaque pargfid[16]; + unsigned int flags; + string bname<>; + gfx_dict xdata; /* Extra data */ +}; + + + struct gfx_write_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + unsigned int size; + unsigned int flag; + gfx_dict xdata; /* Extra data */ +}; + + struct gfx_statfs_req { + opaque gfid[16]; + gfx_dict xdata; /* Extra data */ +} ; + struct gfx_statfs_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gf_statfs statfs; +} ; + + struct gfx_lk_req { + opaque gfid[16]; + int64_t fd; + unsigned int cmd; + unsigned int type; + gf_proto_flock flock; + gfx_dict xdata; /* Extra data */ +} ; + struct gfx_lk_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gf_proto_flock flock; +} ; + +struct gfx_lease_req { + opaque gfid[16]; + gf_proto_lease lease; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_lease_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gf_proto_lease lease; +} ; + +struct gfx_recall_lease_req { + opaque gfid[16]; + unsigned int lease_type; + opaque tid[16]; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_inodelk_req { + opaque gfid[16]; + unsigned int cmd; + unsigned int type; + gf_proto_flock flock; + string volume<>; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_finodelk_req { + opaque gfid[16]; + quad_t fd; + unsigned int cmd; + unsigned int type; + gf_proto_flock flock; + string volume<>; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_flush_req { + opaque gfid[16]; + quad_t fd; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_fsync_req { + opaque gfid[16]; + quad_t fd; + unsigned int data; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_setxattr_req { + opaque gfid[16]; + unsigned int flags; + gfx_dict dict; + gfx_dict xdata; /* Extra data */ +} ; + + + + struct gfx_fsetxattr_req { + opaque gfid[16]; + int64_t fd; + unsigned int flags; + gfx_dict dict; + gfx_dict xdata; /* Extra data */ +} ; + + + + struct gfx_xattrop_req { + opaque gfid[16]; + unsigned int flags; + gfx_dict dict; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_common_dict_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_dict dict; + gfx_iattx prestat; + gfx_iattx poststat; +}; + + + struct gfx_fxattrop_req { + opaque gfid[16]; + quad_t fd; + unsigned int flags; + gfx_dict dict; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_getxattr_req { + opaque gfid[16]; + unsigned int namelen; + string name<>; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_fgetxattr_req { + opaque gfid[16]; + quad_t fd; + unsigned int namelen; + string name<>; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_removexattr_req { + opaque gfid[16]; + string name<>; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_fremovexattr_req { + opaque gfid[16]; + quad_t fd; + string name<>; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_fsyncdir_req { + opaque gfid[16]; + quad_t fd; + int data; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_readdir_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + unsigned int size; + gfx_dict xdata; /* Extra data */ +}; + + struct gfx_readdirp_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + unsigned int size; + gfx_dict xdata; +} ; + + +struct gfx_access_req { + opaque gfid[16]; + unsigned int mask; + gfx_dict xdata; /* Extra data */ +} ; + + +struct gfx_create_req { + opaque pargfid[16]; + unsigned int flags; + unsigned int mode; + unsigned int umask; + string bname<>; + gfx_dict xdata; /* Extra data */ +} ; +struct gfx_create_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_iattx stat; + u_quad_t fd; + gfx_iattx preparent; + gfx_iattx postparent; +} ; + +struct gfx_ftruncate_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + gfx_dict xdata; /* Extra data */ +} ; + + +struct gfx_fstat_req { + opaque gfid[16]; + quad_t fd; + gfx_dict xdata; /* Extra data */ +} ; + + +struct gfx_entrylk_req { + opaque gfid[16]; + unsigned int cmd; + unsigned int type; + u_quad_t namelen; + string name<>; + string volume<>; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_fentrylk_req { + opaque gfid[16]; + quad_t fd; + unsigned int cmd; + unsigned int type; + u_quad_t namelen; + string name<>; + string volume<>; + gfx_dict xdata; /* Extra data */ +}; + + struct gfx_setattr_req { + opaque gfid[16]; + gfx_iattx stbuf; + int valid; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_fallocate_req { + opaque gfid[16]; + quad_t fd; + unsigned int flags; + u_quad_t offset; + u_quad_t size; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_discard_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + u_quad_t size; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_zerofill_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + u_quad_t size; + gfx_dict xdata; +} ; + +struct gfx_rchecksum_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + unsigned int flags; + unsigned int weak_checksum; + opaque strong_checksum<>; +} ; + + +struct gfx_ipc_req { + int op; + gfx_dict xdata; +}; + + +struct gfx_seek_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + int what; + gfx_dict xdata; +}; + +struct gfx_seek_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; + u_quad_t offset; +}; + + + 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; + gfx_dict dict; +} ; + + + struct gfx_getspec_req { + unsigned int flags; + string key<>; + gfx_dict xdata; /* Extra data */ +} ; + struct gfx_getspec_rsp { + int op_ret; + int op_errno; + string spec<>; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_notify_req { + unsigned int flags; + string buf<>; + gfx_dict xdata; /* Extra data */ +} ; + struct gfx_notify_rsp { + int op_ret; + int op_errno; + unsigned int flags; + string buf<>; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_releasedir_req { + opaque gfid[16]; + quad_t fd; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_release_req { + opaque gfid[16]; + quad_t fd; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_dirlist { + u_quad_t d_ino; + u_quad_t d_off; + unsigned int d_len; + unsigned int d_type; + string name<>; + gfx_dirlist *nextentry; +}; + + +struct gfx_readdir_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_dirlist *reply; +}; + +struct gfx_dirplist { + u_quad_t d_ino; + u_quad_t d_off; + unsigned int d_len; + unsigned int d_type; + string name<>; + gfx_iattx stat; + gfx_dict dict; + gfx_dirplist *nextentry; +}; + +struct gfx_readdirp_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_dirplist *reply; +}; + +struct gfx_set_lk_ver_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; + int lk_ver; +}; + +struct gfx_set_lk_ver_req { + string uid<>; + int lk_ver; +}; + +struct gfx_event_notify_req { + int op; + gfx_dict dict; +}; + + +struct gfx_getsnap_name_uuid_req { + gfx_dict dict; +}; + +struct gfx_getsnap_name_uuid_rsp { + int op_ret; + int op_errno; + gfx_dict dict; + string op_errstr<>; +}; + +struct gfx_getactivelk_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; + gfs3_locklist *reply; +}; + +struct gfx_getactivelk_req { + opaque gfid[16]; + gfx_dict xdata; +}; + +struct gfx_setactivelk_req { + opaque gfid[16]; + gfs3_locklist *request; + gfx_dict xdata; +}; + +struct gfs4_inodelk_contention_req { + opaque gfid[16]; + struct gf_proto_flock flock; + unsigned int pid; + string domain<>; + opaque xdata<>; +}; + +struct gfs4_entrylk_contention_req { + opaque gfid[16]; + unsigned int type; + unsigned int pid; + string name<>; + string domain<>; + opaque xdata<>; +}; diff --git a/rpc/xdr/src/libgfxdr.sym b/rpc/xdr/src/libgfxdr.sym new file mode 100644 index 00000000000..8fa0e0ddd8a --- /dev/null +++ b/rpc/xdr/src/libgfxdr.sym @@ -0,0 +1,350 @@ +xdr_auth_glusterfs_parms +xdr_auth_glusterfs_parms_v2 +xdr_auth_glusterfs_params_v3 +xdr_changelog_event_req +xdr_changelog_event_rsp +xdr_changelog_probe_req +xdr_changelog_probe_rsp +xdr_dirpath +xdr_free_exports_list +xdr_free_mountlist +xdr_gd1_mgmt_brick_op_req +xdr_gd1_mgmt_brick_op_rsp +xdr_gd1_mgmt_cluster_lock_req +xdr_gd1_mgmt_cluster_lock_rsp +xdr_gd1_mgmt_cluster_unlock_req +xdr_gd1_mgmt_cluster_unlock_rsp +xdr_gd1_mgmt_commit_op_req +xdr_gd1_mgmt_commit_op_rsp +xdr_gd1_mgmt_friend_req +xdr_gd1_mgmt_friend_rsp +xdr_gd1_mgmt_friend_update +xdr_gd1_mgmt_friend_update_rsp +xdr_gd1_mgmt_probe_req +xdr_gd1_mgmt_probe_rsp +xdr_gd1_mgmt_stage_op_req +xdr_gd1_mgmt_stage_op_rsp +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 +xdr_gd1_mgmt_v3_post_val_rsp +xdr_gd1_mgmt_v3_pre_val_req +xdr_gd1_mgmt_v3_pre_val_rsp +xdr_gd1_mgmt_v3_unlock_req +xdr_gd1_mgmt_v3_unlock_rsp +xdr_gf1_cli_fsm_log_req +xdr_gf1_cli_fsm_log_rsp +xdr_gf1_cli_getwd_req +xdr_gf1_cli_getwd_rsp +xdr_gf1_cli_mount_req +xdr_gf1_cli_mount_rsp +xdr_gf1_cli_peer_list_req +xdr_gf1_cli_peer_list_rsp +xdr_gf1_cli_umount_req +xdr_gf1_cli_umount_rsp +xdr_gf_cli_req +xdr_gf_cli_rsp +xdr_gf_common_rsp +xdr_gf_dump_req +xdr_gf_dump_rsp +xdr_gf_event_notify_req +xdr_gf_event_notify_rsp +xdr_gf_getsnap_name_uuid_req +xdr_gf_getsnap_name_uuid_rsp +xdr_gf_getspec_req +xdr_gf_getspec_rsp +xdr_gf_get_volume_info_req +xdr_gf_get_volume_info_rsp +xdr_gf_mgmt_hndsk_req +xdr_gf_mgmt_hndsk_rsp +xdr_gfs3_access_req +xdr_gfs3_cbk_cache_invalidation_req +xdr_gfs3_compound_req +xdr_gfs3_compound_rsp +xdr_gfs3_create_req +xdr_gfs3_create_rsp +xdr_gfs3_discard_req +xdr_gfs3_discard_rsp +xdr_gfs3_entrylk_req +xdr_gfs3_fallocate_req +xdr_gfs3_fallocate_rsp +xdr_gfs3_fentrylk_req +xdr_gfs3_fgetxattr_req +xdr_gfs3_fgetxattr_rsp +xdr_gfs3_finodelk_req +xdr_gfs3_flush_req +xdr_gfs3_fremovexattr_req +xdr_gfs3_fsetattr_req +xdr_gfs3_fsetattr_req_v2 +xdr_gfs3_fsetattr_rsp +xdr_gfs3_fsetxattr_req +xdr_gfs3_fstat_req +xdr_gfs3_fstat_rsp +xdr_gfs3_fsyncdir_req +xdr_gfs3_fsync_req +xdr_gfs3_fsync_rsp +xdr_gfs3_ftruncate_req +xdr_gfs3_ftruncate_rsp +xdr_gfs3_fxattrop_req +xdr_gfs3_fxattrop_rsp +xdr_gfs3_getactivelk_req +xdr_gfs3_getactivelk_rsp +xdr_gfs3_getxattr_req +xdr_gfs3_getxattr_rsp +xdr_gfs3_inodelk_req +xdr_gfs3_ipc_req +xdr_gfs3_ipc_rsp +xdr_gfs3_lease_req +xdr_gfs3_lease_rsp +xdr_gfs3_link_req +xdr_gfs3_link_rsp +xdr_gfs3_lk_req +xdr_gfs3_lk_rsp +xdr_gfs3_lookup_req +xdr_gfs3_lookup_rsp +xdr_gfs3_mkdir_req +xdr_gfs3_mkdir_rsp +xdr_gfs3_mknod_req +xdr_gfs3_mknod_rsp +xdr_gfs3_opendir_req +xdr_gfs3_opendir_rsp +xdr_gfs3_open_req +xdr_gfs3_open_rsp +xdr_gfs3_rchecksum_req +xdr_gfs3_rchecksum_req_v2 +xdr_gfs3_rchecksum_rsp +xdr_gfs3_readdirp_req +xdr_gfs3_readdirp_rsp +xdr_gfs3_readdir_req +xdr_gfs3_readdir_rsp +xdr_gfs3_readlink_req +xdr_gfs3_readlink_rsp +xdr_gfs3_read_req +xdr_gfs3_read_rsp +xdr_gfs3_recall_lease_req +xdr_gfs3_releasedir_req +xdr_gfs3_release_req +xdr_gfs3_removexattr_req +xdr_gfs3_rename_req +xdr_gfs3_rename_rsp +xdr_gfs3_rmdir_req +xdr_gfs3_rmdir_rsp +xdr_gfs3_seek_req +xdr_gfs3_seek_rsp +xdr_gfs3_setactivelk_req +xdr_gfs3_setactivelk_rsp +xdr_gfs3_setattr_req +xdr_gfs3_setattr_rsp +xdr_gfs3_setxattr_req +xdr_gfs3_statfs_req +xdr_gfs3_statfs_rsp +xdr_gfs3_stat_req +xdr_gfs3_stat_rsp +xdr_gfs3_symlink_req +xdr_gfs3_symlink_rsp +xdr_gfs3_truncate_req +xdr_gfs3_truncate_rsp +xdr_gfs3_unlink_req +xdr_gfs3_unlink_rsp +xdr_gfs3_write_req +xdr_gfs3_write_rsp +xdr_gfs3_xattrop_req +xdr_gfs3_xattrop_rsp +xdr_gfs3_zerofill_req +xdr_gfs3_zerofill_rsp +xdr_gfs4_entrylk_contention_req +xdr_gfs4_entrylk_contention_rsp +xdr_gfs4_icreate_req +xdr_gfs4_icreate_rsp +xdr_gfs4_inodelk_contention_req +xdr_gfs4_inodelk_contention_rsp +xdr_gfs4_namelink_req +xdr_gfs4_namelink_rsp +xdr_gf_set_lk_ver_req +xdr_gf_set_lk_ver_rsp +xdr_gf_setvolume_req +xdr_gf_setvolume_rsp +xdr_gf_statedump +xdr_length_round_up +xdr_mon +xdr_mountres3 +xdr_mountstat3 +xdr_nlm_sm_status +xdr_pmap_brick_by_port_req +xdr_pmap_brick_by_port_rsp +xdr_pmap_port_by_brick_req +xdr_pmap_port_by_brick_rsp +xdr_pmap_signin_req +xdr_pmap_signin_rsp +xdr_pmap_signout_req +xdr_pmap_signout_rsp +xdr_serialize_access3res +xdr_serialize_commit3res +xdr_serialize_create3res +xdr_serialize_exports +xdr_serialize_fsinfo3res +xdr_serialize_fsstat3res +xdr_serialize_generic +xdr_serialize_getaclreply +xdr_serialize_getattr3res +xdr_serialize_link3res +xdr_serialize_lookup3res +xdr_serialize_mkdir3res +xdr_serialize_mknod3res +xdr_serialize_mountlist +xdr_serialize_mountres3 +xdr_serialize_mountstat3 +xdr_serialize_nlm4_res +xdr_serialize_nlm4_shareres +xdr_serialize_nlm4_testargs +xdr_serialize_nlm4_testres +xdr_serialize_pathconf3res +xdr_serialize_read3res +xdr_serialize_read3res_nocopy +xdr_serialize_readdir3res +xdr_serialize_readdirp3res +xdr_serialize_readlink3res +xdr_serialize_remove3res +xdr_serialize_rename3res +xdr_serialize_rmdir3res +xdr_serialize_setaclreply +xdr_serialize_setattr3res +xdr_serialize_symlink3res +xdr_serialize_write3res +xdr_sm_stat +xdr_sm_stat_res +xdr_to_access3args +xdr_to_commit3args +xdr_to_create3args +xdr_to_fsinfo3args +xdr_to_fsstat3args +xdr_to_generic +xdr_to_getaclargs +xdr_to_getattr3args +xdr_to_link3args +xdr_to_lookup3args +xdr_to_mkdir3args +xdr_to_mknod3args +xdr_to_mountpath +xdr_to_nlm4_cancelargs +xdr_to_nlm4_freeallargs +xdr_to_nlm4_lockargs +xdr_to_nlm4_shareargs +xdr_to_nlm4_testargs +xdr_to_nlm4_unlockargs +xdr_to_pathconf3args +xdr_to_read3args +xdr_to_readdir3args +xdr_to_readdirp3args +xdr_to_readlink3args +xdr_to_remove3args +xdr_to_rename3args +xdr_to_rmdir3args +xdr_to_setaclargs +xdr_to_setattr3args +xdr_to_symlink3args +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 +xdr_gfx_common_rsp +xdr_gfx_common_iatt_rsp +xdr_gfx_common_2iatt_rsp +xdr_gfx_common_3iatt_rsp +xdr_gfx_fsetattr_req +xdr_gfx_rchecksum_req +xdr_gfx_icreate_req +xdr_gfx_namelink_req +xdr_gfx_stat_req +xdr_gfx_readlink_req +xdr_gfx_readlink_rsp +xdr_gfx_mknod_req +xdr_gfx_mkdir_req +xdr_gfx_unlink_req +xdr_gfx_rmdir_req +xdr_gfx_symlink_req +xdr_gfx_rename_req +xdr_gfx_rename_rsp +xdr_gfx_link_req +xdr_gfx_truncate_req +xdr_gfx_open_req +xdr_gfx_open_rsp +xdr_gfx_opendir_req +xdr_gfx_read_req +xdr_gfx_read_rsp +xdr_gfx_lookup_req +xdr_gfx_write_req +xdr_gfx_statfs_req +xdr_gfx_statfs_rsp +xdr_gfx_lk_req +xdr_gfx_lk_rsp +xdr_gfx_lease_req +xdr_gfx_lease_rsp +xdr_gfx_recall_lease_req +xdr_gfx_inodelk_req +xdr_gfx_finodelk_req +xdr_gfx_flush_req +xdr_gfx_fsync_req +xdr_gfx_setxattr_req +xdr_gfx_fsetxattr_req +xdr_gfx_xattrop_req +xdr_gfx_common_dict_rsp +xdr_gfx_fxattrop_req +xdr_gfx_getxattr_req +xdr_gfx_fgetxattr_req +xdr_gfx_removexattr_req +xdr_gfx_fremovexattr_req +xdr_gfx_fsyncdir_req +xdr_gfx_readdir_req +xdr_gfx_readdirp_req +xdr_gfx_access_req +xdr_gfx_create_req +xdr_gfx_create_rsp +xdr_gfx_ftruncate_req +xdr_gfx_fstat_req +xdr_gfx_entrylk_req +xdr_gfx_fentrylk_req +xdr_gfx_setattr_req +xdr_gfx_fallocate_req +xdr_gfx_discard_req +xdr_gfx_zerofill_req +xdr_gfx_rchecksum_rsp +xdr_gfx_ipc_req +xdr_gfx_seek_req +xdr_gfx_seek_rsp +xdr_gfx_setvolume_req +xdr_gfx_setvolume_rsp +xdr_gfx_getspec_req +xdr_gfx_getspec_rsp +xdr_gfx_notify_req +xdr_gfx_notify_rsp +xdr_gfx_releasedir_req +xdr_gfx_release_req +xdr_gfx_dirlist +xdr_gfx_readdir_rsp +xdr_gfx_dirplist +xdr_gfx_readdirp_rsp +xdr_gfx_set_lk_ver_rsp +xdr_gfx_set_lk_ver_req +xdr_gfx_event_notify_req +xdr_gfx_getsnap_name_uuid_req +xdr_gfx_getsnap_name_uuid_rsp +xdr_gfx_getactivelk_rsp +xdr_gfx_getactivelk_req +xdr_gfx_setactivelk_req +xdr_gfx_put_req +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 new file mode 100644 index 00000000000..e8366df400c --- /dev/null +++ b/rpc/xdr/src/mount3udp.x @@ -0,0 +1,32 @@ +/* + Copyright (c) 2007-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. +*/ + +#ifdef RPC_XDR +%#include "rpc-pragmas.h" +#endif +%#include <glusterfs/compat.h> + +/* This is used by rpcgen to auto generate the rpc stubs. + * mount3udp_svc.c is heavily modified though + */ + +%#include "xdr-nfs3.h" + +const MNTUDPPATHLEN = 1024; + +typedef string mntudpdirpath<MNTPATHLEN>; + +program MOUNTUDP_PROGRAM { + version MOUNTUDP_V3 { + void MOUNTUDPPROC3_NULL(void) = 0; + mountres3 MOUNTUDPPROC3_MNT (mntudpdirpath) = 1; + mountstat3 MOUNTUDPPROC3_UMNT (mntudpdirpath) = 3; + } = 3; +} = 100005; diff --git a/rpc/xdr/src/msg-nfs3.c b/rpc/xdr/src/msg-nfs3.c index d760d43b5d2..d14a731b62a 100644 --- a/rpc/xdr/src/msg-nfs3.c +++ b/rpc/xdr/src/msg-nfs3.c @@ -1,27 +1,13 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include <sys/uio.h> #include <rpc/rpc.h> #include <rpc/xdr.h> @@ -32,524 +18,464 @@ #include "xdr-generic.h" #include "xdr-common.h" - /* Decode the mount path from the network message in inmsg * into the memory referenced by outpath.iov_base. * The size allocated for outpath.iov_base is outpath.iov_len. * The size of the path extracted from the message is returned. */ ssize_t -xdr_to_mountpath (struct iovec outpath, struct iovec inmsg) +xdr_to_mountpath(struct iovec outpath, struct iovec inmsg) { - XDR xdr; - ssize_t ret = -1; - char *mntpath = NULL; + XDR xdr; + ssize_t ret = -1; + char *mntpath = NULL; - if ((!outpath.iov_base) || (!inmsg.iov_base)) - return -1; + if ((!outpath.iov_base) || (!inmsg.iov_base)) + return -1; - xdrmem_create (&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len, - XDR_DECODE); + xdrmem_create(&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len, + XDR_DECODE); - mntpath = outpath.iov_base; - if (!xdr_dirpath (&xdr, (dirpath *)&mntpath)) { - ret = -1; - goto ret; - } + mntpath = outpath.iov_base; + if (!xdr_dirpath(&xdr, (dirpath *)&mntpath)) { + ret = -1; + goto ret; + } - ret = xdr_decoded_length (xdr); + ret = xdr_decoded_length(xdr); ret: - return ret; + return ret; } -/* +/* Translate the mountres3 structure in res into XDR format into memory + * referenced by outmsg.iov_base. + * Returns the number of bytes used in encoding into XDR format. + */ ssize_t -xdr_serialize_generic (struct iovec outmsg, void *res, xdrproc_t proc) +xdr_serialize_mountres3(struct iovec outmsg, mountres3 *res) { - ssize_t ret = -1; - XDR xdr; - - if ((!outmsg.iov_base) || (!res) || (!proc)) - return -1; - - xdrmem_create (&xdr, outmsg.iov_base, (unsigned int)outmsg.iov_len, - XDR_ENCODE); - - if (!proc (&xdr, res)) { - ret = -1; - goto ret; - } - - ret = xdr_encoded_length (xdr); - -ret: - return ret; + return xdr_serialize_generic(outmsg, (void *)res, (xdrproc_t)xdr_mountres3); } - ssize_t -xdr_to_generic (struct iovec inmsg, void *args, xdrproc_t proc) +xdr_serialize_mountbody(struct iovec outmsg, mountbody *mb) { - XDR xdr; - ssize_t ret = -1; - - if ((!inmsg.iov_base) || (!args) || (!proc)) - return -1; - - xdrmem_create (&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len, - XDR_DECODE); - - if (!proc (&xdr, args)) { - ret = -1; - goto ret; - } - - ret = xdr_decoded_length (xdr); -ret: - return ret; + return xdr_serialize_generic(outmsg, (void *)mb, (xdrproc_t)xdr_mountbody); } - ssize_t -xdr_to_generic_payload (struct iovec inmsg, void *args, xdrproc_t proc, - struct iovec *pendingpayload) +xdr_serialize_mountlist(struct iovec outmsg, mountlist *ml) { - XDR xdr; - ssize_t ret = -1; - - if ((!inmsg.iov_base) || (!args) || (!proc)) - return -1; - - xdrmem_create (&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len, - XDR_DECODE); - - if (!proc (&xdr, args)) { - ret = -1; - goto ret; - } - - ret = xdr_decoded_length (xdr); - - if (pendingpayload) { - pendingpayload->iov_base = xdr_decoded_remaining_addr (xdr); - pendingpayload->iov_len = xdr_decoded_remaining_len (xdr); - } - -ret: - return ret; + return xdr_serialize_generic(outmsg, (void *)ml, (xdrproc_t)xdr_mountlist); } -*/ -/* Translate the mountres3 structure in res into XDR format into memory - * referenced by outmsg.iov_base. - * Returns the number of bytes used in encoding into XDR format. - */ ssize_t -xdr_serialize_mountres3 (struct iovec outmsg, mountres3 *res) +xdr_serialize_mountstat3(struct iovec outmsg, mountstat3 *m) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_mountres3); + return xdr_serialize_generic(outmsg, (void *)m, (xdrproc_t)xdr_mountstat3); } - ssize_t -xdr_serialize_mountbody (struct iovec outmsg, mountbody *mb) +xdr_to_getattr3args(struct iovec inmsg, getattr3args *ga) { - return xdr_serialize_generic (outmsg, (void *)mb, - (xdrproc_t)xdr_mountbody); + return xdr_to_generic(inmsg, (void *)ga, (xdrproc_t)xdr_getattr3args); } ssize_t -xdr_serialize_mountlist (struct iovec outmsg, mountlist *ml) +xdr_serialize_getattr3res(struct iovec outmsg, getattr3res *res) { - return xdr_serialize_generic (outmsg, (void *)ml, - (xdrproc_t)xdr_mountlist); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_getattr3res); } - ssize_t -xdr_serialize_mountstat3 (struct iovec outmsg, mountstat3 *m) +xdr_serialize_setattr3res(struct iovec outmsg, setattr3res *res) { - return xdr_serialize_generic (outmsg, (void *)m, - (xdrproc_t)xdr_mountstat3); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_setattr3res); } - ssize_t -xdr_to_getattr3args (struct iovec inmsg, getattr3args *ga) +xdr_to_setattr3args(struct iovec inmsg, setattr3args *sa) { - return xdr_to_generic (inmsg, (void *)ga, - (xdrproc_t)xdr_getattr3args); + return xdr_to_generic(inmsg, (void *)sa, (xdrproc_t)xdr_setattr3args); } - ssize_t -xdr_serialize_getattr3res (struct iovec outmsg, getattr3res *res) +xdr_serialize_lookup3res(struct iovec outmsg, lookup3res *res) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_getattr3res); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_lookup3res); } - ssize_t -xdr_serialize_setattr3res (struct iovec outmsg, setattr3res *res) +xdr_to_lookup3args(struct iovec inmsg, lookup3args *la) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_setattr3res); + return xdr_to_generic(inmsg, (void *)la, (xdrproc_t)xdr_lookup3args); } - ssize_t -xdr_to_setattr3args (struct iovec inmsg, setattr3args *sa) +xdr_to_access3args(struct iovec inmsg, access3args *ac) { - return xdr_to_generic (inmsg, (void *)sa, - (xdrproc_t)xdr_setattr3args); + return xdr_to_generic(inmsg, (void *)ac, (xdrproc_t)xdr_access3args); } - ssize_t -xdr_serialize_lookup3res (struct iovec outmsg, lookup3res *res) +xdr_serialize_access3res(struct iovec outmsg, access3res *res) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_lookup3res); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_access3res); } - ssize_t -xdr_to_lookup3args (struct iovec inmsg, lookup3args *la) +xdr_to_readlink3args(struct iovec inmsg, readlink3args *ra) { - return xdr_to_generic (inmsg, (void *)la, - (xdrproc_t)xdr_lookup3args); + return xdr_to_generic(inmsg, (void *)ra, (xdrproc_t)xdr_readlink3args); } - ssize_t -xdr_to_access3args (struct iovec inmsg, access3args *ac) +xdr_serialize_readlink3res(struct iovec outmsg, readlink3res *res) { - return xdr_to_generic (inmsg,(void *)ac, - (xdrproc_t)xdr_access3args); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_readlink3res); } - ssize_t -xdr_serialize_access3res (struct iovec outmsg, access3res *res) +xdr_to_read3args(struct iovec inmsg, read3args *ra) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_access3res); + return xdr_to_generic(inmsg, (void *)ra, (xdrproc_t)xdr_read3args); } - ssize_t -xdr_to_readlink3args (struct iovec inmsg, readlink3args *ra) +xdr_serialize_read3res(struct iovec outmsg, read3res *res) { - return xdr_to_generic (inmsg, (void *)ra, - (xdrproc_t)xdr_readlink3args); + return xdr_serialize_generic(outmsg, (void *)res, (xdrproc_t)xdr_read3res); } - ssize_t -xdr_serialize_readlink3res (struct iovec outmsg, readlink3res *res) +xdr_serialize_read3res_nocopy(struct iovec outmsg, read3res *res) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_readlink3res); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_read3res_nocopy); } - ssize_t -xdr_to_read3args (struct iovec inmsg, read3args *ra) +xdr_to_write3args(struct iovec inmsg, write3args *wa) { - return xdr_to_generic (inmsg, (void *)ra, (xdrproc_t)xdr_read3args); + return xdr_to_generic(inmsg, (void *)wa, (xdrproc_t)xdr_write3args); } - ssize_t -xdr_serialize_read3res (struct iovec outmsg, read3res *res) +xdr_to_write3args_nocopy(struct iovec inmsg, write3args *wa, + struct iovec *payload) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_read3res); + return xdr_to_generic_payload(inmsg, (void *)wa, (xdrproc_t)xdr_write3args, + payload); } ssize_t -xdr_serialize_read3res_nocopy (struct iovec outmsg, read3res *res) +xdr_serialize_write3res(struct iovec outmsg, write3res *res) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_read3res_nocopy); + return xdr_serialize_generic(outmsg, (void *)res, (xdrproc_t)xdr_write3res); } - ssize_t -xdr_to_write3args (struct iovec inmsg, write3args *wa) +xdr_to_create3args(struct iovec inmsg, create3args *ca) { - return xdr_to_generic (inmsg, (void *)wa,(xdrproc_t)xdr_write3args); + return xdr_to_generic(inmsg, (void *)ca, (xdrproc_t)xdr_create3args); } - ssize_t -xdr_to_write3args_nocopy (struct iovec inmsg, write3args *wa, - struct iovec *payload) +xdr_serialize_create3res(struct iovec outmsg, create3res *res) { - return xdr_to_generic_payload (inmsg, (void *)wa, - (xdrproc_t)xdr_write3args, payload); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_create3res); } - ssize_t -xdr_serialize_write3res (struct iovec outmsg, write3res *res) +xdr_serialize_mkdir3res(struct iovec outmsg, mkdir3res *res) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_write3res); + return xdr_serialize_generic(outmsg, (void *)res, (xdrproc_t)xdr_mkdir3res); } - ssize_t -xdr_to_create3args (struct iovec inmsg, create3args *ca) +xdr_to_mkdir3args(struct iovec inmsg, mkdir3args *ma) { - return xdr_to_generic (inmsg, (void *)ca, - (xdrproc_t)xdr_create3args); + return xdr_to_generic(inmsg, (void *)ma, (xdrproc_t)xdr_mkdir3args); } - ssize_t -xdr_serialize_create3res (struct iovec outmsg, create3res *res) +xdr_to_symlink3args(struct iovec inmsg, symlink3args *sa) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_create3res); + return xdr_to_generic(inmsg, (void *)sa, (xdrproc_t)xdr_symlink3args); } - ssize_t -xdr_serialize_mkdir3res (struct iovec outmsg, mkdir3res *res) +xdr_serialize_symlink3res(struct iovec outmsg, symlink3res *res) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_mkdir3res); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_symlink3res); } - ssize_t -xdr_to_mkdir3args (struct iovec inmsg, mkdir3args *ma) +xdr_to_mknod3args(struct iovec inmsg, mknod3args *ma) { - return xdr_to_generic (inmsg, (void *)ma, - (xdrproc_t)xdr_mkdir3args); + return xdr_to_generic(inmsg, (void *)ma, (xdrproc_t)xdr_mknod3args); } - ssize_t -xdr_to_symlink3args (struct iovec inmsg, symlink3args *sa) +xdr_serialize_mknod3res(struct iovec outmsg, mknod3res *res) { - return xdr_to_generic (inmsg, (void *)sa, - (xdrproc_t)xdr_symlink3args); + return xdr_serialize_generic(outmsg, (void *)res, (xdrproc_t)xdr_mknod3res); } - ssize_t -xdr_serialize_symlink3res (struct iovec outmsg, symlink3res *res) +xdr_to_remove3args(struct iovec inmsg, remove3args *ra) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_symlink3res); + return xdr_to_generic(inmsg, (void *)ra, (xdrproc_t)xdr_remove3args); } - ssize_t -xdr_to_mknod3args (struct iovec inmsg, mknod3args *ma) +xdr_serialize_remove3res(struct iovec outmsg, remove3res *res) { - return xdr_to_generic (inmsg, (void *)ma, - (xdrproc_t)xdr_mknod3args); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_remove3res); } - ssize_t -xdr_serialize_mknod3res (struct iovec outmsg, mknod3res *res) +xdr_to_rmdir3args(struct iovec inmsg, rmdir3args *ra) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_mknod3res); + return xdr_to_generic(inmsg, (void *)ra, (xdrproc_t)xdr_rmdir3args); } - ssize_t -xdr_to_remove3args (struct iovec inmsg, remove3args *ra) +xdr_serialize_rmdir3res(struct iovec outmsg, rmdir3res *res) { - return xdr_to_generic (inmsg, (void *)ra, - (xdrproc_t)xdr_remove3args); + return xdr_serialize_generic(outmsg, (void *)res, (xdrproc_t)xdr_rmdir3res); } - ssize_t -xdr_serialize_remove3res (struct iovec outmsg, remove3res *res) +xdr_serialize_rename3res(struct iovec outmsg, rename3res *res) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_remove3res); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_rename3res); } - ssize_t -xdr_to_rmdir3args (struct iovec inmsg, rmdir3args *ra) +xdr_to_rename3args(struct iovec inmsg, rename3args *ra) { - return xdr_to_generic (inmsg, (void *)ra, - (xdrproc_t)xdr_rmdir3args); + return xdr_to_generic(inmsg, (void *)ra, (xdrproc_t)xdr_rename3args); } - ssize_t -xdr_serialize_rmdir3res (struct iovec outmsg, rmdir3res *res) +xdr_serialize_link3res(struct iovec outmsg, link3res *li) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_rmdir3res); + return xdr_serialize_generic(outmsg, (void *)li, (xdrproc_t)xdr_link3res); } - ssize_t -xdr_serialize_rename3res (struct iovec outmsg, rename3res *res) +xdr_to_link3args(struct iovec inmsg, link3args *la) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_rename3res); + return xdr_to_generic(inmsg, (void *)la, (xdrproc_t)xdr_link3args); } - ssize_t -xdr_to_rename3args (struct iovec inmsg, rename3args *ra) +xdr_to_readdir3args(struct iovec inmsg, readdir3args *rd) { - return xdr_to_generic (inmsg, (void *)ra, - (xdrproc_t)xdr_rename3args); + return xdr_to_generic(inmsg, (void *)rd, (xdrproc_t)xdr_readdir3args); } - ssize_t -xdr_serialize_link3res (struct iovec outmsg, link3res *li) +xdr_serialize_readdir3res(struct iovec outmsg, readdir3res *res) { - return xdr_serialize_generic (outmsg, (void *)li, - (xdrproc_t)xdr_link3res); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_readdir3res); } - ssize_t -xdr_to_link3args (struct iovec inmsg, link3args *la) +xdr_to_readdirp3args(struct iovec inmsg, readdirp3args *rp) { - return xdr_to_generic (inmsg, (void *)la, (xdrproc_t)xdr_link3args); + return xdr_to_generic(inmsg, (void *)rp, (xdrproc_t)xdr_readdirp3args); } - ssize_t -xdr_to_readdir3args (struct iovec inmsg, readdir3args *rd) +xdr_serialize_readdirp3res(struct iovec outmsg, readdirp3res *res) { - return xdr_to_generic (inmsg, (void *)rd, - (xdrproc_t)xdr_readdir3args); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_readdirp3res); } - ssize_t -xdr_serialize_readdir3res (struct iovec outmsg, readdir3res *res) +xdr_to_fsstat3args(struct iovec inmsg, fsstat3args *fa) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_readdir3res); + return xdr_to_generic(inmsg, (void *)fa, (xdrproc_t)xdr_fsstat3args); } - ssize_t -xdr_to_readdirp3args (struct iovec inmsg, readdirp3args *rp) +xdr_serialize_fsstat3res(struct iovec outmsg, fsstat3res *res) { - return xdr_to_generic (inmsg, (void *)rp, - (xdrproc_t)xdr_readdirp3args); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_fsstat3res); } - ssize_t -xdr_serialize_readdirp3res (struct iovec outmsg, readdirp3res *res) +xdr_to_fsinfo3args(struct iovec inmsg, fsinfo3args *fi) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_readdirp3res); + return xdr_to_generic(inmsg, (void *)fi, (xdrproc_t)xdr_fsinfo3args); } - ssize_t -xdr_to_fsstat3args (struct iovec inmsg, fsstat3args *fa) +xdr_serialize_fsinfo3res(struct iovec outmsg, fsinfo3res *res) { - return xdr_to_generic (inmsg, (void *)fa, - (xdrproc_t)xdr_fsstat3args); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_fsinfo3res); } - ssize_t -xdr_serialize_fsstat3res (struct iovec outmsg, fsstat3res *res) +xdr_to_pathconf3args(struct iovec inmsg, pathconf3args *pc) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_fsstat3res); + return xdr_to_generic(inmsg, (void *)pc, (xdrproc_t)xdr_pathconf3args); } ssize_t -xdr_to_fsinfo3args (struct iovec inmsg, fsinfo3args *fi) +xdr_serialize_pathconf3res(struct iovec outmsg, pathconf3res *res) { - return xdr_to_generic (inmsg, (void *)fi, - (xdrproc_t)xdr_fsinfo3args); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_pathconf3res); } - ssize_t -xdr_serialize_fsinfo3res (struct iovec outmsg, fsinfo3res *res) +xdr_to_commit3args(struct iovec inmsg, commit3args *ca) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_fsinfo3res); + return xdr_to_generic(inmsg, (void *)ca, (xdrproc_t)xdr_commit3args); } +ssize_t +xdr_serialize_commit3res(struct iovec outmsg, commit3res *res) +{ + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_commit3res); +} ssize_t -xdr_to_pathconf3args (struct iovec inmsg, pathconf3args *pc) +xdr_serialize_exports(struct iovec outmsg, exports *elist) { - return xdr_to_generic (inmsg, (void *)pc, - (xdrproc_t)xdr_pathconf3args);} + XDR xdr; + ssize_t ret = -1; + + if ((!outmsg.iov_base) || (!elist)) + return -1; + + xdrmem_create(&xdr, outmsg.iov_base, (unsigned int)outmsg.iov_len, + XDR_ENCODE); + + if (!xdr_exports(&xdr, elist)) + goto ret; + + ret = xdr_decoded_length(xdr); +ret: + return ret; +} ssize_t -xdr_serialize_pathconf3res (struct iovec outmsg, pathconf3res *res) +xdr_serialize_nfsstat3(struct iovec outmsg, nfsstat3 *s) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_pathconf3res); + return xdr_serialize_generic(outmsg, (void *)s, (xdrproc_t)xdr_nfsstat3); } +ssize_t +xdr_to_nlm4_testargs(struct iovec inmsg, nlm4_testargs *args) +{ + return xdr_to_generic(inmsg, (void *)args, (xdrproc_t)xdr_nlm4_testargs); +} ssize_t -xdr_to_commit3args (struct iovec inmsg, commit3args *ca) +xdr_serialize_nlm4_testres(struct iovec outmsg, nlm4_testres *res) { - return xdr_to_generic (inmsg, (void *)ca, - (xdrproc_t)xdr_commit3args); + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_nlm4_testres); } +ssize_t +xdr_to_nlm4_lockargs(struct iovec inmsg, nlm4_lockargs *args) +{ + return xdr_to_generic(inmsg, (void *)args, (xdrproc_t)xdr_nlm4_lockargs); +} ssize_t -xdr_serialize_commit3res (struct iovec outmsg, commit3res *res) +xdr_serialize_nlm4_res(struct iovec outmsg, nlm4_res *res) { - return xdr_serialize_generic (outmsg, (void *)res, - (xdrproc_t)xdr_commit3res); + return xdr_serialize_generic(outmsg, (void *)res, (xdrproc_t)xdr_nlm4_res); } +ssize_t +xdr_to_nlm4_cancelargs(struct iovec inmsg, nlm4_cancargs *args) +{ + return xdr_to_generic(inmsg, (void *)args, (xdrproc_t)xdr_nlm4_cancargs); +} ssize_t -xdr_serialize_exports (struct iovec outmsg, exports *elist) +xdr_to_nlm4_unlockargs(struct iovec inmsg, nlm4_unlockargs *args) { - XDR xdr; - ssize_t ret = -1; + return xdr_to_generic(inmsg, (void *)args, (xdrproc_t)xdr_nlm4_unlockargs); +} - if ((!outmsg.iov_base) || (!elist)) - return -1; +ssize_t +xdr_to_nlm4_shareargs(struct iovec inmsg, nlm4_shareargs *args) +{ + return xdr_to_generic(inmsg, (void *)args, (xdrproc_t)xdr_nlm4_shareargs); +} - xdrmem_create (&xdr, outmsg.iov_base, (unsigned int)outmsg.iov_len, - XDR_ENCODE); +ssize_t +xdr_serialize_nlm4_shareres(struct iovec outmsg, nlm4_shareres *res) +{ + return xdr_serialize_generic(outmsg, (void *)res, + (xdrproc_t)xdr_nlm4_shareres); +} - if (!xdr_exports (&xdr, elist)) - goto ret; +ssize_t +xdr_serialize_nlm4_testargs(struct iovec outmsg, nlm4_testargs *args) +{ + return xdr_serialize_generic(outmsg, (void *)args, + (xdrproc_t)xdr_nlm4_testargs); +} - ret = xdr_decoded_length (xdr); +ssize_t +xdr_to_nlm4_res(struct iovec inmsg, nlm4_res *args) +{ + return xdr_to_generic(inmsg, (void *)args, (xdrproc_t)xdr_nlm4_res); +} -ret: - return ret; +ssize_t +xdr_to_nlm4_freeallargs(struct iovec inmsg, nlm4_freeallargs *args) +{ + return xdr_to_generic(inmsg, (void *)args, (xdrproc_t)xdr_nlm4_freeallargs); } +ssize_t +xdr_to_getaclargs(struct iovec inmsg, getaclargs *args) +{ + return xdr_to_generic(inmsg, (void *)args, (xdrproc_t)xdr_getaclargs); +} ssize_t -xdr_serialize_nfsstat3 (struct iovec outmsg, nfsstat3 *s) +xdr_to_setaclargs(struct iovec inmsg, setaclargs *args) { - return xdr_serialize_generic (outmsg, (void *)s, - (xdrproc_t)xdr_nfsstat3); + return xdr_to_generic(inmsg, (void *)args, (xdrproc_t)xdr_setaclargs); } +ssize_t +xdr_serialize_getaclreply(struct iovec inmsg, getaclreply *res) +{ + return xdr_serialize_generic(inmsg, (void *)res, + (xdrproc_t)xdr_getaclreply); +} +ssize_t +xdr_serialize_setaclreply(struct iovec inmsg, setaclreply *res) +{ + return xdr_serialize_generic(inmsg, (void *)res, + (xdrproc_t)xdr_setaclreply); +} diff --git a/rpc/xdr/src/msg-nfs3.h b/rpc/xdr/src/msg-nfs3.h index f828979e79f..869ddc3524a 100644 --- a/rpc/xdr/src/msg-nfs3.h +++ b/rpc/xdr/src/msg-nfs3.h @@ -1,186 +1,219 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _MSG_NFS3_H_ #define _MSG_NFS3_H_ -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include "xdr-nfs3.h" - +#include "nlm4-xdr.h" +#include "acl3-xdr.h" #include <sys/types.h> #include <sys/uio.h> extern ssize_t -xdr_to_mountpath (struct iovec outpath, struct iovec inmsg); +xdr_to_mountpath(struct iovec outpath, struct iovec inmsg); + +extern ssize_t +xdr_serialize_mountres3(struct iovec outmsg, mountres3 *res); + +extern ssize_t +xdr_serialize_mountbody(struct iovec outmsg, mountbody *mb); + +extern ssize_t +xdr_to_getattr3args(struct iovec inmsg, getattr3args *ga); + +extern ssize_t +xdr_serialize_getattr3res(struct iovec outmsg, getattr3res *res); + +extern ssize_t +xdr_serialize_setattr3res(struct iovec outmsg, setattr3res *res); + +extern ssize_t +xdr_to_setattr3args(struct iovec inmsg, setattr3args *sa); + +extern ssize_t +xdr_serialize_lookup3res(struct iovec outmsg, lookup3res *res); + +extern ssize_t +xdr_to_lookup3args(struct iovec inmsg, lookup3args *la); + +extern ssize_t +xdr_to_access3args(struct iovec inmsg, access3args *ac); + +extern ssize_t +xdr_serialize_access3res(struct iovec outmsg, access3res *res); + +extern ssize_t +xdr_to_readlink3args(struct iovec inmsg, readlink3args *ra); extern ssize_t -xdr_serialize_mountres3 (struct iovec outmsg, mountres3 *res); +xdr_serialize_readlink3res(struct iovec outmsg, readlink3res *res); extern ssize_t -xdr_serialize_mountbody (struct iovec outmsg, mountbody *mb); +xdr_to_read3args(struct iovec inmsg, read3args *ra); extern ssize_t -xdr_to_getattr3args (struct iovec inmsg, getattr3args *ga); +xdr_serialize_read3res(struct iovec outmsg, read3res *res); extern ssize_t -xdr_serialize_getattr3res (struct iovec outmsg, getattr3res *res); +xdr_serialize_read3res_nocopy(struct iovec outmsg, read3res *res); extern ssize_t -xdr_serialize_setattr3res (struct iovec outmsg, setattr3res *res); +xdr_to_write3args(struct iovec inmsg, write3args *wa); extern ssize_t -xdr_to_setattr3args (struct iovec inmsg, setattr3args *sa); +xdr_to_write3args_nocopy(struct iovec inmsg, write3args *wa, + struct iovec *payload); extern ssize_t -xdr_serialize_lookup3res (struct iovec outmsg, lookup3res *res); +xdr_serialize_write3res(struct iovec outmsg, write3res *res); extern ssize_t -xdr_to_lookup3args (struct iovec inmsg, lookup3args *la); +xdr_to_create3args(struct iovec inmsg, create3args *ca); extern ssize_t -xdr_to_access3args (struct iovec inmsg, access3args *ac); +xdr_serialize_create3res(struct iovec outmsg, create3res *res); extern ssize_t -xdr_serialize_access3res (struct iovec outmsg, access3res *res); +xdr_serialize_mkdir3res(struct iovec outmsg, mkdir3res *res); extern ssize_t -xdr_to_readlink3args (struct iovec inmsg, readlink3args *ra); +xdr_to_mkdir3args(struct iovec inmsg, mkdir3args *ma); extern ssize_t -xdr_serialize_readlink3res (struct iovec outmsg, readlink3res *res); +xdr_to_symlink3args(struct iovec inmsg, symlink3args *sa); extern ssize_t -xdr_to_read3args (struct iovec inmsg, read3args *ra); +xdr_serialize_symlink3res(struct iovec outmsg, symlink3res *res); extern ssize_t -xdr_serialize_read3res (struct iovec outmsg, read3res *res); +xdr_to_mknod3args(struct iovec inmsg, mknod3args *ma); extern ssize_t -xdr_serialize_read3res_nocopy (struct iovec outmsg, read3res *res); +xdr_serialize_mknod3res(struct iovec outmsg, mknod3res *res); extern ssize_t -xdr_to_write3args (struct iovec inmsg, write3args *wa); +xdr_to_remove3args(struct iovec inmsg, remove3args *ra); extern ssize_t -xdr_to_write3args_nocopy (struct iovec inmsg, write3args *wa, - struct iovec *payload); +xdr_serialize_remove3res(struct iovec outmsg, remove3res *res); extern ssize_t -xdr_serialize_write3res (struct iovec outmsg, write3res *res); +xdr_to_rmdir3args(struct iovec inmsg, rmdir3args *ra); extern ssize_t -xdr_to_create3args (struct iovec inmsg, create3args *ca); +xdr_serialize_rmdir3res(struct iovec outmsg, rmdir3res *res); extern ssize_t -xdr_serialize_create3res (struct iovec outmsg, create3res *res); +xdr_serialize_rename3res(struct iovec outmsg, rename3res *res); extern ssize_t -xdr_serialize_mkdir3res (struct iovec outmsg, mkdir3res *res); +xdr_to_rename3args(struct iovec inmsg, rename3args *ra); extern ssize_t -xdr_to_mkdir3args (struct iovec inmsg, mkdir3args *ma); +xdr_serialize_link3res(struct iovec outmsg, link3res *li); extern ssize_t -xdr_to_symlink3args (struct iovec inmsg, symlink3args *sa); +xdr_to_link3args(struct iovec inmsg, link3args *la); extern ssize_t -xdr_serialize_symlink3res (struct iovec outmsg, symlink3res *res); +xdr_to_readdir3args(struct iovec inmsg, readdir3args *rd); extern ssize_t -xdr_to_mknod3args (struct iovec inmsg, mknod3args *ma); +xdr_serialize_readdir3res(struct iovec outmsg, readdir3res *res); extern ssize_t -xdr_serialize_mknod3res (struct iovec outmsg, mknod3res *res); +xdr_to_readdirp3args(struct iovec inmsg, readdirp3args *rp); extern ssize_t -xdr_to_remove3args (struct iovec inmsg, remove3args *ra); +xdr_serialize_readdirp3res(struct iovec outmsg, readdirp3res *res); extern ssize_t -xdr_serialize_remove3res (struct iovec outmsg, remove3res *res); +xdr_to_fsstat3args(struct iovec inmsg, fsstat3args *fa); extern ssize_t -xdr_to_rmdir3args (struct iovec inmsg, rmdir3args *ra); +xdr_serialize_fsstat3res(struct iovec outmsg, fsstat3res *res); extern ssize_t -xdr_serialize_rmdir3res (struct iovec outmsg, rmdir3res *res); +xdr_to_fsinfo3args(struct iovec inmsg, fsinfo3args *fi); extern ssize_t -xdr_serialize_rename3res (struct iovec outmsg, rename3res *res); +xdr_serialize_fsinfo3res(struct iovec outmsg, fsinfo3res *res); extern ssize_t -xdr_to_rename3args (struct iovec inmsg, rename3args *ra); +xdr_to_pathconf3args(struct iovec inmsg, pathconf3args *pc); extern ssize_t -xdr_serialize_link3res (struct iovec outmsg, link3res *li); +xdr_serialize_pathconf3res(struct iovec outmsg, pathconf3res *res); extern ssize_t -xdr_to_link3args (struct iovec inmsg, link3args *la); +xdr_to_commit3args(struct iovec inmsg, commit3args *ca); extern ssize_t -xdr_to_readdir3args (struct iovec inmsg, readdir3args *rd); +xdr_serialize_commit3res(struct iovec outmsg, commit3res *res); extern ssize_t -xdr_serialize_readdir3res (struct iovec outmsg, readdir3res *res); +xdr_serialize_exports(struct iovec outmsg, exports *elist); extern ssize_t -xdr_to_readdirp3args (struct iovec inmsg, readdirp3args *rp); +xdr_serialize_mountlist(struct iovec outmsg, mountlist *ml); extern ssize_t -xdr_serialize_readdirp3res (struct iovec outmsg, readdirp3res *res); +xdr_serialize_mountstat3(struct iovec outmsg, mountstat3 *m); extern ssize_t -xdr_to_fsstat3args (struct iovec inmsg, fsstat3args *fa); +xdr_serialize_nfsstat3(struct iovec outmsg, nfsstat3 *s); extern ssize_t -xdr_serialize_fsstat3res (struct iovec outmsg, fsstat3res *res); +xdr_to_nlm4_testargs(struct iovec inmsg, nlm4_testargs *args); extern ssize_t -xdr_to_fsinfo3args (struct iovec inmsg, fsinfo3args *fi); +xdr_serialize_nlm4_testres(struct iovec outmsg, nlm4_testres *res); extern ssize_t -xdr_serialize_fsinfo3res (struct iovec outmsg, fsinfo3res *res); +xdr_to_nlm4_lockargs(struct iovec inmsg, nlm4_lockargs *args); extern ssize_t -xdr_to_pathconf3args (struct iovec inmsg, pathconf3args *pc); +xdr_serialize_nlm4_res(struct iovec outmsg, nlm4_res *res); extern ssize_t -xdr_serialize_pathconf3res (struct iovec outmsg, pathconf3res *res); +xdr_to_nlm4_cancelargs(struct iovec inmsg, nlm4_cancargs *args); extern ssize_t -xdr_to_commit3args (struct iovec inmsg, commit3args *ca); +xdr_to_nlm4_unlockargs(struct iovec inmsg, nlm4_unlockargs *args); extern ssize_t -xdr_serialize_commit3res (struct iovec outmsg, commit3res *res); +xdr_to_nlm4_shareargs(struct iovec inmsg, nlm4_shareargs *args); extern ssize_t -xdr_serialize_exports (struct iovec outmsg, exports *elist); +xdr_serialize_nlm4_shareres(struct iovec outmsg, nlm4_shareres *res); extern ssize_t -xdr_serialize_mountlist (struct iovec outmsg, mountlist *ml); +xdr_serialize_nlm4_testargs(struct iovec outmsg, nlm4_testargs *args); extern ssize_t -xdr_serialize_mountstat3 (struct iovec outmsg, mountstat3 *m); +xdr_to_nlm4_res(struct iovec inmsg, nlm4_res *args); extern ssize_t -xdr_serialize_nfsstat3 (struct iovec outmsg, nfsstat3 *s); +xdr_to_nlm4_freeallargs(struct iovec inmsg, nlm4_freeallargs *args); + +extern ssize_t +xdr_to_getaclargs(struct iovec inmsg, getaclargs *args); + +extern ssize_t +xdr_to_setaclargs(struct iovec inmsg, setaclargs *args); + +extern ssize_t +xdr_serialize_getaclreply(struct iovec inmsg, getaclreply *res); + +extern ssize_t +xdr_serialize_setaclreply(struct iovec inmsg, setaclreply *res); + #endif diff --git a/rpc/xdr/src/nlm4-xdr.x b/rpc/xdr/src/nlm4-xdr.x new file mode 100644 index 00000000000..847b0e64491 --- /dev/null +++ b/rpc/xdr/src/nlm4-xdr.x @@ -0,0 +1,167 @@ +/* + Copyright (c) 2007-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. +*/ + +#ifdef RPC_XDR +%#include "rpc-pragmas.h" +#endif +%#include <glusterfs/compat.h> + +/* .x file defined as according to the RFC */ + +%#include "xdr-common.h" + +const MAXNETOBJ_SZ = 1024; +const LM_MAXSTRLEN = 1024; +const MAXNAMELEN = 1025; + +typedef opaque nlm4_netobj<MAXNETOBJ_SZ>; + +#ifdef RPC_HDR +%/* +% * The following enums are actually bit encoded for efficient +% * boolean algebra.... DON'T change them..... +% */ +#endif +enum fsh_mode { + fsm_DN = 0, /* deny none */ + fsm_DR = 1, /* deny read */ + fsm_DW = 2, /* deny write */ + fsm_DRW = 3 /* deny read/write */ +}; + +enum fsh_access { + fsa_NONE = 0, /* for completeness */ + fsa_R = 1, /* read only */ + fsa_W = 2, /* write only */ + fsa_RW = 3 /* read/write */ +}; + +#ifdef RPC_HDR +%/* definitions for NLM version 4 */ +#endif +enum nlm4_stats { + nlm4_granted = 0, + nlm4_denied = 1, + nlm4_denied_nolock = 2, + nlm4_blocked = 3, + nlm4_denied_grace_period = 4, + nlm4_deadlck = 5, + nlm4_rofs = 6, + nlm4_stale_fh = 7, + nlm4_fbig = 8, + nlm4_failed = 9 +}; + +struct nlm4_stat { + nlm4_stats stat; +}; + +struct nlm4_holder { + bool exclusive; + u_int32_t svid; + nlm4_netobj oh; + u_int64_t l_offset; + u_int64_t l_len; +}; + +struct nlm4_lock { + string caller_name<LM_MAXSTRLEN>; + nlm4_netobj fh; + nlm4_netobj oh; + u_int32_t svid; + u_int64_t l_offset; + u_int64_t l_len; +}; + +struct nlm4_share { + string caller_name<LM_MAXSTRLEN>; + nlm4_netobj fh; + nlm4_netobj oh; + fsh_mode mode; + fsh_access access; +}; + +union nlm4_testrply switch (nlm4_stats stat) { + case nlm4_denied: + nlm4_holder holder; + default: + void; +}; + +struct nlm4_testres { + nlm4_netobj cookie; + nlm4_testrply stat; +}; + +struct nlm4_testargs { + nlm4_netobj cookie; + bool exclusive; + nlm4_lock alock; +}; + +struct nlm4_res { + nlm4_netobj cookie; + nlm4_stat stat; +}; + +struct nlm4_lockargs { + nlm4_netobj cookie; + bool block; + bool exclusive; + nlm4_lock alock; + bool reclaim; /* used for recovering locks */ + int32_t state; /* specify local status monitor state */ +}; + +struct nlm4_cancargs { + nlm4_netobj cookie; + bool block; + bool exclusive; + nlm4_lock alock; +}; + +struct nlm4_unlockargs { + nlm4_netobj cookie; + nlm4_lock alock; +}; + +struct nlm4_shareargs { + nlm4_netobj cookie; + nlm4_share share; + bool reclaim; +}; + +struct nlm4_shareres { + nlm4_netobj cookie; + nlm4_stats stat; + int32_t sequence; +}; + +struct nlm4_freeallargs { + string name<LM_MAXSTRLEN>; /* client hostname */ + uint32_t state; /* unused */ +}; + +/* + * argument for the procedure called by rpc.statd when a monitored host + * status change. + * XXX assumes LM_MAXSTRLEN == SM_MAXSTRLEN + */ +struct nlm_sm_status { + string mon_name<LM_MAXSTRLEN>; /* name of host */ + int state; /* new state */ + opaque priv[16]; /* private data */ +}; + +program NLMCBK_PROGRAM { + version NLMCBK_V1 { + void NLMCBK_SM_NOTIFY(nlm_sm_status) = 16; + } = 1; +} = 100021; diff --git a/rpc/xdr/src/nsm-xdr.x b/rpc/xdr/src/nsm-xdr.x new file mode 100644 index 00000000000..7c16a741f1d --- /dev/null +++ b/rpc/xdr/src/nsm-xdr.x @@ -0,0 +1,62 @@ +/* + * Copyright (c) 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. + */ + +#ifdef RPC_XDR +%#include "rpc-pragmas.h" +#endif +%#include <glusterfs/compat.h> + +/* + * This defines the maximum length of the string + * identifying the caller. + */ +const SM_MAXSTRLEN = 1024; + +struct sm_name { + string mon_name<SM_MAXSTRLEN>; +}; + +enum res { + STAT_SUCC = 0, /* NSM agrees to monitor. */ + STAT_FAIL = 1 /* NSM cannot monitor. */ +}; + +struct sm_stat_res { + res res_stat; + int state; +}; + +struct sm_stat { + int state; /* state number of NSM */ +}; + +struct my_id { + string my_name<SM_MAXSTRLEN>; /* hostname */ + int my_prog; /* RPC program number */ + int my_vers; /* program version number */ + int my_proc; /* procedure number */ +}; + +struct mon_id { + string mon_name<SM_MAXSTRLEN>; /* name of the host to be monitored */ + my_id my_id; +}; + +struct mon { + mon_id mon_id; + opaque priv[16]; /* private information */ +}; + +struct nsm_callback_status { + string mon_name<SM_MAXSTRLEN>; + int state; + opaque priv[16]; /* for private information */ +}; + diff --git a/rpc/xdr/src/portmap-xdr.c b/rpc/xdr/src/portmap-xdr.c deleted file mode 100644 index 7033213c0bd..00000000000 --- a/rpc/xdr/src/portmap-xdr.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include "xdr-common.h" -#include "compat.h" - -#if defined(__GNUC__) -#if __GNUC__ >= 4 -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif -#endif - -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#include "portmap-xdr.h" - -bool_t -xdr_pmap_port_by_brick_req (XDR *xdrs, pmap_port_by_brick_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->brick, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_pmap_port_by_brick_rsp (XDR *xdrs, pmap_port_by_brick_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - - if (xdrs->x_op == XDR_ENCODE) { - buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->status)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - } else { - IXDR_PUT_LONG(buf, objp->op_ret); - IXDR_PUT_LONG(buf, objp->op_errno); - IXDR_PUT_LONG(buf, objp->status); - IXDR_PUT_LONG(buf, objp->port); - } - return TRUE; - } else if (xdrs->x_op == XDR_DECODE) { - buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->status)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - } else { - objp->op_ret = IXDR_GET_LONG(buf); - objp->op_errno = IXDR_GET_LONG(buf); - objp->status = IXDR_GET_LONG(buf); - objp->port = IXDR_GET_LONG(buf); - } - return TRUE; - } - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->status)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_pmap_brick_by_port_req (XDR *xdrs, pmap_brick_by_port_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_pmap_brick_by_port_rsp (XDR *xdrs, pmap_brick_by_port_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - - if (xdrs->x_op == XDR_ENCODE) { - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->status)) - return FALSE; - - } else { - IXDR_PUT_LONG(buf, objp->op_ret); - IXDR_PUT_LONG(buf, objp->op_errno); - IXDR_PUT_LONG(buf, objp->status); - } - if (!xdr_string (xdrs, &objp->brick, ~0)) - return FALSE; - return TRUE; - } else if (xdrs->x_op == XDR_DECODE) { - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->status)) - return FALSE; - - } else { - objp->op_ret = IXDR_GET_LONG(buf); - objp->op_errno = IXDR_GET_LONG(buf); - objp->status = IXDR_GET_LONG(buf); - } - if (!xdr_string (xdrs, &objp->brick, ~0)) - return FALSE; - return TRUE; - } - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->status)) - return FALSE; - if (!xdr_string (xdrs, &objp->brick, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_pmap_signup_req (XDR *xdrs, pmap_signup_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->brick, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_pmap_signup_rsp (XDR *xdrs, pmap_signup_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - return TRUE; -} - -bool_t -xdr_pmap_signin_req (XDR *xdrs, pmap_signin_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->brick, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_pmap_signin_rsp (XDR *xdrs, pmap_signin_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - return TRUE; -} - -bool_t -xdr_pmap_signout_req (XDR *xdrs, pmap_signout_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->brick, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_pmap_signout_rsp (XDR *xdrs, pmap_signout_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - return TRUE; -} diff --git a/rpc/xdr/src/portmap-xdr.h b/rpc/xdr/src/portmap-xdr.h deleted file mode 100644 index 2686da287b4..00000000000 --- a/rpc/xdr/src/portmap-xdr.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include "xdr-common.h" -#include "compat.h" - -#if defined(__GNUC__) -#if __GNUC__ >= 4 -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif -#endif - -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#ifndef _PORTMAP_XDR_H_RPCGEN -#define _PORTMAP_XDR_H_RPCGEN - -#include <rpc/rpc.h> - - -#ifdef __cplusplus -extern "C" { -#endif - - -struct pmap_port_by_brick_req { - char *brick; -}; -typedef struct pmap_port_by_brick_req pmap_port_by_brick_req; - -struct pmap_port_by_brick_rsp { - int op_ret; - int op_errno; - int status; - int port; -}; -typedef struct pmap_port_by_brick_rsp pmap_port_by_brick_rsp; - -struct pmap_brick_by_port_req { - int port; -}; -typedef struct pmap_brick_by_port_req pmap_brick_by_port_req; - -struct pmap_brick_by_port_rsp { - int op_ret; - int op_errno; - int status; - char *brick; -}; -typedef struct pmap_brick_by_port_rsp pmap_brick_by_port_rsp; - -struct pmap_signup_req { - char *brick; - int port; -}; -typedef struct pmap_signup_req pmap_signup_req; - -struct pmap_signup_rsp { - int op_ret; - int op_errno; -}; -typedef struct pmap_signup_rsp pmap_signup_rsp; - -struct pmap_signin_req { - char *brick; - int port; -}; -typedef struct pmap_signin_req pmap_signin_req; - -struct pmap_signin_rsp { - int op_ret; - int op_errno; -}; -typedef struct pmap_signin_rsp pmap_signin_rsp; - -struct pmap_signout_req { - char *brick; - int port; -}; -typedef struct pmap_signout_req pmap_signout_req; - -struct pmap_signout_rsp { - int op_ret; - int op_errno; -}; -typedef struct pmap_signout_rsp pmap_signout_rsp; - -/* the xdr functions */ - -#if defined(__STDC__) || defined(__cplusplus) -extern bool_t xdr_pmap_port_by_brick_req (XDR *, pmap_port_by_brick_req*); -extern bool_t xdr_pmap_port_by_brick_rsp (XDR *, pmap_port_by_brick_rsp*); -extern bool_t xdr_pmap_brick_by_port_req (XDR *, pmap_brick_by_port_req*); -extern bool_t xdr_pmap_brick_by_port_rsp (XDR *, pmap_brick_by_port_rsp*); -extern bool_t xdr_pmap_signup_req (XDR *, pmap_signup_req*); -extern bool_t xdr_pmap_signup_rsp (XDR *, pmap_signup_rsp*); -extern bool_t xdr_pmap_signin_req (XDR *, pmap_signin_req*); -extern bool_t xdr_pmap_signin_rsp (XDR *, pmap_signin_rsp*); -extern bool_t xdr_pmap_signout_req (XDR *, pmap_signout_req*); -extern bool_t xdr_pmap_signout_rsp (XDR *, pmap_signout_rsp*); - -#else /* K&R C */ -extern bool_t xdr_pmap_port_by_brick_req (); -extern bool_t xdr_pmap_port_by_brick_rsp (); -extern bool_t xdr_pmap_brick_by_port_req (); -extern bool_t xdr_pmap_brick_by_port_rsp (); -extern bool_t xdr_pmap_signup_req (); -extern bool_t xdr_pmap_signup_rsp (); -extern bool_t xdr_pmap_signin_req (); -extern bool_t xdr_pmap_signin_rsp (); -extern bool_t xdr_pmap_signout_req (); -extern bool_t xdr_pmap_signout_rsp (); - -#endif /* K&R C */ - -#ifdef __cplusplus -} -#endif - -#endif /* !_PORTMAP_XDR_H_RPCGEN */ diff --git a/rpc/xdr/src/portmap-xdr.x b/rpc/xdr/src/portmap-xdr.x index f60dcc76c8e..23515572b9f 100644 --- a/rpc/xdr/src/portmap-xdr.x +++ b/rpc/xdr/src/portmap-xdr.x @@ -1,3 +1,17 @@ +/* + * Copyright (c) 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. + */ + +#ifdef RPC_XDR +%#include "rpc-pragmas.h" +#endif +%#include <glusterfs/compat.h> struct pmap_port_by_brick_req { string brick<>; @@ -23,20 +37,10 @@ struct pmap_brick_by_port_rsp { }; -struct pmap_signup_req { - string brick<>; - int port; -}; - -struct pmap_signup_rsp { - int op_ret; - int op_errno; -}; - - struct pmap_signin_req { string brick<>; int port; + int pid; }; struct pmap_signin_rsp { @@ -47,6 +51,7 @@ struct pmap_signin_rsp { struct pmap_signout_req { string brick<>; int port; + int rdma_port; }; struct pmap_signout_rsp { diff --git a/rpc/xdr/src/rpc-common-xdr.x b/rpc/xdr/src/rpc-common-xdr.x new file mode 100644 index 00000000000..baf8b4313c8 --- /dev/null +++ b/rpc/xdr/src/rpc-common-xdr.x @@ -0,0 +1,66 @@ +/* + * Copyright (c) 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. + */ + +#ifdef RPC_XDR +%#include "rpc-pragmas.h" +#endif +%#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" + +struct auth_glusterfs_parms_v2 { + int pid; + unsigned int uid; + unsigned int gid; + unsigned int groups<>; + opaque lk_owner<>; +}; + +struct auth_glusterfs_parms { + u_quad_t lk_owner; + unsigned int pid; + unsigned int uid; + unsigned int gid; + unsigned int ngrps; + unsigned groups[16]; +}; + +struct gf_dump_req { + u_quad_t gfs_id; +}; + +struct gf_statedump { + unsigned int pid; +}; + +struct gf_prog_detail { + string progname<>; + u_quad_t prognum; + u_quad_t progver; + struct gf_prog_detail *next; +}; + + +struct gf_dump_rsp { + u_quad_t gfs_id; + int op_ret; + int op_errno; + struct gf_prog_detail *prog; +}; + + +struct gf_common_rsp { + int op_ret; + int op_errno; + opaque xdata<>; /* Extra data */ +} ; diff --git a/rpc/xdr/src/rpc-pragmas.h b/rpc/xdr/src/rpc-pragmas.h new file mode 100644 index 00000000000..4c54cf6f1df --- /dev/null +++ b/rpc/xdr/src/rpc-pragmas.h @@ -0,0 +1,28 @@ +/* + 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. +*/ + +#ifndef GLUSTERFS_RPC_PRAGMAS_H +#define GLUSTERFS_RPC_PRAGMAS_H + +#if defined(__GNUC__) +#if __GNUC__ >= 4 +#if !defined(__clang__) +#if !defined(__NetBSD__) +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif +#else +#pragma clang diagnostic ignored "-Wunused-variable" +#pragma clang diagnostic ignored "-Wunused-value" +#endif +#endif +#endif + +#endif /* GLUSTERFS_RPC_PRAGMAS_H */ diff --git a/rpc/xdr/src/xdr-generic.c b/rpc/xdr/src/xdr-generic.c index 5d5cf7197fb..20b54eb0a8a 100644 --- a/rpc/xdr/src/xdr-generic.c +++ b/rpc/xdr/src/xdr-generic.c @@ -1,134 +1,120 @@ /* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 "xdr-generic.h" - ssize_t -xdr_serialize_generic (struct iovec outmsg, void *res, xdrproc_t proc) +xdr_serialize_generic(struct iovec outmsg, void *res, xdrproc_t proc) { - ssize_t ret = -1; - XDR xdr; + ssize_t ret = -1; + XDR xdr; - if ((!outmsg.iov_base) || (!res) || (!proc)) - return -1; + if ((!outmsg.iov_base) || (!res) || (!proc)) + return -1; - xdrmem_create (&xdr, outmsg.iov_base, (unsigned int)outmsg.iov_len, - XDR_ENCODE); + xdrmem_create(&xdr, outmsg.iov_base, (unsigned int)outmsg.iov_len, + XDR_ENCODE); - if (!proc (&xdr, res)) { - ret = -1; - goto ret; - } + if (!PROC(&xdr, res)) { + ret = -1; + goto ret; + } - ret = xdr_encoded_length (xdr); + ret = xdr_encoded_length(xdr); ret: - return ret; + return ret; } - ssize_t -xdr_to_generic (struct iovec inmsg, void *args, xdrproc_t proc) +xdr_to_generic(struct iovec inmsg, void *args, xdrproc_t proc) { - XDR xdr; - ssize_t ret = -1; + XDR xdr; + ssize_t ret = -1; - if ((!inmsg.iov_base) || (!args) || (!proc)) - return -1; + if ((!inmsg.iov_base) || (!args) || (!proc)) + return -1; - xdrmem_create (&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len, - XDR_DECODE); + xdrmem_create(&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len, + XDR_DECODE); - if (!proc (&xdr, args)) { - ret = -1; - goto ret; - } + if (!PROC(&xdr, args)) { + ret = -1; + goto ret; + } - ret = xdr_decoded_length (xdr); + ret = xdr_decoded_length(xdr); ret: - return ret; + return ret; } - ssize_t -xdr_to_generic_payload (struct iovec inmsg, void *args, xdrproc_t proc, - struct iovec *pendingpayload) +xdr_to_generic_payload(struct iovec inmsg, void *args, xdrproc_t proc, + struct iovec *pendingpayload) { - XDR xdr; - ssize_t ret = -1; + XDR xdr; + ssize_t ret = -1; - if ((!inmsg.iov_base) || (!args) || (!proc)) - return -1; + if ((!inmsg.iov_base) || (!args) || (!proc)) + return -1; - xdrmem_create (&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len, - XDR_DECODE); + xdrmem_create(&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len, + XDR_DECODE); - if (!proc (&xdr, args)) { - ret = -1; - goto ret; - } + if (!PROC(&xdr, args)) { + ret = -1; + goto ret; + } - ret = xdr_decoded_length (xdr); + ret = xdr_decoded_length(xdr); - if (pendingpayload) { - pendingpayload->iov_base = xdr_decoded_remaining_addr (xdr); - pendingpayload->iov_len = xdr_decoded_remaining_len (xdr); - } + if (pendingpayload) { + pendingpayload->iov_base = xdr_decoded_remaining_addr(xdr); + pendingpayload->iov_len = xdr_decoded_remaining_len(xdr); + } ret: - return ret; + return ret; } ssize_t -xdr_length_round_up (size_t len, size_t bufsize) +xdr_length_round_up(size_t len, size_t bufsize) { - int roundup = 0; + int roundup = 0; - roundup = len % XDR_BYTES_PER_UNIT; - if (roundup > 0) - roundup = XDR_BYTES_PER_UNIT - roundup; + roundup = len % XDR_BYTES_PER_UNIT; + if (roundup > 0) + roundup = XDR_BYTES_PER_UNIT - roundup; - if ((roundup > 0) && ((roundup + len) <= bufsize)) - len += roundup; + if ((roundup > 0) && ((roundup + len) <= bufsize)) + len += roundup; - return len; + return len; } int -xdr_bytes_round_up (struct iovec *vec, size_t bufsize) +xdr_bytes_round_up(struct iovec *vec, size_t bufsize) { - vec->iov_len = xdr_length_round_up (vec->iov_len, bufsize); - return 0; + vec->iov_len = xdr_length_round_up(vec->iov_len, bufsize); + return 0; } - void -xdr_vector_round_up (struct iovec *vec, int vcount, uint32_t count) +xdr_vector_round_up(struct iovec *vec, int vcount, uint32_t count) { - uint32_t round_count = 0; + uint32_t round_count = 0; - round_count = xdr_length_round_up (count, 1048576); - round_count -= count; - if (round_count == 0) - return; + round_count = xdr_length_round_up(count, 1048576); + round_count -= count; + if (round_count == 0 || vcount <= 0) + return; - vec[vcount-1].iov_len += round_count; + vec[vcount - 1].iov_len += round_count; } diff --git a/rpc/xdr/src/xdr-generic.h b/rpc/xdr/src/xdr-generic.h index 24054e11c75..794dda508cc 100644 --- a/rpc/xdr/src/xdr-generic.h +++ b/rpc/xdr/src/xdr-generic.h @@ -1,58 +1,76 @@ /* - Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _XDR_GENERIC_H #define _XDR_GENERIC_H #include <sys/uio.h> -//#include <rpc/rpc.h> #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) -#define xdr_encoded_length(xdr) (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) -#define xdr_decoded_length(xdr) (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) +#define xdr_decoded_remaining_addr(xdr) ((&xdr)->x_private) +#define xdr_decoded_remaining_len(xdr) ((&xdr)->x_handy) +#define xdr_encoded_length(xdr) \ + (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) +#define xdr_decoded_length(xdr) \ + (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base)) -#define XDR_BYTES_PER_UNIT 4 +#define XDR_BYTES_PER_UNIT 4 -ssize_t -xdr_serialize_generic (struct iovec outmsg, void *res, xdrproc_t proc); +/* + On OSX > 10.9 + ------------- + typedef bool_t (*xdrproc_t)(XDR *, void *, unsigned int); + + On OSX < 10.9 + ------------ + typedef bool_t (*xdrproc_t)(XDR *, ...); + + FreeBSD all versions + ------------ + typedef bool_t (*xdrproc_t)(XDR *, ...); + + NetBSD 6.1.4 + ----------- + typedef bool_t (*xdrproc_t)(XDR *, const void *); + + Linux all versions + ----------- + typedef bool_t (*xdrproc_t)(XDR *, void *,...); +*/ + +#if defined(__NetBSD__) +#define PROC(xdr, res) proc(xdr, res) +#else +#define PROC(xdr, res) proc(xdr, res, 0) +#endif ssize_t -xdr_to_generic (struct iovec inmsg, void *args, xdrproc_t proc); +xdr_serialize_generic(struct iovec outmsg, void *res, xdrproc_t proc); ssize_t -xdr_to_generic_payload (struct iovec inmsg, void *args, xdrproc_t proc, - struct iovec *pendingpayload); +xdr_to_generic(struct iovec inmsg, void *args, xdrproc_t proc); +ssize_t +xdr_to_generic_payload(struct iovec inmsg, void *args, xdrproc_t proc, + struct iovec *pendingpayload); extern int -xdr_bytes_round_up (struct iovec *vec, size_t bufsize); +xdr_bytes_round_up(struct iovec *vec, size_t bufsize); extern ssize_t -xdr_length_round_up (size_t len, size_t bufsize); +xdr_length_round_up(size_t len, size_t bufsize); void -xdr_vector_round_up (struct iovec *vec, int vcount, uint32_t count); +xdr_vector_round_up(struct iovec *vec, int vcount, uint32_t count); #endif /* !_XDR_GENERIC_H */ diff --git a/rpc/xdr/src/xdr-nfs3.c b/rpc/xdr/src/xdr-nfs3.c index 2b2b1049c08..cfccaaa89b8 100644 --- a/rpc/xdr/src/xdr-nfs3.c +++ b/rpc/xdr/src/xdr-nfs3.c @@ -1,1898 +1,1907 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 "xdr-nfs3.h" -#include "mem-pool.h" - -#if GF_DARWIN_HOST_OS -#define xdr_u_quad_t xdr_u_int64_t -#define xdr_quad_t xdr_int64_t -#define xdr_uint32_t xdr_u_int32_t -#define xdr_uint64_t xdr_u_int64_t +#if defined(__GNUC__) +#if __GNUC__ >= 4 +#if !defined(__clang__) +#if !defined(__NetBSD__) +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif +#else +#pragma clang diagnostic ignored "-Wunused-variable" +#pragma clang diagnostic ignored "-Wunused-value" +#endif #endif +#endif + +#include "xdr-nfs3.h" +#include <glusterfs/mem-pool.h> +#include "xdr-common.h" bool_t -xdr_uint64 (XDR *xdrs, uint64 *objp) +xdr_uint64(XDR *xdrs, uint64 *objp) { - if (!xdr_uint64_t (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_uint64_t(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_int64 (XDR *xdrs, int64 *objp) +xdr_int64(XDR *xdrs, int64 *objp) { - if (!xdr_int64_t (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_int64_t(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_uint32 (XDR *xdrs, uint32 *objp) +xdr_uint32(XDR *xdrs, uint32 *objp) { - if (!xdr_uint32_t (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_uint32_t(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_int32 (XDR *xdrs, int32 *objp) +xdr_int32(XDR *xdrs, int32 *objp) { - if (!xdr_int32_t (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_int32_t(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_filename3 (XDR *xdrs, filename3 *objp) +xdr_filename3(XDR *xdrs, filename3 *objp) { - if (!xdr_string (xdrs, objp, ~0)) - return FALSE; - return TRUE; + if (!xdr_string(xdrs, objp, ~0)) + return FALSE; + return TRUE; } bool_t -xdr_nfspath3 (XDR *xdrs, nfspath3 *objp) +xdr_nfspath3(XDR *xdrs, nfspath3 *objp) { - if (!xdr_string (xdrs, objp, ~0)) - return FALSE; - return TRUE; + if (!xdr_string(xdrs, objp, ~0)) + return FALSE; + return TRUE; } bool_t -xdr_fileid3 (XDR *xdrs, fileid3 *objp) +xdr_fileid3(XDR *xdrs, fileid3 *objp) { - if (!xdr_uint64 (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_uint64(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_cookie3 (XDR *xdrs, cookie3 *objp) +xdr_cookie3(XDR *xdrs, cookie3 *objp) { - if (!xdr_uint64 (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_uint64(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_cookieverf3 (XDR *xdrs, cookieverf3 objp) +xdr_cookieverf3(XDR *xdrs, cookieverf3 objp) { - if (!xdr_opaque (xdrs, objp, NFS3_COOKIEVERFSIZE)) - return FALSE; - return TRUE; + if (!xdr_opaque(xdrs, objp, NFS3_COOKIEVERFSIZE)) + return FALSE; + return TRUE; } bool_t -xdr_createverf3 (XDR *xdrs, createverf3 objp) +xdr_createverf3(XDR *xdrs, createverf3 objp) { - if (!xdr_opaque (xdrs, objp, NFS3_CREATEVERFSIZE)) - return FALSE; - return TRUE; + if (!xdr_opaque(xdrs, objp, NFS3_CREATEVERFSIZE)) + return FALSE; + return TRUE; } bool_t -xdr_writeverf3 (XDR *xdrs, writeverf3 objp) +xdr_writeverf3(XDR *xdrs, writeverf3 objp) { - if (!xdr_opaque (xdrs, objp, NFS3_WRITEVERFSIZE)) - return FALSE; - return TRUE; + if (!xdr_opaque(xdrs, objp, NFS3_WRITEVERFSIZE)) + return FALSE; + return TRUE; } bool_t -xdr_uid3 (XDR *xdrs, uid3 *objp) +xdr_uid3(XDR *xdrs, uid3 *objp) { - if (!xdr_uint32 (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_uint32(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_gid3 (XDR *xdrs, gid3 *objp) +xdr_gid3(XDR *xdrs, gid3 *objp) { - if (!xdr_uint32 (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_uint32(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_size3 (XDR *xdrs, size3 *objp) +xdr_size3(XDR *xdrs, size3 *objp) { - if (!xdr_uint64 (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_uint64(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_offset3 (XDR *xdrs, offset3 *objp) +xdr_offset3(XDR *xdrs, offset3 *objp) { - if (!xdr_uint64 (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_uint64(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_mode3 (XDR *xdrs, mode3 *objp) +xdr_mode3(XDR *xdrs, mode3 *objp) { - if (!xdr_uint32 (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_uint32(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_count3 (XDR *xdrs, count3 *objp) +xdr_count3(XDR *xdrs, count3 *objp) { - if (!xdr_uint32 (xdrs, objp)) - return FALSE; - return TRUE; + if (!xdr_uint32(xdrs, objp)) + return FALSE; + return TRUE; } bool_t -xdr_nfsstat3 (XDR *xdrs, nfsstat3 *objp) +xdr_nfsstat3(XDR *xdrs, nfsstat3 *objp) { - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; + if (!xdr_enum(xdrs, (enum_t *)objp)) + return FALSE; + return TRUE; } bool_t -xdr_ftype3 (XDR *xdrs, ftype3 *objp) +xdr_ftype3(XDR *xdrs, ftype3 *objp) { - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; + if (!xdr_enum(xdrs, (enum_t *)objp)) + return FALSE; + return TRUE; } bool_t -xdr_specdata3 (XDR *xdrs, specdata3 *objp) +xdr_specdata3(XDR *xdrs, specdata3 *objp) { - if (!xdr_uint32 (xdrs, &objp->specdata1)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->specdata2)) - return FALSE; - return TRUE; + if (!xdr_uint32(xdrs, &objp->specdata1)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->specdata2)) + return FALSE; + return TRUE; } bool_t -xdr_nfs_fh3 (XDR *xdrs, nfs_fh3 *objp) +xdr_nfs_fh3(XDR *xdrs, nfs_fh3 *objp) { - if (!xdr_bytes (xdrs, (char **)&objp->data.data_val, (u_int *) &objp->data.data_len, NFS3_FHSIZE)) - return FALSE; - return TRUE; + if (!xdr_bytes(xdrs, (char **)&objp->data.data_val, + (u_int *)&objp->data.data_len, NFS3_FHSIZE)) + return FALSE; + return TRUE; } bool_t -xdr_nfstime3 (XDR *xdrs, nfstime3 *objp) +xdr_nfstime3(XDR *xdrs, nfstime3 *objp) { - if (!xdr_uint32 (xdrs, &objp->seconds)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->nseconds)) - return FALSE; - return TRUE; + if (!xdr_uint32(xdrs, &objp->seconds)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->nseconds)) + return FALSE; + return TRUE; } bool_t -xdr_fattr3 (XDR *xdrs, fattr3 *objp) +xdr_fattr3(XDR *xdrs, fattr3 *objp) { - if (!xdr_ftype3 (xdrs, &objp->type)) - return FALSE; - if (!xdr_mode3 (xdrs, &objp->mode)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->nlink)) - return FALSE; - if (!xdr_uid3 (xdrs, &objp->uid)) - return FALSE; - if (!xdr_gid3 (xdrs, &objp->gid)) - return FALSE; - if (!xdr_size3 (xdrs, &objp->size)) - return FALSE; - if (!xdr_size3 (xdrs, &objp->used)) - return FALSE; - if (!xdr_specdata3 (xdrs, &objp->rdev)) - return FALSE; - if (!xdr_uint64 (xdrs, &objp->fsid)) - return FALSE; - if (!xdr_fileid3 (xdrs, &objp->fileid)) - return FALSE; - if (!xdr_nfstime3 (xdrs, &objp->atime)) - return FALSE; - if (!xdr_nfstime3 (xdrs, &objp->mtime)) - return FALSE; - if (!xdr_nfstime3 (xdrs, &objp->ctime)) - return FALSE; - return TRUE; + if (!xdr_ftype3(xdrs, &objp->type)) + return FALSE; + if (!xdr_mode3(xdrs, &objp->mode)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->nlink)) + return FALSE; + if (!xdr_uid3(xdrs, &objp->uid)) + return FALSE; + if (!xdr_gid3(xdrs, &objp->gid)) + return FALSE; + if (!xdr_size3(xdrs, &objp->size)) + return FALSE; + if (!xdr_size3(xdrs, &objp->used)) + return FALSE; + if (!xdr_specdata3(xdrs, &objp->rdev)) + return FALSE; + if (!xdr_uint64(xdrs, &objp->fsid)) + return FALSE; + if (!xdr_fileid3(xdrs, &objp->fileid)) + return FALSE; + if (!xdr_nfstime3(xdrs, &objp->atime)) + return FALSE; + if (!xdr_nfstime3(xdrs, &objp->mtime)) + return FALSE; + if (!xdr_nfstime3(xdrs, &objp->ctime)) + return FALSE; + return TRUE; } bool_t -xdr_post_op_attr (XDR *xdrs, post_op_attr *objp) +xdr_post_op_attr(XDR *xdrs, post_op_attr *objp) { - if (!xdr_bool (xdrs, &objp->attributes_follow)) - return FALSE; - switch (objp->attributes_follow) { - case TRUE: - if (!xdr_fattr3 (xdrs, &objp->post_op_attr_u.attributes)) - return FALSE; - break; - case FALSE: - break; - default: - return FALSE; - } - return TRUE; + if (!xdr_bool(xdrs, &objp->attributes_follow)) + return FALSE; + switch (objp->attributes_follow) { + case TRUE: + if (!xdr_fattr3(xdrs, &objp->post_op_attr_u.attributes)) + return FALSE; + break; + case FALSE: + break; + default: + return FALSE; + } + return TRUE; } bool_t -xdr_wcc_attr (XDR *xdrs, wcc_attr *objp) +xdr_wcc_attr(XDR *xdrs, wcc_attr *objp) { - if (!xdr_size3 (xdrs, &objp->size)) - return FALSE; - if (!xdr_nfstime3 (xdrs, &objp->mtime)) - return FALSE; - if (!xdr_nfstime3 (xdrs, &objp->ctime)) - return FALSE; - return TRUE; + if (!xdr_size3(xdrs, &objp->size)) + return FALSE; + if (!xdr_nfstime3(xdrs, &objp->mtime)) + return FALSE; + if (!xdr_nfstime3(xdrs, &objp->ctime)) + return FALSE; + return TRUE; } bool_t -xdr_pre_op_attr (XDR *xdrs, pre_op_attr *objp) +xdr_pre_op_attr(XDR *xdrs, pre_op_attr *objp) { - if (!xdr_bool (xdrs, &objp->attributes_follow)) - return FALSE; - switch (objp->attributes_follow) { - case TRUE: - if (!xdr_wcc_attr (xdrs, &objp->pre_op_attr_u.attributes)) - return FALSE; - break; - case FALSE: - break; - default: - return FALSE; - } - return TRUE; + if (!xdr_bool(xdrs, &objp->attributes_follow)) + return FALSE; + switch (objp->attributes_follow) { + case TRUE: + if (!xdr_wcc_attr(xdrs, &objp->pre_op_attr_u.attributes)) + return FALSE; + break; + case FALSE: + break; + default: + return FALSE; + } + return TRUE; } bool_t -xdr_wcc_data (XDR *xdrs, wcc_data *objp) +xdr_wcc_data(XDR *xdrs, wcc_data *objp) { - if (!xdr_pre_op_attr (xdrs, &objp->before)) - return FALSE; - if (!xdr_post_op_attr (xdrs, &objp->after)) - return FALSE; - return TRUE; + if (!xdr_pre_op_attr(xdrs, &objp->before)) + return FALSE; + if (!xdr_post_op_attr(xdrs, &objp->after)) + return FALSE; + return TRUE; } bool_t -xdr_post_op_fh3 (XDR *xdrs, post_op_fh3 *objp) -{ - if (!xdr_bool (xdrs, &objp->handle_follows)) - return FALSE; - switch (objp->handle_follows) { - case TRUE: - if (!xdr_nfs_fh3 (xdrs, &objp->post_op_fh3_u.handle)) - return FALSE; - break; - case FALSE: - break; - default: - return FALSE; - } - return TRUE; -} - -bool_t -xdr_time_how (XDR *xdrs, time_how *objp) -{ - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; +xdr_post_op_fh3(XDR *xdrs, post_op_fh3 *objp) +{ + if (!xdr_bool(xdrs, &objp->handle_follows)) + return FALSE; + switch (objp->handle_follows) { + case TRUE: + if (!xdr_nfs_fh3(xdrs, &objp->post_op_fh3_u.handle)) + return FALSE; + break; + case FALSE: + break; + default: + return FALSE; + } + return TRUE; +} + +bool_t +xdr_time_how(XDR *xdrs, time_how *objp) +{ + if (!xdr_enum(xdrs, (enum_t *)objp)) + return FALSE; + return TRUE; } bool_t -xdr_set_mode3 (XDR *xdrs, set_mode3 *objp) +xdr_set_mode3(XDR *xdrs, set_mode3 *objp) { - if (!xdr_bool (xdrs, &objp->set_it)) - return FALSE; - switch (objp->set_it) { - case TRUE: - if (!xdr_mode3 (xdrs, &objp->set_mode3_u.mode)) - return FALSE; - break; - default: - break; - } - return TRUE; + if (!xdr_bool(xdrs, &objp->set_it)) + return FALSE; + switch (objp->set_it) { + case TRUE: + if (!xdr_mode3(xdrs, &objp->set_mode3_u.mode)) + return FALSE; + break; + default: + break; + } + return TRUE; } bool_t -xdr_set_uid3 (XDR *xdrs, set_uid3 *objp) +xdr_set_uid3(XDR *xdrs, set_uid3 *objp) { - if (!xdr_bool (xdrs, &objp->set_it)) - return FALSE; - switch (objp->set_it) { - case TRUE: - if (!xdr_uid3 (xdrs, &objp->set_uid3_u.uid)) - return FALSE; - break; - default: - break; - } - return TRUE; + if (!xdr_bool(xdrs, &objp->set_it)) + return FALSE; + switch (objp->set_it) { + case TRUE: + if (!xdr_uid3(xdrs, &objp->set_uid3_u.uid)) + return FALSE; + break; + default: + break; + } + return TRUE; } bool_t -xdr_set_gid3 (XDR *xdrs, set_gid3 *objp) +xdr_set_gid3(XDR *xdrs, set_gid3 *objp) { - if (!xdr_bool (xdrs, &objp->set_it)) - return FALSE; - switch (objp->set_it) { - case TRUE: - if (!xdr_gid3 (xdrs, &objp->set_gid3_u.gid)) - return FALSE; - break; - default: - break; - } - return TRUE; + if (!xdr_bool(xdrs, &objp->set_it)) + return FALSE; + switch (objp->set_it) { + case TRUE: + if (!xdr_gid3(xdrs, &objp->set_gid3_u.gid)) + return FALSE; + break; + default: + break; + } + return TRUE; } bool_t -xdr_set_size3 (XDR *xdrs, set_size3 *objp) +xdr_set_size3(XDR *xdrs, set_size3 *objp) { - if (!xdr_bool (xdrs, &objp->set_it)) - return FALSE; - switch (objp->set_it) { - case TRUE: - if (!xdr_size3 (xdrs, &objp->set_size3_u.size)) - return FALSE; - break; - default: - break; - } - return TRUE; + if (!xdr_bool(xdrs, &objp->set_it)) + return FALSE; + switch (objp->set_it) { + case TRUE: + if (!xdr_size3(xdrs, &objp->set_size3_u.size)) + return FALSE; + break; + default: + break; + } + return TRUE; } bool_t -xdr_set_atime (XDR *xdrs, set_atime *objp) +xdr_set_atime(XDR *xdrs, set_atime *objp) { - if (!xdr_time_how (xdrs, &objp->set_it)) - return FALSE; - switch (objp->set_it) { - case SET_TO_CLIENT_TIME: - if (!xdr_nfstime3 (xdrs, &objp->set_atime_u.atime)) - return FALSE; - break; - default: - break; - } - return TRUE; + if (!xdr_time_how(xdrs, &objp->set_it)) + return FALSE; + switch (objp->set_it) { + case SET_TO_CLIENT_TIME: + if (!xdr_nfstime3(xdrs, &objp->set_atime_u.atime)) + return FALSE; + break; + default: + break; + } + return TRUE; } bool_t -xdr_set_mtime (XDR *xdrs, set_mtime *objp) +xdr_set_mtime(XDR *xdrs, set_mtime *objp) { - if (!xdr_time_how (xdrs, &objp->set_it)) - return FALSE; - switch (objp->set_it) { - case SET_TO_CLIENT_TIME: - if (!xdr_nfstime3 (xdrs, &objp->set_mtime_u.mtime)) - return FALSE; - break; - default: - break; - } - return TRUE; + if (!xdr_time_how(xdrs, &objp->set_it)) + return FALSE; + switch (objp->set_it) { + case SET_TO_CLIENT_TIME: + if (!xdr_nfstime3(xdrs, &objp->set_mtime_u.mtime)) + return FALSE; + break; + default: + break; + } + return TRUE; } bool_t -xdr_sattr3 (XDR *xdrs, sattr3 *objp) +xdr_sattr3(XDR *xdrs, sattr3 *objp) { - if (!xdr_set_mode3 (xdrs, &objp->mode)) - return FALSE; - if (!xdr_set_uid3 (xdrs, &objp->uid)) - return FALSE; - if (!xdr_set_gid3 (xdrs, &objp->gid)) - return FALSE; - if (!xdr_set_size3 (xdrs, &objp->size)) - return FALSE; - if (!xdr_set_atime (xdrs, &objp->atime)) - return FALSE; - if (!xdr_set_mtime (xdrs, &objp->mtime)) - return FALSE; - return TRUE; + if (!xdr_set_mode3(xdrs, &objp->mode)) + return FALSE; + if (!xdr_set_uid3(xdrs, &objp->uid)) + return FALSE; + if (!xdr_set_gid3(xdrs, &objp->gid)) + return FALSE; + if (!xdr_set_size3(xdrs, &objp->size)) + return FALSE; + if (!xdr_set_atime(xdrs, &objp->atime)) + return FALSE; + if (!xdr_set_mtime(xdrs, &objp->mtime)) + return FALSE; + return TRUE; } bool_t -xdr_diropargs3 (XDR *xdrs, diropargs3 *objp) +xdr_diropargs3(XDR *xdrs, diropargs3 *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->dir)) - return FALSE; - if (!xdr_filename3 (xdrs, &objp->name)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->dir)) + return FALSE; + if (!xdr_filename3(xdrs, &objp->name)) + return FALSE; + return TRUE; } bool_t -xdr_getattr3args (XDR *xdrs, getattr3args *objp) +xdr_getattr3args(XDR *xdrs, getattr3args *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->object)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->object)) + return FALSE; + return TRUE; } bool_t -xdr_getattr3resok (XDR *xdrs, getattr3resok *objp) +xdr_getattr3resok(XDR *xdrs, getattr3resok *objp) { - if (!xdr_fattr3 (xdrs, &objp->obj_attributes)) - return FALSE; - return TRUE; + if (!xdr_fattr3(xdrs, &objp->obj_attributes)) + return FALSE; + return TRUE; } bool_t -xdr_getattr3res (XDR *xdrs, getattr3res *objp) +xdr_getattr3res(XDR *xdrs, getattr3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_getattr3resok (xdrs, &objp->getattr3res_u.resok)) - return FALSE; - break; - default: - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_getattr3resok(xdrs, &objp->getattr3res_u.resok)) + return FALSE; + break; + default: + break; + } + return TRUE; } bool_t -xdr_sattrguard3 (XDR *xdrs, sattrguard3 *objp) +xdr_sattrguard3(XDR *xdrs, sattrguard3 *objp) { - if (!xdr_bool (xdrs, &objp->check)) - return FALSE; - switch (objp->check) { - case TRUE: - if (!xdr_nfstime3 (xdrs, &objp->sattrguard3_u.obj_ctime)) - return FALSE; - break; - case FALSE: - break; - default: - return FALSE; - } - return TRUE; + if (!xdr_bool(xdrs, &objp->check)) + return FALSE; + switch (objp->check) { + case TRUE: + if (!xdr_nfstime3(xdrs, &objp->sattrguard3_u.obj_ctime)) + return FALSE; + break; + case FALSE: + break; + default: + return FALSE; + } + return TRUE; } bool_t -xdr_setattr3args (XDR *xdrs, setattr3args *objp) +xdr_setattr3args(XDR *xdrs, setattr3args *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->object)) - return FALSE; - if (!xdr_sattr3 (xdrs, &objp->new_attributes)) - return FALSE; - if (!xdr_sattrguard3 (xdrs, &objp->guard)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->object)) + return FALSE; + if (!xdr_sattr3(xdrs, &objp->new_attributes)) + return FALSE; + if (!xdr_sattrguard3(xdrs, &objp->guard)) + return FALSE; + return TRUE; } bool_t -xdr_setattr3resok (XDR *xdrs, setattr3resok *objp) +xdr_setattr3resok(XDR *xdrs, setattr3resok *objp) { - if (!xdr_wcc_data (xdrs, &objp->obj_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->obj_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_setattr3resfail (XDR *xdrs, setattr3resfail *objp) +xdr_setattr3resfail(XDR *xdrs, setattr3resfail *objp) { - if (!xdr_wcc_data (xdrs, &objp->obj_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->obj_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_setattr3res (XDR *xdrs, setattr3res *objp) +xdr_setattr3res(XDR *xdrs, setattr3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_setattr3resok (xdrs, &objp->setattr3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_setattr3resfail (xdrs, &objp->setattr3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_setattr3resok(xdrs, &objp->setattr3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_setattr3resfail(xdrs, &objp->setattr3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_lookup3args (XDR *xdrs, lookup3args *objp) +xdr_lookup3args(XDR *xdrs, lookup3args *objp) { - if (!xdr_diropargs3 (xdrs, &objp->what)) - return FALSE; - return TRUE; + if (!xdr_diropargs3(xdrs, &objp->what)) + return FALSE; + return TRUE; } bool_t -xdr_lookup3resok (XDR *xdrs, lookup3resok *objp) +xdr_lookup3resok(XDR *xdrs, lookup3resok *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->object)) - return FALSE; - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - if (!xdr_post_op_attr (xdrs, &objp->dir_attributes)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->object)) + return FALSE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + if (!xdr_post_op_attr(xdrs, &objp->dir_attributes)) + return FALSE; + return TRUE; } bool_t -xdr_lookup3resfail (XDR *xdrs, lookup3resfail *objp) +xdr_lookup3resfail(XDR *xdrs, lookup3resfail *objp) { - if (!xdr_post_op_attr (xdrs, &objp->dir_attributes)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->dir_attributes)) + return FALSE; + return TRUE; } bool_t -xdr_lookup3res (XDR *xdrs, lookup3res *objp) +xdr_lookup3res(XDR *xdrs, lookup3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_lookup3resok (xdrs, &objp->lookup3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_lookup3resfail (xdrs, &objp->lookup3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_lookup3resok(xdrs, &objp->lookup3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_lookup3resfail(xdrs, &objp->lookup3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_access3args (XDR *xdrs, access3args *objp) +xdr_access3args(XDR *xdrs, access3args *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->object)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->access)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->object)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->access)) + return FALSE; + return TRUE; } bool_t -xdr_access3resok (XDR *xdrs, access3resok *objp) +xdr_access3resok(XDR *xdrs, access3resok *objp) { - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->access)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->access)) + return FALSE; + return TRUE; } bool_t -xdr_access3resfail (XDR *xdrs, access3resfail *objp) +xdr_access3resfail(XDR *xdrs, access3resfail *objp) { - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + return TRUE; } bool_t -xdr_access3res (XDR *xdrs, access3res *objp) +xdr_access3res(XDR *xdrs, access3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_access3resok (xdrs, &objp->access3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_access3resfail (xdrs, &objp->access3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_access3resok(xdrs, &objp->access3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_access3resfail(xdrs, &objp->access3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_readlink3args (XDR *xdrs, readlink3args *objp) +xdr_readlink3args(XDR *xdrs, readlink3args *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->symlink)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->symlink)) + return FALSE; + return TRUE; } bool_t -xdr_readlink3resok (XDR *xdrs, readlink3resok *objp) +xdr_readlink3resok(XDR *xdrs, readlink3resok *objp) { - if (!xdr_post_op_attr (xdrs, &objp->symlink_attributes)) - return FALSE; - if (!xdr_nfspath3 (xdrs, &objp->data)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->symlink_attributes)) + return FALSE; + if (!xdr_nfspath3(xdrs, &objp->data)) + return FALSE; + return TRUE; } bool_t -xdr_readlink3resfail (XDR *xdrs, readlink3resfail *objp) +xdr_readlink3resfail(XDR *xdrs, readlink3resfail *objp) { - if (!xdr_post_op_attr (xdrs, &objp->symlink_attributes)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->symlink_attributes)) + return FALSE; + return TRUE; } bool_t -xdr_readlink3res (XDR *xdrs, readlink3res *objp) +xdr_readlink3res(XDR *xdrs, readlink3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_readlink3resok (xdrs, &objp->readlink3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_readlink3resfail (xdrs, &objp->readlink3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_readlink3resok(xdrs, &objp->readlink3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_readlink3resfail(xdrs, &objp->readlink3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_read3args (XDR *xdrs, read3args *objp) +xdr_read3args(XDR *xdrs, read3args *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->file)) - return FALSE; - if (!xdr_offset3 (xdrs, &objp->offset)) - return FALSE; - if (!xdr_count3 (xdrs, &objp->count)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->file)) + return FALSE; + if (!xdr_offset3(xdrs, &objp->offset)) + return FALSE; + if (!xdr_count3(xdrs, &objp->count)) + return FALSE; + return TRUE; } bool_t -xdr_read3resok_nocopy (XDR *xdrs, read3resok *objp) +xdr_read3resok_nocopy(XDR *xdrs, read3resok *objp) { - if (!xdr_post_op_attr (xdrs, &objp->file_attributes)) - return FALSE; - if (!xdr_count3 (xdrs, &objp->count)) - return FALSE; - if (!xdr_bool (xdrs, &objp->eof)) - return FALSE; - if (!xdr_u_int (xdrs, (u_int *) &objp->data.data_len)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->file_attributes)) + return FALSE; + if (!xdr_count3(xdrs, &objp->count)) + return FALSE; + if (!xdr_bool(xdrs, &objp->eof)) + return FALSE; + if (!xdr_u_int(xdrs, (u_int *)&objp->data.data_len)) + return FALSE; + return TRUE; } - bool_t -xdr_read3resok (XDR *xdrs, read3resok *objp) +xdr_read3resok(XDR *xdrs, read3resok *objp) { - if (!xdr_post_op_attr (xdrs, &objp->file_attributes)) - return FALSE; - if (!xdr_count3 (xdrs, &objp->count)) - return FALSE; - if (!xdr_bool (xdrs, &objp->eof)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->data.data_val, (u_int *) &objp->data.data_len, ~0)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->file_attributes)) + return FALSE; + if (!xdr_count3(xdrs, &objp->count)) + return FALSE; + if (!xdr_bool(xdrs, &objp->eof)) + return FALSE; + if (!xdr_bytes(xdrs, (char **)&objp->data.data_val, + (u_int *)&objp->data.data_len, ~0)) + return FALSE; + return TRUE; } bool_t -xdr_read3resfail (XDR *xdrs, read3resfail *objp) +xdr_read3resfail(XDR *xdrs, read3resfail *objp) { - if (!xdr_post_op_attr (xdrs, &objp->file_attributes)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->file_attributes)) + return FALSE; + return TRUE; } - bool_t -xdr_read3res_nocopy (XDR *xdrs, read3res *objp) +xdr_read3res_nocopy(XDR *xdrs, read3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_read3resok_nocopy (xdrs, &objp->read3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_read3resfail (xdrs, &objp->read3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_read3resok_nocopy(xdrs, &objp->read3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_read3resfail(xdrs, &objp->read3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } - bool_t -xdr_read3res (XDR *xdrs, read3res *objp) +xdr_read3res(XDR *xdrs, read3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_read3resok (xdrs, &objp->read3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_read3resfail (xdrs, &objp->read3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_read3resok(xdrs, &objp->read3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_read3resfail(xdrs, &objp->read3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_stable_how (XDR *xdrs, stable_how *objp) +xdr_stable_how(XDR *xdrs, stable_how *objp) { - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; + if (!xdr_enum(xdrs, (enum_t *)objp)) + return FALSE; + return TRUE; } bool_t -xdr_write3args (XDR *xdrs, write3args *objp) +xdr_write3args(XDR *xdrs, write3args *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->file)) - return FALSE; - if (!xdr_offset3 (xdrs, &objp->offset)) - return FALSE; - if (!xdr_count3 (xdrs, &objp->count)) - return FALSE; - if (!xdr_stable_how (xdrs, &objp->stable)) - return FALSE; + if (!xdr_nfs_fh3(xdrs, &objp->file)) + return FALSE; + if (!xdr_offset3(xdrs, &objp->offset)) + return FALSE; + if (!xdr_count3(xdrs, &objp->count)) + return FALSE; + if (!xdr_stable_how(xdrs, &objp->stable)) + return FALSE; - /* Added specifically to avoid copies from the xdr buffer into - * the write3args structure, which will also require an already - * allocated buffer. That is not optimal. - */ - if (!xdr_u_int (xdrs, (u_int *) &objp->data.data_len)) - return FALSE; + /* Added specifically to avoid copies from the xdr buffer into + * the write3args structure, which will also require an already + * allocated buffer. That is not optimal. + */ + if (!xdr_u_int(xdrs, (u_int *)&objp->data.data_len)) + return FALSE; - /* The remaining bytes in the xdr buffer are the bytes that need to be - * written. See how these bytes are extracted in the xdr_to_write3args - * code path. Be careful, while using the write3args structure, since - * only the data.data_len has been filled. The actual data is - * extracted in xdr_to_write3args path. - */ + /* The remaining bytes in the xdr buffer are the bytes that need to be + * written. See how these bytes are extracted in the xdr_to_write3args + * code path. Be careful, while using the write3args structure, since + * only the data.data_len has been filled. The actual data is + * extracted in xdr_to_write3args path. + */ - /* if (!xdr_bytes (xdrs, (char **)&objp->data.data_val, (u_int *) &objp->data.data_len, ~0)) - return FALSE; - */ - return TRUE; + /* if (!xdr_bytes (xdrs, (char **)&objp->data.data_val, (u_int *) + &objp->data.data_len, ~0)) return FALSE; + */ + return TRUE; } bool_t -xdr_write3resok (XDR *xdrs, write3resok *objp) +xdr_write3resok(XDR *xdrs, write3resok *objp) { - if (!xdr_wcc_data (xdrs, &objp->file_wcc)) - return FALSE; - if (!xdr_count3 (xdrs, &objp->count)) - return FALSE; - if (!xdr_stable_how (xdrs, &objp->committed)) - return FALSE; - if (!xdr_writeverf3 (xdrs, objp->verf)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->file_wcc)) + return FALSE; + if (!xdr_count3(xdrs, &objp->count)) + return FALSE; + if (!xdr_stable_how(xdrs, &objp->committed)) + return FALSE; + if (!xdr_writeverf3(xdrs, objp->verf)) + return FALSE; + return TRUE; } bool_t -xdr_write3resfail (XDR *xdrs, write3resfail *objp) +xdr_write3resfail(XDR *xdrs, write3resfail *objp) { - if (!xdr_wcc_data (xdrs, &objp->file_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->file_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_write3res (XDR *xdrs, write3res *objp) +xdr_write3res(XDR *xdrs, write3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_write3resok (xdrs, &objp->write3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_write3resfail (xdrs, &objp->write3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_write3resok(xdrs, &objp->write3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_write3resfail(xdrs, &objp->write3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_createmode3 (XDR *xdrs, createmode3 *objp) +xdr_createmode3(XDR *xdrs, createmode3 *objp) { - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; + if (!xdr_enum(xdrs, (enum_t *)objp)) + return FALSE; + return TRUE; } bool_t -xdr_createhow3 (XDR *xdrs, createhow3 *objp) +xdr_createhow3(XDR *xdrs, createhow3 *objp) { - if (!xdr_createmode3 (xdrs, &objp->mode)) - return FALSE; - switch (objp->mode) { - case UNCHECKED: - case GUARDED: - if (!xdr_sattr3 (xdrs, &objp->createhow3_u.obj_attributes)) - return FALSE; - break; - case EXCLUSIVE: - if (!xdr_createverf3 (xdrs, objp->createhow3_u.verf)) - return FALSE; - break; - default: - return FALSE; - } - return TRUE; + if (!xdr_createmode3(xdrs, &objp->mode)) + return FALSE; + switch (objp->mode) { + case UNCHECKED: + case GUARDED: + if (!xdr_sattr3(xdrs, &objp->createhow3_u.obj_attributes)) + return FALSE; + break; + case EXCLUSIVE: + if (!xdr_createverf3(xdrs, objp->createhow3_u.verf)) + return FALSE; + break; + default: + return FALSE; + } + return TRUE; } bool_t -xdr_create3args (XDR *xdrs, create3args *objp) +xdr_create3args(XDR *xdrs, create3args *objp) { - if (!xdr_diropargs3 (xdrs, &objp->where)) - return FALSE; - if (!xdr_createhow3 (xdrs, &objp->how)) - return FALSE; - return TRUE; + if (!xdr_diropargs3(xdrs, &objp->where)) + return FALSE; + if (!xdr_createhow3(xdrs, &objp->how)) + return FALSE; + return TRUE; } bool_t -xdr_create3resok (XDR *xdrs, create3resok *objp) +xdr_create3resok(XDR *xdrs, create3resok *objp) { - if (!xdr_post_op_fh3 (xdrs, &objp->obj)) - return FALSE; - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_post_op_fh3(xdrs, &objp->obj)) + return FALSE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_create3resfail (XDR *xdrs, create3resfail *objp) +xdr_create3resfail(XDR *xdrs, create3resfail *objp) { - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_create3res (XDR *xdrs, create3res *objp) +xdr_create3res(XDR *xdrs, create3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_create3resok (xdrs, &objp->create3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_create3resfail (xdrs, &objp->create3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_create3resok(xdrs, &objp->create3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_create3resfail(xdrs, &objp->create3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_mkdir3args (XDR *xdrs, mkdir3args *objp) +xdr_mkdir3args(XDR *xdrs, mkdir3args *objp) { - if (!xdr_diropargs3 (xdrs, &objp->where)) - return FALSE; - if (!xdr_sattr3 (xdrs, &objp->attributes)) - return FALSE; - return TRUE; + if (!xdr_diropargs3(xdrs, &objp->where)) + return FALSE; + if (!xdr_sattr3(xdrs, &objp->attributes)) + return FALSE; + return TRUE; } bool_t -xdr_mkdir3resok (XDR *xdrs, mkdir3resok *objp) +xdr_mkdir3resok(XDR *xdrs, mkdir3resok *objp) { - if (!xdr_post_op_fh3 (xdrs, &objp->obj)) - return FALSE; - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_post_op_fh3(xdrs, &objp->obj)) + return FALSE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_mkdir3resfail (XDR *xdrs, mkdir3resfail *objp) +xdr_mkdir3resfail(XDR *xdrs, mkdir3resfail *objp) { - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_mkdir3res (XDR *xdrs, mkdir3res *objp) +xdr_mkdir3res(XDR *xdrs, mkdir3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_mkdir3resok (xdrs, &objp->mkdir3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_mkdir3resfail (xdrs, &objp->mkdir3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_mkdir3resok(xdrs, &objp->mkdir3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_mkdir3resfail(xdrs, &objp->mkdir3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_symlinkdata3 (XDR *xdrs, symlinkdata3 *objp) +xdr_symlinkdata3(XDR *xdrs, symlinkdata3 *objp) { - if (!xdr_sattr3 (xdrs, &objp->symlink_attributes)) - return FALSE; - if (!xdr_nfspath3 (xdrs, &objp->symlink_data)) - return FALSE; - return TRUE; + if (!xdr_sattr3(xdrs, &objp->symlink_attributes)) + return FALSE; + if (!xdr_nfspath3(xdrs, &objp->symlink_data)) + return FALSE; + return TRUE; } bool_t -xdr_symlink3args (XDR *xdrs, symlink3args *objp) +xdr_symlink3args(XDR *xdrs, symlink3args *objp) { - if (!xdr_diropargs3 (xdrs, &objp->where)) - return FALSE; - if (!xdr_symlinkdata3 (xdrs, &objp->symlink)) - return FALSE; - return TRUE; + if (!xdr_diropargs3(xdrs, &objp->where)) + return FALSE; + if (!xdr_symlinkdata3(xdrs, &objp->symlink)) + return FALSE; + return TRUE; } bool_t -xdr_symlink3resok (XDR *xdrs, symlink3resok *objp) +xdr_symlink3resok(XDR *xdrs, symlink3resok *objp) { - if (!xdr_post_op_fh3 (xdrs, &objp->obj)) - return FALSE; - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_post_op_fh3(xdrs, &objp->obj)) + return FALSE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_symlink3resfail (XDR *xdrs, symlink3resfail *objp) +xdr_symlink3resfail(XDR *xdrs, symlink3resfail *objp) { - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_symlink3res (XDR *xdrs, symlink3res *objp) +xdr_symlink3res(XDR *xdrs, symlink3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_symlink3resok (xdrs, &objp->symlink3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_symlink3resfail (xdrs, &objp->symlink3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_symlink3resok(xdrs, &objp->symlink3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_symlink3resfail(xdrs, &objp->symlink3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_devicedata3 (XDR *xdrs, devicedata3 *objp) +xdr_devicedata3(XDR *xdrs, devicedata3 *objp) { - if (!xdr_sattr3 (xdrs, &objp->dev_attributes)) - return FALSE; - if (!xdr_specdata3 (xdrs, &objp->spec)) - return FALSE; - return TRUE; + if (!xdr_sattr3(xdrs, &objp->dev_attributes)) + return FALSE; + if (!xdr_specdata3(xdrs, &objp->spec)) + return FALSE; + return TRUE; } bool_t -xdr_mknoddata3 (XDR *xdrs, mknoddata3 *objp) +xdr_mknoddata3(XDR *xdrs, mknoddata3 *objp) { - if (!xdr_ftype3 (xdrs, &objp->type)) - return FALSE; - switch (objp->type) { - case NF3CHR: - case NF3BLK: - if (!xdr_devicedata3 (xdrs, &objp->mknoddata3_u.device)) - return FALSE; - break; - case NF3SOCK: - case NF3FIFO: - if (!xdr_sattr3 (xdrs, &objp->mknoddata3_u.pipe_attributes)) - return FALSE; - break; - default: - break; - } - return TRUE; + if (!xdr_ftype3(xdrs, &objp->type)) + return FALSE; + switch (objp->type) { + case NF3CHR: + case NF3BLK: + if (!xdr_devicedata3(xdrs, &objp->mknoddata3_u.device)) + return FALSE; + break; + case NF3SOCK: + case NF3FIFO: + if (!xdr_sattr3(xdrs, &objp->mknoddata3_u.pipe_attributes)) + return FALSE; + break; + default: + break; + } + return TRUE; } bool_t -xdr_mknod3args (XDR *xdrs, mknod3args *objp) +xdr_mknod3args(XDR *xdrs, mknod3args *objp) { - if (!xdr_diropargs3 (xdrs, &objp->where)) - return FALSE; - if (!xdr_mknoddata3 (xdrs, &objp->what)) - return FALSE; - return TRUE; + if (!xdr_diropargs3(xdrs, &objp->where)) + return FALSE; + if (!xdr_mknoddata3(xdrs, &objp->what)) + return FALSE; + return TRUE; } bool_t -xdr_mknod3resok (XDR *xdrs, mknod3resok *objp) +xdr_mknod3resok(XDR *xdrs, mknod3resok *objp) { - if (!xdr_post_op_fh3 (xdrs, &objp->obj)) - return FALSE; - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_post_op_fh3(xdrs, &objp->obj)) + return FALSE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_mknod3resfail (XDR *xdrs, mknod3resfail *objp) +xdr_mknod3resfail(XDR *xdrs, mknod3resfail *objp) { - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_mknod3res (XDR *xdrs, mknod3res *objp) +xdr_mknod3res(XDR *xdrs, mknod3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_mknod3resok (xdrs, &objp->mknod3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_mknod3resfail (xdrs, &objp->mknod3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_mknod3resok(xdrs, &objp->mknod3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_mknod3resfail(xdrs, &objp->mknod3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_remove3args (XDR *xdrs, remove3args *objp) +xdr_remove3args(XDR *xdrs, remove3args *objp) { - if (!xdr_diropargs3 (xdrs, &objp->object)) - return FALSE; - return TRUE; + if (!xdr_diropargs3(xdrs, &objp->object)) + return FALSE; + return TRUE; } bool_t -xdr_remove3resok (XDR *xdrs, remove3resok *objp) +xdr_remove3resok(XDR *xdrs, remove3resok *objp) { - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_remove3resfail (XDR *xdrs, remove3resfail *objp) +xdr_remove3resfail(XDR *xdrs, remove3resfail *objp) { - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_remove3res (XDR *xdrs, remove3res *objp) +xdr_remove3res(XDR *xdrs, remove3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_remove3resok (xdrs, &objp->remove3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_remove3resfail (xdrs, &objp->remove3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_remove3resok(xdrs, &objp->remove3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_remove3resfail(xdrs, &objp->remove3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_rmdir3args (XDR *xdrs, rmdir3args *objp) +xdr_rmdir3args(XDR *xdrs, rmdir3args *objp) { - if (!xdr_diropargs3 (xdrs, &objp->object)) - return FALSE; - return TRUE; + if (!xdr_diropargs3(xdrs, &objp->object)) + return FALSE; + return TRUE; } bool_t -xdr_rmdir3resok (XDR *xdrs, rmdir3resok *objp) +xdr_rmdir3resok(XDR *xdrs, rmdir3resok *objp) { - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_rmdir3resfail (XDR *xdrs, rmdir3resfail *objp) +xdr_rmdir3resfail(XDR *xdrs, rmdir3resfail *objp) { - if (!xdr_wcc_data (xdrs, &objp->dir_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->dir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_rmdir3res (XDR *xdrs, rmdir3res *objp) +xdr_rmdir3res(XDR *xdrs, rmdir3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_rmdir3resok (xdrs, &objp->rmdir3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_rmdir3resfail (xdrs, &objp->rmdir3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_rmdir3resok(xdrs, &objp->rmdir3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_rmdir3resfail(xdrs, &objp->rmdir3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_rename3args (XDR *xdrs, rename3args *objp) +xdr_rename3args(XDR *xdrs, rename3args *objp) { - if (!xdr_diropargs3 (xdrs, &objp->from)) - return FALSE; - if (!xdr_diropargs3 (xdrs, &objp->to)) - return FALSE; - return TRUE; + if (!xdr_diropargs3(xdrs, &objp->from)) + return FALSE; + if (!xdr_diropargs3(xdrs, &objp->to)) + return FALSE; + return TRUE; } bool_t -xdr_rename3resok (XDR *xdrs, rename3resok *objp) +xdr_rename3resok(XDR *xdrs, rename3resok *objp) { - if (!xdr_wcc_data (xdrs, &objp->fromdir_wcc)) - return FALSE; - if (!xdr_wcc_data (xdrs, &objp->todir_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->fromdir_wcc)) + return FALSE; + if (!xdr_wcc_data(xdrs, &objp->todir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_rename3resfail (XDR *xdrs, rename3resfail *objp) +xdr_rename3resfail(XDR *xdrs, rename3resfail *objp) { - if (!xdr_wcc_data (xdrs, &objp->fromdir_wcc)) - return FALSE; - if (!xdr_wcc_data (xdrs, &objp->todir_wcc)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->fromdir_wcc)) + return FALSE; + if (!xdr_wcc_data(xdrs, &objp->todir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_rename3res (XDR *xdrs, rename3res *objp) +xdr_rename3res(XDR *xdrs, rename3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_rename3resok (xdrs, &objp->rename3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_rename3resfail (xdrs, &objp->rename3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_rename3resok(xdrs, &objp->rename3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_rename3resfail(xdrs, &objp->rename3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_link3args (XDR *xdrs, link3args *objp) +xdr_link3args(XDR *xdrs, link3args *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->file)) - return FALSE; - if (!xdr_diropargs3 (xdrs, &objp->link)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->file)) + return FALSE; + if (!xdr_diropargs3(xdrs, &objp->link)) + return FALSE; + return TRUE; } bool_t -xdr_link3resok (XDR *xdrs, link3resok *objp) +xdr_link3resok(XDR *xdrs, link3resok *objp) { - if (!xdr_post_op_attr (xdrs, &objp->file_attributes)) - return FALSE; - if (!xdr_wcc_data (xdrs, &objp->linkdir_wcc)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->file_attributes)) + return FALSE; + if (!xdr_wcc_data(xdrs, &objp->linkdir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_link3resfail (XDR *xdrs, link3resfail *objp) +xdr_link3resfail(XDR *xdrs, link3resfail *objp) { - if (!xdr_post_op_attr (xdrs, &objp->file_attributes)) - return FALSE; - if (!xdr_wcc_data (xdrs, &objp->linkdir_wcc)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->file_attributes)) + return FALSE; + if (!xdr_wcc_data(xdrs, &objp->linkdir_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_link3res (XDR *xdrs, link3res *objp) +xdr_link3res(XDR *xdrs, link3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_link3resok (xdrs, &objp->link3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_link3resfail (xdrs, &objp->link3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_link3resok(xdrs, &objp->link3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_link3resfail(xdrs, &objp->link3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_readdir3args (XDR *xdrs, readdir3args *objp) +xdr_readdir3args(XDR *xdrs, readdir3args *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->dir)) - return FALSE; - if (!xdr_cookie3 (xdrs, &objp->cookie)) - return FALSE; - if (!xdr_cookieverf3 (xdrs, objp->cookieverf)) - return FALSE; - if (!xdr_count3 (xdrs, &objp->count)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->dir)) + return FALSE; + if (!xdr_cookie3(xdrs, &objp->cookie)) + return FALSE; + if (!xdr_cookieverf3(xdrs, objp->cookieverf)) + return FALSE; + if (!xdr_count3(xdrs, &objp->count)) + return FALSE; + return TRUE; } bool_t -xdr_entry3 (XDR *xdrs, entry3 *objp) +xdr_entry3(XDR *xdrs, entry3 *objp) { - if (!xdr_fileid3 (xdrs, &objp->fileid)) - return FALSE; - if (!xdr_filename3 (xdrs, &objp->name)) - return FALSE; - if (!xdr_cookie3 (xdrs, &objp->cookie)) - return FALSE; - if (!xdr_pointer (xdrs, (char **)&objp->nextentry, sizeof (entry3), (xdrproc_t) xdr_entry3)) - return FALSE; - return TRUE; + if (!xdr_fileid3(xdrs, &objp->fileid)) + return FALSE; + if (!xdr_filename3(xdrs, &objp->name)) + return FALSE; + if (!xdr_cookie3(xdrs, &objp->cookie)) + return FALSE; + if (!xdr_pointer(xdrs, (char **)&objp->nextentry, sizeof(entry3), + (xdrproc_t)xdr_entry3)) + return FALSE; + return TRUE; } bool_t -xdr_dirlist3 (XDR *xdrs, dirlist3 *objp) +xdr_dirlist3(XDR *xdrs, dirlist3 *objp) { - if (!xdr_pointer (xdrs, (char **)&objp->entries, sizeof (entry3), (xdrproc_t) xdr_entry3)) - return FALSE; - if (!xdr_bool (xdrs, &objp->eof)) - return FALSE; - return TRUE; + if (!xdr_pointer(xdrs, (char **)&objp->entries, sizeof(entry3), + (xdrproc_t)xdr_entry3)) + return FALSE; + if (!xdr_bool(xdrs, &objp->eof)) + return FALSE; + return TRUE; } bool_t -xdr_readdir3resok (XDR *xdrs, readdir3resok *objp) +xdr_readdir3resok(XDR *xdrs, readdir3resok *objp) { - if (!xdr_post_op_attr (xdrs, &objp->dir_attributes)) - return FALSE; - if (!xdr_cookieverf3 (xdrs, objp->cookieverf)) - return FALSE; - if (!xdr_dirlist3 (xdrs, &objp->reply)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->dir_attributes)) + return FALSE; + if (!xdr_cookieverf3(xdrs, objp->cookieverf)) + return FALSE; + if (!xdr_dirlist3(xdrs, &objp->reply)) + return FALSE; + return TRUE; } bool_t -xdr_readdir3resfail (XDR *xdrs, readdir3resfail *objp) +xdr_readdir3resfail(XDR *xdrs, readdir3resfail *objp) { - if (!xdr_post_op_attr (xdrs, &objp->dir_attributes)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->dir_attributes)) + return FALSE; + return TRUE; } bool_t -xdr_readdir3res (XDR *xdrs, readdir3res *objp) +xdr_readdir3res(XDR *xdrs, readdir3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_readdir3resok (xdrs, &objp->readdir3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_readdir3resfail (xdrs, &objp->readdir3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_readdir3resok(xdrs, &objp->readdir3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_readdir3resfail(xdrs, &objp->readdir3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_readdirp3args (XDR *xdrs, readdirp3args *objp) +xdr_readdirp3args(XDR *xdrs, readdirp3args *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->dir)) - return FALSE; - if (!xdr_cookie3 (xdrs, &objp->cookie)) - return FALSE; - if (!xdr_cookieverf3 (xdrs, objp->cookieverf)) - return FALSE; - if (!xdr_count3 (xdrs, &objp->dircount)) - return FALSE; - if (!xdr_count3 (xdrs, &objp->maxcount)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->dir)) + return FALSE; + if (!xdr_cookie3(xdrs, &objp->cookie)) + return FALSE; + if (!xdr_cookieverf3(xdrs, objp->cookieverf)) + return FALSE; + if (!xdr_count3(xdrs, &objp->dircount)) + return FALSE; + if (!xdr_count3(xdrs, &objp->maxcount)) + return FALSE; + return TRUE; } bool_t -xdr_entryp3 (XDR *xdrs, entryp3 *objp) +xdr_entryp3(XDR *xdrs, entryp3 *objp) { - if (!xdr_fileid3 (xdrs, &objp->fileid)) - return FALSE; - if (!xdr_filename3 (xdrs, &objp->name)) - return FALSE; - if (!xdr_cookie3 (xdrs, &objp->cookie)) - return FALSE; - if (!xdr_post_op_attr (xdrs, &objp->name_attributes)) - return FALSE; - if (!xdr_post_op_fh3 (xdrs, &objp->name_handle)) - return FALSE; - if (!xdr_pointer (xdrs, (char **)&objp->nextentry, sizeof (entryp3), (xdrproc_t) xdr_entryp3)) - return FALSE; - return TRUE; + if (!xdr_fileid3(xdrs, &objp->fileid)) + return FALSE; + if (!xdr_filename3(xdrs, &objp->name)) + return FALSE; + if (!xdr_cookie3(xdrs, &objp->cookie)) + return FALSE; + if (!xdr_post_op_attr(xdrs, &objp->name_attributes)) + return FALSE; + if (!xdr_post_op_fh3(xdrs, &objp->name_handle)) + return FALSE; + if (!xdr_pointer(xdrs, (char **)&objp->nextentry, sizeof(entryp3), + (xdrproc_t)xdr_entryp3)) + return FALSE; + return TRUE; } bool_t -xdr_dirlistp3 (XDR *xdrs, dirlistp3 *objp) +xdr_dirlistp3(XDR *xdrs, dirlistp3 *objp) { - if (!xdr_pointer (xdrs, (char **)&objp->entries, sizeof (entryp3), (xdrproc_t) xdr_entryp3)) - return FALSE; - if (!xdr_bool (xdrs, &objp->eof)) - return FALSE; - return TRUE; + if (!xdr_pointer(xdrs, (char **)&objp->entries, sizeof(entryp3), + (xdrproc_t)xdr_entryp3)) + return FALSE; + if (!xdr_bool(xdrs, &objp->eof)) + return FALSE; + return TRUE; } bool_t -xdr_readdirp3resok (XDR *xdrs, readdirp3resok *objp) +xdr_readdirp3resok(XDR *xdrs, readdirp3resok *objp) { - if (!xdr_post_op_attr (xdrs, &objp->dir_attributes)) - return FALSE; - if (!xdr_cookieverf3 (xdrs, objp->cookieverf)) - return FALSE; - if (!xdr_dirlistp3 (xdrs, &objp->reply)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->dir_attributes)) + return FALSE; + if (!xdr_cookieverf3(xdrs, objp->cookieverf)) + return FALSE; + if (!xdr_dirlistp3(xdrs, &objp->reply)) + return FALSE; + return TRUE; } bool_t -xdr_readdirp3resfail (XDR *xdrs, readdirp3resfail *objp) +xdr_readdirp3resfail(XDR *xdrs, readdirp3resfail *objp) { - if (!xdr_post_op_attr (xdrs, &objp->dir_attributes)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->dir_attributes)) + return FALSE; + return TRUE; } bool_t -xdr_readdirp3res (XDR *xdrs, readdirp3res *objp) +xdr_readdirp3res(XDR *xdrs, readdirp3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_readdirp3resok (xdrs, &objp->readdirp3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_readdirp3resfail (xdrs, &objp->readdirp3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_readdirp3resok(xdrs, &objp->readdirp3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_readdirp3resfail(xdrs, &objp->readdirp3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_fsstat3args (XDR *xdrs, fsstat3args *objp) +xdr_fsstat3args(XDR *xdrs, fsstat3args *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->fsroot)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->fsroot)) + return FALSE; + return TRUE; } bool_t -xdr_fsstat3resok (XDR *xdrs, fsstat3resok *objp) +xdr_fsstat3resok(XDR *xdrs, fsstat3resok *objp) { - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - if (!xdr_size3 (xdrs, &objp->tbytes)) - return FALSE; - if (!xdr_size3 (xdrs, &objp->fbytes)) - return FALSE; - if (!xdr_size3 (xdrs, &objp->abytes)) - return FALSE; - if (!xdr_size3 (xdrs, &objp->tfiles)) - return FALSE; - if (!xdr_size3 (xdrs, &objp->ffiles)) - return FALSE; - if (!xdr_size3 (xdrs, &objp->afiles)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->invarsec)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + if (!xdr_size3(xdrs, &objp->tbytes)) + return FALSE; + if (!xdr_size3(xdrs, &objp->fbytes)) + return FALSE; + if (!xdr_size3(xdrs, &objp->abytes)) + return FALSE; + if (!xdr_size3(xdrs, &objp->tfiles)) + return FALSE; + if (!xdr_size3(xdrs, &objp->ffiles)) + return FALSE; + if (!xdr_size3(xdrs, &objp->afiles)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->invarsec)) + return FALSE; + return TRUE; } bool_t -xdr_fsstat3resfail (XDR *xdrs, fsstat3resfail *objp) +xdr_fsstat3resfail(XDR *xdrs, fsstat3resfail *objp) { - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + return TRUE; } bool_t -xdr_fsstat3res (XDR *xdrs, fsstat3res *objp) +xdr_fsstat3res(XDR *xdrs, fsstat3res *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_fsstat3resok (xdrs, &objp->fsstat3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_fsstat3resfail (xdrs, &objp->fsstat3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_fsstat3resok(xdrs, &objp->fsstat3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_fsstat3resfail(xdrs, &objp->fsstat3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_fsinfo3args (XDR *xdrs, fsinfo3args *objp) +xdr_fsinfo3args(XDR *xdrs, fsinfo3args *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->fsroot)) - return FALSE; - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->fsroot)) + return FALSE; + return TRUE; } bool_t -xdr_fsinfo3resok (XDR *xdrs, fsinfo3resok *objp) +xdr_fsinfo3resok(XDR *xdrs, fsinfo3resok *objp) { - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->rtmax)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->rtpref)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->rtmult)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->wtmax)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->wtpref)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->wtmult)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->dtpref)) - return FALSE; - if (!xdr_size3 (xdrs, &objp->maxfilesize)) - return FALSE; - if (!xdr_nfstime3 (xdrs, &objp->time_delta)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->properties)) - return FALSE; - return TRUE; -} - -bool_t -xdr_fsinfo3resfail (XDR *xdrs, fsinfo3resfail *objp) -{ - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - return TRUE; -} - -bool_t -xdr_fsinfo3res (XDR *xdrs, fsinfo3res *objp) -{ - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_fsinfo3resok (xdrs, &objp->fsinfo3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_fsinfo3resfail (xdrs, &objp->fsinfo3res_u.resfail)) - return FALSE; - break; - } - return TRUE; -} - -bool_t -xdr_pathconf3args (XDR *xdrs, pathconf3args *objp) -{ - if (!xdr_nfs_fh3 (xdrs, &objp->object)) - return FALSE; - return TRUE; -} - -bool_t -xdr_pathconf3resok (XDR *xdrs, pathconf3resok *objp) -{ - register int32_t *buf; - - - if (xdrs->x_op == XDR_ENCODE) { - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->linkmax)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->name_max)) - return FALSE; - buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_bool (xdrs, &objp->no_trunc)) - return FALSE; - if (!xdr_bool (xdrs, &objp->chown_restricted)) - return FALSE; - if (!xdr_bool (xdrs, &objp->case_insensitive)) - return FALSE; - if (!xdr_bool (xdrs, &objp->case_preserving)) - return FALSE; - } else { - IXDR_PUT_BOOL(buf, objp->no_trunc); - IXDR_PUT_BOOL(buf, objp->chown_restricted); - IXDR_PUT_BOOL(buf, objp->case_insensitive); - IXDR_PUT_BOOL(buf, objp->case_preserving); - } - return TRUE; - } else if (xdrs->x_op == XDR_DECODE) { - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->linkmax)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->name_max)) - return FALSE; - buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_bool (xdrs, &objp->no_trunc)) - return FALSE; - if (!xdr_bool (xdrs, &objp->chown_restricted)) - return FALSE; - if (!xdr_bool (xdrs, &objp->case_insensitive)) - return FALSE; - if (!xdr_bool (xdrs, &objp->case_preserving)) - return FALSE; - } else { - objp->no_trunc = IXDR_GET_BOOL(buf); - objp->chown_restricted = IXDR_GET_BOOL(buf); - objp->case_insensitive = IXDR_GET_BOOL(buf); - objp->case_preserving = IXDR_GET_BOOL(buf); - } - return TRUE; - } - - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->linkmax)) - return FALSE; - if (!xdr_uint32 (xdrs, &objp->name_max)) - return FALSE; - if (!xdr_bool (xdrs, &objp->no_trunc)) - return FALSE; - if (!xdr_bool (xdrs, &objp->chown_restricted)) - return FALSE; - if (!xdr_bool (xdrs, &objp->case_insensitive)) - return FALSE; - if (!xdr_bool (xdrs, &objp->case_preserving)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->rtmax)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->rtpref)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->rtmult)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->wtmax)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->wtpref)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->wtmult)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->dtpref)) + return FALSE; + if (!xdr_size3(xdrs, &objp->maxfilesize)) + return FALSE; + if (!xdr_nfstime3(xdrs, &objp->time_delta)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->properties)) + return FALSE; + return TRUE; } bool_t -xdr_pathconf3resfail (XDR *xdrs, pathconf3resfail *objp) +xdr_fsinfo3resfail(XDR *xdrs, fsinfo3resfail *objp) { - if (!xdr_post_op_attr (xdrs, &objp->obj_attributes)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + return TRUE; +} + +bool_t +xdr_fsinfo3res(XDR *xdrs, fsinfo3res *objp) +{ + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_fsinfo3resok(xdrs, &objp->fsinfo3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_fsinfo3resfail(xdrs, &objp->fsinfo3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_pathconf3res (XDR *xdrs, pathconf3res *objp) +xdr_pathconf3args(XDR *xdrs, pathconf3args *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_pathconf3resok (xdrs, &objp->pathconf3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_pathconf3resfail (xdrs, &objp->pathconf3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->object)) + return FALSE; + return TRUE; } bool_t -xdr_commit3args (XDR *xdrs, commit3args *objp) +xdr_pathconf3resok(XDR *xdrs, pathconf3resok *objp) { - if (!xdr_nfs_fh3 (xdrs, &objp->file)) - return FALSE; - if (!xdr_offset3 (xdrs, &objp->offset)) - return FALSE; - if (!xdr_count3 (xdrs, &objp->count)) - return FALSE; - return TRUE; + register int32_t *buf; + + if (xdrs->x_op == XDR_ENCODE) { + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->linkmax)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->name_max)) + return FALSE; + buf = XDR_INLINE(xdrs, 4 * BYTES_PER_XDR_UNIT); + if (buf == NULL) { + if (!xdr_bool(xdrs, &objp->no_trunc)) + return FALSE; + if (!xdr_bool(xdrs, &objp->chown_restricted)) + return FALSE; + if (!xdr_bool(xdrs, &objp->case_insensitive)) + return FALSE; + if (!xdr_bool(xdrs, &objp->case_preserving)) + return FALSE; + } else { + IXDR_PUT_BOOL(buf, objp->no_trunc); + IXDR_PUT_BOOL(buf, objp->chown_restricted); + IXDR_PUT_BOOL(buf, objp->case_insensitive); + IXDR_PUT_BOOL(buf, objp->case_preserving); + } + return TRUE; + } else if (xdrs->x_op == XDR_DECODE) { + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->linkmax)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->name_max)) + return FALSE; + buf = XDR_INLINE(xdrs, 4 * BYTES_PER_XDR_UNIT); + if (buf == NULL) { + if (!xdr_bool(xdrs, &objp->no_trunc)) + return FALSE; + if (!xdr_bool(xdrs, &objp->chown_restricted)) + return FALSE; + if (!xdr_bool(xdrs, &objp->case_insensitive)) + return FALSE; + if (!xdr_bool(xdrs, &objp->case_preserving)) + return FALSE; + } else { + objp->no_trunc = IXDR_GET_BOOL(buf); + objp->chown_restricted = IXDR_GET_BOOL(buf); + objp->case_insensitive = IXDR_GET_BOOL(buf); + objp->case_preserving = IXDR_GET_BOOL(buf); + } + return TRUE; + } + + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->linkmax)) + return FALSE; + if (!xdr_uint32(xdrs, &objp->name_max)) + return FALSE; + if (!xdr_bool(xdrs, &objp->no_trunc)) + return FALSE; + if (!xdr_bool(xdrs, &objp->chown_restricted)) + return FALSE; + if (!xdr_bool(xdrs, &objp->case_insensitive)) + return FALSE; + if (!xdr_bool(xdrs, &objp->case_preserving)) + return FALSE; + return TRUE; } bool_t -xdr_commit3resok (XDR *xdrs, commit3resok *objp) +xdr_pathconf3resfail(XDR *xdrs, pathconf3resfail *objp) { - if (!xdr_wcc_data (xdrs, &objp->file_wcc)) - return FALSE; - if (!xdr_writeverf3 (xdrs, objp->verf)) - return FALSE; - return TRUE; + if (!xdr_post_op_attr(xdrs, &objp->obj_attributes)) + return FALSE; + return TRUE; } bool_t -xdr_commit3resfail (XDR *xdrs, commit3resfail *objp) +xdr_pathconf3res(XDR *xdrs, pathconf3res *objp) { - if (!xdr_wcc_data (xdrs, &objp->file_wcc)) - return FALSE; - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_pathconf3resok(xdrs, &objp->pathconf3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_pathconf3resfail(xdrs, &objp->pathconf3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_commit3res (XDR *xdrs, commit3res *objp) +xdr_commit3args(XDR *xdrs, commit3args *objp) { - if (!xdr_nfsstat3 (xdrs, &objp->status)) - return FALSE; - switch (objp->status) { - case NFS3_OK: - if (!xdr_commit3resok (xdrs, &objp->commit3res_u.resok)) - return FALSE; - break; - default: - if (!xdr_commit3resfail (xdrs, &objp->commit3res_u.resfail)) - return FALSE; - break; - } - return TRUE; + if (!xdr_nfs_fh3(xdrs, &objp->file)) + return FALSE; + if (!xdr_offset3(xdrs, &objp->offset)) + return FALSE; + if (!xdr_count3(xdrs, &objp->count)) + return FALSE; + return TRUE; } bool_t -xdr_fhandle3 (XDR *xdrs, fhandle3 *objp) +xdr_commit3resok(XDR *xdrs, commit3resok *objp) { - if (!xdr_bytes (xdrs, (char **)&objp->fhandle3_val, (u_int *) &objp->fhandle3_len, FHSIZE3)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->file_wcc)) + return FALSE; + if (!xdr_writeverf3(xdrs, objp->verf)) + return FALSE; + return TRUE; } bool_t -xdr_dirpath (XDR *xdrs, dirpath *objp) +xdr_commit3resfail(XDR *xdrs, commit3resfail *objp) { - if (!xdr_string (xdrs, objp, MNTPATHLEN)) - return FALSE; - return TRUE; + if (!xdr_wcc_data(xdrs, &objp->file_wcc)) + return FALSE; + return TRUE; } bool_t -xdr_name (XDR *xdrs, name *objp) +xdr_commit3res(XDR *xdrs, commit3res *objp) { - if (!xdr_string (xdrs, objp, MNTNAMLEN)) - return FALSE; - return TRUE; + if (!xdr_nfsstat3(xdrs, &objp->status)) + return FALSE; + switch (objp->status) { + case NFS3_OK: + if (!xdr_commit3resok(xdrs, &objp->commit3res_u.resok)) + return FALSE; + break; + default: + if (!xdr_commit3resfail(xdrs, &objp->commit3res_u.resfail)) + return FALSE; + break; + } + return TRUE; } bool_t -xdr_mountstat3 (XDR *xdrs, mountstat3 *objp) +xdr_fhandle3(XDR *xdrs, fhandle3 *objp) { - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; + if (!xdr_bytes(xdrs, (char **)&objp->fhandle3_val, + (u_int *)&objp->fhandle3_len, FHSIZE3)) + return FALSE; + return TRUE; } bool_t -xdr_mountres3_ok (XDR *xdrs, mountres3_ok *objp) +xdr_dirpath(XDR *xdrs, dirpath *objp) { - if (!xdr_fhandle3 (xdrs, &objp->fhandle)) - return FALSE; - if (!xdr_array (xdrs, (char **)&objp->auth_flavors.auth_flavors_val, (u_int *) &objp->auth_flavors.auth_flavors_len, ~0, - sizeof (int), (xdrproc_t) xdr_int)) - return FALSE; - return TRUE; + if (!xdr_string(xdrs, objp, MNTPATHLEN)) + return FALSE; + return TRUE; } bool_t -xdr_mountres3 (XDR *xdrs, mountres3 *objp) +xdr_name(XDR *xdrs, name *objp) { - if (!xdr_mountstat3 (xdrs, &objp->fhs_status)) - return FALSE; - switch (objp->fhs_status) { - case MNT3_OK: - if (!xdr_mountres3_ok (xdrs, &objp->mountres3_u.mountinfo)) - return FALSE; - break; - default: - break; - } - return TRUE; + if (!xdr_string(xdrs, objp, MNTNAMLEN)) + return FALSE; + return TRUE; } bool_t -xdr_mountlist (XDR *xdrs, mountlist *objp) +xdr_mountstat3(XDR *xdrs, mountstat3 *objp) { - if (!xdr_pointer (xdrs, (char **)objp, sizeof (struct mountbody), (xdrproc_t) xdr_mountbody)) - return FALSE; - return TRUE; + if (!xdr_enum(xdrs, (enum_t *)objp)) + return FALSE; + return TRUE; } bool_t -xdr_mountbody (XDR *xdrs, mountbody *objp) +xdr_mountres3_ok(XDR *xdrs, mountres3_ok *objp) { - if (!xdr_name (xdrs, &objp->ml_hostname)) - return FALSE; - if (!xdr_dirpath (xdrs, &objp->ml_directory)) - return FALSE; - if (!xdr_mountlist (xdrs, &objp->ml_next)) - return FALSE; - return TRUE; + if (!xdr_fhandle3(xdrs, &objp->fhandle)) + return FALSE; + if (!xdr_array(xdrs, (char **)&objp->auth_flavors.auth_flavors_val, + (u_int *)&objp->auth_flavors.auth_flavors_len, ~0, + sizeof(int), (xdrproc_t)xdr_int)) + return FALSE; + return TRUE; } bool_t -xdr_groups (XDR *xdrs, groups *objp) +xdr_mountres3(XDR *xdrs, mountres3 *objp) { - if (!xdr_pointer (xdrs, (char **)objp, sizeof (struct groupnode), (xdrproc_t) xdr_groupnode)) - return FALSE; - return TRUE; + if (!xdr_mountstat3(xdrs, &objp->fhs_status)) + return FALSE; + switch (objp->fhs_status) { + case MNT3_OK: + if (!xdr_mountres3_ok(xdrs, &objp->mountres3_u.mountinfo)) + return FALSE; + break; + default: + break; + } + return TRUE; } bool_t -xdr_groupnode (XDR *xdrs, groupnode *objp) +xdr_mountlist(XDR *xdrs, mountlist *objp) { - if (!xdr_name (xdrs, &objp->gr_name)) - return FALSE; - if (!xdr_groups (xdrs, &objp->gr_next)) - return FALSE; - return TRUE; + if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct mountbody), + (xdrproc_t)xdr_mountbody)) + return FALSE; + return TRUE; } bool_t -xdr_exports (XDR *xdrs, exports *objp) +xdr_mountbody(XDR *xdrs, mountbody *objp) { - if (!xdr_pointer (xdrs, (char **)objp, sizeof (struct exportnode), (xdrproc_t) xdr_exportnode)) - return FALSE; - return TRUE; + if (!xdr_name(xdrs, &objp->ml_hostname)) + return FALSE; + if (!xdr_dirpath(xdrs, &objp->ml_directory)) + return FALSE; + if (!xdr_mountlist(xdrs, &objp->ml_next)) + return FALSE; + return TRUE; } bool_t -xdr_exportnode (XDR *xdrs, exportnode *objp) +xdr_groups(XDR *xdrs, groups *objp) { - if (!xdr_dirpath (xdrs, &objp->ex_dir)) - return FALSE; - if (!xdr_groups (xdrs, &objp->ex_groups)) - return FALSE; - if (!xdr_exports (xdrs, &objp->ex_next)) - return FALSE; - return TRUE; + if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct groupnode), + (xdrproc_t)xdr_groupnode)) + return FALSE; + return TRUE; } -void -xdr_free_exports_list (struct exportnode *first) +bool_t +xdr_groupnode(XDR *xdrs, groupnode *objp) { - struct exportnode *elist = NULL; + if (!xdr_name(xdrs, &objp->gr_name)) + return FALSE; + if (!xdr_groups(xdrs, &objp->gr_next)) + return FALSE; + return TRUE; +} - if (!first) - return; +bool_t +xdr_exports(XDR *xdrs, exports *objp) +{ + if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct exportnode), + (xdrproc_t)xdr_exportnode)) + return FALSE; + return TRUE; +} - while (first) { - elist = first->ex_next; - if (first->ex_dir) - GF_FREE (first->ex_dir); +bool_t +xdr_exportnode(XDR *xdrs, exportnode *objp) +{ + if (!xdr_dirpath(xdrs, &objp->ex_dir)) + return FALSE; + if (!xdr_groups(xdrs, &objp->ex_groups)) + return FALSE; + if (!xdr_exports(xdrs, &objp->ex_next)) + return FALSE; + return TRUE; +} - if (first->ex_groups) { - if (first->ex_groups->gr_name) - GF_FREE (first->ex_groups->gr_name); - GF_FREE (first->ex_groups); - } +static void +xdr_free_groupnode(struct groupnode *group) +{ + if (!group) + return; - GF_FREE (first); - first = elist; - } + if (group->gr_next) + xdr_free_groupnode(group->gr_next); + GF_FREE(group->gr_name); + GF_FREE(group); } - void -xdr_free_mountlist (mountlist ml) +xdr_free_exports_list(struct exportnode *first) { - struct mountbody *next = NULL; + struct exportnode *elist = NULL; - if (!ml) - return; + if (!first) + return; - while (ml) { - GF_FREE (ml->ml_hostname); - GF_FREE (ml->ml_directory); - next = ml->ml_next; - GF_FREE (ml); - ml = next; - } + while (first) { + elist = first->ex_next; + GF_FREE(first->ex_dir); - return; + xdr_free_groupnode(first->ex_groups); + + GF_FREE(first); + first = elist; + } } +void +xdr_free_mountlist(mountlist ml) +{ + struct mountbody *next = NULL; + + if (!ml) + return; + + while (ml) { + GF_FREE(ml->ml_hostname); + GF_FREE(ml->ml_directory); + next = ml->ml_next; + GF_FREE(ml); + ml = next; + } + + return; +} /* Free statements are based on the way sunrpc xdr decoding * code performs memory allocations. */ void -xdr_free_write3args_nocopy (write3args *wa) +xdr_free_write3args_nocopy(write3args *wa) { - if (!wa) - return; + if (!wa) + return; - FREE (wa->file.data.data_val); + FREE(wa->file.data.data_val); } - - diff --git a/rpc/xdr/src/xdr-nfs3.h b/rpc/xdr/src/xdr-nfs3.h index 9e5ccd186ca..b7f5abefffd 100644 --- a/rpc/xdr/src/xdr-nfs3.h +++ b/rpc/xdr/src/xdr-nfs3.h @@ -1,20 +1,11 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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 _XDR_NFS3_H @@ -23,25 +14,27 @@ #include <rpc/rpc.h> #include <sys/types.h> -#define NFS3_FHSIZE 64 -#define NFS3_COOKIEVERFSIZE 8 -#define NFS3_CREATEVERFSIZE 8 -#define NFS3_WRITEVERFSIZE 8 +#define NFS3_FHSIZE 64 +#define NFS3_COOKIEVERFSIZE 8 +#define NFS3_CREATEVERFSIZE 8 +#define NFS3_WRITEVERFSIZE 8 -#define NFS3_ENTRY3_FIXED_SIZE 24 -#define NFS3_POSTOPATTR_SIZE 88 -#define NFS3_READDIR_RESOK_SIZE (NFS3_POSTOPATTR_SIZE + sizeof (bool_t) + NFS3_COOKIEVERFSIZE) +#define NFS3_ENTRY3_FIXED_SIZE 24 +#define NFS3_POSTOPATTR_SIZE 88 +#define NFS3_READDIR_RESOK_SIZE \ + (NFS3_POSTOPATTR_SIZE + sizeof(bool_t) + NFS3_COOKIEVERFSIZE) /* In size of post_op_fh3, the length of the file handle will have to be * included separately since we have variable length fh. Here we only account * for the field for handle_follows and for the file handle length field. */ -#define NFS3_POSTOPFH3_FIXED_SIZE (sizeof (bool_t) + sizeof (uint32_t)) +#define NFS3_POSTOPFH3_FIXED_SIZE (sizeof(bool_t) + sizeof(uint32_t)) /* Similarly, the size of the entry will have to include the variable length * file handle and the length of the entry name. */ -#define NFS3_ENTRYP3_FIXED_SIZE (NFS3_ENTRY3_FIXED_SIZE + NFS3_POSTOPATTR_SIZE + NFS3_POSTOPFH3_FIXED_SIZE) +#define NFS3_ENTRYP3_FIXED_SIZE \ + (NFS3_ENTRY3_FIXED_SIZE + NFS3_POSTOPATTR_SIZE + NFS3_POSTOPFH3_FIXED_SIZE) typedef uint64_t uint64; typedef int64_t int64; @@ -61,283 +54,284 @@ typedef uint64 offset3; typedef uint32 mode3; typedef uint32 count3; -#define NFS3MODE_SETXUID 0x00800 -#define NFS3MODE_SETXGID 0x00400 -#define NFS3MODE_SAVESWAPTXT 0x00200 -#define NFS3MODE_ROWNER 0x00100 -#define NFS3MODE_WOWNER 0x00080 -#define NFS3MODE_XOWNER 0x00040 -#define NFS3MODE_RGROUP 0x00020 -#define NFS3MODE_WGROUP 0x00010 -#define NFS3MODE_XGROUP 0x00008 -#define NFS3MODE_ROTHER 0x00004 -#define NFS3MODE_WOTHER 0x00002 -#define NFS3MODE_XOTHER 0x00001 +#define NFS3MODE_SETXUID 0x00800 +#define NFS3MODE_SETXGID 0x00400 +#define NFS3MODE_SAVESWAPTXT 0x00200 +#define NFS3MODE_ROWNER 0x00100 +#define NFS3MODE_WOWNER 0x00080 +#define NFS3MODE_XOWNER 0x00040 +#define NFS3MODE_RGROUP 0x00020 +#define NFS3MODE_WGROUP 0x00010 +#define NFS3MODE_XGROUP 0x00008 +#define NFS3MODE_ROTHER 0x00004 +#define NFS3MODE_WOTHER 0x00002 +#define NFS3MODE_XOTHER 0x00001 enum nfsstat3 { - NFS3_OK = 0, - NFS3ERR_PERM = 1, - NFS3ERR_NOENT = 2, - NFS3ERR_IO = 5, - NFS3ERR_NXIO = 6, - NFS3ERR_ACCES = 13, - NFS3ERR_EXIST = 17, - NFS3ERR_XDEV = 18, - NFS3ERR_NODEV = 19, - NFS3ERR_NOTDIR = 20, - NFS3ERR_ISDIR = 21, - NFS3ERR_INVAL = 22, - NFS3ERR_FBIG = 27, - NFS3ERR_NOSPC = 28, - NFS3ERR_ROFS = 30, - NFS3ERR_MLINK = 31, - NFS3ERR_NAMETOOLONG = 63, - NFS3ERR_NOTEMPTY = 66, - NFS3ERR_DQUOT = 69, - NFS3ERR_STALE = 70, - NFS3ERR_REMOTE = 71, - NFS3ERR_BADHANDLE = 10001, - NFS3ERR_NOT_SYNC = 10002, - NFS3ERR_BAD_COOKIE = 10003, - NFS3ERR_NOTSUPP = 10004, - NFS3ERR_TOOSMALL = 10005, - NFS3ERR_SERVERFAULT = 10006, - NFS3ERR_BADTYPE = 10007, - NFS3ERR_JUKEBOX = 10008, + NFS3_OK = 0, + NFS3ERR_PERM = 1, + NFS3ERR_NOENT = 2, + NFS3ERR_IO = 5, + NFS3ERR_NXIO = 6, + NFS3ERR_ACCES = 13, + NFS3ERR_EXIST = 17, + NFS3ERR_XDEV = 18, + NFS3ERR_NODEV = 19, + NFS3ERR_NOTDIR = 20, + NFS3ERR_ISDIR = 21, + NFS3ERR_INVAL = 22, + NFS3ERR_FBIG = 27, + NFS3ERR_NOSPC = 28, + NFS3ERR_ROFS = 30, + NFS3ERR_MLINK = 31, + NFS3ERR_NAMETOOLONG = 63, + NFS3ERR_NOTEMPTY = 66, + NFS3ERR_DQUOT = 69, + NFS3ERR_STALE = 70, + NFS3ERR_REMOTE = 71, + NFS3ERR_BADHANDLE = 10001, + NFS3ERR_NOT_SYNC = 10002, + NFS3ERR_BAD_COOKIE = 10003, + NFS3ERR_NOTSUPP = 10004, + NFS3ERR_TOOSMALL = 10005, + NFS3ERR_SERVERFAULT = 10006, + NFS3ERR_BADTYPE = 10007, + NFS3ERR_JUKEBOX = 10008, + NFS3ERR_END_OF_LIST = -1, }; typedef enum nfsstat3 nfsstat3; enum ftype3 { - NF3REG = 1, - NF3DIR = 2, - NF3BLK = 3, - NF3CHR = 4, - NF3LNK = 5, - NF3SOCK = 6, - NF3FIFO = 7, + NF3REG = 1, + NF3DIR = 2, + NF3BLK = 3, + NF3CHR = 4, + NF3LNK = 5, + NF3SOCK = 6, + NF3FIFO = 7, }; typedef enum ftype3 ftype3; struct specdata3 { - uint32 specdata1; - uint32 specdata2; + uint32 specdata1; + uint32 specdata2; }; typedef struct specdata3 specdata3; struct nfs_fh3 { - struct { - u_int data_len; - char *data_val; - } data; + struct { + u_int data_len; + char *data_val; + } data; }; typedef struct nfs_fh3 nfs_fh3; struct nfstime3 { - uint32 seconds; - uint32 nseconds; + uint32 seconds; + uint32 nseconds; }; typedef struct nfstime3 nfstime3; struct fattr3 { - ftype3 type; - mode3 mode; - uint32 nlink; - uid3 uid; - gid3 gid; - size3 size; - size3 used; - specdata3 rdev; - uint64 fsid; - fileid3 fileid; - nfstime3 atime; - nfstime3 mtime; - nfstime3 ctime; + ftype3 type; + mode3 mode; + uint32 nlink; + uid3 uid; + gid3 gid; + size3 size; + size3 used; + specdata3 rdev; + uint64 fsid; + fileid3 fileid; + nfstime3 atime; + nfstime3 mtime; + nfstime3 ctime; }; typedef struct fattr3 fattr3; struct post_op_attr { - bool_t attributes_follow; - union { - fattr3 attributes; - } post_op_attr_u; + bool_t attributes_follow; + union { + fattr3 attributes; + } post_op_attr_u; }; typedef struct post_op_attr post_op_attr; struct wcc_attr { - size3 size; - nfstime3 mtime; - nfstime3 ctime; + size3 size; + nfstime3 mtime; + nfstime3 ctime; }; typedef struct wcc_attr wcc_attr; struct pre_op_attr { - bool_t attributes_follow; - union { - wcc_attr attributes; - } pre_op_attr_u; + bool_t attributes_follow; + union { + wcc_attr attributes; + } pre_op_attr_u; }; typedef struct pre_op_attr pre_op_attr; struct wcc_data { - pre_op_attr before; - post_op_attr after; + pre_op_attr before; + post_op_attr after; }; typedef struct wcc_data wcc_data; struct post_op_fh3 { - bool_t handle_follows; - union { - nfs_fh3 handle; - } post_op_fh3_u; + bool_t handle_follows; + union { + nfs_fh3 handle; + } post_op_fh3_u; }; typedef struct post_op_fh3 post_op_fh3; enum time_how { - DONT_CHANGE = 0, - SET_TO_SERVER_TIME = 1, - SET_TO_CLIENT_TIME = 2, + DONT_CHANGE = 0, + SET_TO_SERVER_TIME = 1, + SET_TO_CLIENT_TIME = 2, }; typedef enum time_how time_how; struct set_mode3 { - bool_t set_it; - union { - mode3 mode; - } set_mode3_u; + bool_t set_it; + union { + mode3 mode; + } set_mode3_u; }; typedef struct set_mode3 set_mode3; struct set_uid3 { - bool_t set_it; - union { - uid3 uid; - } set_uid3_u; + bool_t set_it; + union { + uid3 uid; + } set_uid3_u; }; typedef struct set_uid3 set_uid3; struct set_gid3 { - bool_t set_it; - union { - gid3 gid; - } set_gid3_u; + bool_t set_it; + union { + gid3 gid; + } set_gid3_u; }; typedef struct set_gid3 set_gid3; struct set_size3 { - bool_t set_it; - union { - size3 size; - } set_size3_u; + bool_t set_it; + union { + size3 size; + } set_size3_u; }; typedef struct set_size3 set_size3; struct set_atime { - time_how set_it; - union { - nfstime3 atime; - } set_atime_u; + time_how set_it; + union { + nfstime3 atime; + } set_atime_u; }; typedef struct set_atime set_atime; struct set_mtime { - time_how set_it; - union { - nfstime3 mtime; - } set_mtime_u; + time_how set_it; + union { + nfstime3 mtime; + } set_mtime_u; }; typedef struct set_mtime set_mtime; struct sattr3 { - set_mode3 mode; - set_uid3 uid; - set_gid3 gid; - set_size3 size; - set_atime atime; - set_mtime mtime; + set_mode3 mode; + set_uid3 uid; + set_gid3 gid; + set_size3 size; + set_atime atime; + set_mtime mtime; }; typedef struct sattr3 sattr3; struct diropargs3 { - nfs_fh3 dir; - filename3 name; + nfs_fh3 dir; + filename3 name; }; typedef struct diropargs3 diropargs3; struct getattr3args { - nfs_fh3 object; + nfs_fh3 object; }; typedef struct getattr3args getattr3args; struct getattr3resok { - fattr3 obj_attributes; + fattr3 obj_attributes; }; typedef struct getattr3resok getattr3resok; struct getattr3res { - nfsstat3 status; - union { - getattr3resok resok; - } getattr3res_u; + nfsstat3 status; + union { + getattr3resok resok; + } getattr3res_u; }; typedef struct getattr3res getattr3res; struct sattrguard3 { - bool_t check; - union { - nfstime3 obj_ctime; - } sattrguard3_u; + bool_t check; + union { + nfstime3 obj_ctime; + } sattrguard3_u; }; typedef struct sattrguard3 sattrguard3; struct setattr3args { - nfs_fh3 object; - sattr3 new_attributes; - sattrguard3 guard; + nfs_fh3 object; + sattr3 new_attributes; + sattrguard3 guard; }; typedef struct setattr3args setattr3args; struct setattr3resok { - wcc_data obj_wcc; + wcc_data obj_wcc; }; typedef struct setattr3resok setattr3resok; struct setattr3resfail { - wcc_data obj_wcc; + wcc_data obj_wcc; }; typedef struct setattr3resfail setattr3resfail; struct setattr3res { - nfsstat3 status; - union { - setattr3resok resok; - setattr3resfail resfail; - } setattr3res_u; + nfsstat3 status; + union { + setattr3resok resok; + setattr3resfail resfail; + } setattr3res_u; }; typedef struct setattr3res setattr3res; struct lookup3args { - diropargs3 what; + diropargs3 what; }; typedef struct lookup3args lookup3args; struct lookup3resok { - nfs_fh3 object; - post_op_attr obj_attributes; - post_op_attr dir_attributes; + nfs_fh3 object; + post_op_attr obj_attributes; + post_op_attr dir_attributes; }; typedef struct lookup3resok lookup3resok; struct lookup3resfail { - post_op_attr dir_attributes; + post_op_attr dir_attributes; }; typedef struct lookup3resfail lookup3resfail; struct lookup3res { - nfsstat3 status; - union { - lookup3resok resok; - lookup3resfail resfail; - } lookup3res_u; + nfsstat3 status; + union { + lookup3resok resok; + lookup3resfail resfail; + } lookup3res_u; }; typedef struct lookup3res lookup3res; #define ACCESS3_READ 0x0001 @@ -348,104 +342,104 @@ typedef struct lookup3res lookup3res; #define ACCESS3_EXECUTE 0x0020 struct access3args { - nfs_fh3 object; - uint32 access; + nfs_fh3 object; + uint32 access; }; typedef struct access3args access3args; struct access3resok { - post_op_attr obj_attributes; - uint32 access; + post_op_attr obj_attributes; + uint32 access; }; typedef struct access3resok access3resok; struct access3resfail { - post_op_attr obj_attributes; + post_op_attr obj_attributes; }; typedef struct access3resfail access3resfail; struct access3res { - nfsstat3 status; - union { - access3resok resok; - access3resfail resfail; - } access3res_u; + nfsstat3 status; + union { + access3resok resok; + access3resfail resfail; + } access3res_u; }; typedef struct access3res access3res; struct readlink3args { - nfs_fh3 symlink; + nfs_fh3 symlink; }; typedef struct readlink3args readlink3args; struct readlink3resok { - post_op_attr symlink_attributes; - nfspath3 data; + post_op_attr symlink_attributes; + nfspath3 data; }; typedef struct readlink3resok readlink3resok; struct readlink3resfail { - post_op_attr symlink_attributes; + post_op_attr symlink_attributes; }; typedef struct readlink3resfail readlink3resfail; struct readlink3res { - nfsstat3 status; - union { - readlink3resok resok; - readlink3resfail resfail; - } readlink3res_u; + nfsstat3 status; + union { + readlink3resok resok; + readlink3resfail resfail; + } readlink3res_u; }; typedef struct readlink3res readlink3res; struct read3args { - nfs_fh3 file; - offset3 offset; - count3 count; + nfs_fh3 file; + offset3 offset; + count3 count; }; typedef struct read3args read3args; struct read3resok { - post_op_attr file_attributes; - count3 count; - bool_t eof; - struct { - u_int data_len; - char *data_val; - } data; + post_op_attr file_attributes; + count3 count; + bool_t eof; + struct { + u_int data_len; + char *data_val; + } data; }; typedef struct read3resok read3resok; struct read3resfail { - post_op_attr file_attributes; + post_op_attr file_attributes; }; typedef struct read3resfail read3resfail; struct read3res { - nfsstat3 status; - union { - read3resok resok; - read3resfail resfail; - } read3res_u; + nfsstat3 status; + union { + read3resok resok; + read3resfail resfail; + } read3res_u; }; typedef struct read3res read3res; enum stable_how { - UNSTABLE = 0, - DATA_SYNC = 1, - FILE_SYNC = 2, + UNSTABLE = 0, + DATA_SYNC = 1, + FILE_SYNC = 2, }; typedef enum stable_how stable_how; struct write3args { - nfs_fh3 file; - offset3 offset; - count3 count; - stable_how stable; - struct { - u_int data_len; - char *data_val; - } data; + nfs_fh3 file; + offset3 offset; + count3 count; + stable_how stable; + struct { + u_int data_len; + char *data_val; + } data; }; typedef struct write3args write3args; @@ -454,393 +448,395 @@ typedef struct write3args write3args; * sizeof (nfs_fh3) rather than first trying to extract the fh size of the * network followed by a sized-read of the file handle. */ -#define NFS3_WRITE3ARGS_SIZE (sizeof (uint32_t) + NFS3_FHSIZE + sizeof (offset3) + sizeof (count3) + sizeof (uint32_t)) +#define NFS3_WRITE3ARGS_SIZE \ + (sizeof(uint32_t) + NFS3_FHSIZE + sizeof(offset3) + sizeof(count3) + \ + sizeof(uint32_t)) struct write3resok { - wcc_data file_wcc; - count3 count; - stable_how committed; - writeverf3 verf; + wcc_data file_wcc; + count3 count; + stable_how committed; + writeverf3 verf; }; typedef struct write3resok write3resok; struct write3resfail { - wcc_data file_wcc; + wcc_data file_wcc; }; typedef struct write3resfail write3resfail; struct write3res { - nfsstat3 status; - union { - write3resok resok; - write3resfail resfail; - } write3res_u; + nfsstat3 status; + union { + write3resok resok; + write3resfail resfail; + } write3res_u; }; typedef struct write3res write3res; enum createmode3 { - UNCHECKED = 0, - GUARDED = 1, - EXCLUSIVE = 2, + UNCHECKED = 0, + GUARDED = 1, + EXCLUSIVE = 2, }; typedef enum createmode3 createmode3; struct createhow3 { - createmode3 mode; - union { - sattr3 obj_attributes; - createverf3 verf; - } createhow3_u; + createmode3 mode; + union { + sattr3 obj_attributes; + createverf3 verf; + } createhow3_u; }; typedef struct createhow3 createhow3; struct create3args { - diropargs3 where; - createhow3 how; + diropargs3 where; + createhow3 how; }; typedef struct create3args create3args; struct create3resok { - post_op_fh3 obj; - post_op_attr obj_attributes; - wcc_data dir_wcc; + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; }; typedef struct create3resok create3resok; struct create3resfail { - wcc_data dir_wcc; + wcc_data dir_wcc; }; typedef struct create3resfail create3resfail; struct create3res { - nfsstat3 status; - union { - create3resok resok; - create3resfail resfail; - } create3res_u; + nfsstat3 status; + union { + create3resok resok; + create3resfail resfail; + } create3res_u; }; typedef struct create3res create3res; struct mkdir3args { - diropargs3 where; - sattr3 attributes; + diropargs3 where; + sattr3 attributes; }; typedef struct mkdir3args mkdir3args; struct mkdir3resok { - post_op_fh3 obj; - post_op_attr obj_attributes; - wcc_data dir_wcc; + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; }; typedef struct mkdir3resok mkdir3resok; struct mkdir3resfail { - wcc_data dir_wcc; + wcc_data dir_wcc; }; typedef struct mkdir3resfail mkdir3resfail; struct mkdir3res { - nfsstat3 status; - union { - mkdir3resok resok; - mkdir3resfail resfail; - } mkdir3res_u; + nfsstat3 status; + union { + mkdir3resok resok; + mkdir3resfail resfail; + } mkdir3res_u; }; typedef struct mkdir3res mkdir3res; struct symlinkdata3 { - sattr3 symlink_attributes; - nfspath3 symlink_data; + sattr3 symlink_attributes; + nfspath3 symlink_data; }; typedef struct symlinkdata3 symlinkdata3; struct symlink3args { - diropargs3 where; - symlinkdata3 symlink; + diropargs3 where; + symlinkdata3 symlink; }; typedef struct symlink3args symlink3args; struct symlink3resok { - post_op_fh3 obj; - post_op_attr obj_attributes; - wcc_data dir_wcc; + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; }; typedef struct symlink3resok symlink3resok; struct symlink3resfail { - wcc_data dir_wcc; + wcc_data dir_wcc; }; typedef struct symlink3resfail symlink3resfail; struct symlink3res { - nfsstat3 status; - union { - symlink3resok resok; - symlink3resfail resfail; - } symlink3res_u; + nfsstat3 status; + union { + symlink3resok resok; + symlink3resfail resfail; + } symlink3res_u; }; typedef struct symlink3res symlink3res; struct devicedata3 { - sattr3 dev_attributes; - specdata3 spec; + sattr3 dev_attributes; + specdata3 spec; }; typedef struct devicedata3 devicedata3; struct mknoddata3 { - ftype3 type; - union { - devicedata3 device; - sattr3 pipe_attributes; - } mknoddata3_u; + ftype3 type; + union { + devicedata3 device; + sattr3 pipe_attributes; + } mknoddata3_u; }; typedef struct mknoddata3 mknoddata3; struct mknod3args { - diropargs3 where; - mknoddata3 what; + diropargs3 where; + mknoddata3 what; }; typedef struct mknod3args mknod3args; struct mknod3resok { - post_op_fh3 obj; - post_op_attr obj_attributes; - wcc_data dir_wcc; + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; }; typedef struct mknod3resok mknod3resok; struct mknod3resfail { - wcc_data dir_wcc; + wcc_data dir_wcc; }; typedef struct mknod3resfail mknod3resfail; struct mknod3res { - nfsstat3 status; - union { - mknod3resok resok; - mknod3resfail resfail; - } mknod3res_u; + nfsstat3 status; + union { + mknod3resok resok; + mknod3resfail resfail; + } mknod3res_u; }; typedef struct mknod3res mknod3res; struct remove3args { - diropargs3 object; + diropargs3 object; }; typedef struct remove3args remove3args; struct remove3resok { - wcc_data dir_wcc; + wcc_data dir_wcc; }; typedef struct remove3resok remove3resok; struct remove3resfail { - wcc_data dir_wcc; + wcc_data dir_wcc; }; typedef struct remove3resfail remove3resfail; struct remove3res { - nfsstat3 status; - union { - remove3resok resok; - remove3resfail resfail; - } remove3res_u; + nfsstat3 status; + union { + remove3resok resok; + remove3resfail resfail; + } remove3res_u; }; typedef struct remove3res remove3res; struct rmdir3args { - diropargs3 object; + diropargs3 object; }; typedef struct rmdir3args rmdir3args; struct rmdir3resok { - wcc_data dir_wcc; + wcc_data dir_wcc; }; typedef struct rmdir3resok rmdir3resok; struct rmdir3resfail { - wcc_data dir_wcc; + wcc_data dir_wcc; }; typedef struct rmdir3resfail rmdir3resfail; struct rmdir3res { - nfsstat3 status; - union { - rmdir3resok resok; - rmdir3resfail resfail; - } rmdir3res_u; + nfsstat3 status; + union { + rmdir3resok resok; + rmdir3resfail resfail; + } rmdir3res_u; }; typedef struct rmdir3res rmdir3res; struct rename3args { - diropargs3 from; - diropargs3 to; + diropargs3 from; + diropargs3 to; }; typedef struct rename3args rename3args; struct rename3resok { - wcc_data fromdir_wcc; - wcc_data todir_wcc; + wcc_data fromdir_wcc; + wcc_data todir_wcc; }; typedef struct rename3resok rename3resok; struct rename3resfail { - wcc_data fromdir_wcc; - wcc_data todir_wcc; + wcc_data fromdir_wcc; + wcc_data todir_wcc; }; typedef struct rename3resfail rename3resfail; struct rename3res { - nfsstat3 status; - union { - rename3resok resok; - rename3resfail resfail; - } rename3res_u; + nfsstat3 status; + union { + rename3resok resok; + rename3resfail resfail; + } rename3res_u; }; typedef struct rename3res rename3res; struct link3args { - nfs_fh3 file; - diropargs3 link; + nfs_fh3 file; + diropargs3 link; }; typedef struct link3args link3args; struct link3resok { - post_op_attr file_attributes; - wcc_data linkdir_wcc; + post_op_attr file_attributes; + wcc_data linkdir_wcc; }; typedef struct link3resok link3resok; struct link3resfail { - post_op_attr file_attributes; - wcc_data linkdir_wcc; + post_op_attr file_attributes; + wcc_data linkdir_wcc; }; typedef struct link3resfail link3resfail; struct link3res { - nfsstat3 status; - union { - link3resok resok; - link3resfail resfail; - } link3res_u; + nfsstat3 status; + union { + link3resok resok; + link3resfail resfail; + } link3res_u; }; typedef struct link3res link3res; struct readdir3args { - nfs_fh3 dir; - cookie3 cookie; - cookieverf3 cookieverf; - count3 count; + nfs_fh3 dir; + cookie3 cookie; + cookieverf3 cookieverf; + count3 count; }; typedef struct readdir3args readdir3args; struct entry3 { - fileid3 fileid; - filename3 name; - cookie3 cookie; - struct entry3 *nextentry; + fileid3 fileid; + filename3 name; + cookie3 cookie; + struct entry3 *nextentry; }; typedef struct entry3 entry3; struct dirlist3 { - entry3 *entries; - bool_t eof; + entry3 *entries; + bool_t eof; }; typedef struct dirlist3 dirlist3; struct readdir3resok { - post_op_attr dir_attributes; - cookieverf3 cookieverf; - dirlist3 reply; + post_op_attr dir_attributes; + cookieverf3 cookieverf; + dirlist3 reply; }; typedef struct readdir3resok readdir3resok; struct readdir3resfail { - post_op_attr dir_attributes; + post_op_attr dir_attributes; }; typedef struct readdir3resfail readdir3resfail; struct readdir3res { - nfsstat3 status; - union { - readdir3resok resok; - readdir3resfail resfail; - } readdir3res_u; + nfsstat3 status; + union { + readdir3resok resok; + readdir3resfail resfail; + } readdir3res_u; }; typedef struct readdir3res readdir3res; struct readdirp3args { - nfs_fh3 dir; - cookie3 cookie; - cookieverf3 cookieverf; - count3 dircount; - count3 maxcount; + nfs_fh3 dir; + cookie3 cookie; + cookieverf3 cookieverf; + count3 dircount; + count3 maxcount; }; typedef struct readdirp3args readdirp3args; struct entryp3 { - fileid3 fileid; - filename3 name; - cookie3 cookie; - post_op_attr name_attributes; - post_op_fh3 name_handle; - struct entryp3 *nextentry; + fileid3 fileid; + filename3 name; + cookie3 cookie; + post_op_attr name_attributes; + post_op_fh3 name_handle; + struct entryp3 *nextentry; }; typedef struct entryp3 entryp3; struct dirlistp3 { - entryp3 *entries; - bool_t eof; + entryp3 *entries; + bool_t eof; }; typedef struct dirlistp3 dirlistp3; struct readdirp3resok { - post_op_attr dir_attributes; - cookieverf3 cookieverf; - dirlistp3 reply; + post_op_attr dir_attributes; + cookieverf3 cookieverf; + dirlistp3 reply; }; typedef struct readdirp3resok readdirp3resok; struct readdirp3resfail { - post_op_attr dir_attributes; + post_op_attr dir_attributes; }; typedef struct readdirp3resfail readdirp3resfail; struct readdirp3res { - nfsstat3 status; - union { - readdirp3resok resok; - readdirp3resfail resfail; - } readdirp3res_u; + nfsstat3 status; + union { + readdirp3resok resok; + readdirp3resfail resfail; + } readdirp3res_u; }; typedef struct readdirp3res readdirp3res; struct fsstat3args { - nfs_fh3 fsroot; + nfs_fh3 fsroot; }; typedef struct fsstat3args fsstat3args; struct fsstat3resok { - post_op_attr obj_attributes; - size3 tbytes; - size3 fbytes; - size3 abytes; - size3 tfiles; - size3 ffiles; - size3 afiles; - uint32 invarsec; + post_op_attr obj_attributes; + size3 tbytes; + size3 fbytes; + size3 abytes; + size3 tfiles; + size3 ffiles; + size3 afiles; + uint32 invarsec; }; typedef struct fsstat3resok fsstat3resok; struct fsstat3resfail { - post_op_attr obj_attributes; + post_op_attr obj_attributes; }; typedef struct fsstat3resfail fsstat3resfail; struct fsstat3res { - nfsstat3 status; - union { - fsstat3resok resok; - fsstat3resfail resfail; - } fsstat3res_u; + nfsstat3 status; + union { + fsstat3resok resok; + fsstat3resfail resfail; + } fsstat3res_u; }; typedef struct fsstat3res fsstat3res; #define FSF3_LINK 0x0001 @@ -849,93 +845,93 @@ typedef struct fsstat3res fsstat3res; #define FSF3_CANSETTIME 0x0010 struct fsinfo3args { - nfs_fh3 fsroot; + nfs_fh3 fsroot; }; typedef struct fsinfo3args fsinfo3args; struct fsinfo3resok { - post_op_attr obj_attributes; - uint32 rtmax; - uint32 rtpref; - uint32 rtmult; - uint32 wtmax; - uint32 wtpref; - uint32 wtmult; - uint32 dtpref; - size3 maxfilesize; - nfstime3 time_delta; - uint32 properties; + post_op_attr obj_attributes; + uint32 rtmax; + uint32 rtpref; + uint32 rtmult; + uint32 wtmax; + uint32 wtpref; + uint32 wtmult; + uint32 dtpref; + size3 maxfilesize; + nfstime3 time_delta; + uint32 properties; }; typedef struct fsinfo3resok fsinfo3resok; struct fsinfo3resfail { - post_op_attr obj_attributes; + post_op_attr obj_attributes; }; typedef struct fsinfo3resfail fsinfo3resfail; struct fsinfo3res { - nfsstat3 status; - union { - fsinfo3resok resok; - fsinfo3resfail resfail; - } fsinfo3res_u; + nfsstat3 status; + union { + fsinfo3resok resok; + fsinfo3resfail resfail; + } fsinfo3res_u; }; typedef struct fsinfo3res fsinfo3res; struct pathconf3args { - nfs_fh3 object; + nfs_fh3 object; }; typedef struct pathconf3args pathconf3args; struct pathconf3resok { - post_op_attr obj_attributes; - uint32 linkmax; - uint32 name_max; - bool_t no_trunc; - bool_t chown_restricted; - bool_t case_insensitive; - bool_t case_preserving; + post_op_attr obj_attributes; + uint32 linkmax; + uint32 name_max; + bool_t no_trunc; + bool_t chown_restricted; + bool_t case_insensitive; + bool_t case_preserving; }; typedef struct pathconf3resok pathconf3resok; struct pathconf3resfail { - post_op_attr obj_attributes; + post_op_attr obj_attributes; }; typedef struct pathconf3resfail pathconf3resfail; struct pathconf3res { - nfsstat3 status; - union { - pathconf3resok resok; - pathconf3resfail resfail; - } pathconf3res_u; + nfsstat3 status; + union { + pathconf3resok resok; + pathconf3resfail resfail; + } pathconf3res_u; }; typedef struct pathconf3res pathconf3res; struct commit3args { - nfs_fh3 file; - offset3 offset; - count3 count; + nfs_fh3 file; + offset3 offset; + count3 count; }; typedef struct commit3args commit3args; struct commit3resok { - wcc_data file_wcc; - writeverf3 verf; + wcc_data file_wcc; + writeverf3 verf; }; typedef struct commit3resok commit3resok; struct commit3resfail { - wcc_data file_wcc; + wcc_data file_wcc; }; typedef struct commit3resfail commit3resfail; struct commit3res { - nfsstat3 status; - union { - commit3resok resok; - commit3resfail resfail; - } commit3res_u; + nfsstat3 status; + union { + commit3resok resok; + commit3resfail resfail; + } commit3res_u; }; typedef struct commit3res commit3res; #define MNTPATHLEN 1024 @@ -943,8 +939,8 @@ typedef struct commit3res commit3res; #define FHSIZE3 NFS3_FHSIZE typedef struct { - u_int fhandle3_len; - char *fhandle3_val; + u_int fhandle3_len; + char *fhandle3_val; } fhandle3; typedef char *dirpath; @@ -952,255 +948,404 @@ typedef char *dirpath; typedef char *name; enum mountstat3 { - MNT3_OK = 0, - MNT3ERR_PERM = 1, - MNT3ERR_NOENT = 2, - MNT3ERR_IO = 5, - MNT3ERR_ACCES = 13, - MNT3ERR_NOTDIR = 20, - MNT3ERR_INVAL = 22, - MNT3ERR_NAMETOOLONG = 63, - MNT3ERR_NOTSUPP = 10004, - MNT3ERR_SERVERFAULT = 10006, + MNT3_OK = 0, + MNT3ERR_PERM = 1, + MNT3ERR_NOENT = 2, + MNT3ERR_IO = 5, + MNT3ERR_ACCES = 13, + MNT3ERR_NOTDIR = 20, + MNT3ERR_INVAL = 22, + MNT3ERR_NAMETOOLONG = 63, + MNT3ERR_NOTSUPP = 10004, + MNT3ERR_SERVERFAULT = 10006, }; typedef enum mountstat3 mountstat3; struct mountres3_ok { - fhandle3 fhandle; - struct { - u_int auth_flavors_len; - int *auth_flavors_val; - } auth_flavors; + fhandle3 fhandle; + struct { + u_int auth_flavors_len; + int *auth_flavors_val; + } auth_flavors; }; typedef struct mountres3_ok mountres3_ok; struct mountres3 { - mountstat3 fhs_status; - union { - mountres3_ok mountinfo; - } mountres3_u; + mountstat3 fhs_status; + union { + mountres3_ok mountinfo; + } mountres3_u; }; typedef struct mountres3 mountres3; typedef struct mountbody *mountlist; struct mountbody { - name ml_hostname; - dirpath ml_directory; - mountlist ml_next; + name ml_hostname; + dirpath ml_directory; + mountlist ml_next; }; typedef struct mountbody mountbody; typedef struct groupnode *groups; struct groupnode { - name gr_name; - groups gr_next; + name gr_name; + groups gr_next; }; typedef struct groupnode groupnode; typedef struct exportnode *exports; struct exportnode { - dirpath ex_dir; - groups ex_groups; - exports ex_next; + dirpath ex_dir; + groups ex_groups; + exports ex_next; }; typedef struct exportnode exportnode; -#define NFS_PROGRAM 100003 -#define NFS_V3 3 - -#define NFS3_NULL 0 -#define NFS3_GETATTR 1 -#define NFS3_SETATTR 2 -#define NFS3_LOOKUP 3 -#define NFS3_ACCESS 4 -#define NFS3_READLINK 5 -#define NFS3_READ 6 -#define NFS3_WRITE 7 -#define NFS3_CREATE 8 -#define NFS3_MKDIR 9 -#define NFS3_SYMLINK 10 -#define NFS3_MKNOD 11 -#define NFS3_REMOVE 12 -#define NFS3_RMDIR 13 -#define NFS3_RENAME 14 -#define NFS3_LINK 15 -#define NFS3_READDIR 16 -#define NFS3_READDIRP 17 -#define NFS3_FSSTAT 18 -#define NFS3_FSINFO 19 -#define NFS3_PATHCONF 20 -#define NFS3_COMMIT 21 -#define NFS3_PROC_COUNT 22 - -#define MOUNT_PROGRAM 100005 -#define MOUNT_V3 3 -#define MOUNT_V1 1 - -#define MOUNT3_NULL 0 -#define MOUNT3_MNT 1 -#define MOUNT3_DUMP 2 -#define MOUNT3_UMNT 3 -#define MOUNT3_UMNTALL 4 -#define MOUNT3_EXPORT 5 -#define MOUNT3_PROC_COUNT 6 - -#define MOUNT1_NULL 0 -#define MOUNT1_DUMP 2 -#define MOUNT1_UMNT 3 -#define MOUNT1_EXPORT 5 -#define MOUNT1_PROC_COUNT 6 +#define NFS_PROGRAM 100003 +#define NFS_V3 3 + +#define NFS3_NULL 0 +#define NFS3_GETATTR 1 +#define NFS3_SETATTR 2 +#define NFS3_LOOKUP 3 +#define NFS3_ACCESS 4 +#define NFS3_READLINK 5 +#define NFS3_READ 6 +#define NFS3_WRITE 7 +#define NFS3_CREATE 8 +#define NFS3_MKDIR 9 +#define NFS3_SYMLINK 10 +#define NFS3_MKNOD 11 +#define NFS3_REMOVE 12 +#define NFS3_RMDIR 13 +#define NFS3_RENAME 14 +#define NFS3_LINK 15 +#define NFS3_READDIR 16 +#define NFS3_READDIRP 17 +#define NFS3_FSSTAT 18 +#define NFS3_FSINFO 19 +#define NFS3_PATHCONF 20 +#define NFS3_COMMIT 21 +#define NFS3_PROC_COUNT 22 + +#define MOUNT_PROGRAM 100005 +#define MOUNT_V3 3 +#define MOUNT_V1 1 + +#define MOUNT3_NULL 0 +#define MOUNT3_MNT 1 +#define MOUNT3_DUMP 2 +#define MOUNT3_UMNT 3 +#define MOUNT3_UMNTALL 4 +#define MOUNT3_EXPORT 5 +#define MOUNT3_PROC_COUNT 6 + +#define MOUNT1_NULL 0 +#define MOUNT1_MNT 1 +#define MOUNT1_DUMP 2 +#define MOUNT1_UMNT 3 +#define MOUNT1_UMNTALL 4 +#define MOUNT1_EXPORT 5 +#define MOUNT1_PROC_COUNT 6 /* the xdr functions */ -extern bool_t xdr_uint64 (XDR *, uint64*); -extern bool_t xdr_int64 (XDR *, int64*); -extern bool_t xdr_uint32 (XDR *, uint32*); -extern bool_t xdr_int32 (XDR *, int32*); -extern bool_t xdr_filename3 (XDR *, filename3*); -extern bool_t xdr_nfspath3 (XDR *, nfspath3*); -extern bool_t xdr_fileid3 (XDR *, fileid3*); -extern bool_t xdr_cookie3 (XDR *, cookie3*); -extern bool_t xdr_cookieverf3 (XDR *, cookieverf3); -extern bool_t xdr_createverf3 (XDR *, createverf3); -extern bool_t xdr_writeverf3 (XDR *, writeverf3); -extern bool_t xdr_uid3 (XDR *, uid3*); -extern bool_t xdr_gid3 (XDR *, gid3*); -extern bool_t xdr_size3 (XDR *, size3*); -extern bool_t xdr_offset3 (XDR *, offset3*); -extern bool_t xdr_mode3 (XDR *, mode3*); -extern bool_t xdr_count3 (XDR *, count3*); -extern bool_t xdr_nfsstat3 (XDR *, nfsstat3*); -extern bool_t xdr_ftype3 (XDR *, ftype3*); -extern bool_t xdr_specdata3 (XDR *, specdata3*); -extern bool_t xdr_nfs_fh3 (XDR *, nfs_fh3*); -extern bool_t xdr_nfstime3 (XDR *, nfstime3*); -extern bool_t xdr_fattr3 (XDR *, fattr3*); -extern bool_t xdr_post_op_attr (XDR *, post_op_attr*); -extern bool_t xdr_wcc_attr (XDR *, wcc_attr*); -extern bool_t xdr_pre_op_attr (XDR *, pre_op_attr*); -extern bool_t xdr_wcc_data (XDR *, wcc_data*); -extern bool_t xdr_post_op_fh3 (XDR *, post_op_fh3*); -extern bool_t xdr_time_how (XDR *, time_how*); -extern bool_t xdr_set_mode3 (XDR *, set_mode3*); -extern bool_t xdr_set_uid3 (XDR *, set_uid3*); -extern bool_t xdr_set_gid3 (XDR *, set_gid3*); -extern bool_t xdr_set_size3 (XDR *, set_size3*); -extern bool_t xdr_set_atime (XDR *, set_atime*); -extern bool_t xdr_set_mtime (XDR *, set_mtime*); -extern bool_t xdr_sattr3 (XDR *, sattr3*); -extern bool_t xdr_diropargs3 (XDR *, diropargs3*); -extern bool_t xdr_getattr3args (XDR *, getattr3args*); -extern bool_t xdr_getattr3resok (XDR *, getattr3resok*); -extern bool_t xdr_getattr3res (XDR *, getattr3res*); -extern bool_t xdr_sattrguard3 (XDR *, sattrguard3*); -extern bool_t xdr_setattr3args (XDR *, setattr3args*); -extern bool_t xdr_setattr3resok (XDR *, setattr3resok*); -extern bool_t xdr_setattr3resfail (XDR *, setattr3resfail*); -extern bool_t xdr_setattr3res (XDR *, setattr3res*); -extern bool_t xdr_lookup3args (XDR *, lookup3args*); -extern bool_t xdr_lookup3resok (XDR *, lookup3resok*); -extern bool_t xdr_lookup3resfail (XDR *, lookup3resfail*); -extern bool_t xdr_lookup3res (XDR *, lookup3res*); -extern bool_t xdr_access3args (XDR *, access3args*); -extern bool_t xdr_access3resok (XDR *, access3resok*); -extern bool_t xdr_access3resfail (XDR *, access3resfail*); -extern bool_t xdr_access3res (XDR *, access3res*); -extern bool_t xdr_readlink3args (XDR *, readlink3args*); -extern bool_t xdr_readlink3resok (XDR *, readlink3resok*); -extern bool_t xdr_readlink3resfail (XDR *, readlink3resfail*); -extern bool_t xdr_readlink3res (XDR *, readlink3res*); -extern bool_t xdr_read3args (XDR *, read3args*); -extern bool_t xdr_read3resok (XDR *, read3resok*); -extern bool_t xdr_read3resfail (XDR *, read3resfail*); -extern bool_t xdr_read3res (XDR *, read3res*); -extern bool_t xdr_read3res_nocopy (XDR *xdrs, read3res *objp); -extern bool_t xdr_stable_how (XDR *, stable_how*); -extern bool_t xdr_write3args (XDR *, write3args*); -extern bool_t xdr_write3resok (XDR *, write3resok*); -extern bool_t xdr_write3resfail (XDR *, write3resfail*); -extern bool_t xdr_write3res (XDR *, write3res*); -extern bool_t xdr_createmode3 (XDR *, createmode3*); -extern bool_t xdr_createhow3 (XDR *, createhow3*); -extern bool_t xdr_create3args (XDR *, create3args*); -extern bool_t xdr_create3resok (XDR *, create3resok*); -extern bool_t xdr_create3resfail (XDR *, create3resfail*); -extern bool_t xdr_create3res (XDR *, create3res*); -extern bool_t xdr_mkdir3args (XDR *, mkdir3args*); -extern bool_t xdr_mkdir3resok (XDR *, mkdir3resok*); -extern bool_t xdr_mkdir3resfail (XDR *, mkdir3resfail*); -extern bool_t xdr_mkdir3res (XDR *, mkdir3res*); -extern bool_t xdr_symlinkdata3 (XDR *, symlinkdata3*); -extern bool_t xdr_symlink3args (XDR *, symlink3args*); -extern bool_t xdr_symlink3resok (XDR *, symlink3resok*); -extern bool_t xdr_symlink3resfail (XDR *, symlink3resfail*); -extern bool_t xdr_symlink3res (XDR *, symlink3res*); -extern bool_t xdr_devicedata3 (XDR *, devicedata3*); -extern bool_t xdr_mknoddata3 (XDR *, mknoddata3*); -extern bool_t xdr_mknod3args (XDR *, mknod3args*); -extern bool_t xdr_mknod3resok (XDR *, mknod3resok*); -extern bool_t xdr_mknod3resfail (XDR *, mknod3resfail*); -extern bool_t xdr_mknod3res (XDR *, mknod3res*); -extern bool_t xdr_remove3args (XDR *, remove3args*); -extern bool_t xdr_remove3resok (XDR *, remove3resok*); -extern bool_t xdr_remove3resfail (XDR *, remove3resfail*); -extern bool_t xdr_remove3res (XDR *, remove3res*); -extern bool_t xdr_rmdir3args (XDR *, rmdir3args*); -extern bool_t xdr_rmdir3resok (XDR *, rmdir3resok*); -extern bool_t xdr_rmdir3resfail (XDR *, rmdir3resfail*); -extern bool_t xdr_rmdir3res (XDR *, rmdir3res*); -extern bool_t xdr_rename3args (XDR *, rename3args*); -extern bool_t xdr_rename3resok (XDR *, rename3resok*); -extern bool_t xdr_rename3resfail (XDR *, rename3resfail*); -extern bool_t xdr_rename3res (XDR *, rename3res*); -extern bool_t xdr_link3args (XDR *, link3args*); -extern bool_t xdr_link3resok (XDR *, link3resok*); -extern bool_t xdr_link3resfail (XDR *, link3resfail*); -extern bool_t xdr_link3res (XDR *, link3res*); -extern bool_t xdr_readdir3args (XDR *, readdir3args*); -extern bool_t xdr_entry3 (XDR *, entry3*); -extern bool_t xdr_dirlist3 (XDR *, dirlist3*); -extern bool_t xdr_readdir3resok (XDR *, readdir3resok*); -extern bool_t xdr_readdir3resfail (XDR *, readdir3resfail*); -extern bool_t xdr_readdir3res (XDR *, readdir3res*); -extern bool_t xdr_readdirp3args (XDR *, readdirp3args*); -extern bool_t xdr_entryp3 (XDR *, entryp3*); -extern bool_t xdr_dirlistp3 (XDR *, dirlistp3*); -extern bool_t xdr_readdirp3resok (XDR *, readdirp3resok*); -extern bool_t xdr_readdirp3resfail (XDR *, readdirp3resfail*); -extern bool_t xdr_readdirp3res (XDR *, readdirp3res*); -extern bool_t xdr_fsstat3args (XDR *, fsstat3args*); -extern bool_t xdr_fsstat3resok (XDR *, fsstat3resok*); -extern bool_t xdr_fsstat3resfail (XDR *, fsstat3resfail*); -extern bool_t xdr_fsstat3res (XDR *, fsstat3res*); -extern bool_t xdr_fsinfo3args (XDR *, fsinfo3args*); -extern bool_t xdr_fsinfo3resok (XDR *, fsinfo3resok*); -extern bool_t xdr_fsinfo3resfail (XDR *, fsinfo3resfail*); -extern bool_t xdr_fsinfo3res (XDR *, fsinfo3res*); -extern bool_t xdr_pathconf3args (XDR *, pathconf3args*); -extern bool_t xdr_pathconf3resok (XDR *, pathconf3resok*); -extern bool_t xdr_pathconf3resfail (XDR *, pathconf3resfail*); -extern bool_t xdr_pathconf3res (XDR *, pathconf3res*); -extern bool_t xdr_commit3args (XDR *, commit3args*); -extern bool_t xdr_commit3resok (XDR *, commit3resok*); -extern bool_t xdr_commit3resfail (XDR *, commit3resfail*); -extern bool_t xdr_commit3res (XDR *, commit3res*); -extern bool_t xdr_fhandle3 (XDR *, fhandle3*); -extern bool_t xdr_dirpath (XDR *, dirpath*); -extern bool_t xdr_name (XDR *, name*); -extern bool_t xdr_mountstat3 (XDR *, mountstat3*); -extern bool_t xdr_mountres3_ok (XDR *, mountres3_ok*); -extern bool_t xdr_mountres3 (XDR *, mountres3*); -extern bool_t xdr_mountlist (XDR *, mountlist*); -extern bool_t xdr_mountbody (XDR *, mountbody*); -extern bool_t xdr_groups (XDR *, groups*); -extern bool_t xdr_groupnode (XDR *, groupnode*); -extern bool_t xdr_exports (XDR *, exports*); -extern bool_t xdr_exportnode (XDR *, exportnode*); - -extern void xdr_free_exports_list (struct exportnode *first); -extern void xdr_free_mountlist (mountlist ml); - -extern void xdr_free_write3args_nocopy (write3args *wa); +extern bool_t +xdr_uint64(XDR *, uint64 *); +extern bool_t +xdr_int64(XDR *, int64 *); +extern bool_t +xdr_uint32(XDR *, uint32 *); +extern bool_t +xdr_int32(XDR *, int32 *); +extern bool_t +xdr_filename3(XDR *, filename3 *); +extern bool_t +xdr_nfspath3(XDR *, nfspath3 *); +extern bool_t +xdr_fileid3(XDR *, fileid3 *); +extern bool_t +xdr_cookie3(XDR *, cookie3 *); +extern bool_t +xdr_cookieverf3(XDR *, cookieverf3); +extern bool_t +xdr_createverf3(XDR *, createverf3); +extern bool_t +xdr_writeverf3(XDR *, writeverf3); +extern bool_t +xdr_uid3(XDR *, uid3 *); +extern bool_t +xdr_gid3(XDR *, gid3 *); +extern bool_t +xdr_size3(XDR *, size3 *); +extern bool_t +xdr_offset3(XDR *, offset3 *); +extern bool_t +xdr_mode3(XDR *, mode3 *); +extern bool_t +xdr_count3(XDR *, count3 *); +extern bool_t +xdr_nfsstat3(XDR *, nfsstat3 *); +extern bool_t +xdr_ftype3(XDR *, ftype3 *); +extern bool_t +xdr_specdata3(XDR *, specdata3 *); +extern bool_t +xdr_nfs_fh3(XDR *, nfs_fh3 *); +extern bool_t +xdr_nfstime3(XDR *, nfstime3 *); +extern bool_t +xdr_fattr3(XDR *, fattr3 *); +extern bool_t +xdr_post_op_attr(XDR *, post_op_attr *); +extern bool_t +xdr_wcc_attr(XDR *, wcc_attr *); +extern bool_t +xdr_pre_op_attr(XDR *, pre_op_attr *); +extern bool_t +xdr_wcc_data(XDR *, wcc_data *); +extern bool_t +xdr_post_op_fh3(XDR *, post_op_fh3 *); +extern bool_t +xdr_time_how(XDR *, time_how *); +extern bool_t +xdr_set_mode3(XDR *, set_mode3 *); +extern bool_t +xdr_set_uid3(XDR *, set_uid3 *); +extern bool_t +xdr_set_gid3(XDR *, set_gid3 *); +extern bool_t +xdr_set_size3(XDR *, set_size3 *); +extern bool_t +xdr_set_atime(XDR *, set_atime *); +extern bool_t +xdr_set_mtime(XDR *, set_mtime *); +extern bool_t +xdr_sattr3(XDR *, sattr3 *); +extern bool_t +xdr_diropargs3(XDR *, diropargs3 *); +extern bool_t +xdr_getattr3args(XDR *, getattr3args *); +extern bool_t +xdr_getattr3resok(XDR *, getattr3resok *); +extern bool_t +xdr_getattr3res(XDR *, getattr3res *); +extern bool_t +xdr_sattrguard3(XDR *, sattrguard3 *); +extern bool_t +xdr_setattr3args(XDR *, setattr3args *); +extern bool_t +xdr_setattr3resok(XDR *, setattr3resok *); +extern bool_t +xdr_setattr3resfail(XDR *, setattr3resfail *); +extern bool_t +xdr_setattr3res(XDR *, setattr3res *); +extern bool_t +xdr_lookup3args(XDR *, lookup3args *); +extern bool_t +xdr_lookup3resok(XDR *, lookup3resok *); +extern bool_t +xdr_lookup3resfail(XDR *, lookup3resfail *); +extern bool_t +xdr_lookup3res(XDR *, lookup3res *); +extern bool_t +xdr_access3args(XDR *, access3args *); +extern bool_t +xdr_access3resok(XDR *, access3resok *); +extern bool_t +xdr_access3resfail(XDR *, access3resfail *); +extern bool_t +xdr_access3res(XDR *, access3res *); +extern bool_t +xdr_readlink3args(XDR *, readlink3args *); +extern bool_t +xdr_readlink3resok(XDR *, readlink3resok *); +extern bool_t +xdr_readlink3resfail(XDR *, readlink3resfail *); +extern bool_t +xdr_readlink3res(XDR *, readlink3res *); +extern bool_t +xdr_read3args(XDR *, read3args *); +extern bool_t +xdr_read3resok(XDR *, read3resok *); +extern bool_t +xdr_read3resfail(XDR *, read3resfail *); +extern bool_t +xdr_read3res(XDR *, read3res *); +extern bool_t +xdr_read3res_nocopy(XDR *xdrs, read3res *objp); +extern bool_t +xdr_stable_how(XDR *, stable_how *); +extern bool_t +xdr_write3args(XDR *, write3args *); +extern bool_t +xdr_write3resok(XDR *, write3resok *); +extern bool_t +xdr_write3resfail(XDR *, write3resfail *); +extern bool_t +xdr_write3res(XDR *, write3res *); +extern bool_t +xdr_createmode3(XDR *, createmode3 *); +extern bool_t +xdr_createhow3(XDR *, createhow3 *); +extern bool_t +xdr_create3args(XDR *, create3args *); +extern bool_t +xdr_create3resok(XDR *, create3resok *); +extern bool_t +xdr_create3resfail(XDR *, create3resfail *); +extern bool_t +xdr_create3res(XDR *, create3res *); +extern bool_t +xdr_mkdir3args(XDR *, mkdir3args *); +extern bool_t +xdr_mkdir3resok(XDR *, mkdir3resok *); +extern bool_t +xdr_mkdir3resfail(XDR *, mkdir3resfail *); +extern bool_t +xdr_mkdir3res(XDR *, mkdir3res *); +extern bool_t +xdr_symlinkdata3(XDR *, symlinkdata3 *); +extern bool_t +xdr_symlink3args(XDR *, symlink3args *); +extern bool_t +xdr_symlink3resok(XDR *, symlink3resok *); +extern bool_t +xdr_symlink3resfail(XDR *, symlink3resfail *); +extern bool_t +xdr_symlink3res(XDR *, symlink3res *); +extern bool_t +xdr_devicedata3(XDR *, devicedata3 *); +extern bool_t +xdr_mknoddata3(XDR *, mknoddata3 *); +extern bool_t +xdr_mknod3args(XDR *, mknod3args *); +extern bool_t +xdr_mknod3resok(XDR *, mknod3resok *); +extern bool_t +xdr_mknod3resfail(XDR *, mknod3resfail *); +extern bool_t +xdr_mknod3res(XDR *, mknod3res *); +extern bool_t +xdr_remove3args(XDR *, remove3args *); +extern bool_t +xdr_remove3resok(XDR *, remove3resok *); +extern bool_t +xdr_remove3resfail(XDR *, remove3resfail *); +extern bool_t +xdr_remove3res(XDR *, remove3res *); +extern bool_t +xdr_rmdir3args(XDR *, rmdir3args *); +extern bool_t +xdr_rmdir3resok(XDR *, rmdir3resok *); +extern bool_t +xdr_rmdir3resfail(XDR *, rmdir3resfail *); +extern bool_t +xdr_rmdir3res(XDR *, rmdir3res *); +extern bool_t +xdr_rename3args(XDR *, rename3args *); +extern bool_t +xdr_rename3resok(XDR *, rename3resok *); +extern bool_t +xdr_rename3resfail(XDR *, rename3resfail *); +extern bool_t +xdr_rename3res(XDR *, rename3res *); +extern bool_t +xdr_link3args(XDR *, link3args *); +extern bool_t +xdr_link3resok(XDR *, link3resok *); +extern bool_t +xdr_link3resfail(XDR *, link3resfail *); +extern bool_t +xdr_link3res(XDR *, link3res *); +extern bool_t +xdr_readdir3args(XDR *, readdir3args *); +extern bool_t +xdr_entry3(XDR *, entry3 *); +extern bool_t +xdr_dirlist3(XDR *, dirlist3 *); +extern bool_t +xdr_readdir3resok(XDR *, readdir3resok *); +extern bool_t +xdr_readdir3resfail(XDR *, readdir3resfail *); +extern bool_t +xdr_readdir3res(XDR *, readdir3res *); +extern bool_t +xdr_readdirp3args(XDR *, readdirp3args *); +extern bool_t +xdr_entryp3(XDR *, entryp3 *); +extern bool_t +xdr_dirlistp3(XDR *, dirlistp3 *); +extern bool_t +xdr_readdirp3resok(XDR *, readdirp3resok *); +extern bool_t +xdr_readdirp3resfail(XDR *, readdirp3resfail *); +extern bool_t +xdr_readdirp3res(XDR *, readdirp3res *); +extern bool_t +xdr_fsstat3args(XDR *, fsstat3args *); +extern bool_t +xdr_fsstat3resok(XDR *, fsstat3resok *); +extern bool_t +xdr_fsstat3resfail(XDR *, fsstat3resfail *); +extern bool_t +xdr_fsstat3res(XDR *, fsstat3res *); +extern bool_t +xdr_fsinfo3args(XDR *, fsinfo3args *); +extern bool_t +xdr_fsinfo3resok(XDR *, fsinfo3resok *); +extern bool_t +xdr_fsinfo3resfail(XDR *, fsinfo3resfail *); +extern bool_t +xdr_fsinfo3res(XDR *, fsinfo3res *); +extern bool_t +xdr_pathconf3args(XDR *, pathconf3args *); +extern bool_t +xdr_pathconf3resok(XDR *, pathconf3resok *); +extern bool_t +xdr_pathconf3resfail(XDR *, pathconf3resfail *); +extern bool_t +xdr_pathconf3res(XDR *, pathconf3res *); +extern bool_t +xdr_commit3args(XDR *, commit3args *); +extern bool_t +xdr_commit3resok(XDR *, commit3resok *); +extern bool_t +xdr_commit3resfail(XDR *, commit3resfail *); +extern bool_t +xdr_commit3res(XDR *, commit3res *); +extern bool_t +xdr_fhandle3(XDR *, fhandle3 *); +extern bool_t +xdr_dirpath(XDR *, dirpath *); +extern bool_t +xdr_name(XDR *, name *); +extern bool_t +xdr_mountstat3(XDR *, mountstat3 *); +extern bool_t +xdr_mountres3_ok(XDR *, mountres3_ok *); +extern bool_t +xdr_mountres3(XDR *, mountres3 *); +extern bool_t +xdr_mountlist(XDR *, mountlist *); +extern bool_t +xdr_mountbody(XDR *, mountbody *); +extern bool_t +xdr_groups(XDR *, groups *); +extern bool_t +xdr_groupnode(XDR *, groupnode *); +extern bool_t +xdr_exports(XDR *, exports *); +extern bool_t +xdr_exportnode(XDR *, exportnode *); + +extern void +xdr_free_exports_list(struct exportnode *first); +extern void +xdr_free_mountlist(mountlist ml); + +extern void +xdr_free_write3args_nocopy(write3args *wa); #endif |
