diff options
Diffstat (limited to 'rpc')
66 files changed, 10403 insertions, 6810 deletions
diff --git a/rpc/rpc-lib/src/Makefile.am b/rpc/rpc-lib/src/Makefile.am index fcf091e9b..f19c3c8a4 100644 --- a/rpc/rpc-lib/src/Makefile.am +++ b/rpc/rpc-lib/src/Makefile.am @@ -2,15 +2,18 @@ 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 + rpc-drc.c + libgfrpc_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la 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 + rpc-clnt.h rpcsvc-common.h protocol-common.h rpc-drc.h -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \ +AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ -I$(top_srcdir)/rpc/xdr/src \ - -DRPC_TRANSPORTDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/rpc-transport\" + -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 4faaddb9e..db488434c 100644 --- a/rpc/rpc-lib/src/auth-glusterfs.c +++ b/rpc/rpc-lib/src/auth-glusterfs.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. */ @@ -29,94 +20,9 @@ #include "dict.h" #include "xdr-rpc.h" #include "xdr-common.h" +#include "rpc-common-xdr.h" -bool_t -xdr_auth_glusterfs_parms (XDR *xdrs, auth_glusterfs_parms *objp) -{ - 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; -} - +/* V1 */ ssize_t xdr_to_glusterfs_auth (char *buf, struct auth_glusterfs_parms *req) @@ -146,7 +52,7 @@ auth_glusterfs_request_init (rpcsvc_request_t *req, void *priv) { if (!req) return -1; - memset (req->verf.authdata, 0, RPCSVC_MAX_AUTH_BYTES); + memset (req->verf.authdata, 0, GF_MAX_AUTH_BYTES); req->verf.datalen = 0; req->verf.flavour = AUTH_NULL; @@ -155,9 +61,12 @@ auth_glusterfs_request_init (rpcsvc_request_t *req, void *priv) int auth_glusterfs_authenticate (rpcsvc_request_t *req, void *priv) { - int ret = RPCSVC_AUTH_REJECT; struct auth_glusterfs_parms au = {0,}; - int gidcount = 0; + + int ret = RPCSVC_AUTH_REJECT; + int j = 0; + int i = 0; + int gidcount = 0; if (!req) return ret; @@ -173,7 +82,11 @@ int auth_glusterfs_authenticate (rpcsvc_request_t *req, void *priv) req->pid = au.pid; req->uid = au.uid; req->gid = au.gid; - req->lk_owner = au.lk_owner; + 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; if (req->auxgidcount > 16) { @@ -183,12 +96,30 @@ int auth_glusterfs_authenticate (rpcsvc_request_t *req, void *priv) 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]; + RPC_AUTH_ROOT_SQUASH(req); + 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); + ", gid: %d, owner: %s", + req->pid, req->uid, req->gid, lkowner_utoa (&req->lk_owner)); ret = RPCSVC_AUTH_ACCEPT; err: return ret; @@ -213,3 +144,133 @@ rpcsvc_auth_glusterfs_init (rpcsvc_t *svc, dict_t *options) { return &rpcsvc_auth_glusterfs; } + +/* V2 */ + +ssize_t +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, 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) +{ + if (!req) + return -1; + memset (req->verf.authdata, 0, GF_MAX_AUTH_BYTES); + req->verf.datalen = 0; + req->verf.flavour = AUTH_NULL; + + 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; + + 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; + + if (req->auxgidcount > GF_MAX_AUX_GROUPS) { + gf_log ("", GF_LOG_WARNING, + "more than max aux gids found (%d) , truncating it " + "to %d and continuing", au.groups.groups_len, + GF_MAX_AUX_GROUPS); + req->auxgidcount = GF_MAX_AUX_GROUPS; + } + + if (req->lk_owner.len > GF_MAX_LOCK_OWNER_LEN) { + gf_log ("", GF_LOG_WARNING, + "lkowner field > 1k, 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-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]; + + RPC_AUTH_ROOT_SQUASH(req); + + 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; +} + +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) +{ + return &rpcsvc_auth_glusterfs_v2; +} diff --git a/rpc/rpc-lib/src/auth-null.c b/rpc/rpc-lib/src/auth-null.c index ee50ab669..ebdcc8ff8 100644 --- a/rpc/rpc-lib/src/auth-null.c +++ b/rpc/rpc-lib/src/auth-null.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. */ @@ -34,10 +25,10 @@ auth_null_request_init (rpcsvc_request_t *req, void *priv) if (!req) return -1; - memset (req->cred.authdata, 0, RPCSVC_MAX_AUTH_BYTES); + memset (req->cred.authdata, 0, GF_MAX_AUTH_BYTES); req->cred.datalen = 0; - memset (req->verf.authdata, 0, RPCSVC_MAX_AUTH_BYTES); + memset (req->verf.authdata, 0, GF_MAX_AUTH_BYTES); req->verf.datalen = 0; return 0; diff --git a/rpc/rpc-lib/src/auth-unix.c b/rpc/rpc-lib/src/auth-unix.c index c48743db9..fa5f0576e 100644 --- a/rpc/rpc-lib/src/auth-unix.c +++ b/rpc/rpc-lib/src/auth-unix.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. */ @@ -35,7 +26,7 @@ auth_unix_request_init (rpcsvc_request_t *req, void *priv) { if (!req) return -1; - memset (req->verf.authdata, 0, RPCSVC_MAX_AUTH_BYTES); + memset (req->verf.authdata, 0, GF_MAX_AUTH_BYTES); req->verf.datalen = 0; req->verf.flavour = AUTH_NULL; @@ -51,6 +42,7 @@ int auth_unix_authenticate (rpcsvc_request_t *req, void *priv) if (!req) return ret; + req->auxgids = req->auxgidsmall; ret = xdr_to_auth_unix_cred (req->cred.authdata, req->cred.datalen, &aup, machname, req->auxgids); if (ret == -1) { diff --git a/rpc/rpc-lib/src/protocol-common.h b/rpc/rpc-lib/src/protocol-common.h index 5eea8b528..8bef906cc 100644 --- a/rpc/rpc-lib/src/protocol-common.h +++ b/rpc/rpc-lib/src/protocol-common.h @@ -1,20 +1,11 @@ /* - 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 @@ -64,6 +55,10 @@ enum gf_fop_procnum { GFS3_OP_READDIRP, GFS3_OP_RELEASE, GFS3_OP_RELEASEDIR, + GFS3_OP_FREMOVEXATTR, + GFS3_OP_FALLOCATE, + GFS3_OP_DISCARD, + GFS3_OP_ZEROFILL, GFS3_OP_MAXVALUE, } ; @@ -72,49 +67,11 @@ enum gf_handshake_procnum { GF_HNDSK_SETVOLUME, GF_HNDSK_GETSPEC, GF_HNDSK_PING, + GF_HNDSK_SET_LK_VER, + GF_HNDSK_EVENT_NOTIFY, GF_HNDSK_MAXVALUE, }; -enum gf_mgmt_procnum_ { - GD_MGMT_NULL, /* 0 */ - GD_MGMT_PROBE_QUERY, - GD_MGMT_FRIEND_ADD, - GD_MGMT_CLUSTER_LOCK, - GD_MGMT_CLUSTER_UNLOCK, - GD_MGMT_STAGE_OP, - GD_MGMT_COMMIT_OP, - GD_MGMT_FRIEND_REMOVE, - GD_MGMT_FRIEND_UPDATE, - GD_MGMT_CLI_PROBE, - GD_MGMT_CLI_DEPROBE, - GD_MGMT_CLI_LIST_FRIENDS, - GD_MGMT_CLI_CREATE_VOLUME, - GD_MGMT_CLI_GET_VOLUME, - GD_MGMT_CLI_DELETE_VOLUME, - GD_MGMT_CLI_START_VOLUME, - GD_MGMT_CLI_STOP_VOLUME, - GD_MGMT_CLI_RENAME_VOLUME, - GD_MGMT_CLI_DEFRAG_VOLUME, - GD_MGMT_CLI_SET_VOLUME, - GD_MGMT_CLI_ADD_BRICK, - GD_MGMT_CLI_REMOVE_BRICK, - GD_MGMT_CLI_REPLACE_BRICK, - GD_MGMT_CLI_LOG_FILENAME, - GD_MGMT_CLI_LOG_LOCATE, - GD_MGMT_CLI_LOG_ROTATE, - GD_MGMT_CLI_SYNC_VOLUME, - GD_MGMT_CLI_RESET_VOLUME, - GD_MGMT_CLI_FSM_LOG, - GD_MGMT_CLI_GSYNC_SET, - GD_MGMT_CLI_PROFILE_VOLUME, - GD_MGMT_BRICK_OP, - GD_MGMT_CLI_LOG_LEVEL, - GD_MGMT_CLI_STATUS_VOLUME, - GD_MGMT_MAXVALUE, -}; - -typedef enum gf_mgmt_procnum_ gf_mgmt_procnum; - enum gf_pmap_procnum { GF_PMAP_NULL = 0, GF_PMAP_PORTBYBRICK, @@ -140,8 +97,10 @@ enum gf_probe_resp { 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_ADD_FAILED, + GF_PROBE_QUORUM_NOT_MET }; enum gf_deprobe_resp { @@ -149,29 +108,18 @@ enum gf_deprobe_resp { GF_DEPROBE_LOCALHOST, GF_DEPROBE_NOT_FRIEND, GF_DEPROBE_BRICK_EXIST, - GF_DEPROBE_FRIEND_DOWN + GF_DEPROBE_FRIEND_DOWN, + GF_DEPROBE_QUORUM_NOT_MET, }; enum gf_cbk_procnum { GF_CBK_NULL = 0, GF_CBK_FETCHSPEC, GF_CBK_INO_FLUSH, + GF_CBK_EVENT_NOTIFY, GF_CBK_MAXVALUE, }; -enum glusterd_mgmt_procnum { - GLUSTERD_MGMT_NULL, /* 0 */ - GLUSTERD_MGMT_PROBE_QUERY, - GLUSTERD_MGMT_FRIEND_ADD, - GLUSTERD_MGMT_CLUSTER_LOCK, - GLUSTERD_MGMT_CLUSTER_UNLOCK, - GLUSTERD_MGMT_STAGE_OP, - GLUSTERD_MGMT_COMMIT_OP, - GLUSTERD_MGMT_FRIEND_REMOVE, - GLUSTERD_MGMT_FRIEND_UPDATE, - GLUSTERD_MGMT_MAXVALUE, -}; - enum gluster_cli_procnum { GLUSTER_CLI_NULL, /* 0 */ GLUSTER_CLI_PROBE, @@ -189,8 +137,6 @@ enum gluster_cli_procnum { GLUSTER_CLI_ADD_BRICK, GLUSTER_CLI_REMOVE_BRICK, GLUSTER_CLI_REPLACE_BRICK, - GLUSTER_CLI_LOG_FILENAME, - GLUSTER_CLI_LOG_LOCATE, GLUSTER_CLI_LOG_ROTATE, GLUSTER_CLI_GETSPEC, GLUSTER_CLI_PMAP_PORTBYBRICK, @@ -202,42 +148,87 @@ enum gluster_cli_procnum { GLUSTER_CLI_QUOTA, GLUSTER_CLI_TOP_VOLUME, GLUSTER_CLI_GETWD, - GLUSTER_CLI_LOG_LEVEL, 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_MAXVALUE, }; -enum gf_brick_procnum { - GF_BRICK_NULL = 0, - GF_BRICK_TERMINATE = 1, - GF_BRICK_XLATOR_INFO = 2, - GF_BRICK_XLATOR_HEAL = 3, - GF_BRICK_MAX_VALUE +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, }; +enum glusterd_friend_procnum { + GLUSTERD_FRIEND_NULL, /* 0 */ + GLUSTERD_PROBE_QUERY, + GLUSTERD_FRIEND_ADD, + GLUSTERD_FRIEND_REMOVE, + GLUSTERD_FRIEND_UPDATE, + GLUSTERD_FRIEND_MAXVALUE, +}; -#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 +enum glusterd_brick_procnum { + 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_MAXVALUE, +}; -#define GLUSTERD1_MGMT_PROGRAM 1298433 /* Completely random */ -#define GLUSTERD1_MGMT_VERSION 1 /* 0.0.1 */ -#define GLUSTERD1_MGMT_PROCCNT GD_MGMT_MAXVALUE +enum glusterd_mgmt_hndsk_procnum { + GD_MGMT_HNDSK_NULL, + GD_MGMT_HNDSK_VERSIONS, + GD_MGMT_HNDSK_VERSIONS_ACK, + GD_MGMT_HNDSK_MAXVALUE, +}; -#define GD_MGMT_PROGRAM 1238433 /* Completely random */ -#define GD_MGMT_VERSION 1 /* 0.0.1 */ -#define GD_MGMT_PROCCNT GLUSTERD_MGMT_MAXVALUE +typedef enum { + GF_AFR_OP_INVALID, + GF_AFR_OP_HEAL_INDEX, + GF_AFR_OP_HEAL_FULL, + GF_AFR_OP_INDEX_SUMMARY, + GF_AFR_OP_HEALED_FILES, + GF_AFR_OP_HEAL_FAILED_FILES, + GF_AFR_OP_SPLIT_BRAIN_FILES, + GF_AFR_OP_STATISTICS, + GF_AFR_OP_STATISTICS_HEAL_COUNT, + GF_AFR_OP_STATISTICS_HEAL_COUNT_PER_REPLICA, +} gf_xl_afr_op_t ; -#define GLUSTER_CLI_PROGRAM 1238463 /* Completely random */ -#define GLUSTER_CLI_VERSION 1 /* 0.0.1 */ -#define GLUSTER_CLI_PROCCNT GLUSTER_CLI_MAXVALUE +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_VALIDATE, + GLUSTERD_MGMT_V3_UNLOCK, + GLUSTERD_MGMT_V3_MAXVALUE, +}; #define GLUSTER_HNDSK_PROGRAM 14398633 /* Completely random */ -#define GLUSTER_HNDSK_VERSION 1 /* 0.0.1 */ +#define GLUSTER_HNDSK_VERSION 2 /* 0.0.2 */ #define GLUSTER_PMAP_PROGRAM 34123456 #define GLUSTER_PMAP_VERSION 1 @@ -245,10 +236,29 @@ enum gf_brick_procnum { #define GLUSTER_CBK_PROGRAM 52743234 /* Completely random */ #define GLUSTER_CBK_VERSION 1 /* 0.0.1 */ -#define GLUSTER_HNDSK_PROGRAM 14398633 /* Completely random */ -#define GLUSTER_HNDSK_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 + +/* Second version */ +#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 + +/* Third version */ +#define GD_MGMT_V3_PROGRAM 2210013 /* Completely random */ +#define GD_MGMT_V3_VERSION 3 + +/* OP-VERSION handshake */ +#define GD_MGMT_HNDSK_PROGRAM 1239873 /* Completely random */ +#define GD_MGMT_HNDSK_VERSION 1 -#define GLUSTERFS_PROGRAM 4867634 /*Completely random*/ -#define GLUSTERFS_VERSION 1 -#define GLUSTERFS_PROCCNT GF_BRICK_MAX_VALUE #endif /* !_PROTOCOL_COMMON_H */ diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c index f01ece0cd..ac98a5c91 100644 --- a/rpc/rpc-lib/src/rpc-clnt.c +++ b/rpc/rpc-lib/src/rpc-clnt.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. */ @@ -23,7 +14,7 @@ #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" @@ -32,6 +23,7 @@ #include "protocol-common.h" #include "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); @@ -74,8 +66,8 @@ _is_lock_fop (struct saved_frame *sframe) { int fop = 0; - if (SFRAME_GET_PROGNUM (sframe) == GLUSTER3_1_FOP_PROGRAM && - SFRAME_GET_PROGVER (sframe) == GLUSTER3_1_FOP_VERSION) + 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) || @@ -152,9 +144,8 @@ call_bail (void *data) 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 timespec timeout = {0,}; struct iovec iov = {0,}; GF_VALIDATE_OR_GOTO ("client", data, out); @@ -172,7 +163,7 @@ call_bail (void *data) call-once timer */ if (conn->timer) { timeout.tv_sec = 10; - timeout.tv_usec = 0; + timeout.tv_nsec = 0; gf_timer_call_cancel (clnt->ctx, conn->timer); conn->timer = gf_timer_call_after (clnt->ctx, @@ -182,7 +173,8 @@ call_bail (void *data) if (conn->timer == NULL) { gf_log (conn->trans->name, GF_LOG_WARNING, - "Cannot create bailout timer"); + "Cannot create bailout timer for %s", + conn->trans->peerinfo.identifier); } } @@ -199,21 +191,21 @@ call_bail (void *data) 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); + gf_time_fmt (frame_sent, sizeof frame_sent, + trav->saved_at.tv_sec, gf_timefmt_FT); 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", + "bailing out frame type(%s) op(%s(%d)) xid = 0x%x " + "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, frame_sent, - conn->frame_timeout); + conn->frame_timeout, conn->trans->peerinfo.identifier); clnt = rpc_clnt_ref (clnt); trav->rpcreq->rpc_status = -1; @@ -235,7 +227,7 @@ __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 timespec timeout = {0, }; struct saved_frame *saved_frame = NULL; conn = &rpc_clnt->conn; @@ -249,7 +241,7 @@ __save_frame (struct rpc_clnt *rpc_clnt, call_frame_t *frame, /* TODO: make timeout configurable */ if (conn->timer == NULL) { timeout.tv_sec = 10; - timeout.tv_usec = 0; + timeout.tv_nsec = 0; conn->timer = gf_timer_call_after (rpc_clnt->ctx, timeout, call_bail, @@ -348,20 +340,16 @@ out: void 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,}; - + char timestr[1024] = {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); + gf_time_fmt (timestr, sizeof timestr, + trav->saved_at.tv_sec, gf_timefmt_FT); snprintf (timestr + strlen (timestr), sizeof(timestr) - strlen (timestr), ".%"GF_PRI_SUSECONDS, trav->saved_at.tv_usec); @@ -372,22 +360,21 @@ saved_frames_unwind (struct saved_frames *saved_frames) gf_log_callingfn (trav->rpcreq->conn->trans->name, GF_LOG_ERROR, "forced unwinding frame type(%s) op(%s(%d)) " - "called at %s", + "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->procnum, timestr, + trav->rpcreq->xid); 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); } @@ -411,7 +398,7 @@ rpc_clnt_reconnect (void *trans_ptr) { rpc_transport_t *trans = NULL; rpc_clnt_connection_t *conn = NULL; - struct timeval tv = {0, 0}; + struct timespec ts = {0, 0}; int32_t ret = 0; struct rpc_clnt *clnt = NULL; @@ -430,23 +417,15 @@ rpc_clnt_reconnect (void *trans_ptr) conn->reconnect = 0; if (conn->connected == 0) { - tv.tv_sec = 3; + ts.tv_sec = 3; + ts.tv_nsec = 0; 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, + gf_timer_call_after (clnt->ctx, ts, rpc_clnt_reconnect, trans); } else { @@ -467,7 +446,7 @@ rpc_clnt_reconnect (void *trans_ptr) int rpc_clnt_fill_request_info (struct rpc_clnt *clnt, rpc_request_info_t *info) { - struct saved_frame saved_frame = {{}, 0}; + struct saved_frame saved_frame; int ret = -1; pthread_mutex_lock (&clnt->conn.lock); @@ -553,6 +532,12 @@ rpc_clnt_connection_cleanup (rpc_clnt_connection_t *conn) } conn->connected = 0; + + if (conn->ping_timer) { + gf_timer_call_cancel (clnt->ctx, conn->ping_timer); + conn->ping_timer = NULL; + conn->ping_started = 0; + } } pthread_mutex_unlock (&conn->lock); @@ -678,15 +663,13 @@ rpc_clnt_reply_init (rpc_clnt_connection_t *conn, rpc_transport_pollin_t *msg, } gf_log (conn->trans->name, GF_LOG_TRACE, - "received rpc message (RPC XID: 0x%ux" + "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->trans->name); - req->rpc_status = 0; - out: if (ret != 0) { req->rpc_status = -1; @@ -743,7 +726,8 @@ rpc_clnt_handle_cbk (struct rpc_clnt *clnt, rpc_transport_pollin_t *msg) if (found && (procnum < program->numactors) && (program->actors[procnum].actor)) { - program->actors[procnum].actor (&progmsg); + program->actors[procnum].actor (clnt, program->mydata, + &progmsg); } out: @@ -837,17 +821,19 @@ out: return; } +static void +rpc_clnt_destroy (struct rpc_clnt *rpc); int 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, }; + 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 timespec ts = {0, }; conn = mydata; if (conn == NULL) { @@ -864,11 +850,13 @@ rpc_clnt_notify (rpc_transport_t *trans, void *mydata, pthread_mutex_lock (&conn->lock); { - if (conn->reconnect == NULL) { - tv.tv_sec = 10; + if (!conn->rpc_clnt->disabled + && (conn->reconnect == NULL)) { + ts.tv_sec = 10; + ts.tv_nsec = 0; conn->reconnect = - gf_timer_call_after (clnt->ctx, tv, + gf_timer_call_after (clnt->ctx, ts, rpc_clnt_reconnect, conn->trans); } @@ -882,9 +870,7 @@ rpc_clnt_notify (rpc_transport_t *trans, void *mydata, } case RPC_TRANSPORT_CLEANUP: - /* this event should not be received on a client for, a - * transport is only disconnected, but never destroyed. - */ + rpc_clnt_destroy (clnt); ret = 0; break; @@ -897,6 +883,12 @@ rpc_clnt_notify (rpc_transport_t *trans, void *mydata, case RPC_TRANSPORT_MSG_RECEIVED: { + pthread_mutex_lock (&conn->lock); + { + gettimeofday (&conn->last_received, NULL); + } + pthread_mutex_unlock (&conn->lock); + pollin = data; if (pollin->is_reply) ret = rpc_clnt_handle_reply (clnt, pollin); @@ -922,6 +914,14 @@ rpc_clnt_notify (rpc_transport_t *trans, void *mydata, case RPC_TRANSPORT_CONNECT: { + /* 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; + if (clnt->notifyfn) ret = clnt->notifyfn (clnt, clnt->mydata, RPC_CLNT_CONNECT, NULL); @@ -948,7 +948,7 @@ rpc_clnt_connection_deinit (rpc_clnt_connection_t *conn) } -inline int +static inline int rpc_clnt_connection_init (struct rpc_clnt *clnt, glusterfs_ctx_t *ctx, dict_t *options, char *name) { @@ -1005,8 +1005,8 @@ out: } struct rpc_clnt * -rpc_clnt_new (dict_t *options, - glusterfs_ctx_t *ctx, char *name) +rpc_clnt_new (dict_t *options, glusterfs_ctx_t *ctx, char *name, + uint32_t reqpool_size) { int ret = -1; struct rpc_clnt *rpc = NULL; @@ -1019,8 +1019,10 @@ rpc_clnt_new (dict_t *options, pthread_mutex_init (&rpc->lock, NULL); rpc->ctx = ctx; - rpc->reqpool = mem_pool_new (struct rpc_req, - RPC_CLNT_DEFAULT_REQUEST_COUNT); + 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); @@ -1029,7 +1031,7 @@ rpc_clnt_new (dict_t *options, } rpc->saved_frames_pool = mem_pool_new (struct saved_frame, - RPC_CLNT_DEFAULT_REQUEST_COUNT); + reqpool_size); if (rpc->saved_frames_pool == NULL) { pthread_mutex_destroy (&rpc->lock); mem_pool_destroy (rpc->reqpool); @@ -1050,6 +1052,8 @@ rpc_clnt_new (dict_t *options, goto out; } + rpc->auth_null = dict_get_str_boolean (options, "auth-null", 0); + rpc = rpc_clnt_ref (rpc); INIT_LIST_HEAD (&rpc->programs); @@ -1085,7 +1089,7 @@ rpc_clnt_register_notify (struct rpc_clnt *rpc, rpc_clnt_notify_t fn, } ssize_t -xdr_serialize_glusterfs_auth (char *dest, struct auth_glusterfs_parms *au) +xdr_serialize_glusterfs_auth (char *dest, struct auth_glusterfs_parms_v2 *au) { ssize_t ret = -1; XDR xdr; @@ -1093,10 +1097,9 @@ xdr_serialize_glusterfs_auth (char *dest, struct auth_glusterfs_parms *au) if ((!dest) || (!au)) return -1; - xdrmem_create (&xdr, dest, 1024, - XDR_ENCODE); + xdrmem_create (&xdr, dest, GF_MAX_AUTH_BYTES, XDR_ENCODE); - if (!xdr_auth_glusterfs_parms (&xdr, au)) { + if (!xdr_auth_glusterfs_parms_v2 (&xdr, au)) { gf_log (THIS->name, GF_LOG_WARNING, "failed to encode auth glusterfs elements"); ret = -1; @@ -1111,8 +1114,8 @@ ret: int -rpc_clnt_fill_request (int prognum, int progver, int procnum, int payload, - uint64_t xid, struct auth_glusterfs_parms *au, +rpc_clnt_fill_request (int prognum, int progver, int procnum, + uint64_t xid, struct auth_glusterfs_parms_v2 *au, struct rpc_msg *request, char *auth_data) { int ret = -1; @@ -1131,19 +1134,26 @@ rpc_clnt_fill_request (int prognum, int progver, int procnum, int payload, 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. + /* TODO: Using AUTH_(GLUSTERFS/NULL) in a kludgy way 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 (ret == -1) { - gf_log ("rpc-clnt", GF_LOG_DEBUG, "cannot encode 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_length = ret; + if (auth_data) { + ret = xdr_serialize_glusterfs_auth (auth_data, au); + if (ret == -1) { + gf_log ("rpc-clnt", GF_LOG_DEBUG, + "cannot encode credentials"); + goto out; + } + request->rm_call.cb_cred.oa_flavor = AUTH_GLUSTERFS_v2; + request->rm_call.cb_cred.oa_base = auth_data; + request->rm_call.cb_cred.oa_length = ret; + } else { + 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; + } 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; @@ -1191,26 +1201,43 @@ out: 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, + int procnum, size_t hdrsize, uint64_t xid, + struct auth_glusterfs_parms_v2 *au, 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, }; + 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) || (!au)) { goto out; } + /* Fill the rpc structure and XDR it into the buffer got above. */ + if (clnt->auth_null) + ret = rpc_clnt_fill_request (prognum, progver, procnum, + xid, NULL, &request, NULL); + else + ret = rpc_clnt_fill_request (prognum, progver, procnum, + 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; + } + + 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_get (clnt->ctx->iobuf_pool); + request_iob = iobuf_get2 (clnt->ctx->iobuf_pool, (xdr_size + hdrsize)); if (!request_iob) { goto out; } @@ -1219,19 +1246,8 @@ rpc_clnt_record_build_record (struct rpc_clnt *clnt, int prognum, int progver, 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); + hdrsize); if (!recordhdr.iov_base) { gf_log (clnt->conn.trans->name, GF_LOG_ERROR, @@ -1252,39 +1268,45 @@ out: 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, + 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; + struct auth_glusterfs_parms_v2 au = {0, }; + struct iobuf *request_iob = NULL; + char owner[4] = {0,}; 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; + au.pid = call_frame->root->pid; + au.uid = call_frame->root->uid; + au.gid = call_frame->root->gid; + au.groups.groups_len = call_frame->root->ngrps; + au.lk_owner.lk_owner_len = call_frame->root->lk_owner.len; - 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); + if (au.groups.groups_len) + au.groups.groups_val = call_frame->root->groups; - memcpy (au.groups, call_frame->root->groups, sizeof (au.groups)); + if (call_frame->root->lk_owner.len) + au.lk_owner.lk_owner_val = call_frame->root->lk_owner.data; + else { + owner[0] = (char)(au.pid & 0xff); + owner[1] = (char)((au.pid >> 8) & 0xff); + owner[2] = (char)((au.pid >> 16) & 0xff); + owner[3] = (char)((au.pid >> 24) & 0xff); - //rpc_transport_get_myname (clnt->conn.trans, myname, UNIX_PATH_MAX); - //au.aup_machname = myname; + au.lk_owner.lk_owner_val = owner; + au.lk_owner.lk_owner_len = 4; + } + + gf_log (clnt->conn.trans->name, GF_LOG_TRACE, "Auth Info: pid: %u, uid: %d" + ", gid: %d, owner: %s", au.pid, au.uid, au.gid, + lkowner_utoa (&call_frame->root->lk_owner)); - /* Assuming the client program would like to speak to the same versioned - * program on server. - */ request_iob = rpc_clnt_record_build_record (clnt, prog->prognum, prog->progver, - procnum, payload_len, + procnum, hdrlen, callid, &au, rpchdr); if (!request_iob) { @@ -1299,7 +1321,7 @@ out: int rpcclnt_cbk_program_register (struct rpc_clnt *clnt, - rpcclnt_cb_program_t *program) + rpcclnt_cb_program_t *program, void *mydata) { int ret = -1; char already_registered = 0; @@ -1339,6 +1361,8 @@ rpcclnt_cbk_program_register (struct rpc_clnt *clnt, memcpy (tmp, program, sizeof (*tmp)); INIT_LIST_HEAD (&tmp->program); + tmp->mydata = mydata; + pthread_mutex_lock (&clnt->lock); { list_add_tail (&tmp->program, &clnt->programs); @@ -1386,6 +1410,12 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, goto out; } + conn = &rpc->conn; + + if (conn->trans == NULL) { + goto out; + } + rpcreq = mem_get (rpc->reqpool); if (rpcreq == NULL) { goto out; @@ -1405,8 +1435,6 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, callid = rpc_clnt_new_callid (rpc); - conn = &rpc->conn; - rpcreq->prog = prog; rpcreq->procnum = procnum; rpcreq->conn = conn; @@ -1419,11 +1447,6 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, proglen += iov_length (proghdr, proghdrcount); } - if (progpayload) { - proglen += iov_length (progpayload, - progpayloadcount); - } - request_iob = rpc_clnt_record (rpc, frame, prog, procnum, proglen, &rpchdr, callid); @@ -1455,10 +1478,6 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, 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, @@ -1466,19 +1485,18 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, if (ret == -1) { gf_log (conn->trans->name, GF_LOG_WARNING, "failed to submit rpc-request " - "(XID: 0x%ux Program: %s, ProgVers: %d, " + "(XID: 0x%x 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, " + "(XID: 0x%x Program: %s, ProgVers: %d, " "Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->prog->progname, rpcreq->prog->progver, rpcreq->procnum, rpc->conn.trans->name); @@ -1493,7 +1511,9 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, ret = 0; out: - iobuf_unref (request_iob); + if (request_iob) { + iobuf_unref (request_iob); + } if (new_iobref && iobref) { iobref_unref (iobref); @@ -1525,19 +1545,21 @@ rpc_clnt_ref (struct rpc_clnt *rpc) static void -rpc_clnt_destroy (struct rpc_clnt *rpc) +rpc_clnt_trigger_destroy (struct rpc_clnt *rpc) { if (!rpc) return; - if (rpc->conn.trans) { - rpc->conn.trans->mydata = NULL; - rpc_transport_unref (rpc->conn.trans); - //rpc_transport_destroy (rpc->conn.trans); - } + rpc_clnt_disable (rpc); + rpc_transport_unref (rpc->conn.trans); +} + +static void +rpc_clnt_destroy (struct rpc_clnt *rpc) +{ + 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); @@ -1564,13 +1586,78 @@ rpc_clnt_unref (struct rpc_clnt *rpc) } pthread_mutex_unlock (&rpc->lock); if (!count) { - rpc_clnt_destroy (rpc); + rpc_clnt_trigger_destroy (rpc); return NULL; } return rpc; } +char +rpc_clnt_is_disabled (struct rpc_clnt *rpc) +{ + + rpc_clnt_connection_t *conn = NULL; + char disabled = 0; + + if (!rpc) { + goto out; + } + + conn = &rpc->conn; + + pthread_mutex_lock (&conn->lock); + { + disabled = rpc->disabled; + } + pthread_mutex_unlock (&conn->lock); + +out: + return disabled; +} + +void +rpc_clnt_disable (struct rpc_clnt *rpc) +{ + rpc_clnt_connection_t *conn = NULL; + + if (!rpc) { + goto out; + } + + conn = &rpc->conn; + + pthread_mutex_lock (&conn->lock); + { + rpc->disabled = 1; + + if (conn->timer) { + gf_timer_call_cancel (rpc->ctx, conn->timer); + conn->timer = NULL; + } + + if (conn->reconnect) { + gf_timer_call_cancel (rpc->ctx, conn->reconnect); + conn->reconnect = NULL; + } + conn->connected = 0; + + if (conn->ping_timer) { + gf_timer_call_cancel (rpc->ctx, conn->ping_timer); + conn->ping_timer = NULL; + conn->ping_started = 0; + } + + } + pthread_mutex_unlock (&conn->lock); + + rpc_transport_disconnect (rpc->conn.trans); + +out: + return; +} + + void rpc_clnt_reconfig (struct rpc_clnt *rpc, struct rpc_clnt_config *config) { @@ -1598,7 +1685,7 @@ rpc_clnt_reconfig (struct rpc_clnt *rpc, struct rpc_clnt_config *config) 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)", + "changing hostname to %s (from %s)", config->remote_host, rpc->conn.config.remote_host); FREE (rpc->conn.config.remote_host); @@ -1611,54 +1698,3 @@ rpc_clnt_reconfig (struct rpc_clnt *rpc, struct rpc_clnt_config *config) rpc->conn.config.remote_host = gf_strdup (config->remote_host); } } - -int -rpc_clnt_transport_unix_options_build (dict_t **options, char *filepath) -{ - dict_t *dict = NULL; - char *fpath = NULL; - int ret = -1; - - GF_ASSERT (filepath); - GF_ASSERT (options); - - dict = dict_new (); - if (!dict) - goto out; - - fpath = gf_strdup (filepath); - if (!fpath) { - ret = -1; - goto out; - } - - ret = dict_set_dynstr (dict, "transport.socket.connect-path", fpath); - if (ret) - goto out; - - ret = dict_set_str (dict, "transport.address-family", "unix"); - if (ret) - goto out; - - 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; - - ret = dict_set_str (dict, "transport.socket.keepalive", "off"); - if (ret) - goto out; - - *options = dict; -out: - if (ret) { - if (fpath) - GF_FREE (fpath); - if (dict) - dict_unref (dict); - } - return ret; -} diff --git a/rpc/rpc-lib/src/rpc-clnt.h b/rpc/rpc-lib/src/rpc-clnt.h index e3b2ec3f1..584963ad0 100644 --- a/rpc/rpc-lib/src/rpc-clnt.h +++ b/rpc/rpc-lib/src/rpc-clnt.h @@ -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. */ #ifndef __RPC_CLNT_H @@ -31,8 +22,6 @@ typedef enum { RPC_CLNT_MSG } 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) @@ -89,7 +78,7 @@ typedef struct rpc_clnt_program { 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. @@ -117,15 +106,17 @@ typedef struct rpcclnt_cb_program { /* 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; } 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; @@ -172,7 +163,7 @@ struct rpc_req { void *conn_private; }; -struct rpc_clnt { +typedef struct rpc_clnt { pthread_mutex_t lock; rpc_clnt_notify_t notifyfn; rpc_clnt_connection_t conn; @@ -189,11 +180,13 @@ struct rpc_clnt { glusterfs_ctx_t *ctx; int refcount; -}; + int auth_null; + char disabled; +} rpc_clnt_t; struct rpc_clnt *rpc_clnt_new (dict_t *options, glusterfs_ctx_t *ctx, - char *name); + char *name, uint32_t reqpool_size); int rpc_clnt_start (struct rpc_clnt *rpc); @@ -229,10 +222,11 @@ rpc_clnt_ref (struct rpc_clnt *rpc); struct rpc_clnt * rpc_clnt_unref (struct rpc_clnt *rpc); +int rpc_clnt_connection_cleanup (rpc_clnt_connection_t *conn); + void rpc_clnt_set_connected (rpc_clnt_connection_t *conn); void rpc_clnt_unset_connected (rpc_clnt_connection_t *conn); - void rpc_clnt_reconnect (void *trans_ptr); void rpc_clnt_reconfig (struct rpc_clnt *rpc, struct rpc_clnt_config *config); @@ -241,8 +235,12 @@ void rpc_clnt_reconfig (struct rpc_clnt *rpc, struct rpc_clnt_config *config); * procedure handlers. */ int rpcclnt_cbk_program_register (struct rpc_clnt *svc, - rpcclnt_cb_program_t *program); + rpcclnt_cb_program_t *program, void *mydata); + +void +rpc_clnt_disable (struct rpc_clnt *rpc); + +char +rpc_clnt_is_disabled (struct rpc_clnt *rpc); -int -rpc_clnt_transport_unix_options_build (dict_t **options, char *filepath); #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 ff8785c67..000000000 --- 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 000000000..8181e6aee --- /dev/null +++ b/rpc/rpc-lib/src/rpc-drc.c @@ -0,0 +1,872 @@ +/* + 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 _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include "rpcsvc.h" +#ifndef RPC_DRC_H +#include "rpc-drc.h" +#endif +#include "locking.h" +#include "hashfn.h" +#include "common-utils.h" +#include "statedump.h" +#include "mem-pool.h" + +#include <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; + rpcsvc_request_t *req = NULL; + drc_cached_op_t *reply = NULL; + + GF_ASSERT (item); + GF_ASSERT (rb_node_data); + GF_ASSERT (param); + + req = (rpcsvc_request_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->progver == reply->progversion) + return 0; + + return 1; +} + +/** + * drc_rb_calloc - used by rbtree api to allocate memory for nodes + * + * @param allocator - the libavl_allocator structure used by rbtree + * @param size - not needed by this function + * @return pointer to new cached reply (node in rbtree) + */ +static void * +drc_rb_calloc (struct libavl_allocator *allocator, size_t size) +{ + rpcsvc_drc_globals_t *drc = NULL; + + /* get the drc pointer by simple typecast, since allocator + * is the first member of rpcsvc_drc_globals_t + */ + drc = (rpcsvc_drc_globals_t *)allocator; + + return mem_get (drc->mempool); +} + +/** + * drc_rb_free - used by rbtree api to free a node + * + * @param a - the libavl_allocator structure used by rbtree api + * @param block - node that needs to be freed + * @return void + */ +static void +drc_rb_free (struct libavl_allocator *a, void *block) +{ + mem_put (block); +} + +/** + * 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); + + drc->allocator.libavl_malloc = drc_rb_calloc; + drc->allocator.libavl_free = drc_rb_free; + + client->rbtree = rb_create (drc_compare_reqs, drc, + (struct libavl_allocator *)drc); + 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; + + client->ref = 0; + client->sock_union = (union gf_sock_union)*sockaddr; + client->op_count = 0; + + 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); + 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) +{ + GF_ASSERT (drc); + GF_ASSERT (client->ref); + + client->ref--; + if (!client->ref) { + 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; + + 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 = client; + } + + client = rpcsvc_drc_client_ref (req->trans->drc_client); + + if (client->op_count == 0) + goto out; + + reply = rb_find (client->rbtree, req); + + out: + if (client) + rpcsvc_drc_client_unref (req->svc->drc, client); + + 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; + + (void *)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 != reply) { + /* should never happen */ + gf_log (GF_RPCSVC, GF_LOG_ERROR, + "DRC failed to detect duplicates"); + return -1; + } else if (*tmp_reply == NULL) { + /* mem alloc failed */ + 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_get (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; + + 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, "%d", drc->cache_hits); + + gf_proc_dump_build_key (key, "drc", "in_transit_duplicate_requests"); + gf_proc_dump_write (key, "%d", 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, "%d", 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 out; + + 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 */ + rpcsvc_drc_client_unref (drc, client); + trans->drc_client = NULL; + break; + + default: + break; + } + + out: + 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; + static gf_boolean_t drc_inited = _gf_false; + + GF_ASSERT (svc); + GF_ASSERT (options); + + /* Already inited */ + if (drc_inited) + return 0; + + if (!svc->drc) { + drc = GF_CALLOC (1, sizeof (rpcsvc_drc_globals_t), + gf_common_mt_drc_globals_t); + if (!drc) + return -1; + + svc->drc = drc; + LOCK_INIT (&drc->lock); + } else { + drc = svc->drc; + } + + LOCK (&drc->lock); + if (drc->type != DRC_TYPE_NONE) { + ret = 0; + goto out; + } + + /* 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_true); + if (ret == -1) { + gf_log (GF_RPCSVC, GF_LOG_INFO, "drc user options need second look"); + ret = _gf_true; + } + drc->enable_drc = ret; + + if (ret == _gf_false) { + /* drc off */ + gf_log (GF_RPCSVC, GF_LOG_DEBUG, "DRC is off"); + ret = 0; + goto out; + } + + /* 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; + } + + drc->type = drc_type; + + /* Set the global cache size (no. of ops to cache) */ + ret = dict_get_uint32 (options, "nfs.drc-size", &drc_size); + if (ret) { + gf_log (GF_RPCSVC, GF_LOG_DEBUG, "drc size not set." + " Continuing with default size"); + drc_size = DRC_DEFAULT_CACHE_SIZE; + } + + 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) { + gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get mempool for" + " DRC, drc-size: %d", drc->global_cache_size); + ret = -1; + goto out; + } + + /* 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) { + gf_log (GF_RPCSVC, GF_LOG_ERROR, + "registration of drc_notify function failed"); + goto out; + } + + gf_log (GF_RPCSVC, GF_LOG_DEBUG, "drc init successful"); + drc->status = DRC_INITIATED; + drc_inited = _gf_true; + + out: + UNLOCK (&drc->lock); + 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_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; + + if ((!svc) || (!options)) + return (-1); + + drc = svc->drc; + /* reconfig for drc-size */ + if (dict_get_uint32 (options, "nfs.drc-size", &drc_size)) + drc_size = DRC_DEFAULT_CACHE_SIZE; + + if (drc->global_cache_size != drc_size) { + gf_log (GF_RPCSVC, GF_LOG_DEBUG, "nfs.drc-size size can not " + "be reconfigured without NFS server restart."); + return (-1); + } + + /* reconfig for nfs.drc */ + ret = dict_get_str_boolean (options, "nfs.drc", _gf_true); + if (ret < 0) { + ret = _gf_true; + } + enable_drc = ret; + + if (drc->enable_drc == enable_drc) + return 0; + + drc->enable_drc = enable_drc; + if (enable_drc) { + if (drc == NULL) + return rpcsvc_drc_init(svc, options); + } else { + if (drc == NULL) + 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); +} diff --git a/rpc/rpc-lib/src/rpc-drc.h b/rpc/rpc-lib/src/rpc-drc.h new file mode 100644 index 000000000..7dfaef978 --- /dev/null +++ b/rpc/rpc-lib/src/rpc-drc.h @@ -0,0 +1,104 @@ +/* + 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 + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include "rpcsvc-common.h" +#include "rpcsvc.h" +#include "locking.h" +#include "dict.h" +#include "rb.h" + +/* per-client cache structure */ +struct drc_client { + uint32_t ref; + union gf_sock_union sock_union; + /* pointers to the cache */ + struct rb_table *rbtree; + /* no. of ops currently cached */ + uint32_t op_count; + struct list_head client_list; +}; + +struct drc_cached_op { + drc_op_state_t state; + uint32_t xid; + 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; +}; + +/* 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; + drc_type_t type; + /* configurable size parameter */ + uint32_t global_cache_size; + drc_lru_factor_t lru_factor; + gf_lock_t lock; + drc_status_t status; + uint32_t op_count; + uint64_t cache_hits; + uint64_t intransit_hits; + struct mem_pool *mempool; + struct list_head cache_head; + uint32_t client_count; + struct list_head clients_head; + gf_boolean_t enable_drc; +}; + +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_reconfigure (rpcsvc_t *svc, dict_t *options); + +#endif /* RPC_DRC_H */ diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c index b97ba61bf..c24d41084 100644 --- a/rpc/rpc-lib/src/rpc-transport.c +++ b/rpc/rpc-lib/src/rpc-transport.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 <dlfcn.h> @@ -78,6 +69,19 @@ out: return ret; } +int +rpc_transport_throttle (rpc_transport_t *this, gf_boolean_t onoff) +{ + int ret = 0; + + if (!this->ops->throttle) + return -ENOSYS; + + ret = this->ops->throttle (this, onoff); + + return ret; +} + int32_t rpc_transport_get_peeraddr (rpc_transport_t *this, char *peeraddr, int addrlen, struct sockaddr_storage *sa, size_t salen) @@ -154,6 +158,7 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) 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; + xlator_t *this = NULL; GF_VALIDATE_OR_GOTO("rpc-transport", options, fail); GF_VALIDATE_OR_GOTO("rpc-transport", ctx, fail); @@ -178,7 +183,7 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) gf_log ("dict", GF_LOG_DEBUG, "setting transport-type failed"); else - gf_log ("rpc-transport", GF_LOG_WARNING, + gf_log ("rpc-transport", GF_LOG_DEBUG, "missing 'option transport-type'. defaulting to " "\"socket\""); } else { @@ -259,13 +264,15 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_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, + 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, @@ -273,22 +280,22 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) goto fail; } - trans->init = dlsym (handle, "init"); + *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; } - trans->fini = dlsym (handle, "fini"); + *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; } - trans->reconfigure = dlsym (handle, "reconfigure"); - if (trans->fini == NULL) { + *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()); } @@ -299,14 +306,15 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) 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, + 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"); @@ -317,7 +325,7 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) trans->options = options; pthread_mutex_init (&trans->lock, NULL); - trans->xl = THIS; + trans->xl = this; ret = trans->init (trans); if (ret != 0) { @@ -326,25 +334,27 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) goto fail; } - return_trans = trans; + return_trans = trans; - if (name) { - GF_FREE (name); - } + GF_FREE (name); return return_trans; fail: if (trans) { - if (trans->name) { - GF_FREE (trans->name); - } + GF_FREE (trans->name); + + if (trans->dl_handle) + dlclose (trans->dl_handle); GF_FREE (trans); } - if (name) { - GF_FREE (name); + GF_FREE (name); + + if (vol_opt && !list_empty (&vol_opt->list)) { + list_del_init (&vol_opt->list); + GF_FREE (vol_opt); } return NULL; @@ -432,8 +442,10 @@ rpc_transport_destroy (rpc_transport_t *this) pthread_mutex_destroy (&this->lock); - if (this->name) - GF_FREE (this->name); + GF_FREE (this->name); + + if (this->dl_handle) + dlclose (this->dl_handle); GF_FREE (this); fail: @@ -470,7 +482,7 @@ rpc_transport_unref (rpc_transport_t *this) pthread_mutex_lock (&this->lock); { - refcount = --this->refcount; + refcount = --this->refcount; } pthread_mutex_unlock (&this->lock); @@ -478,7 +490,9 @@ rpc_transport_unref (rpc_transport_t *this) if (this->mydata) this->notify (this, this->mydata, RPC_TRANSPORT_CLEANUP, NULL); - rpc_transport_destroy (this); + this->mydata = NULL; + this->notify = NULL; + rpc_transport_destroy (this); } ret = 0; @@ -520,6 +534,8 @@ out: 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. @@ -546,6 +562,63 @@ out: } int +rpc_transport_unix_options_build (dict_t **options, char *filepath, + int frame_timeout) +{ + dict_t *dict = NULL; + char *fpath = NULL; + int ret = -1; + + GF_ASSERT (filepath); + GF_ASSERT (options); + + dict = dict_new (); + if (!dict) + goto out; + + fpath = gf_strdup (filepath); + if (!fpath) { + ret = -1; + goto out; + } + + ret = dict_set_dynstr (dict, "transport.socket.connect-path", fpath); + if (ret) + goto out; + + ret = dict_set_str (dict, "transport.address-family", "unix"); + if (ret) + goto out; + + 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; + + ret = dict_set_str (dict, "transport.socket.keepalive", "off"); + if (ret) + goto out; + + if (frame_timeout > 0) { + ret = dict_set_int32 (dict, "frame-timeout", frame_timeout); + if (ret) + goto out; + } + + *options = dict; +out: + if (ret) { + GF_FREE (fpath); + if (dict) + dict_unref (dict); + } + return ret; +} + +int rpc_transport_inet_options_build (dict_t **options, const char *hostname, int port) { @@ -580,7 +653,7 @@ rpc_transport_inet_options_build (dict_t **options, const char *hostname, "failed to set remote-port with %d", port); goto out; } - ret = dict_set_str (dict, "transport.address-family", "inet/inet6"); + ret = dict_set_str (dict, "transport.address-family", "inet"); if (ret) { gf_log (THIS->name, GF_LOG_WARNING, "failed to set addr-family with inet"); @@ -597,8 +670,7 @@ rpc_transport_inet_options_build (dict_t **options, const char *hostname, *options = dict; out: if (ret) { - if (host) - GF_FREE (host); + GF_FREE (host); if (dict) dict_unref (dict); } diff --git a/rpc/rpc-lib/src/rpc-transport.h b/rpc/rpc-lib/src/rpc-transport.h index e3fb17128..2db9072ae 100644 --- a/rpc/rpc-lib/src/rpc-transport.h +++ b/rpc/rpc-lib/src/rpc-transport.h @@ -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. */ #ifndef __RPC_TRANSPORT_H__ @@ -45,10 +36,10 @@ #endif /* AI_ADDRCONFIG */ /* Given the 4-byte fragment header, returns non-zero if this fragment - * is the last fragment for the RPC record being assemebled. + * is the last fragment for the RPC record being assembled. * RPC Record marking standard defines a 32 bit value as the fragment * header with the MSB signifying whether the fragment is the last - * fragment for the record being asembled. + * fragment for the record being assembled. */ #define RPC_LASTFRAG(fraghdr) ((uint32_t)(fraghdr & 0x80000000U)) @@ -77,9 +68,14 @@ typedef struct rpc_transport rpc_transport_t; #include "rpcsvc-common.h" struct peer_info { - struct sockaddr_storage sockaddr; - socklen_t sockaddr_len; - char identifier[UNIX_PATH_MAX]; + 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; + //Volume mounted by client + char volname[1024]; }; typedef struct peer_info peer_info_t; @@ -182,38 +178,42 @@ typedef int (*rpc_transport_notify_t) (rpc_transport_t *, void *mydata, struct rpc_transport { - struct rpc_transport_ops *ops; + 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 *private; + struct _client_t *xl_private; void *xl; /* Used for THIS */ - void *mydata; - pthread_mutex_t lock; - int32_t refcount; + void *mydata; + pthread_mutex_t lock; + int32_t refcount; + + int32_t outstanding_rpc_count; 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); + 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; + 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; + void *dl_handle; /* handle of dlopen() */ }; struct rpc_transport_ops { @@ -224,9 +224,9 @@ struct rpc_transport_ops { 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 (*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, @@ -237,6 +237,7 @@ struct rpc_transport_ops { 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); }; @@ -290,6 +291,9 @@ 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, @@ -302,5 +306,9 @@ rpc_transport_keepalive_options_set (dict_t *options, int32_t interval, int32_t time); int +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); #endif /* __RPC_TRANSPORT_H__ */ diff --git a/rpc/rpc-lib/src/rpcsvc-auth.c b/rpc/rpc-lib/src/rpcsvc-auth.c index d62bd100b..4cb86a758 100644 --- a/rpc/rpc-lib/src/rpcsvc-auth.c +++ b/rpc/rpc-lib/src/rpcsvc-auth.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 "rpcsvc.h" @@ -29,6 +20,8 @@ rpcsvc_auth_unix_init (rpcsvc_t *svc, dict_t *options); extern rpcsvc_auth_t * 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); int rpcsvc_auth_add_initer (struct list_head *list, char *idfier, @@ -66,6 +59,16 @@ rpcsvc_auth_add_initers (rpcsvc_t *svc) 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-unix", (rpcsvc_auth_initer_t) rpcsvc_auth_unix_init); @@ -175,6 +178,29 @@ err: } int +rpcsvc_set_addr_namelookup (rpcsvc_t *svc, dict_t *options) +{ + int ret; + static char *addrlookup_key = "rpc-auth.addr.namelookup"; + + if (!svc || !options) + return (-1); + + /* 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; + } + + 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) { int ret = -1; @@ -201,6 +227,26 @@ rpcsvc_set_allow_insecure (rpcsvc_t *svc, dict_t *options) } int +rpcsvc_set_root_squash (rpcsvc_t *svc, dict_t *options) +{ + int ret = -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; + + if (svc->root_squash) + gf_log (GF_RPCSVC, GF_LOG_DEBUG, "root squashing enabled "); + + return 0; +} + +int rpcsvc_auth_init (rpcsvc_t *svc, dict_t *options) { int ret = -1; @@ -209,6 +255,8 @@ rpcsvc_auth_init (rpcsvc_t *svc, dict_t *options) return -1; (void) rpcsvc_set_allow_insecure (svc, options); + (void) rpcsvc_set_root_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"); @@ -225,6 +273,25 @@ out: return ret; } +int +rpcsvc_auth_reconf (rpcsvc_t *svc, dict_t *options) +{ + int ret = 0; + + if ((!svc) || (!options)) + return (-1); + + ret = rpcsvc_set_allow_insecure (svc, options); + if (ret) + return (-1); + + ret = rpcsvc_set_root_squash (svc, options); + if (ret) + return (-1); + + return rpcsvc_set_addr_namelookup (svc, options); +} + rpcsvc_auth_t * __rpcsvc_auth_get_handler (rpcsvc_request_t *req) @@ -303,6 +370,9 @@ rpcsvc_auth_request_init (rpcsvc_request_t *req) if (!auth->authops->request_init) ret = auth->authops->request_init (req, auth->authprivate); + req->auxgids = req->auxgidsmall; /* reset to auxgidlarge during + unsersialize if necessary */ + req->auxgidlarge = NULL; err: return ret; } @@ -342,14 +412,10 @@ err: int 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; + 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; @@ -367,59 +433,27 @@ rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen) if (count >= arrlen) break; - gen = gf_asprintf (&srchstr, "rpc-auth.%s", auth->name); - if (gen == -1) { + result = gf_asprintf (&srchstr, "rpc-auth.%s.%s", + auth->name, volname); + if (result == -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"); - } - + ret = dict_get_str_boolean (svc->options, srchstr, 0xC00FFEE); 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) { + switch (ret) { + case _gf_true: + result = RPCSVC_AUTH_ACCEPT; autharr[count] = auth->auth->authnum; ++count; + break; + case _gf_false: + result = RPCSVC_AUTH_REJECT; + break; + default: + result = RPCSVC_AUTH_DONTCARE; } } @@ -434,8 +468,12 @@ rpcsvc_auth_unix_auxgids (rpcsvc_request_t *req, int *arrlen) return NULL; /* In case of AUTH_NULL auxgids are not used */ - if ((req->cred.flavour != AUTH_UNIX) && - (req->cred.flavour != AUTH_GLUSTERFS)) { + switch (req->cred.flavour) { + case AUTH_UNIX: + case AUTH_GLUSTERFS: + case AUTH_GLUSTERFS_v2: + break; + default: gf_log ("rpc", GF_LOG_DEBUG, "auth type not unix or glusterfs"); return NULL; } diff --git a/rpc/rpc-lib/src/rpcsvc-common.h b/rpc/rpc-lib/src/rpcsvc-common.h index b03776dee..aed55e039 100644 --- a/rpc/rpc-lib/src/rpcsvc-common.h +++ b/rpc/rpc-lib/src/rpcsvc-common.h @@ -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. */ #ifndef _RPCSVC_COMMON_H @@ -39,6 +30,8 @@ struct rpcsvc_state; 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. */ @@ -59,24 +52,75 @@ typedef struct rpcsvc_state { dict_t *options; /* Allow insecure ports. */ - int allow_insecure; + gf_boolean_t allow_insecure; gf_boolean_t register_portmap; + gf_boolean_t root_squash; glusterfs_ctx_t *ctx; /* list of connections which will listen for incoming connections */ - struct list_head listeners; + struct list_head listeners; /* list of programs registered with rpcsvc */ - struct list_head programs; + struct list_head programs; /* list of notification callbacks */ - struct list_head notify; - int notify_count; + struct list_head notify; + int notify_count; void *mydata; /* This is xlator */ - rpcsvc_notify_t notifyfn; + 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; } rpcsvc_t; +/* 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; + +enum drc_type { + DRC_TYPE_NONE = 0, + DRC_TYPE_IN_MEMORY = 1 +}; +typedef enum drc_type drc_type_t; + +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; + +enum drc_xid_state { + DRC_XID_MONOTONOUS = 0, + DRC_XID_WRAPPED = 1 +}; +typedef enum drc_xid_state drc_xid_state_t; + +enum drc_op_state { + DRC_OP_IN_TRANSIT = 0, + DRC_OP_CACHED = 1 +}; +typedef enum drc_op_state drc_op_state_t; + +enum drc_policy { + DRC_LRU = 0 +}; +typedef enum drc_policy drc_policy_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 125d52fc7..037c157f2 100644 --- a/rpc/rpc-lib/src/rpcsvc.c +++ b/rpc/rpc-lib/src/rpcsvc.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. */ #ifndef _CONFIG_H @@ -34,6 +25,10 @@ #include "iobuf.h" #include "globals.h" #include "xdr-common.h" +#include "xdr-generic.h" +#include "rpc-common-xdr.h" +#include "syncop.h" +#include "rpc-drc.h" #include <errno.h> #include <pthread.h> @@ -47,6 +42,7 @@ #include <stdio.h> #include "xdr-rpcclnt.h" +#include "glusterfs-acl.h" struct rpcsvc_program gluster_dump_prog; @@ -133,6 +129,37 @@ rpcsvc_get_program_vector_sizer (rpcsvc_t *svc, uint32_t prognum, return NULL; } +int +rpcsvc_request_outstanding (rpcsvc_t *svc, rpc_transport_t *trans, int delta) +{ + int ret = 0; + int old_count = 0; + int new_count = 0; + int limit = 0; + + pthread_mutex_lock (&trans->lock); + { + limit = svc->outstanding_rpc_limit; + if (!limit) + goto unlock; + + old_count = trans->outstanding_rpc_count; + trans->outstanding_rpc_count += delta; + new_count = trans->outstanding_rpc_count; + + if (old_count <= limit && new_count > limit) + ret = rpc_transport_throttle (trans, _gf_true); + + if (old_count > limit && new_count <= limit) + ret = rpc_transport_throttle (trans, _gf_false); + } +unlock: + pthread_mutex_unlock (&trans->lock); + + 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. @@ -168,7 +195,11 @@ rpcsvc_program_actor (rpcsvc_request_t *req) if (!found) { if (err != PROG_MISMATCH) { - gf_log (GF_RPCSVC, GF_LOG_WARNING, + /* 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)", req->prognum, req->progver); err = PROG_UNAVAIL; @@ -207,6 +238,8 @@ rpcsvc_program_actor (rpcsvc_request_t *req) goto err; } + req->synctask = program->synctask; + err = SUCCESS; gf_log (GF_RPCSVC, GF_LOG_TRACE, "Actor found: %s - %s", program->progname, actor->procname); @@ -221,7 +254,7 @@ err: /* this procedure can only pass 4 arguments to registered notifyfn. To send more * arguments call wrapper->notify directly. */ -inline void +static inline void rpcsvc_program_notify (rpcsvc_listener_t *listener, rpcsvc_event_t event, void *data) { @@ -244,7 +277,7 @@ out: } -inline int +static inline int rpcsvc_accept (rpcsvc_t *svc, rpc_transport_t *listen_trans, rpc_transport_t *new_trans) { @@ -274,8 +307,20 @@ rpcsvc_request_destroy (rpcsvc_request_t *req) iobref_unref (req->iobref); } + if (req->hdr_iobuf) + iobuf_unref (req->hdr_iobuf); + + /* 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. + */ + rpcsvc_request_outstanding (req->svc, req->trans, -1); + rpc_transport_unref (req->trans); + GF_FREE (req->auxgidlarge); + mem_put (req); out: @@ -305,7 +350,9 @@ rpcsvc_request_init (rpcsvc_t *svc, rpc_transport_t *trans, req->msg[0] = progmsg; req->iobref = iobref_ref (msg->iobref); if (msg->vectored) { - for (i = 1; i < msg->count; i++) { + /* msg->vector[2] is defined in structure. prevent a + out of bound access */ + for (i = 1; i < min (msg->count, 2); i++) { req->msg[i] = msg->vector[i]; } } @@ -356,6 +403,12 @@ rpcsvc_request_create (rpcsvc_t *svc, rpc_transport_t *trans, goto err; } + /* 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. + */ + ret = rpcsvc_request_outstanding (svc, trans, +1); + msgbuf = msg->vector[0].iov_base; msglen = msg->vector[0].iov_len; @@ -415,6 +468,7 @@ rpcsvc_request_create (rpcsvc_t *svc, rpc_transport_t *trans, * since we are not handling authentication failures for now. */ req->rpc_status = MSG_ACCEPTED; + req->reply = NULL; ret = 0; err: if (ret == -1) { @@ -430,14 +484,39 @@ err: int +rpcsvc_check_and_reply_error (int ret, call_frame_t *frame, void *opaque) +{ + rpcsvc_request_t *req = NULL; + + req = opaque; + + if (ret) + gf_log ("rpcsvc", GF_LOG_ERROR, + "rpc actor failed to complete successfully"); + + if (ret == RPCSVC_ACTOR_ERROR) { + ret = rpcsvc_error_reply (req); + if (ret) + gf_log ("rpcsvc", GF_LOG_WARNING, + "failed to queue error reply"); + } + + return 0; +} + +int rpcsvc_handle_rpc_call (rpcsvc_t *svc, rpc_transport_t *trans, rpc_transport_pollin_t *msg) { - rpcsvc_actor_t *actor = NULL; - rpcsvc_request_t *req = NULL; - int ret = -1; - uint16_t port = 0; - gf_boolean_t is_unix = _gf_false; + 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; + gf_boolean_t unprivileged = _gf_false; + drc_cached_op_t *reply = NULL; + rpcsvc_drc_globals_t *drc = NULL; if (!trans || !svc) return -1; @@ -467,18 +546,13 @@ rpcsvc_handle_rpc_call (rpcsvc_t *svc, rpc_transport_t *trans, gf_log ("rpcsvc", GF_LOG_TRACE, "Client port: %d", (int)port); - if ((port > 1024) && (0 == svc->allow_insecure)) { - /* Non-privileged user, fail request */ - gf_log ("glusterd", GF_LOG_ERROR, - "Request received from non-" - "privileged port. Failing request"); - return -1; - } + if (port > 1024) + unprivileged = _gf_true; } req = rpcsvc_request_create (svc, trans, msg); if (!req) - goto err; + goto out; if (!rpcsvc_request_accepted (req)) goto err_reply; @@ -487,40 +561,85 @@ rpcsvc_handle_rpc_call (rpcsvc_t *svc, rpc_transport_t *trans, if (!actor) goto err_reply; - if (actor && (req->rpc_err == SUCCESS)) { + 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; + } + + /* DRC */ + if (rpcsvc_need_drc (req)) { + drc = req->svc->drc; + + 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; + + } /* 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; + + } /* 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->mydata; - if (req->count == 2) { - if (actor->vector_actor) { - ret = actor->vector_actor (req, &req->msg[1], 1, - req->iobref); - } 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; - } - } else if (actor->actor) { - ret = actor->actor (req); + 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; } - } -err_reply: - if (ret == RPCSVC_ACTOR_ERROR) { - ret = rpcsvc_error_reply (req); + if (req->synctask) { + if (msg->hdr_iobuf) + req->hdr_iobuf = iobuf_ref (msg->hdr_iobuf); + + ret = synctask_new (THIS->ctx->env, + (synctask_fn_t) actor_fn, + rpcsvc_check_and_reply_error, NULL, + req); + } else { + ret = actor_fn (req); + } } - if (ret) - gf_log ("rpcsvc", GF_LOG_WARNING, "failed to queue error reply"); +err_reply: + 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: +out: return ret; } @@ -538,6 +657,9 @@ rpcsvc_handle_disconnect (rpcsvc_t *svc, rpc_transport_t *trans) pthread_mutex_lock (&svc->rpclock); { + if (!svc->notify_count) + goto unlock; + wrappers = GF_CALLOC (svc->notify_count, sizeof (*wrapper), gf_common_mt_rpcsvc_wrapper_t); if (!wrappers) { @@ -678,7 +800,7 @@ err: return txrecord; } -inline int +static inline int rpcsvc_get_callid (rpcsvc_t *rpc) { return GF_UNIVERSAL_ANSWER; @@ -761,16 +883,28 @@ rpcsvc_callback_build_record (rpcsvc_t *rpc, int prognum, int progver, 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 (%"PRIu64")", xid); + 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); + 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; } @@ -779,15 +913,6 @@ rpcsvc_callback_build_record (rpcsvc_t *rpc, int prognum, int progver, record = iobuf_ptr (request_iob); /* Now we have it. */ - /* 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; - } - recordhdr = rpcsvc_callback_build_header (record, pagesize, &request, payload); @@ -861,21 +986,22 @@ out: 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)) { + if ((!trans) || (!rpchdr) || (!rpchdr->iov_base)) { goto out; } - reply.msg.rpchdr = hdrvec; - reply.msg.rpchdrcount = hdrcount; + reply.msg.rpchdr = rpchdr; + reply.msg.rpchdrcount = rpchdrcount; reply.msg.proghdr = proghdr; reply.msg.proghdrcount = proghdrcount; reply.msg.progpayload = progpayload; @@ -931,13 +1057,14 @@ out: */ struct iobuf * rpcsvc_record_build_record (rpcsvc_request_t *req, size_t payload, - struct iovec *recbuf) + 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; @@ -945,19 +1072,25 @@ rpcsvc_record_build_record (rpcsvc_request_t *req, size_t payload, 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; + 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) { @@ -1012,7 +1145,9 @@ rpcsvc_submit_generic (rpcsvc_request_t *req, struct iovec *proghdr, 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; if ((!req) || (!req->trans)) return -1; @@ -1030,7 +1165,7 @@ rpcsvc_submit_generic (rpcsvc_request_t *req, struct iovec *proghdr, 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); + 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; @@ -1047,20 +1182,31 @@ rpcsvc_submit_generic (rpcsvc_request_t *req, struct iovec *proghdr, iobref_add (iobref, replyiob); + /* cache the request in the duplicate request cache for appropriate ops */ + if (req->reply) { + drc = req->svc->drc; + + LOCK (&drc->lock); + ret = rpcsvc_cache_reply (req, iobref, &recordhdr, 1, + proghdr, hdrcount, + payload, payloadcount); + UNLOCK (&drc->lock); + } + 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%ux, Program: %s, ProgVers: %d, Proc: %d) to " + "(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->name); } else { gf_log (GF_RPCSVC, GF_LOG_TRACE, - "submitted reply for rpc-message (XID: 0x%ux, " + "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, @@ -1090,7 +1236,7 @@ rpcsvc_error_reply (rpcsvc_request_t *req) 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. @@ -1103,12 +1249,13 @@ rpcsvc_error_reply (rpcsvc_request_t *req) inline int rpcsvc_program_register_portmap (rpcsvc_program_t *newprog, uint32_t port) { - int ret = 0; + 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" @@ -1116,7 +1263,7 @@ rpcsvc_program_register_portmap (rpcsvc_program_t *newprog, uint32_t port) goto out; } - ret = 0; + ret = 0; /* SUCCESS */ out: return ret; } @@ -1125,7 +1272,7 @@ out: inline int rpcsvc_program_unregister_portmap (rpcsvc_program_t *prog) { - int ret = 0; + int ret = -1; if (!prog) goto out; @@ -1247,28 +1394,44 @@ rpcsvc_submit_message (rpcsvc_request_t *req, struct iovec *proghdr, 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) { + rpcsvc_program_t *prog = NULL; + if (!svc || !program) { goto out; } - ret = rpcsvc_program_unregister_portmap (prog); + ret = rpcsvc_program_unregister_portmap (program); if (ret == -1) { gf_log (GF_RPCSVC, GF_LOG_ERROR, "portmap unregistration of" " program failed"); goto out; } + pthread_mutex_lock (&svc->rpclock); + { + list_for_each_entry (prog, &svc->programs, program) { + if ((prog->prognum == program->prognum) + && (prog->progver == program->progver)) { + break; + } + } + } + pthread_mutex_unlock (&svc->rpclock); + + if (prog == NULL) { + ret = -1; + 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); { - list_del (&prog->program); + list_del_init (&prog->program); } pthread_mutex_unlock (&svc->rpclock); @@ -1276,8 +1439,8 @@ rpcsvc_program_unregister (rpcsvc_t *svc, rpcsvc_program_t *prog) 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); + ": %s, Num: %d, Ver: %d, Port: %d", program->progname, + program->prognum, program->progver, program->progport); } return ret; @@ -1466,6 +1629,7 @@ rpcsvc_create_listeners (rpcsvc_t *svc, dict_t *options, char *name) } GF_FREE (transport_name); + transport_name = NULL; count++; } @@ -1477,17 +1641,13 @@ rpcsvc_create_listeners (rpcsvc_t *svc, dict_t *options, char *name) 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); return count; } @@ -1664,15 +1824,17 @@ rpcsvc_dump (rpcsvc_request_t *req) uint32_t dump_rsp_len = 0; if (!req) - goto fail; + goto sendrsp; ret = build_prog_details (req, &rsp); if (ret < 0) { op_errno = -ret; - goto fail; + goto sendrsp; } -fail: + op_errno = 0; + +sendrsp: rsp.op_errno = gf_errno_to_error (op_errno); rsp.op_ret = ret; @@ -1682,17 +1844,14 @@ fail: iov.iov_base = rsp_buf; iov.iov_len = dump_rsp_len; - ret = xdr_serialize_dump_rsp (iov, &rsp); + ret = xdr_serialize_generic (iov, &rsp, (xdrproc_t)xdr_gf_dump_rsp); if (ret < 0) { - if (req) - req->rpc_err = GARBAGE_ARGS; - op_errno = EINVAL; - goto fail; + ret = RPCSVC_ACTOR_ERROR; + } else { + rpcsvc_submit_generic (req, &iov, 1, NULL, 0, NULL); + ret = 0; } - ret = rpcsvc_submit_generic (req, &iov, 1, NULL, 0, - NULL); - free_prog_details (&rsp); return ret; @@ -1731,12 +1890,92 @@ rpcsvc_init_options (rpcsvc_t *svc, dict_t *options) gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Portmap registration " "disabled"); - ret = 0; + ret = rpcsvc_set_outstanding_rpc_limit (svc, options); out: return ret; } 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 = (xlator_t *) svc->mydata; + 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); + } + + /* If found the srchkey, delete old key/val pair + * and set the key with new value. + */ + if (!dict_get_str (options, srchkey, &keyval)) { + dict_del (svc->options, srchkey); + ret = dict_set_str (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); + } + + /* If found the srchkey, delete old key/val pair + * and set the key with new value. + */ + if (!dict_get_str (options, srchkey, &keyval)) { + dict_del (svc->options, srchkey); + ret = dict_set_str (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_transport_unix_options_build (dict_t **options, char *filepath) { dict_t *dict = NULL; @@ -1775,21 +2014,63 @@ rpcsvc_transport_unix_options_build (dict_t **options, char *filepath) *options = dict; out: if (ret) { - if (fpath) - GF_FREE (fpath); + GF_FREE (fpath); if (dict) dict_unref (dict); } return ret; } +/* + * Reconfigure() the rpc.outstanding-rpc-limit param. + */ +int +rpcsvc_set_outstanding_rpc_limit (rpcsvc_t *svc, dict_t *options) +{ + int ret = -1; /* FAILURE */ + int rpclim = 0; + static char *rpclimkey = "rpc.outstanding-rpc-limit"; + + if ((!svc) || (!options)) + return (-1); + + /* Reconfigure() the rpc.outstanding-rpc-limit param */ + ret = dict_get_int32 (options, rpclimkey, &rpclim); + if (ret < 0) { + /* Fall back to default for FAILURE */ + rpclim = RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT; + } else { + /* SUCCESS: round off to multiple of 8. + * If the input value fails Boundary check, fall back to + * default i.e. RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT. + * NB: value 0 is special, means its unset i.e. unlimited. + */ + rpclim = ((rpclim + 8 - 1) >> 3) * 8; + if (rpclim < RPCSVC_MIN_OUTSTANDING_RPC_LIMIT) { + rpclim = RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT; + } else 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); +} + /* The global RPC service initializer. */ 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) { rpcsvc_t *svc = NULL; - int ret = -1, poolcount = 0; + int ret = -1; if ((!ctx) || (!options)) return NULL; @@ -1810,7 +2091,8 @@ rpcsvc_init (xlator_t *xl, glusterfs_ctx_t *ctx, dict_t *options) goto free_svc; } - poolcount = RPCSVC_POOLCOUNT_MULT * svc->memfactor; + 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); @@ -1841,6 +2123,7 @@ rpcsvc_init (xlator_t *xl, glusterfs_ctx_t *ctx, dict_t *options) "failed to register DUMP program"); goto free_svc; } + ret = 0; free_svc: if (ret == -1) { @@ -1853,17 +2136,16 @@ free_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)) + if ((!options) || (!ip)) return -1; ret = dict_get_str (options, pattern, &addrstr); @@ -1877,88 +2159,91 @@ rpcsvc_transport_peer_check_search (dict_t *options, char *pattern, char *clstr) goto err; } - addrtok = strtok_r (addrstr, ",", &svptr); + dup_addrstr = gf_strdup (addrstr); + addrtok = strtok_r (dup_addrstr, ",", &svptr); while (addrtok) { /* CASEFOLD not present on Solaris */ #ifdef FNM_CASEFOLD - ret = fnmatch (addrtok, clstr, FNM_CASEFOLD); + ret = fnmatch (addrtok, ip, FNM_CASEFOLD); #else - ret = fnmatch (addrtok, clstr, 0); + ret = fnmatch (addrtok, ip, 0); #endif if (ret == 0) goto err; + /* compare hostnames if applicable */ + if (hostname) { +#ifdef FNM_CASEFOLD + ret = fnmatch (addrtok, hostname, FNM_CASEFOLD); +#else + ret = fnmatch (addrtok, hostname, 0); +#endif + if (ret == 0) + goto err; + } + addrtok = strtok_r (NULL, ",", &svptr); } ret = -1; err: + GF_FREE (dup_addrstr); 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; + int ret = RPCSVC_AUTH_DONTCARE; char *srchstr = NULL; - char globalrule[] = "rpc-auth.addr.allow"; - if ((!options) || (!clstr)) + 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; + ret = RPCSVC_AUTH_REJECT; out: return ret; } -int -rpcsvc_transport_peer_check_reject (dict_t *options, char *volname, char *clstr) +static int +rpcsvc_transport_peer_check_reject (dict_t *options, char *volname, + char *ip, char *hostname) { - int ret = RPCSVC_AUTH_DONTCARE; + int ret = RPCSVC_AUTH_DONTCARE; char *srchstr = NULL; - char generalrule[] = "rpc-auth.addr.reject"; - if ((!options) || (!clstr)) + if ((!options) || (!ip) || (!volname)) 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 = 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; + } - 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_REJECT; @@ -1969,313 +2254,132 @@ out: } -/* 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 | +/* 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_allow_reject_volume_check (int allow, int reject) { - int final = RPCSVC_AUTH_REJECT; - - /* 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; - - return final; -} - - -/* 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 | - */ -int -rpcsvc_combine_gen_spec_addr_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; - 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; - - return final; -} - + if (allow == RPCSVC_AUTH_REJECT || + reject == RPCSVC_AUTH_REJECT) + return RPCSVC_AUTH_REJECT; + if (allow == RPCSVC_AUTH_ACCEPT || + reject == RPCSVC_AUTH_ACCEPT) + return RPCSVC_AUTH_ACCEPT; -/* 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; + return RPCSVC_AUTH_DONTCARE; } - int -rpcsvc_transport_peer_check_name (dict_t *options, char *volname, - rpc_transport_t *trans) +rpcsvc_auth_check (rpcsvc_t *svc, char *volname, + rpc_transport_t *trans) { - int ret = RPCSVC_AUTH_REJECT; - int aret = RPCSVC_AUTH_REJECT; - int rjret = RPCSVC_AUTH_REJECT; - char clstr[RPCSVC_PEER_STRLEN]; - - if (!trans) + int ret = RPCSVC_AUTH_REJECT; + int accept = RPCSVC_AUTH_REJECT; + int reject = RPCSVC_AUTH_REJECT; + char *hostname = NULL; + char *ip = NULL; + char client_ip[RPCSVC_PEER_STRLEN] = {0}; + char *allow_str = NULL; + char *reject_str = NULL; + char *srchstr = NULL; + dict_t *options = NULL; + + if (!svc || !volname || !trans) 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; - } - - 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: - return ret; -} - - -int -rpcsvc_transport_peer_check_addr (dict_t *options, char *volname, - rpc_transport_t *trans) -{ - 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) + /* Fetch the options from svc struct and validate */ + options = svc->options; + if (!options) return ret; - ret = rpcsvc_transport_peeraddr (trans, clstr, RPCSVC_PEER_STRLEN, - &sastorage, sizeof (sastorage)); + ret = rpcsvc_transport_peername (trans, client_ip, 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; - } - - 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: - return ret; -} - - -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. + /* 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. */ - 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; - - return ret; -} - - -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)) + 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; - - /* 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, NULL, trans); - addrchk = rpcsvc_transport_peer_check_addr (options, NULL, trans); - - if (namelookup) - ret = rpcsvc_combine_gen_spec_addr_checks (addrchk, - namechk); - else - ret = addrchk; + ret = dict_get_str (options, srchstr, &allow_str); + GF_FREE (srchstr); + if (ret < 0) + return RPCSVC_AUTH_REJECT; - return ret; -} + 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; + } -int -rpcsvc_transport_peer_check (dict_t *options, char *volname, - rpc_transport_t *trans) -{ - int general_chk = RPCSVC_AUTH_REJECT; - int specific_chk = RPCSVC_AUTH_REJECT; + ret = dict_get_str (options, srchstr, &reject_str); + GF_FREE (srchstr); + if (reject_str == NULL && !strcmp ("*", allow_str)) + return RPCSVC_AUTH_ACCEPT; + + /* Non-default rule, authenticate */ + if (!get_host_name (client_ip, &ip)) + ip = client_ip; + + /* addr-namelookup check */ + if (svc->addr_namelookup == _gf_true) { + ret = gf_get_hostname_from_ip (ip, &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; + } + } - if ((!options) || (!volname) || (!trans)) - return RPCSVC_AUTH_REJECT; + accept = rpcsvc_transport_peer_check_allow (options, volname, + ip, hostname); - general_chk = rpcsvc_transport_check_volume_general (options, trans); - specific_chk = rpcsvc_transport_check_volume_specific (options, volname, - trans); + reject = rpcsvc_transport_peer_check_reject (options, volname, + ip, hostname); - return rpcsvc_combine_gen_spec_volume_checks (general_chk, - specific_chk); + if (hostname) + GF_FREE (hostname); + return rpcsvc_combine_allow_reject_volume_check (accept, reject); } - int rpcsvc_transport_privport_check (rpcsvc_t *svc, char *volname, rpc_transport_t *trans) { - struct sockaddr_storage sastorage = {0,}; - struct sockaddr_in *sa = NULL; + union gf_sock_union sock_union; int ret = RPCSVC_AUTH_REJECT; - socklen_t sasize = sizeof (sa); + socklen_t sinsize = sizeof (&sock_union.sin); 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; + memset (&sock_union, 0, sizeof (sock_union)); + if ((!svc) || (!volname) || (!trans)) return ret; - sa = (struct sockaddr_in*) &sastorage; - ret = rpcsvc_transport_peeraddr (trans, NULL, 0, &sastorage, - sasize); + ret = rpcsvc_transport_peeraddr (trans, NULL, 0, &sock_union.storage, + sinsize); if (ret != 0) { gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get peer addr: %s", gai_strerror (ret)); @@ -2283,7 +2387,7 @@ rpcsvc_transport_privport_check (rpcsvc_t *svc, char *volname, goto err; } - port = ntohs (sa->sin_port); + port = ntohs (sock_union.sin.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. @@ -2294,23 +2398,6 @@ rpcsvc_transport_privport_check (rpcsvc_t *svc, char *volname, } /* 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"); - } - - /* 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"); @@ -2318,25 +2405,22 @@ rpcsvc_transport_privport_check (rpcsvc_t *svc, char *volname, 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); + 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 @@ -2344,6 +2428,9 @@ rpcsvc_transport_privport_check (rpcsvc_t *svc, char *volname, " allowed"); err: + if (srchstr) + GF_FREE (srchstr); + return ret; } @@ -2365,22 +2452,22 @@ rpcsvc_volume_allowed (dict_t *options, char *volname) goto out; } - if (!dict_get (options, srchstr)) { - GF_FREE (srchstr); - srchstr = globalrule; - ret = dict_get_str (options, srchstr, &addrstr); - } else + if (!dict_get (options, srchstr)) + ret = dict_get_str (options, globalrule, &addrstr); + else ret = dict_get_str (options, srchstr, &addrstr); out: + GF_FREE (srchstr); + return addrstr; } rpcsvc_actor_t gluster_dump_actors[] = { - [GF_DUMP_NULL] = {"NULL", GF_DUMP_NULL, NULL, NULL, NULL }, - [GF_DUMP_DUMP] = {"DUMP", GF_DUMP_DUMP, rpcsvc_dump, NULL, NULL }, - [GF_DUMP_MAXVALUE] = {"MAXVALUE", GF_DUMP_MAXVALUE, NULL, NULL, NULL }, + [GF_DUMP_NULL] = {"NULL", GF_DUMP_NULL, NULL, NULL, 0, DRC_NA}, + [GF_DUMP_DUMP] = {"DUMP", GF_DUMP_DUMP, rpcsvc_dump, NULL, 0, DRC_NA}, + [GF_DUMP_MAXVALUE] = {"MAXVALUE", GF_DUMP_MAXVALUE, NULL, NULL, 0, DRC_NA}, }; diff --git a/rpc/rpc-lib/src/rpcsvc.h b/rpc/rpc-lib/src/rpcsvc.h index c6f432544..cbc1f4226 100644 --- a/rpc/rpc-lib/src/rpcsvc.h +++ b/rpc/rpc-lib/src/rpcsvc.h @@ -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. */ #ifndef _RPCSVC_H @@ -43,24 +34,28 @@ #include <rpc/rpc_msg.h> #include "compat.h" -#ifndef NGRPS -#define NGRPS 16 -#endif /* !NGRPS */ - #ifndef MAX_IOVEC #define MAX_IOVEC 16 #endif +#define RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT 64 +#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_DEFAULT_MEMFACTOR 8 #define RPCSVC_EVENTPOOL_SIZE_MULT 1024 -#define RPCSVC_POOLCOUNT_MULT 35 +#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 @@ -115,8 +110,6 @@ #define AUTH_KERB 4 /* kerberos style */ #endif /* */ -#define AUTH_GLUSTERFS 5 - typedef struct rpcsvc_program rpcsvc_program_t; struct rpcsvc_notify_wrapper { @@ -143,15 +136,17 @@ struct rpcsvc_config { 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]; + char authdata[GF_MAX_AUTH_BYTES]; } rpcsvc_auth_data_t; #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. @@ -184,13 +179,15 @@ struct rpcsvc_request { gid_t gid; pid_t pid; - uint64_t lk_owner; + gf_lkowner_t lk_owner; uint64_t gfs_id; - /* Might want to move this to AUTH_UNIX specifix state since this array - * is not available for every authenticatino scheme. + /* Might want to move this to AUTH_UNIX specific state since this array + * is not available for every authentication scheme. */ - gid_t auxgids[NGRPS]; + gid_t *auxgids; + gid_t auxgidsmall[SMALL_GROUP_COUNT]; + gid_t *auxgidlarge; int auxgidcount; @@ -217,8 +214,8 @@ struct rpcsvc_request { int auth_err; /* There can be cases of RPC requests where the reply needs to - * be built from multiple sources. For eg. where even the NFS reply can - * contain a payload, as in the NFSv3 read reply. Here the RPC header + * 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. @@ -240,6 +237,9 @@ struct rpcsvc_request { */ rpcsvc_auth_data_t verf; + /* Execute this request's actor function as a synctask? */ + gf_boolean_t synctask; + /* Container for a RPC program wanting to store a temp * request-specific item. */ @@ -247,6 +247,12 @@ struct rpcsvc_request { /* Container for transport to store request-specific item */ void *trans_private; + + /* we need to ref the 'iobuf' in case of 'synctasking' it */ + struct iobuf *hdr_iobuf; + + /* pointer to cached reply for use in DRC */ + drc_cached_op_t *reply; }; #define rpcsvc_request_program(req) ((rpcsvc_program_t *)((req)->prog)) @@ -254,8 +260,6 @@ struct rpcsvc_request { #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)) @@ -272,7 +276,23 @@ struct rpcsvc_request { #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_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 = RPC_NOBODY_UID; \ + if (req->gid == RPC_ROOT_GID) \ + req->gid = RPC_NOBODY_GID; \ + for (gidcount = 0; gidcount < req->auxgidcount; \ + ++gidcount) { \ + if (!req->auxgids[gidcount]) \ + req->auxgids[gidcount] = \ + RPC_NOBODY_GID; \ + } \ + } \ + } while (0); #define RPCSVC_ACTOR_SUCCESS 0 #define RPCSVC_ACTOR_ERROR (-1) @@ -291,9 +311,8 @@ struct rpcsvc_request { * */ 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_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 @@ -307,7 +326,6 @@ typedef void *(*rpcsvc_encode_reply) (void *msg); */ typedef void (*rpcsvc_deallocate_reply) (void *msg); - #define RPCSVC_NAME_MAX 32 /* The descriptor for each procedure/actor that runs * over the RPC service. @@ -323,11 +341,13 @@ typedef struct rpcsvc_actor_desc { * 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 alligned buffers. + * 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; + drc_op_type_t op_type; } rpcsvc_actor_t; /* Describes a program and its version along with the function pointers @@ -382,6 +402,9 @@ struct rpcsvc_program { */ int min_auth; + /* Execute actor function as a synctask? */ + gf_boolean_t synctask; + /* list member to link to list of registered services with rpcsvc */ struct list_head program; }; @@ -418,13 +441,20 @@ extern int rpcsvc_program_register_portmap (rpcsvc_program_t *newprog, uint32_t port); 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); @@ -436,6 +466,13 @@ int rpcsvc_unregister_notify (rpcsvc_t *svc, rpcsvc_notify_t notify, void *mydata); 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 rpcsvc_submit_message (rpcsvc_request_t *req, struct iovec *proghdr, int hdrcount, struct iovec *payload, int payloadcount, struct iobref *iobref); @@ -456,17 +493,17 @@ rpcsvc_error_reply (rpcsvc_request_t *req); extern int rpcsvc_transport_peername (rpc_transport_t *trans, char *hostname, int hostlen); -extern inline int +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, rpc_transport_t *trans); 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 @@ -522,6 +559,9 @@ extern int rpcsvc_auth_init (rpcsvc_t *svc, dict_t *options); extern int +rpcsvc_auth_reconf (rpcsvc_t *svc, dict_t *options); + +extern int rpcsvc_auth_transport_init (rpc_transport_t *xprt); extern int @@ -538,9 +578,6 @@ rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen); 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); - extern char * rpcsvc_volume_allowed (dict_t *options, char *volname); @@ -548,16 +585,22 @@ int rpcsvc_callback_submit (rpcsvc_t *rpc, rpc_transport_t *trans, rpcsvc_cbk_program_t *prog, int procnum, struct iovec *proghdr, int proghdrcount); +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_outstanding_rpc_limit (rpcsvc_t *svc, dict_t *options); +int rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen); -char * -rpcsvc_volume_allowed (dict_t *options, char *volname); rpcsvc_vector_sizer rpcsvc_get_program_vector_sizer (rpcsvc_t *svc, uint32_t prognum, uint32_t progver, uint32_t procnum); - #endif diff --git a/rpc/rpc-lib/src/xdr-common.h b/rpc/rpc-lib/src/xdr-common.h index a93f9540a..34dc9c6a2 100644 --- a/rpc/rpc-lib/src/xdr-common.h +++ b/rpc/rpc-lib/src/xdr-common.h @@ -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. */ #ifndef _XDR_COMMON_H_ @@ -34,7 +25,6 @@ #include <dirent.h> #endif /* __NetBSD__ */ - enum gf_dump_procnum { GF_DUMP_NULL, GF_DUMP_DUMP, @@ -44,6 +34,7 @@ enum gf_dump_procnum { #define GLUSTER_DUMP_PROGRAM 123451501 /* Completely random */ #define GLUSTER_DUMP_VERSION 1 +#define GF_MAX_AUTH_BYTES 2048 #if GF_DARWIN_HOST_OS #define xdr_u_quad_t xdr_u_int64_t @@ -56,6 +47,7 @@ enum gf_dump_procnum { #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 #endif @@ -67,55 +59,9 @@ enum gf_dump_procnum { #define xdr_uint32_t xdr_uint32_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. - * For eg, once the RPC call for NFS has been decoded, thie macro will return + * 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) diff --git a/rpc/rpc-lib/src/xdr-rpc.c b/rpc/rpc-lib/src/xdr-rpc.c index 58a8a5fe6..adb48a531 100644 --- a/rpc/rpc-lib/src/xdr-rpc.c +++ b/rpc/rpc-lib/src/xdr-rpc.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. */ #ifndef _CONFIG_H @@ -43,7 +34,7 @@ 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]; + char opaquebytes[GF_MAX_AUTH_BYTES]; struct opaque_auth *oa = NULL; int ret = -1; @@ -117,7 +108,7 @@ rpc_fill_denied_reply (struct rpc_msg *reply, int rjstat, int auth_err) reply->rm_reply.rp_stat = MSG_DENIED; reply->rjcted_rply.rj_stat = rjstat; if (rjstat == RPC_MISMATCH) { - /* No problem with hardocoding + /* No problem with hardcoding * RPC version numbers. We only support * v2 anyway. */ diff --git a/rpc/rpc-lib/src/xdr-rpc.h b/rpc/rpc-lib/src/xdr-rpc.h index 5dbbbe580..f5f4a941e 100644 --- a/rpc/rpc-lib/src/xdr-rpc.h +++ b/rpc/rpc-lib/src/xdr-rpc.h @@ -1,23 +1,14 @@ /* - 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 @@ -39,6 +30,14 @@ #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 */ +} 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. */ @@ -62,7 +61,7 @@ rpc_reply_to_xdr (struct rpc_msg *reply, char *dest, size_t len, extern int xdr_to_auth_unix_cred (char *msgbuf, int msglen, struct authunix_parms *au, char *machname, gid_t *gids); -/* Macros that simplify accesing the members of an RPC call structure. */ +/* 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) diff --git a/rpc/rpc-lib/src/xdr-rpcclnt.c b/rpc/rpc-lib/src/xdr-rpcclnt.c index 69daa98cb..810d1961b 100644 --- a/rpc/rpc-lib/src/xdr-rpcclnt.c +++ b/rpc/rpc-lib/src/xdr-rpcclnt.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. */ #ifndef _CONFIG_H diff --git a/rpc/rpc-lib/src/xdr-rpcclnt.h b/rpc/rpc-lib/src/xdr-rpcclnt.h index aaba00df0..c08d872f8 100644 --- a/rpc/rpc-lib/src/xdr-rpcclnt.h +++ b/rpc/rpc-lib/src/xdr-rpcclnt.h @@ -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. */ #ifndef _XDR_RPCCLNT_H @@ -33,7 +24,7 @@ #include <rpc/rpc_msg.h> #include <rpc/auth_unix.h> -/* Macros that simplify accesing the members of an RPC call structure. */ +/* 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) diff --git a/rpc/rpc-transport/rdma/src/Makefile.am b/rpc/rpc-transport/rdma/src/Makefile.am index bc888b175..2bf7cf238 100644 --- a/rpc/rpc-transport/rdma/src/Makefile.am +++ b/rpc/rpc-transport/rdma/src/Makefile.am @@ -3,18 +3,20 @@ transport_LTLIBRARIES = rdma.la transportdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/rpc-transport -rdma_la_LDFLAGS = -module -avoidversion +rdma_la_LDFLAGS = -module -avoid-version rdma_la_SOURCES = rdma.c name.c rdma_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ - -libverbs + -libverbs -lrdmacm 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) \ +AM_CPPFLAGS = $(GF_CPPFLAGS) \ -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/rpc/rpc-lib/src/ \ - -I$(top_srcdir)/xlators/protocol/lib/src -shared -nostartfiles $(GF_CFLAGS) + -I$(top_srcdir)/rpc/xdr/src + +AM_CFLAGS = -Wall $(GF_CFLAGS) CLEANFILES = *~ diff --git a/rpc/rpc-transport/rdma/src/name.c b/rpc/rpc-transport/rdma/src/name.c index 5d6c81d5f..c57428ad6 100644 --- a/rpc/rpc-transport/rdma/src/name.c +++ b/rpc/rpc-transport/rdma/src/name.c @@ -1,20 +1,11 @@ /* - Copyright (c) 2008-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> @@ -22,12 +13,7 @@ #include <errno.h> #include <netdb.h> #include <string.h> - -#ifdef CLIENT_PORT_CEILING -#undef CLIENT_PORT_CEILING -#endif - -#define CLIENT_PORT_CEILING 1024 +#include <rdma/rdma_cma.h> #ifndef AF_INET_SDP #define AF_INET_SDP 27 @@ -35,6 +21,8 @@ #include "rpc-transport.h" #include "rdma.h" +#include "common-utils.h" + int32_t gf_resolve_ip6 (const char *hostname, @@ -44,28 +32,43 @@ gf_resolve_ip6 (const char *hostname, struct addrinfo **addr_info); static int32_t -af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr, +af_inet_bind_to_port_lt_ceiling (struct rdma_cm_id *cm_id, + struct sockaddr *sockaddr, socklen_t sockaddr_len, int ceiling) { - int32_t ret = -1; - /* struct sockaddr_in sin = {0, }; */ - uint16_t port = ceiling - 1; + int32_t ret = -1; + uint16_t port = ceiling - 1; + // by default assume none of the ports are blocked and all are available + gf_boolean_t ports[1024] = {_gf_false,}; + int i = 0; + + ret = gf_process_reserved_ports (ports); + if (ret != 0) { + for (i = 0; i < 1024; i++) + ports[i] = _gf_false; + } while (port) { switch (sockaddr->sa_family) { case AF_INET6: - ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons (port); + ((struct sockaddr_in6 *)sockaddr)->sin6_port + = htons (port); break; case AF_INET_SDP: case AF_INET: - ((struct sockaddr_in *)sockaddr)->sin_port = htons (port); + ((struct sockaddr_in *)sockaddr)->sin_port + = htons (port); break; } - - ret = bind (fd, sockaddr, sockaddr_len); + // ignore the reserved ports + if (ports[port] == _gf_true) { + port--; + continue; + } + ret = rdma_bind_addr (cm_id, sockaddr); if (ret == 0) break; @@ -79,11 +82,10 @@ af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr, return ret; } +#if 0 static int32_t -af_unix_client_bind (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t sockaddr_len, - int sock) +af_unix_client_bind (rpc_transport_t *this, struct sockaddr *sockaddr, + socklen_t sockaddr_len, struct rdma_cm_id *cm_id) { data_t *path_data = NULL; struct sockaddr_un *addr = NULL; @@ -95,7 +97,7 @@ af_unix_client_bind (rpc_transport_t *this, 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 specfied " + "transport.rdma.bind-path not specified " "for unix socket, letting connect to assign " "default value"); goto err; @@ -115,6 +117,7 @@ af_unix_client_bind (rpc_transport_t *this, err: return ret; } +#endif static int32_t client_fill_address_family (rpc_transport_t *this, struct sockaddr *sockaddr) @@ -162,13 +165,11 @@ client_fill_address_family (rpc_transport_t *this, struct sockaddr *sockaddr) 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); + sockaddr->sa_family = AF_UNSPEC; return -1; } } @@ -363,6 +364,8 @@ af_inet_server_get_local_sockaddr (rpc_transport_t *this, if (listen_port_data) { listen_port = data_to_uint16 (listen_port_data); } else { + listen_port = GF_DEFAULT_RDMA_LISTEN_PORT; + if (addr->sa_family == AF_INET6) { struct sockaddr_in6 *in = (struct sockaddr_in6 *) addr; in->sin6_addr = in6addr_any; @@ -413,10 +416,8 @@ out: } int32_t -gf_rdma_client_bind (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - int sock) +gf_rdma_client_bind (rpc_transport_t *this, struct sockaddr *sockaddr, + socklen_t *sockaddr_len, struct rdma_cm_id *cm_id) { int ret = 0; @@ -428,22 +429,24 @@ gf_rdma_client_bind (rpc_transport_t *this, *sockaddr_len = sizeof (struct sockaddr_in); case AF_INET6: - ret = af_inet_bind_to_port_lt_ceiling (sock, sockaddr, + ret = af_inet_bind_to_port_lt_ceiling (cm_id, sockaddr, *sockaddr_len, - CLIENT_PORT_CEILING); + GF_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)); + "cannot bind rdma_cm_id to port " + "less than %d (%s)", GF_CLIENT_PORT_CEILING, + strerror (errno)); ret = 0; } break; case AF_UNIX: *sockaddr_len = sizeof (struct sockaddr_un); +#if 0 ret = af_unix_client_bind (this, (struct sockaddr *)sockaddr, *sockaddr_len, sock); +#endif break; default: @@ -530,21 +533,19 @@ gf_rdma_server_get_local_sockaddr (rpc_transport_t *this, 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); + addr->sa_family = AF_UNSPEC; 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; + "to inet"); + addr->sa_family = AF_INET; } switch (addr->sa_family) diff --git a/rpc/rpc-transport/rdma/src/name.h b/rpc/rpc-transport/rdma/src/name.h index 1f6fc89fd..742fc5fc3 100644 --- a/rpc/rpc-transport/rdma/src/name.h +++ b/rpc/rpc-transport/rdma/src/name.h @@ -1,35 +1,23 @@ /* - Copyright (c) 2008-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 _IB_VERBS_NAME_H #define _IB_VERBS_NAME_H -#include <sys/socket.h> -#include <sys/un.h> +#include <rdma/rdma_cma.h> #include "compat.h" int32_t -gf_rdma_client_bind (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - int sock); +gf_rdma_client_bind (rpc_transport_t *this, struct sockaddr *sockaddr, + socklen_t *sockaddr_len, struct rdma_cm_id *cm_id); int32_t gf_rdma_client_get_remote_sockaddr (rpc_transport_t *this, diff --git a/rpc/rpc-transport/rdma/src/rdma.c b/rpc/rpc-transport/rdma/src/rdma.c index b88b884d5..6e6099a98 100644 --- a/rpc/rpc-transport/rdma/src/rdma.c +++ b/rpc/rpc-transport/rdma/src/rdma.c @@ -1,23 +1,13 @@ /* - Copyright (c) 2006-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" @@ -30,119 +20,47 @@ #include "name.h" #include "byte-order.h" #include "xlator.h" +#include "xdr-rpc.h" #include <signal.h> -#define RDMA_LOG_NAME "rpc-transport/rdma" +#define GF_RDMA_LOG_NAME "rpc-transport/rdma" static int32_t -__rdma_ioq_churn (rdma_peer_t *peer); +__gf_rdma_ioq_churn (gf_rdma_peer_t *peer); -rdma_post_t * -rdma_post_ref (rdma_post_t *post); +gf_rdma_post_t * +gf_rdma_post_ref (gf_rdma_post_t *post); int -rdma_post_unref (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 -rdma_get_local_lid (struct ibv_context *context, - int32_t port) -{ - struct ibv_port_attr attr; +gf_rdma_post_unref (gf_rdma_post_t *post); - if (ibv_query_port (context, port, &attr)) - return 0; +static void * +gf_rdma_send_completion_proc (void *data); - return attr.lid; -} +static void * +gf_rdma_recv_completion_proc (void *data); -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"; - } -} +void * +gf_rdma_async_event_thread (void *context); static int32_t -ib_check_active_port (struct ibv_context *ctx, uint8_t port) -{ - struct ibv_port_attr port_attr; - - int32_t ret = 0; - const char *state_str = NULL; - - if (!ctx) { - gf_log_callingfn (RDMA_LOG_NAME, GF_LOG_ERROR, - "Error in supplied context"); - return -1; - } - - ret = ibv_query_port (ctx, port, &port_attr); - - if (ret) { - gf_log (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 (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; -} +gf_rdma_create_qp (rpc_transport_t *this); static int32_t -ib_get_active_port (struct ibv_context *ib_ctx) -{ - struct ibv_device_attr ib_device_attr; - - int32_t ret = -1; - uint8_t ib_port = 0; +__gf_rdma_teardown (rpc_transport_t *this); - if (!ib_ctx) { - gf_log_callingfn (RDMA_LOG_NAME, GF_LOG_ERROR, - "Error in supplied context"); - return -1; - } - if (ibv_query_device (ib_ctx, &ib_device_attr)) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, - "Failed to query device properties"); - return -1; - } +static int32_t +gf_rdma_teardown (rpc_transport_t *this); - 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; +static int32_t +gf_rdma_disconnect (rpc_transport_t *this); - gf_log (RDMA_LOG_NAME, GF_LOG_TRACE, - "Port:(%u) not active", ib_port); - continue; - } - return ret; -} +static void +gf_rdma_cm_handle_disconnect (rpc_transport_t *this); static void -rdma_put_post (rdma_queue_t *queue, - rdma_post_t *post) +gf_rdma_put_post (gf_rdma_queue_t *queue, gf_rdma_post_t *post) { post->ctx.is_request = 0; @@ -167,14 +85,15 @@ rdma_put_post (rdma_queue_t *queue, } -static rdma_post_t * -rdma_new_post (rdma_device_t *device, int32_t len, rdma_post_type_t type) +static gf_rdma_post_t * +gf_rdma_new_post (rpc_transport_t *this, gf_rdma_device_t *device, int32_t len, + gf_rdma_post_type_t type) { - rdma_post_t *post = NULL; - int ret = -1; + gf_rdma_post_t *post = NULL; + int ret = -1; - post = (rdma_post_t *) GF_CALLOC (1, sizeof (*post), - gf_common_mt_rdma_post_t); + post = (gf_rdma_post_t *) GF_CALLOC (1, sizeof (*post), + gf_common_mt_rdma_post_t); if (post == NULL) { goto out; } @@ -185,7 +104,7 @@ rdma_new_post (rdma_device_t *device, int32_t len, rdma_post_type_t type) post->buf = valloc (len); if (!post->buf) { - gf_log_nomem (RDMA_LOG_NAME, GF_LOG_ERROR, len); + gf_log_nomem (GF_RDMA_LOG_NAME, GF_LOG_ERROR, len); goto out; } @@ -194,8 +113,9 @@ rdma_new_post (rdma_device_t *device, int32_t len, rdma_post_type_t type) post->buf_size, IBV_ACCESS_LOCAL_WRITE); if (!post->mr) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, - "memory registration failed"); + gf_log (this->name, GF_LOG_WARNING, + "memory registration failed (%s)", + strerror (errno)); goto out; } @@ -205,9 +125,7 @@ rdma_new_post (rdma_device_t *device, int32_t len, rdma_post_type_t type) ret = 0; out: if (ret != 0) { - if (post->buf != NULL) { - free (post->buf); - } + free (post->buf); GF_FREE (post); post = NULL; @@ -217,10 +135,10 @@ out: } -static rdma_post_t * -rdma_get_post (rdma_queue_t *queue) +static gf_rdma_post_t * +gf_rdma_get_post (gf_rdma_queue_t *queue) { - rdma_post_t *post; + gf_rdma_post_t *post = NULL; pthread_mutex_lock (&queue->lock); { @@ -247,7 +165,7 @@ rdma_get_post (rdma_queue_t *queue) } void -rdma_destroy_post (rdma_post_t *post) +gf_rdma_destroy_post (gf_rdma_post_t *post) { ibv_dereg_mr (post->mr); free (post->buf); @@ -256,10 +174,12 @@ rdma_destroy_post (rdma_post_t *post) static int32_t -__rdma_quota_get (rdma_peer_t *peer) +__gf_rdma_quota_get (gf_rdma_peer_t *peer) { - int32_t ret = -1; - rdma_private_t *priv = peer->trans->private; + int32_t ret = -1; + gf_rdma_private_t *priv = NULL; + + priv = peer->trans->private; if (priv->connected && peer->quota > 0) { ret = peer->quota--; @@ -268,25 +188,9 @@ __rdma_quota_get (rdma_peer_t *peer) return ret; } -/* - static int32_t - rdma_quota_get (rdma_peer_t *peer) - { - int32_t ret = -1; - rdma_private_t *priv = peer->trans->private; - - pthread_mutex_lock (&priv->write_mutex); - { - ret = __rdma_quota_get (peer); - } - pthread_mutex_unlock (&priv->write_mutex); - - return ret; - } -*/ static void -__rdma_ioq_entry_free (rdma_ioq_t *entry) +__gf_rdma_ioq_entry_free (gf_rdma_ioq_t *entry) { list_del_init (&entry->list); @@ -299,48 +203,920 @@ __rdma_ioq_entry_free (rdma_ioq_t *entry) iobref_unref (entry->msg.request.rsp_iobref); entry->msg.request.rsp_iobref = NULL; } - /* TODO: use mem-pool */ + mem_put (entry); } static void -__rdma_ioq_flush (rdma_peer_t *peer) +__gf_rdma_ioq_flush (gf_rdma_peer_t *peer) { - rdma_ioq_t *entry = NULL, *dummy = NULL; + gf_rdma_ioq_t *entry = NULL, *dummy = NULL; list_for_each_entry_safe (entry, dummy, &peer->ioq, list) { - __rdma_ioq_entry_free (entry); + __gf_rdma_ioq_entry_free (entry); } } static int32_t -__rdma_disconnect (rpc_transport_t *this) +__gf_rdma_disconnect (rpc_transport_t *this) { - rdma_private_t *priv = this->private; - int32_t ret = 0; + gf_rdma_private_t *priv = NULL; - if (priv->connected || priv->tcp_connected) { - fcntl (priv->sock, F_SETFL, O_NONBLOCK); - if (shutdown (priv->sock, SHUT_RDWR) != 0) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, - "shutdown () - error: %s", - strerror (errno)); - ret = -errno; - priv->tcp_connected = 0; + priv = this->private; + + if (priv->connected) { + rdma_disconnect (priv->peer.cm_id); + } + + return 0; +} + + +static void +gf_rdma_queue_init (gf_rdma_queue_t *queue) +{ + pthread_mutex_init (&queue->lock, NULL); + + queue->active_posts.next = &queue->active_posts; + queue->active_posts.prev = &queue->active_posts; + queue->passive_posts.next = &queue->passive_posts; + queue->passive_posts.prev = &queue->passive_posts; +} + + +static void +__gf_rdma_destroy_queue (gf_rdma_post_t *post) +{ + gf_rdma_post_t *tmp = NULL; + + while (post->next != post) { + tmp = post->next; + + post->next = post->next->next; + post->next->prev = post; + + gf_rdma_destroy_post (tmp); + } +} + + +static void +gf_rdma_destroy_queue (gf_rdma_queue_t *queue) +{ + if (queue == NULL) { + goto out; + } + + pthread_mutex_lock (&queue->lock); + { + if (queue->passive_count > 0) { + __gf_rdma_destroy_queue (&queue->passive_posts); + queue->passive_count = 0; + } + + if (queue->active_count > 0) { + __gf_rdma_destroy_queue (&queue->active_posts); + queue->active_count = 0; + } + } + pthread_mutex_unlock (&queue->lock); + +out: + return; +} + + +static void +gf_rdma_destroy_posts (rpc_transport_t *this) +{ + gf_rdma_device_t *device = NULL; + gf_rdma_private_t *priv = NULL; + + if (this == NULL) { + goto out; + } + + priv = this->private; + device = priv->device; + + gf_rdma_destroy_queue (&device->sendq); + gf_rdma_destroy_queue (&device->recvq); + +out: + return; +} + + +static int32_t +__gf_rdma_create_posts (rpc_transport_t *this, int32_t count, int32_t size, + gf_rdma_queue_t *q, gf_rdma_post_type_t type) +{ + int32_t i = 0; + int32_t ret = 0; + gf_rdma_private_t *priv = NULL; + gf_rdma_device_t *device = NULL; + + priv = this->private; + device = priv->device; + + for (i=0 ; i<count ; i++) { + gf_rdma_post_t *post = NULL; + + post = gf_rdma_new_post (this, device, size + 2048, type); + if (!post) { + gf_log (this->name, GF_LOG_ERROR, + "post creation failed"); + ret = -1; + break; + } + + gf_rdma_put_post (q, post); + } + return ret; +} + + +static int32_t +gf_rdma_post_recv (struct ibv_srq *srq, + gf_rdma_post_t *post) +{ + struct ibv_sge list = { + .addr = (unsigned long) post->buf, + .length = post->buf_size, + .lkey = post->mr->lkey + }; + + struct ibv_recv_wr wr = { + .wr_id = (unsigned long) post, + .sg_list = &list, + .num_sge = 1, + }, *bad_wr; + + gf_rdma_post_ref (post); + + return ibv_post_srq_recv (srq, &wr, &bad_wr); +} + + +static int32_t +gf_rdma_create_posts (rpc_transport_t *this) +{ + int32_t i = 0, ret = 0; + gf_rdma_post_t *post = NULL; + gf_rdma_private_t *priv = NULL; + gf_rdma_options_t *options = NULL; + gf_rdma_device_t *device = NULL; + + priv = this->private; + options = &priv->options; + device = priv->device; + + ret = __gf_rdma_create_posts (this, options->send_count, + options->send_size, + &device->sendq, GF_RDMA_SEND_POST); + if (!ret) + ret = __gf_rdma_create_posts (this, options->recv_count, + options->recv_size, + &device->recvq, + GF_RDMA_RECV_POST); + + if (!ret) { + for (i=0 ; i<options->recv_count ; i++) { + post = gf_rdma_get_post (&device->recvq); + if (gf_rdma_post_recv (device->srq, post) != 0) { + ret = -1; + break; + } + } + } + + if (ret) + gf_rdma_destroy_posts (this); + + return ret; +} + + +static void +gf_rdma_destroy_cq (rpc_transport_t *this) +{ + gf_rdma_private_t *priv = NULL; + gf_rdma_device_t *device = NULL; + + priv = this->private; + device = priv->device; + + if (device->recv_cq) + ibv_destroy_cq (device->recv_cq); + device->recv_cq = NULL; + + if (device->send_cq) + ibv_destroy_cq (device->send_cq); + device->send_cq = NULL; + + return; +} + + +static int32_t +gf_rdma_create_cq (rpc_transport_t *this) +{ + gf_rdma_private_t *priv = NULL; + gf_rdma_options_t *options = NULL; + gf_rdma_device_t *device = NULL; + uint64_t send_cqe = 0; + int32_t ret = 0; + struct ibv_device_attr device_attr = {{0}, }; + + priv = this->private; + options = &priv->options; + device = priv->device; + + device->recv_cq = ibv_create_cq (priv->device->context, + options->recv_count * 2, + device, + device->recv_chan, + 0); + if (!device->recv_cq) { + gf_log (this->name, GF_LOG_ERROR, + "creation of CQ for device %s failed", + device->device_name); + ret = -1; + goto out; + } else if (ibv_req_notify_cq (device->recv_cq, 0)) { + gf_log (this->name, GF_LOG_ERROR, + "ibv_req_notify_cq on recv CQ of device %s failed", + device->device_name); + ret = -1; + goto out; + } + + do { + ret = ibv_query_device (priv->device->context, &device_attr); + if (ret != 0) { + gf_log (this->name, GF_LOG_ERROR, + "ibv_query_device on %s returned %d (%s)", + 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 (this->name, GF_LOG_ERROR, + "creation of send_cq for device %s failed", + device->device_name); + ret = -1; + goto out; + } + + if (ibv_req_notify_cq (device->send_cq, 0)) { + gf_log (this->name, GF_LOG_ERROR, + "ibv_req_notify_cq on send_cq for device %s" + " failed", device->device_name); + ret = -1; + goto out; + } + } while (0); + +out: + if (ret != 0) + gf_rdma_destroy_cq (this); + + return ret; +} + + +static gf_rdma_device_t * +gf_rdma_get_device (rpc_transport_t *this, struct ibv_context *ibctx, + char *device_name) +{ + glusterfs_ctx_t *ctx = NULL; + gf_rdma_private_t *priv = NULL; + gf_rdma_options_t *options = NULL; + int32_t ret = 0; + int32_t i = 0; + gf_rdma_device_t *trav = NULL, *device = NULL; + gf_rdma_ctx_t *rdma_ctx = NULL; + + priv = this->private; + options = &priv->options; + ctx = this->ctx; + rdma_ctx = ctx->ib; + + trav = rdma_ctx->device; + + while (trav) { + if (!strcmp (trav->device_name, device_name)) + break; + trav = trav->next; + } + + if (!trav) { + trav = GF_CALLOC (1, sizeof (*trav), + gf_common_mt_rdma_device_t); + if (trav == NULL) { + goto out; + } + + priv->device = trav; + trav->context = ibctx; + + trav->request_ctx_pool + = mem_pool_new (gf_rdma_request_context_t, + GF_RDMA_POOL_SIZE); + if (trav->request_ctx_pool == NULL) { + goto out; + } + + trav->ioq_pool + = mem_pool_new (gf_rdma_ioq_t, GF_RDMA_POOL_SIZE); + if (trav->ioq_pool == NULL) { + goto out; + } + + trav->reply_info_pool = mem_pool_new (gf_rdma_reply_info_t, + GF_RDMA_POOL_SIZE); + if (trav->reply_info_pool == NULL) { + goto out; + } + + trav->device_name = gf_strdup (device_name); + + trav->next = rdma_ctx->device; + rdma_ctx->device = trav; + + trav->send_chan = ibv_create_comp_channel (trav->context); + if (!trav->send_chan) { + gf_log (this->name, GF_LOG_ERROR, + "could not create send completion channel for " + "device (%s)", device_name); + goto out; + } + + trav->recv_chan = ibv_create_comp_channel (trav->context); + if (!trav->recv_chan) { + gf_log (this->name, GF_LOG_ERROR, + "could not create recv completion channel for " + "device (%s)", device_name); + + /* TODO: cleanup current mess */ + goto out; + } + + if (gf_rdma_create_cq (this) < 0) { + gf_log (this->name, GF_LOG_ERROR, + "could not create CQ for device (%s)", + device_name); + goto out; + } + + /* protection domain */ + trav->pd = ibv_alloc_pd (trav->context); + + if (!trav->pd) { + gf_log (this->name, GF_LOG_ERROR, + "could not allocate protection domain for " + "device (%s)", device_name); + goto out; + } + + struct ibv_srq_init_attr attr = { + .attr = { + .max_wr = options->recv_count, + .max_sge = 1, + .srq_limit = 10 + } + }; + trav->srq = ibv_create_srq (trav->pd, &attr); + + if (!trav->srq) { + gf_log (this->name, GF_LOG_ERROR, + "could not create SRQ for device (%s)", + device_name); + goto out; + } + + /* queue init */ + gf_rdma_queue_init (&trav->sendq); + gf_rdma_queue_init (&trav->recvq); + + if (gf_rdma_create_posts (this) < 0) { + gf_log (this->name, GF_LOG_ERROR, + "could not allocate posts for device (%s)", + device_name); + goto out; + } + + /* completion threads */ + ret = gf_thread_create (&trav->send_thread, NULL, + gf_rdma_send_completion_proc, + trav->send_chan); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "could not create send completion thread for " + "device (%s)", device_name); + goto out; + } + + ret = gf_thread_create (&trav->recv_thread, NULL, + gf_rdma_recv_completion_proc, + trav->recv_chan); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "could not create recv completion thread " + "for device (%s)", device_name); + return NULL; + } + + ret = gf_thread_create (&trav->async_event_thread, NULL, + gf_rdma_async_event_thread, + ibctx); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "could not create async_event_thread"); + return NULL; + } + + /* qpreg */ + pthread_mutex_init (&trav->qpreg.lock, NULL); + for (i=0; i<42; i++) { + trav->qpreg.ents[i].next = &trav->qpreg.ents[i]; + trav->qpreg.ents[i].prev = &trav->qpreg.ents[i]; + } + } + + device = trav; + trav = NULL; +out: + + if (trav != NULL) { + 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); + } + + return device; +} + + +static rpc_transport_t * +gf_rdma_transport_new (rpc_transport_t *listener, struct rdma_cm_id *cm_id) +{ + gf_rdma_private_t *listener_priv = NULL, *priv = NULL; + rpc_transport_t *this = NULL, *new = NULL; + gf_rdma_options_t *options = NULL; + char *device_name = NULL; + + listener_priv = listener->private; + + this = GF_CALLOC (1, sizeof (rpc_transport_t), + gf_common_mt_rpc_transport_t); + if (this == NULL) { + goto out; + } + + this->listener = listener; + + priv = GF_CALLOC (1, sizeof (gf_rdma_private_t), + gf_common_mt_rdma_private_t); + if (priv == NULL) { + goto out; + } + + this->private = priv; + priv->options = listener_priv->options; + + priv->listener = listener; + priv->entity = GF_RDMA_SERVER; + + options = &priv->options; + + this->ops = listener->ops; + this->init = listener->init; + this->fini = listener->fini; + this->ctx = listener->ctx; + this->name = gf_strdup (listener->name); + this->notify = listener->notify; + this->mydata = listener->mydata; + + this->myinfo.sockaddr_len = sizeof (cm_id->route.addr.src_addr); + memcpy (&this->myinfo.sockaddr, &cm_id->route.addr.src_addr, + this->myinfo.sockaddr_len); + + this->peerinfo.sockaddr_len = sizeof (cm_id->route.addr.dst_addr); + memcpy (&this->peerinfo.sockaddr, &cm_id->route.addr.dst_addr, + this->peerinfo.sockaddr_len); + + priv->peer.trans = this; + gf_rdma_get_transport_identifiers (this); + + device_name = (char *)ibv_get_device_name (cm_id->verbs->device); + if (device_name == NULL) { + gf_log (listener->name, GF_LOG_WARNING, + "cannot get device name (peer:%s me:%s)", + this->peerinfo.identifier, this->myinfo.identifier); + goto out; + } + + priv->device = gf_rdma_get_device (this, cm_id->verbs, + device_name); + if (priv->device == NULL) { + gf_log (listener->name, GF_LOG_WARNING, + "cannot get infiniband device %s (peer:%s me:%s)", + device_name, this->peerinfo.identifier, + this->myinfo.identifier); + goto out; + } + + priv->peer.send_count = options->send_count; + priv->peer.recv_count = options->recv_count; + priv->peer.send_size = options->send_size; + priv->peer.recv_size = options->recv_size; + priv->peer.cm_id = cm_id; + INIT_LIST_HEAD (&priv->peer.ioq); + + pthread_mutex_init (&priv->write_mutex, NULL); + pthread_mutex_init (&priv->recv_mutex, NULL); + + cm_id->context = this; + + new = rpc_transport_ref (this); + this = NULL; +out: + if (this != NULL) { + if (this->private != NULL) { + GF_FREE (this->private); + } + + if (this->name != NULL) { + GF_FREE (this->name); + } + + GF_FREE (this); + } + + return new; +} + + +static int +gf_rdma_cm_handle_connect_request (struct rdma_cm_event *event) +{ + int ret = -1; + rpc_transport_t *this = NULL, *listener = NULL; + struct rdma_cm_id *child_cm_id = NULL, *listener_cm_id = NULL; + struct rdma_conn_param conn_param = {0, }; + gf_rdma_private_t *priv = NULL; + gf_rdma_options_t *options = NULL; + + child_cm_id = event->id; + listener_cm_id = event->listen_id; + + listener = listener_cm_id->context; + priv = listener->private; + options = &priv->options; + + this = gf_rdma_transport_new (listener, child_cm_id); + if (this == NULL) { + gf_log (listener->name, GF_LOG_WARNING, + "could not create a transport for incoming connection" + " (me.name:%s me.identifier:%s)", listener->name, + listener->myinfo.identifier); + rdma_destroy_id (child_cm_id); + goto out; + } + + gf_log (listener->name, GF_LOG_TRACE, + "got a connect request (me:%s peer:%s)", + listener->myinfo.identifier, this->peerinfo.identifier); + + ret = gf_rdma_create_qp (this); + if (ret < 0) { + gf_log (listener->name, GF_LOG_WARNING, + "could not create QP (peer:%s me:%s)", + this->peerinfo.identifier, this->myinfo.identifier); + gf_rdma_cm_handle_disconnect (this); + goto out; + } + + conn_param.responder_resources = 1; + conn_param.initiator_depth = 1; + conn_param.retry_count = options->attr_retry_cnt; + conn_param.rnr_retry_count = options->attr_rnr_retry; + + ret = rdma_accept(child_cm_id, &conn_param); + if (ret < 0) { + gf_log (listener->name, GF_LOG_WARNING, "rdma_accept failed " + "peer:%s me:%s (%s)", this->peerinfo.identifier, + this->myinfo.identifier, strerror (errno)); + gf_rdma_cm_handle_disconnect (this); + goto out; + } + + ret = 0; + +out: + return ret; +} + + +static int +gf_rdma_cm_handle_route_resolved (struct rdma_cm_event *event) +{ + struct rdma_conn_param conn_param = {0, }; + int ret = 0; + rpc_transport_t *this = NULL; + gf_rdma_private_t *priv = NULL; + gf_rdma_peer_t *peer = NULL; + gf_rdma_options_t *options = NULL; + + if (event == NULL) { + goto out; + } + + this = event->id->context; + + priv = this->private; + peer = &priv->peer; + options = &priv->options; + + ret = gf_rdma_create_qp (this); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "could not create QP (peer:%s me:%s)", + this->peerinfo.identifier, this->myinfo.identifier); + gf_rdma_cm_handle_disconnect (this); + goto out; + } + + memset(&conn_param, 0, sizeof conn_param); + conn_param.responder_resources = 1; + conn_param.initiator_depth = 1; + conn_param.retry_count = options->attr_retry_cnt; + conn_param.rnr_retry_count = options->attr_rnr_retry; + + ret = rdma_connect(peer->cm_id, &conn_param); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "rdma_connect failed (%s)", strerror (errno)); + gf_rdma_cm_handle_disconnect (this); + goto out; + } + + gf_log (this->name, GF_LOG_TRACE, "route resolved (me:%s peer:%s)", + this->myinfo.identifier, this->peerinfo.identifier); + + ret = 0; +out: + return ret; +} + + +static int +gf_rdma_cm_handle_addr_resolved (struct rdma_cm_event *event) +{ + rpc_transport_t *this = NULL; + gf_rdma_peer_t *peer = NULL; + gf_rdma_private_t *priv = NULL; + int ret = 0; + + this = event->id->context; + + priv = this->private; + peer = &priv->peer; + + GF_ASSERT (peer->cm_id == event->id); + + this->myinfo.sockaddr_len = sizeof (peer->cm_id->route.addr.src_addr); + memcpy (&this->myinfo.sockaddr, &peer->cm_id->route.addr.src_addr, + this->myinfo.sockaddr_len); + + this->peerinfo.sockaddr_len = sizeof (peer->cm_id->route.addr.dst_addr); + memcpy (&this->peerinfo.sockaddr, &peer->cm_id->route.addr.dst_addr, + this->peerinfo.sockaddr_len); + + gf_rdma_get_transport_identifiers (this); + + ret = rdma_resolve_route(peer->cm_id, 2000); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "rdma_resolve_route failed (me:%s peer:%s) (%s)", + this->myinfo.identifier, this->peerinfo.identifier, + strerror (errno)); + gf_rdma_cm_handle_disconnect (this); + } + + gf_log (this->name, GF_LOG_TRACE, "Address resolved (me:%s peer:%s)", + this->myinfo.identifier, this->peerinfo.identifier); + + return ret; +} + + +static void +gf_rdma_cm_handle_disconnect (rpc_transport_t *this) +{ + gf_rdma_private_t *priv = NULL; + char need_unref = 0, connected = 0; + + priv = this->private; + gf_log (this->name, GF_LOG_DEBUG, + "peer disconnected, cleaning up"); + + pthread_mutex_lock (&priv->write_mutex); + { + if (priv->peer.cm_id != NULL) { + need_unref = 1; + connected = priv->connected; priv->connected = 0; } + + __gf_rdma_teardown (this); } + pthread_mutex_unlock (&priv->write_mutex); + + if (connected) { + rpc_transport_notify (this, RPC_TRANSPORT_DISCONNECT, this); + } + + if (need_unref) + rpc_transport_unref (this); + +} + + +static int +gf_rdma_cm_handle_event_established (struct rdma_cm_event *event) +{ + rpc_transport_t *this = NULL; + gf_rdma_private_t *priv = NULL; + struct rdma_cm_id *cm_id = NULL; + int ret = 0; + + cm_id = event->id; + this = cm_id->context; + priv = this->private; + + priv->connected = 1; + + pthread_mutex_lock (&priv->write_mutex); + { + priv->peer.quota = 1; + priv->peer.quota_set = 0; + } + pthread_mutex_unlock (&priv->write_mutex); + + if (priv->entity == GF_RDMA_CLIENT) { + ret = rpc_transport_notify (this, RPC_TRANSPORT_CONNECT, this); + + } else if (priv->entity == GF_RDMA_SERVER) { + ret = rpc_transport_notify (priv->listener, + RPC_TRANSPORT_ACCEPT, this); + } + + if (ret < 0) { + gf_rdma_disconnect (this); + } + + gf_log (this->name, GF_LOG_TRACE, + "recieved event RDMA_CM_EVENT_ESTABLISHED (me:%s peer:%s)", + this->myinfo.identifier, this->peerinfo.identifier); return ret; } +static int +gf_rdma_cm_handle_event_error (rpc_transport_t *this) +{ + gf_rdma_private_t *priv = NULL; + + priv = this->private; + + if (priv->entity != GF_RDMA_SERVER_LISTENER) { + gf_rdma_cm_handle_disconnect (this); + } + + return 0; +} + + +static int +gf_rdma_cm_handle_device_removal (struct rdma_cm_event *event) +{ + return 0; +} + + +static void * +gf_rdma_cm_event_handler (void *data) +{ + struct rdma_cm_event *event = NULL; + int ret = 0; + rpc_transport_t *this = NULL; + struct rdma_event_channel *event_channel = NULL; + + event_channel = data; + + while (1) { + ret = rdma_get_cm_event (event_channel, &event); + if (ret != 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "rdma_cm_get_event failed (%s)", + strerror (errno)); + break; + } + + switch (event->event) { + case RDMA_CM_EVENT_ADDR_RESOLVED: + gf_rdma_cm_handle_addr_resolved (event); + break; + + case RDMA_CM_EVENT_ROUTE_RESOLVED: + gf_rdma_cm_handle_route_resolved (event); + break; + + case RDMA_CM_EVENT_CONNECT_REQUEST: + gf_rdma_cm_handle_connect_request (event); + break; + + case RDMA_CM_EVENT_ESTABLISHED: + gf_rdma_cm_handle_event_established (event); + break; + + case RDMA_CM_EVENT_ADDR_ERROR: + case RDMA_CM_EVENT_ROUTE_ERROR: + case RDMA_CM_EVENT_CONNECT_ERROR: + case RDMA_CM_EVENT_UNREACHABLE: + case RDMA_CM_EVENT_REJECTED: + this = event->id->context; + + gf_log (this->name, GF_LOG_WARNING, + "cma event %s, error %d (me:%s peer:%s)\n", + rdma_event_str(event->event), event->status, + this->myinfo.identifier, + this->peerinfo.identifier); + + rdma_ack_cm_event (event); + event = NULL; + + gf_rdma_cm_handle_event_error (this); + continue; + + case RDMA_CM_EVENT_DISCONNECTED: + this = event->id->context; + + gf_log (this->name, GF_LOG_DEBUG, + "recieved disconnect (me:%s peer:%s)\n", + this->myinfo.identifier, + this->peerinfo.identifier); + + rdma_ack_cm_event (event); + event = NULL; + + gf_rdma_cm_handle_disconnect (this); + continue; + + case RDMA_CM_EVENT_DEVICE_REMOVAL: + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "device removed"); + gf_rdma_cm_handle_device_removal (event); + break; + + default: + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "unhandled event: %s, ignoring", + rdma_event_str(event->event)); + break; + } + + rdma_ack_cm_event (event); + } + + return NULL; +} + + static int32_t -rdma_post_send (struct ibv_qp *qp, - rdma_post_t *post, - int32_t len) +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, @@ -363,63 +1139,64 @@ rdma_post_send (struct ibv_qp *qp, } int -__rdma_encode_error(rdma_peer_t *peer, rdma_reply_info_t *reply_info, - struct iovec *rpchdr, uint32_t *ptr, - rdma_errcode_t err) +__gf_rdma_encode_error(gf_rdma_peer_t *peer, gf_rdma_reply_info_t *reply_info, + struct iovec *rpchdr, gf_rdma_header_t *hdr, + gf_rdma_errcode_t err) { - uint32_t *startp = NULL; struct rpc_msg *rpc_msg = NULL; - startp = ptr; if (reply_info != NULL) { - *ptr++ = hton32(reply_info->rm_xid); + hdr->rm_xid = 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; + hdr->rm_xid = rpc_msg->rm_xid; } - *ptr++ = hton32(RDMA_VERSION); - *ptr++ = hton32(peer->send_count); - *ptr++ = hton32(RDMA_ERROR); - *ptr++ = hton32(err); + hdr->rm_vers = hton32(GF_RDMA_VERSION); + hdr->rm_credit = hton32(peer->send_count); + hdr->rm_type = hton32(GF_RDMA_ERROR); + hdr->rm_body.rm_error.rm_type = hton32(err); if (err == ERR_VERS) { - *ptr++ = hton32(RDMA_VERSION); - *ptr++ = hton32(RDMA_VERSION); + hdr->rm_body.rm_error.rm_version.gf_rdma_vers_low + = hton32(GF_RDMA_VERSION); + hdr->rm_body.rm_error.rm_version.gf_rdma_vers_high + = hton32(GF_RDMA_VERSION); } - return (int)((unsigned long)ptr - (unsigned long)startp); + return sizeof (*hdr); } int32_t -__rdma_send_error (rdma_peer_t *peer, rdma_ioq_t *entry, rdma_post_t *post, - rdma_reply_info_t *reply_info, rdma_errcode_t err) +__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; + int32_t ret = -1, len = 0; - len = __rdma_encode_error (peer, reply_info, entry->rpchdr, - (uint32_t *)post->buf, err); + len = __gf_rdma_encode_error (peer, reply_info, entry->rpchdr, + (gf_rdma_header_t *)post->buf, err); if (len == -1) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, "encode error returned -1"); goto out; } - rdma_post_ref (post); + gf_rdma_post_ref (post); - ret = rdma_post_send (peer->qp, post, len); + ret = gf_rdma_post_send (peer->qp, post, len); if (!ret) { ret = len; } else { - gf_log (RDMA_LOG_NAME, GF_LOG_WARNING, - "rdma_post_send (to %s) failed with ret = %d (%s)", + 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) : ""); - rdma_post_unref (post); - __rdma_disconnect (peer->trans); + gf_rdma_post_unref (post); + __gf_rdma_disconnect (peer->trans); ret = -1; } @@ -429,24 +1206,24 @@ out: int32_t -__rdma_create_read_chunks_from_vector (rdma_peer_t *peer, - rdma_read_chunk_t **readch_ptr, - int32_t *pos, struct iovec *vector, - int count, - rdma_request_context_t *request_ctx) +__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; - rdma_private_t *priv = NULL; - rdma_device_t *device = NULL; - struct ibv_mr *mr = NULL; - rdma_read_chunk_t *readch = NULL; - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, peer, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, readch_ptr, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, *readch_ptr, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, request_ctx, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, vector, out); + 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; @@ -460,8 +1237,10 @@ __rdma_create_read_chunks_from_vector (rdma_peer_t *peer, vector[i].iov_len, IBV_ACCESS_REMOTE_READ); if (!mr) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, - "memory registration failed"); + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "memory registration failed (%s) (peer:%s)", + strerror (errno), + peer->trans->peerinfo.identifier); goto out; } @@ -486,72 +1265,72 @@ out: int32_t -__rdma_create_read_chunks (rdma_peer_t *peer, rdma_ioq_t *entry, - rdma_chunktype_t type, uint32_t **ptr, - rdma_request_context_t *request_ctx) +__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 (RDMA_LOG_NAME, peer, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, entry, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, ptr, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, *ptr, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, request_ctx, out); + 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 == rdma_areadch) { + if (type == gf_rdma_areadch) { pos = 0; - ret = __rdma_create_read_chunks_from_vector (peer, - (rdma_read_chunk_t **)ptr, - &pos, - entry->rpchdr, - entry->rpchdr_count, - request_ctx); + 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 (RDMA_LOG_NAME, GF_LOG_DEBUG, - "cannot create read chunks from vector, " + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "cannot create read chunks from vector " "entry->rpchdr"); goto out; } - ret = __rdma_create_read_chunks_from_vector (peer, - (rdma_read_chunk_t **)ptr, - &pos, - entry->proghdr, - entry->proghdr_count, - request_ctx); + 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 (RDMA_LOG_NAME, GF_LOG_DEBUG, - "cannot create read chunks from vector, " + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "cannot create read chunks from vector " "entry->proghdr"); } if (entry->prog_payload_count != 0) { - ret = __rdma_create_read_chunks_from_vector (peer, - (rdma_read_chunk_t **)ptr, - &pos, - entry->prog_payload, - entry->prog_payload_count, - request_ctx); + 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 (RDMA_LOG_NAME, GF_LOG_DEBUG, - "cannot create read chunks from vector," + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "cannot create read chunks from vector" " entry->prog_payload"); } } } else { pos = iov_length (entry->rpchdr, entry->rpchdr_count); - ret = __rdma_create_read_chunks_from_vector (peer, - (rdma_read_chunk_t **)ptr, - &pos, - entry->prog_payload, - entry->prog_payload_count, - request_ctx); + 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 (RDMA_LOG_NAME, GF_LOG_DEBUG, - "cannot create read chunks from vector, " + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "cannot create read chunks from vector " "entry->prog_payload"); } } @@ -565,23 +1344,23 @@ out: int32_t -__rdma_create_write_chunks_from_vector (rdma_peer_t *peer, - rdma_write_chunk_t **writech_ptr, - struct iovec *vector, int count, - rdma_request_context_t *request_ctx) +__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; - rdma_private_t *priv = NULL; - rdma_device_t *device = NULL; - struct ibv_mr *mr = NULL; - rdma_write_chunk_t *writech = NULL; - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, peer, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, writech_ptr, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, *writech_ptr, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, request_ctx, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, vector, out); + 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; @@ -594,8 +1373,10 @@ __rdma_create_write_chunks_from_vector (rdma_peer_t *peer, IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE); if (!mr) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, - "memory registration failed"); + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "memory registration failed (%s) (peer:%s)", + strerror (errno), + peer->trans->peerinfo.identifier); goto out; } @@ -618,23 +1399,23 @@ out: int32_t -__rdma_create_write_chunks (rdma_peer_t *peer, rdma_ioq_t *entry, - rdma_chunktype_t chunk_type, uint32_t **ptr, - rdma_request_context_t *request_ctx) +__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; - rdma_write_array_t *warray = NULL; + int32_t ret = -1; + gf_rdma_write_array_t *warray = NULL; - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, peer, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, ptr, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, *ptr, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, request_ctx, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, entry, out); + 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 == rdma_replych) + if ((chunk_type == gf_rdma_replych) && ((entry->msg.request.rsphdr_count != 1) || (entry->msg.request.rsphdr_vec[0].iov_base == NULL))) { - gf_log (RDMA_LOG_NAME, GF_LOG_WARNING, + 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" @@ -645,10 +1426,10 @@ __rdma_create_write_chunks (rdma_peer_t *peer, rdma_ioq_t *entry, } /* - if ((chunk_type == rdma_writech) + if ((chunk_type == gf_rdma_writech) && ((entry->msg.request.rsphdr_count == 0) || (entry->msg.request.rsphdr_vec[0].iov_base == NULL))) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + 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"); @@ -656,21 +1437,21 @@ __rdma_create_write_chunks (rdma_peer_t *peer, rdma_ioq_t *entry, } */ - if (chunk_type == rdma_writech) { - warray = (rdma_write_array_t *)*ptr; + 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 = __rdma_create_write_chunks_from_vector (peer, - (rdma_write_chunk_t **)ptr, - entry->msg.request.rsp_payload, - entry->msg.request.rsp_payload_count, - request_ctx); + 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 (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "cannot create write chunks from vector " "entry->rpc_payload"); goto out; @@ -688,19 +1469,19 @@ __rdma_create_write_chunks (rdma_peer_t *peer, rdma_ioq_t *entry, **ptr = 0; *ptr = *ptr + 1; - warray = (rdma_write_array_t *)*ptr; + 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 = __rdma_create_write_chunks_from_vector (peer, - (rdma_write_chunk_t **)ptr, - entry->msg.request.rsphdr_vec, - entry->msg.request.rsphdr_count, - request_ctx); + 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 (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "cannot create write chunks from vector " "entry->rpchdr"); goto out; @@ -716,8 +1497,8 @@ out: } -inline void -__rdma_deregister_mr (struct ibv_mr **mr, int count) +static inline void +__gf_rdma_deregister_mr (struct ibv_mr **mr, int count) { int i = 0; @@ -735,15 +1516,15 @@ out: static int32_t -__rdma_quota_put (rdma_peer_t *peer) +__gf_rdma_quota_put (gf_rdma_peer_t *peer) { - int32_t ret; + int32_t ret = 0; peer->quota++; ret = peer->quota; if (!list_empty (&peer->ioq)) { - ret = __rdma_ioq_churn (peer); + ret = __gf_rdma_ioq_churn (peer); } return ret; @@ -751,14 +1532,15 @@ __rdma_quota_put (rdma_peer_t *peer) static int32_t -rdma_quota_put (rdma_peer_t *peer) +gf_rdma_quota_put (gf_rdma_peer_t *peer) { - int32_t ret; - rdma_private_t *priv = peer->trans->private; + int32_t ret = 0; + gf_rdma_private_t *priv = NULL; + priv = peer->trans->private; pthread_mutex_lock (&priv->write_mutex); { - ret = __rdma_quota_put (peer); + ret = __gf_rdma_quota_put (peer); } pthread_mutex_unlock (&priv->write_mutex); @@ -768,11 +1550,11 @@ rdma_quota_put (rdma_peer_t *peer) /* to be called with priv->mutex held */ void -__rdma_request_context_destroy (rdma_request_context_t *context) +__gf_rdma_request_context_destroy (gf_rdma_request_context_t *context) { - rdma_peer_t *peer = NULL; - rdma_private_t *priv = NULL; - int32_t ret = 0; + gf_rdma_peer_t *peer = NULL; + gf_rdma_private_t *priv = NULL; + int32_t ret = 0; if (context == NULL) { goto out; @@ -780,18 +1562,18 @@ __rdma_request_context_destroy (rdma_request_context_t *context) peer = context->peer; - __rdma_deregister_mr (context->mr, context->mr_count); + __gf_rdma_deregister_mr (context->mr, context->mr_count); priv = peer->trans->private; if (priv->connected) { - ret = __rdma_quota_put (peer); + ret = __gf_rdma_quota_put (peer); if (ret < 0) { gf_log ("rdma", GF_LOG_DEBUG, "failed to send " "message"); mem_put (context); - __rdma_disconnect (peer->trans); + __gf_rdma_disconnect (peer->trans); goto out; } } @@ -813,15 +1595,14 @@ out: } - void -rdma_post_context_destroy (rdma_post_context_t *ctx) +gf_rdma_post_context_destroy (gf_rdma_post_context_t *ctx) { if (ctx == NULL) { goto out; } - __rdma_deregister_mr (ctx->mr, ctx->mr_count); + __gf_rdma_deregister_mr (ctx->mr, ctx->mr_count); if (ctx->iobref != NULL) { iobref_unref (ctx->iobref); @@ -837,30 +1618,8 @@ out: } -static int32_t -rdma_post_recv (struct ibv_srq *srq, - 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; - - rdma_post_ref (post); - - return ibv_post_srq_recv (srq, &wr, &bad_wr); -} - - int -rdma_post_unref (rdma_post_t *post) +gf_rdma_post_unref (gf_rdma_post_t *post) { int refcount = -1; @@ -875,11 +1634,11 @@ rdma_post_unref (rdma_post_t *post) pthread_mutex_unlock (&post->lock); if (refcount == 0) { - rdma_post_context_destroy (&post->ctx); - if (post->type == RDMA_SEND_POST) { - rdma_put_post (&post->device->sendq, post); + gf_rdma_post_context_destroy (&post->ctx); + if (post->type == GF_RDMA_SEND_POST) { + gf_rdma_put_post (&post->device->sendq, post); } else { - rdma_post_recv (post->device->srq, post); + gf_rdma_post_recv (post->device->srq, post); } } out: @@ -888,7 +1647,7 @@ out: int -rdma_post_get_refcount (rdma_post_t *post) +gf_rdma_post_get_refcount (gf_rdma_post_t *post) { int refcount = -1; @@ -906,8 +1665,8 @@ out: return refcount; } -rdma_post_t * -rdma_post_ref (rdma_post_t *post) +gf_rdma_post_t * +gf_rdma_post_ref (gf_rdma_post_t *post) { if (post == NULL) { goto out; @@ -925,31 +1684,32 @@ out: int32_t -__rdma_ioq_churn_request (rdma_peer_t *peer, rdma_ioq_t *entry, - rdma_post_t *post) +__gf_rdma_ioq_churn_request (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry, + gf_rdma_post_t *post) { - rdma_chunktype_t rtype = rdma_noch, wtype = rdma_noch; - uint64_t send_size = 0; - rdma_header_t *hdr = NULL; - struct rpc_msg *rpc_msg = NULL; - uint32_t *chunkptr = NULL; - char *buf = NULL; - int32_t ret = 0; - rdma_private_t *priv = NULL; - rdma_device_t *device = NULL; - int chunk_count = 0; - 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 (RDMA_LOG_NAME, peer, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, entry, out); - GF_VALIDATE_OR_GOTO (RDMA_LOG_NAME, post, out); + 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 (RDMA_LOG_NAME, GF_LOG_WARNING, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "both write-chunklist and reply-chunk cannot be " "present"); goto out; @@ -959,7 +1719,7 @@ __rdma_ioq_churn_request (rdma_peer_t *peer, rdma_ioq_t *entry, priv = peer->trans->private; device = priv->device; - hdr = (rdma_header_t *)post->buf; + hdr = (gf_rdma_header_t *)post->buf; send_size = iov_length (entry->rpchdr, entry->rpchdr_count) + iov_length (entry->proghdr, entry->proghdr_count) @@ -972,42 +1732,42 @@ __rdma_ioq_churn_request (rdma_peer_t *peer, rdma_ioq_t *entry, } if (send_size > GLUSTERFS_RDMA_INLINE_THRESHOLD) { - rtype = rdma_areadch; + rtype = gf_rdma_areadch; } else if ((send_size + prog_payload_length) < GLUSTERFS_RDMA_INLINE_THRESHOLD) { - rtype = rdma_noch; + rtype = gf_rdma_noch; } else if (entry->prog_payload_count != 0) { - rtype = rdma_readch; + rtype = gf_rdma_readch; } if (entry->msg.request.rsphdr_count != 0) { - wtype = rdma_replych; + wtype = gf_rdma_replych; } else if (entry->msg.request.rsp_payload_count != 0) { - wtype = rdma_writech; + wtype = gf_rdma_writech; } - if (rtype == rdma_readch) { + if (rtype == gf_rdma_readch) { chunk_count += entry->prog_payload_count; - } else if (rtype == rdma_areadch) { + } else if (rtype == gf_rdma_areadch) { chunk_count += entry->rpchdr_count; chunk_count += entry->proghdr_count; } - if (wtype == rdma_writech) { + if (wtype == gf_rdma_writech) { chunk_count += entry->msg.request.rsp_payload_count; - } else if (wtype == rdma_replych) { + } else if (wtype == gf_rdma_replych) { chunk_count += entry->msg.request.rsphdr_count; } - if (chunk_count > RDMA_MAX_SEGMENTS) { + if (chunk_count > GF_RDMA_MAX_SEGMENTS) { ret = -1; - gf_log (RDMA_LOG_NAME, GF_LOG_WARNING, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "chunk count(%d) exceeding maximum allowed RDMA " - "segment count(%d)", chunk_count, RDMA_MAX_SEGMENTS); + "segment count(%d)", chunk_count, GF_RDMA_MAX_SEGMENTS); goto out; } - if ((wtype != rdma_noch) || (rtype != rdma_noch)) { + if ((wtype != gf_rdma_noch) || (rtype != gf_rdma_noch)) { request_ctx = mem_get (device->request_ctx_pool); if (request_ctx == NULL) { ret = -1; @@ -1033,20 +1793,21 @@ __rdma_ioq_churn_request (rdma_peer_t *peer, rdma_ioq_t *entry, * since rpc_msg->rm_xid is already * hton32ed value of actual xid */ - hdr->rm_vers = hton32 (RDMA_VERSION); + hdr->rm_vers = hton32 (GF_RDMA_VERSION); hdr->rm_credit = hton32 (peer->send_count); - if (rtype == rdma_areadch) { - hdr->rm_type = hton32 (RDMA_NOMSG); + if (rtype == gf_rdma_areadch) { + hdr->rm_type = hton32 (GF_RDMA_NOMSG); } else { - hdr->rm_type = hton32 (RDMA_MSG); + hdr->rm_type = hton32 (GF_RDMA_MSG); } chunkptr = &hdr->rm_body.rm_chunks[0]; - if (rtype != rdma_noch) { - ret = __rdma_create_read_chunks (peer, entry, rtype, &chunkptr, - request_ctx); + if (rtype != gf_rdma_noch) { + ret = __gf_rdma_create_read_chunks (peer, entry, rtype, + &chunkptr, + request_ctx); if (ret != 0) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "creation of read chunks failed"); goto out; } @@ -1054,11 +1815,12 @@ __rdma_ioq_churn_request (rdma_peer_t *peer, rdma_ioq_t *entry, *chunkptr++ = 0; /* no read chunks */ } - if (wtype != rdma_noch) { - ret = __rdma_create_write_chunks (peer, entry, wtype, &chunkptr, - request_ctx); + if (wtype != gf_rdma_noch) { + ret = __gf_rdma_create_write_chunks (peer, entry, wtype, + &chunkptr, + request_ctx); if (ret != 0) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "creation of write/reply chunk failed"); goto out; } @@ -1069,14 +1831,14 @@ __rdma_ioq_churn_request (rdma_peer_t *peer, rdma_ioq_t *entry, buf = (char *)chunkptr; - if (rtype != rdma_areadch) { + 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 != rdma_readch) { + if (rtype != gf_rdma_readch) { iov_unload (buf, entry->prog_payload, entry->prog_payload_count); buf += iov_length (entry->prog_payload, @@ -1086,18 +1848,18 @@ __rdma_ioq_churn_request (rdma_peer_t *peer, rdma_ioq_t *entry, len = buf - post->buf; - rdma_post_ref (post); + gf_rdma_post_ref (post); - ret = rdma_post_send (peer->qp, post, len); + ret = gf_rdma_post_send (peer->qp, post, len); if (!ret) { ret = len; } else { - gf_log (RDMA_LOG_NAME, GF_LOG_WARNING, - "rdma_post_send (to %s) failed with ret = %d (%s)", + 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) : ""); - rdma_post_unref (post); - __rdma_disconnect (peer->trans); + gf_rdma_post_unref (post); + __gf_rdma_disconnect (peer->trans); ret = -1; } @@ -1106,7 +1868,7 @@ out: rpc_req = entry->msg.request.rpc_req; if (request_ctx != NULL) { - __rdma_request_context_destroy (rpc_req->conn_private); + __gf_rdma_request_context_destroy (rpc_req->conn_private); } rpc_req->conn_private = NULL; @@ -1116,9 +1878,9 @@ out: } -inline void -__rdma_fill_reply_header (rdma_header_t *header, struct iovec *rpchdr, - rdma_reply_info_t *reply_info, int credits) +static 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; @@ -1132,8 +1894,8 @@ __rdma_fill_reply_header (rdma_header_t *header, struct iovec *rpchdr, header->rm_xid = rpc_msg->rm_xid; } - header->rm_type = hton32 (RDMA_MSG); - header->rm_vers = hton32 (RDMA_VERSION); + 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 */ @@ -1145,31 +1907,36 @@ __rdma_fill_reply_header (rdma_header_t *header, struct iovec *rpchdr, int32_t -__rdma_send_reply_inline (rdma_peer_t *peer, rdma_ioq_t *entry, - rdma_post_t *post, rdma_reply_info_t *reply_info) +__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) { - rdma_header_t *header = NULL; - int32_t send_size = 0, ret = 0; - char *buf = NULL; + 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 (rdma_header_t); /* - * remember, no chunklists in the - * reply - */ + + sizeof (gf_rdma_header_t); /* + * remember, no chunklists in the + * reply + */ if (send_size > GLUSTERFS_RDMA_INLINE_THRESHOLD) { - ret = __rdma_send_error (peer, entry, post, reply_info, - ERR_CHUNK); + ret = __gf_rdma_send_error (peer, entry, post, reply_info, + ERR_CHUNK); + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "msg size (%d) is greater than maximum size " + "of msg that can be sent inlined (%d)", + send_size, GLUSTERFS_RDMA_INLINE_THRESHOLD); goto out; } - header = (rdma_header_t *)post->buf; + header = (gf_rdma_header_t *)post->buf; - __rdma_fill_reply_header (header, entry->rpchdr, reply_info, - peer->send_count); + __gf_rdma_fill_reply_header (header, entry->rpchdr, reply_info, + peer->send_count); buf = (char *)&header->rm_body.rm_chunks[3]; @@ -1190,18 +1957,18 @@ __rdma_send_reply_inline (rdma_peer_t *peer, rdma_ioq_t *entry, entry->prog_payload_count); } - rdma_post_ref (post); + gf_rdma_post_ref (post); - ret = rdma_post_send (peer->qp, post, (buf - post->buf)); + ret = gf_rdma_post_send (peer->qp, post, (buf - post->buf)); if (!ret) { ret = send_size; } else { - gf_log (RDMA_LOG_NAME, GF_LOG_WARNING, - "rdma_post_send (to %s) failed with ret = %d (%s)", + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "posting send (to %s) failed with ret = %d (%s)", peer->trans->peerinfo.identifier, ret, (ret > 0) ? strerror (ret) : ""); - rdma_post_unref (post); - __rdma_disconnect (peer->trans); + gf_rdma_post_unref (post); + __gf_rdma_disconnect (peer->trans); ret = -1; } @@ -1211,17 +1978,18 @@ out: int32_t -__rdma_reply_encode_write_chunks (rdma_peer_t *peer, uint32_t payload_size, - rdma_post_t *post, - rdma_reply_info_t *reply_info, - uint32_t **ptr) +__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; - rdma_write_array_t *target_array = NULL; - int i = 0; + uint32_t chunk_size = 0; + int32_t ret = -1; + gf_rdma_write_array_t *target_array = NULL; + int i = 0; - target_array = (rdma_write_array_t *)*ptr; + target_array = (gf_rdma_write_array_t *)*ptr; for (i = 0; i < reply_info->wc_array->wc_nchunks; i++) { chunk_size += @@ -1229,7 +1997,7 @@ __rdma_reply_encode_write_chunks (rdma_peer_t *peer, uint32_t payload_size, } if (chunk_size < payload_size) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + 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; @@ -1260,18 +2028,17 @@ out: inline int32_t -__rdma_register_local_mr_for_rdma (rdma_peer_t *peer, - struct iovec *vector, int count, - rdma_post_context_t *ctx) +__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; - rdma_private_t *priv = NULL; - rdma_device_t *device = NULL; + 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; - } + GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, ctx, out); + GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, vector, out); priv = peer->trans->private; device = priv->device; @@ -1292,6 +2059,9 @@ __rdma_register_local_mr_for_rdma (rdma_peer_t *peer, vector[i].iov_len, IBV_ACCESS_LOCAL_WRITE); if (ctx->mr[ctx->mr_count] == NULL) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "registering memory for IBV_ACCESS_LOCAL_WRITE " + "failed (%s)", strerror (errno)); goto out; } @@ -1307,15 +2077,15 @@ out: * 2. modifies vec */ int32_t -__rdma_write (rdma_peer_t *peer, rdma_post_t *post, struct iovec *vec, - uint32_t xfer_len, int *idx, rdma_write_chunk_t *writech) +__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, + 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) @@ -1329,7 +2099,8 @@ __rdma_write (rdma_peer_t *peer, rdma_post_t *post, struct iovec *vec, num_sge = i - *idx; - sg_list = GF_CALLOC (num_sge, sizeof (struct ibv_sge), gf_common_mt_sge); + sg_list = GF_CALLOC (num_sge, sizeof (struct ibv_sge), + gf_common_mt_sge); if (sg_list == NULL) { ret = -1; goto out; @@ -1355,13 +2126,14 @@ __rdma_write (rdma_peer_t *peer, rdma_post_t *post, struct iovec *vec, wr.sg_list = sg_list; wr.num_sge = num_sge; - wr.wr_id = (unsigned long) rdma_post_ref (post); + 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 (RDMA_LOG_NAME, GF_LOG_WARNING, "rdma write to " + 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) : ""); @@ -1375,13 +2147,14 @@ out: int32_t -__rdma_do_rdma_write (rdma_peer_t *peer, rdma_post_t *post, - struct iovec *vector, int count, struct iobref *iobref, - rdma_reply_info_t *reply_info) +__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; + 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); @@ -1392,9 +2165,11 @@ __rdma_do_rdma_write (rdma_peer_t *peer, rdma_post_t *post, goto out; } - ret = __rdma_register_local_mr_for_rdma (peer, vector, count, - &post->ctx); + ret = __gf_rdma_register_local_mr_for_rdma (peer, vector, count, + &post->ctx); if (ret == -1) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "registering memory region for rdma failed"); goto out; } @@ -1406,9 +2181,13 @@ __rdma_do_rdma_write (rdma_peer_t *peer, rdma_post_t *post, xfer_len = min (payload_size, reply_info->wc_array->wc_array[i].wc_target.rs_length); - ret = __rdma_write (peer, post, vector, xfer_len, &payload_idx, - &reply_info->wc_array->wc_array[i]); + ret = __gf_rdma_write (peer, post, vector, xfer_len, + &payload_idx, + &reply_info->wc_array->wc_array[i]); if (ret == -1) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "rdma write to client (%s) failed", + peer->trans->peerinfo.identifier); goto out; } @@ -1423,39 +2202,41 @@ out: int32_t -__rdma_send_reply_type_nomsg (rdma_peer_t *peer, rdma_ioq_t *entry, - rdma_post_t *post, rdma_reply_info_t *reply_info) +__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) { - 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]; + 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 = (rdma_header_t *)post->buf; + header = (gf_rdma_header_t *)post->buf; - __rdma_fill_reply_header (header, entry->rpchdr, reply_info, - peer->send_count); + __gf_rdma_fill_reply_header (header, entry->rpchdr, reply_info, + peer->send_count); - header->rm_type = hton32 (RDMA_NOMSG); + 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 = __rdma_reply_encode_write_chunks (peer, payload_size, post, - reply_info, (uint32_t **)&buf); + ret = __gf_rdma_reply_encode_write_chunks (peer, payload_size, post, + reply_info, + (uint32_t **)&buf); if (ret == -1) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "encoding write chunks failed"); - ret = __rdma_send_error (peer, entry, post, reply_info, - ERR_CHUNK); + ret = __gf_rdma_send_error (peer, entry, post, reply_info, + ERR_CHUNK); goto out; } - rdma_post_ref (post); + gf_rdma_post_ref (post); for (i = 0; i < entry->rpchdr_count; i++) { vector[count++] = entry->rpchdr[i]; @@ -1465,21 +2246,24 @@ __rdma_send_reply_type_nomsg (rdma_peer_t *peer, rdma_ioq_t *entry, vector[count++] = entry->proghdr[i]; } - ret = __rdma_do_rdma_write (peer, post, vector, count, entry->iobref, - reply_info); + ret = __gf_rdma_do_gf_rdma_write (peer, post, vector, count, + entry->iobref, reply_info); if (ret == -1) { - rdma_post_unref (post); + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "rdma write to peer (%s) failed", + peer->trans->peerinfo.identifier); + gf_rdma_post_unref (post); goto out; } - ret = rdma_post_send (peer->qp, post, (buf - post->buf)); + ret = gf_rdma_post_send (peer->qp, post, (buf - post->buf)); if (ret) { - gf_log (RDMA_LOG_NAME, GF_LOG_WARNING, - "rdma_post_send to client (%s) failed with " + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "posting a send request to client (%s) failed with " "ret = %d (%s)", peer->trans->peerinfo.identifier, ret, (ret > 0) ? strerror (ret) : ""); ret = -1; - rdma_post_unref (post); + gf_rdma_post_unref (post); } else { ret = payload_size; } @@ -1490,60 +2274,64 @@ out: int32_t -__rdma_send_reply_type_msg (rdma_peer_t *peer, rdma_ioq_t *entry, - rdma_post_t *post, rdma_reply_info_t *reply_info) +__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) { - rdma_header_t *header = NULL; - int32_t send_size = 0, ret = 0; - char *ptr = NULL; - uint32_t payload_size = 0; + 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 (RDMA_LOG_NAME, GF_LOG_WARNING, + 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 = __rdma_send_error (peer, entry, post, reply_info, - ERR_CHUNK); + ret = __gf_rdma_send_error (peer, entry, post, reply_info, + ERR_CHUNK); goto out; } - header = (rdma_header_t *)post->buf; + header = (gf_rdma_header_t *)post->buf; - __rdma_fill_reply_header (header, entry->rpchdr, reply_info, - peer->send_count); + __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 = __rdma_reply_encode_write_chunks (peer, payload_size, post, - reply_info, (uint32_t **)&ptr); + ret = __gf_rdma_reply_encode_write_chunks (peer, payload_size, post, + reply_info, + (uint32_t **)&ptr); if (ret == -1) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "encoding write chunks failed"); - ret = __rdma_send_error (peer, entry, post, reply_info, - ERR_CHUNK); + 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); - rdma_post_ref (post); + gf_rdma_post_ref (post); - ret = __rdma_do_rdma_write (peer, post, entry->prog_payload, - entry->prog_payload_count, entry->iobref, - reply_info); + ret = __gf_rdma_do_gf_rdma_write (peer, post, entry->prog_payload, + entry->prog_payload_count, + entry->iobref, reply_info); if (ret == -1) { - rdma_post_unref (post); + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "rdma write to peer " + "(%s) failed", peer->trans->peerinfo.identifier); + gf_rdma_post_unref (post); goto out; } @@ -1553,13 +2341,13 @@ __rdma_send_reply_type_msg (rdma_peer_t *peer, rdma_ioq_t *entry, iov_unload (ptr, entry->proghdr, entry->proghdr_count); ptr += iov_length (entry->proghdr, entry->proghdr_count); - ret = rdma_post_send (peer->qp, post, (ptr - post->buf)); + ret = gf_rdma_post_send (peer->qp, post, (ptr - post->buf)); if (ret) { - gf_log (RDMA_LOG_NAME, GF_LOG_WARNING, + 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) : ""); - rdma_post_unref (post); + gf_rdma_post_unref (post); ret = -1; } else { ret = send_size + payload_size; @@ -1571,7 +2359,7 @@ out: void -rdma_reply_info_destroy (rdma_reply_info_t *reply_info) +gf_rdma_reply_info_destroy (gf_rdma_reply_info_t *reply_info) { if (reply_info == NULL) { goto out; @@ -1588,11 +2376,11 @@ out: } -rdma_reply_info_t * -rdma_reply_info_alloc (rdma_peer_t *peer) +gf_rdma_reply_info_t * +gf_rdma_reply_info_alloc (gf_rdma_peer_t *peer) { - rdma_reply_info_t *reply_info = NULL; - rdma_private_t *priv = NULL; + gf_rdma_reply_info_t *reply_info = NULL; + gf_rdma_private_t *priv = NULL; priv = peer->trans->private; @@ -1610,15 +2398,16 @@ out: int32_t -__rdma_ioq_churn_reply (rdma_peer_t *peer, rdma_ioq_t *entry, rdma_post_t *post) +__gf_rdma_ioq_churn_reply (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry, + gf_rdma_post_t *post) { - rdma_reply_info_t *reply_info = NULL; - int32_t ret = -1; - rdma_chunktype_t type = rdma_noch; + 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; - } + GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, peer, out); + GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, entry, out); + GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, post, out); reply_info = entry->msg.reply_info; if (reply_info != NULL) { @@ -1626,29 +2415,47 @@ __rdma_ioq_churn_reply (rdma_peer_t *peer, rdma_ioq_t *entry, rdma_post_t *post) } switch (type) { - case rdma_noch: - ret = __rdma_send_reply_inline (peer, entry, post, reply_info); + case gf_rdma_noch: + ret = __gf_rdma_send_reply_inline (peer, entry, post, + reply_info); + if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "failed to send reply to peer (%s) as an " + "inlined rdma msg", + peer->trans->peerinfo.identifier); + } break; - case rdma_replych: - ret = __rdma_send_reply_type_nomsg (peer, entry, post, - reply_info); + case gf_rdma_replych: + ret = __gf_rdma_send_reply_type_nomsg (peer, entry, post, + reply_info); + if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "failed to send reply to peer (%s) as " + "RDMA_NOMSG", peer->trans->peerinfo.identifier); + } break; - case rdma_writech: - ret = __rdma_send_reply_type_msg (peer, entry, post, - reply_info); + case gf_rdma_writech: + ret = __gf_rdma_send_reply_type_msg (peer, entry, post, + reply_info); + if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "failed to send reply with write chunks " + "to peer (%s)", + peer->trans->peerinfo.identifier); + } break; default: - gf_log (RDMA_LOG_NAME, GF_LOG_WARNING, - "invalid chunktype (%d) specified for sending reply", - type); + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "invalid chunktype (%d) specified for sending reply " + " (peer:%s)", type, peer->trans->peerinfo.identifier); break; } if (reply_info != NULL) { - rdma_reply_info_destroy (reply_info); + gf_rdma_reply_info_destroy (reply_info); } out: return ret; @@ -1656,40 +2463,54 @@ out: int32_t -__rdma_ioq_churn_entry (rdma_peer_t *peer, rdma_ioq_t *entry) +__gf_rdma_ioq_churn_entry (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry) { - int32_t ret = 0, quota = 0; - rdma_private_t *priv = NULL; - rdma_device_t *device = NULL; - rdma_options_t *options = NULL; - rdma_post_t *post = NULL; + 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 = __rdma_quota_get (peer); + quota = __gf_rdma_quota_get (peer); if (quota > 0) { - post = rdma_get_post (&device->sendq); + post = gf_rdma_get_post (&device->sendq); if (post == NULL) { - post = rdma_new_post (device, - (options->send_size + 2048), - RDMA_SEND_POST); + post = gf_rdma_new_post (peer->trans, device, + (options->send_size + 2048), + GF_RDMA_SEND_POST); } if (post == NULL) { ret = -1; + gf_log_callingfn (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "not able to get a post to send msg"); goto out; } if (entry->is_request) { - ret = __rdma_ioq_churn_request (peer, entry, post); + ret = __gf_rdma_ioq_churn_request (peer, entry, post); + if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "failed to process request ioq entry " + "to peer(%s)", + peer->trans->peerinfo.identifier); + } } else { - ret = __rdma_ioq_churn_reply (peer, entry, post); + ret = __gf_rdma_ioq_churn_reply (peer, entry, post); + if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "failed to process reply ioq entry " + "to peer (%s)", + peer->trans->peerinfo.identifier); + } } if (ret != 0) { - __rdma_ioq_entry_free (entry); + __gf_rdma_ioq_entry_free (entry); } } else { ret = 0; @@ -1701,17 +2522,17 @@ out: static int32_t -__rdma_ioq_churn (rdma_peer_t *peer) +__gf_rdma_ioq_churn (gf_rdma_peer_t *peer) { - rdma_ioq_t *entry = NULL; - int32_t ret = 0; + gf_rdma_ioq_t *entry = NULL; + int32_t ret = 0; while (!list_empty (&peer->ioq)) { /* pick next entry */ entry = peer->ioq_next; - ret = __rdma_ioq_churn_entry (peer, entry); + ret = __gf_rdma_ioq_churn_entry (peer, entry); if (ret <= 0) break; @@ -1719,7 +2540,7 @@ __rdma_ioq_churn (rdma_peer_t *peer) /* list_for_each_entry_safe (entry, dummy, &peer->ioq, list) { - ret = __rdma_ioq_churn_entry (peer, entry); + ret = __gf_rdma_ioq_churn_entry (peer, entry); if (ret <= 0) { break; } @@ -1731,28 +2552,35 @@ __rdma_ioq_churn (rdma_peer_t *peer) static int32_t -rdma_writev (rpc_transport_t *this, - rdma_ioq_t *entry) +gf_rdma_writev (rpc_transport_t *this, gf_rdma_ioq_t *entry) { - int32_t ret = 0, need_append = 1; - rdma_private_t *priv = this->private; - rdma_peer_t *peer = NULL; + 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"); + gf_log (this->name, GF_LOG_WARNING, + "rdma is not connected to peer (%s)", + this->peerinfo.identifier); ret = -1; goto unlock; } peer = &priv->peer; if (list_empty (&peer->ioq)) { - ret = __rdma_ioq_churn_entry (peer, entry); + ret = __gf_rdma_ioq_churn_entry (peer, entry); if (ret != 0) { need_append = 0; + + if (ret < 0) { + gf_log (this->name, GF_LOG_WARNING, + "processing ioq entry destined " + "to (%s) failed", + this->peerinfo.identifier); + } } } @@ -1766,20 +2594,20 @@ unlock: } -rdma_ioq_t * -rdma_ioq_new (rpc_transport_t *this, rpc_transport_data_t *data) +gf_rdma_ioq_t * +gf_rdma_ioq_new (rpc_transport_t *this, rpc_transport_data_t *data) { - rdma_ioq_t *entry = NULL; - int count = 0, i = 0; - rpc_transport_msg_t *msg = NULL; - rdma_private_t *priv = NULL; + 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; - /* TODO: use mem-pool */ + entry = mem_get (priv->device->ioq_pool); if (entry == NULL) { goto out; @@ -1857,12 +2685,11 @@ out: int32_t -rdma_submit_request (rpc_transport_t *this, - rpc_transport_req_t *req) +gf_rdma_submit_request (rpc_transport_t *this, rpc_transport_req_t *req) { - int32_t ret = 0; - rdma_ioq_t *entry = NULL; - rpc_transport_data_t data = {0, }; + int32_t ret = 0; + gf_rdma_ioq_t *entry = NULL; + rpc_transport_data_t data = {0, }; if (req == NULL) { goto out; @@ -1871,16 +2698,22 @@ rdma_submit_request (rpc_transport_t *this, data.is_request = 1; data.data.req = *req; - entry = rdma_ioq_new (this, &data); + entry = gf_rdma_ioq_new (this, &data); if (entry == NULL) { + gf_log (this->name, GF_LOG_WARNING, + "getting a new ioq entry failed (peer:%s)", + this->peerinfo.identifier); goto out; } - ret = rdma_writev (this, entry); + ret = gf_rdma_writev (this, entry); if (ret > 0) { ret = 0; } else if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "sending request to peer (%s) failed", + this->peerinfo.identifier); rpc_transport_disconnect (this); } @@ -1889,11 +2722,11 @@ out: } int32_t -rdma_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply) +gf_rdma_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply) { - int32_t ret = 0; - rdma_ioq_t *entry = NULL; - rpc_transport_data_t data = {0, }; + int32_t ret = 0; + gf_rdma_ioq_t *entry = NULL; + rpc_transport_data_t data = {0, }; if (reply == NULL) { goto out; @@ -1901,15 +2734,21 @@ rdma_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply) data.data.reply = *reply; - entry = rdma_ioq_new (this, &data); + entry = gf_rdma_ioq_new (this, &data); if (entry == NULL) { + gf_log (this->name, GF_LOG_WARNING, + "getting a new ioq entry failed (peer:%s)", + this->peerinfo.identifier); goto out; } - ret = rdma_writev (this, entry); + ret = gf_rdma_writev (this, entry); if (ret > 0) { ret = 0; } else if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "sending request to peer (%s) failed", + this->peerinfo.identifier); rpc_transport_disconnect (this); } @@ -1917,196 +2756,15 @@ out: return ret; } -#if 0 -static int -rdma_receive (rpc_transport_t *this, char **hdr_p, size_t *hdrlen_p, - struct iobuf **iobuf_p) -{ - 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; - 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 = (rdma_header_t *)copy_from; - if (strcmp (header->colonO, ":O")) { - gf_log (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 (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 -rdma_destroy_cq (rpc_transport_t *this) -{ - rdma_private_t *priv = this->private; - rdma_device_t *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 -rdma_create_cq (rpc_transport_t *this) -{ - rdma_private_t *priv = NULL; - rdma_options_t *options = NULL; - 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 (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 (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 (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 (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 (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) - rdma_destroy_cq (this); - - return ret; -} - static int -rdma_register_peer (rdma_device_t *device, - int32_t qp_num, - rdma_peer_t *peer) +gf_rdma_register_peer (gf_rdma_device_t *device, int32_t qp_num, + gf_rdma_peer_t *peer) { - struct _qpent *ent = NULL; - rdma_qpreg_t *qpreg = NULL; - int32_t hash = 0; - int ret = -1; + struct _qpent *ent = NULL; + gf_rdma_qpreg_t *qpreg = NULL; + int32_t hash = 0; + int ret = -1; qpreg = &device->qpreg; hash = qp_num % 42; @@ -2147,37 +2805,41 @@ unlock: static void -rdma_unregister_peer (rdma_device_t *device, - int32_t qp_num) +gf_rdma_unregister_peer (gf_rdma_device_t *device, int32_t qp_num) { - struct _qpent *ent; - rdma_qpreg_t *qpreg = &device->qpreg; - int32_t hash = qp_num % 42; + 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--; + { + 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 rdma_peer_t * -__rdma_lookup_peer (rdma_device_t *device, int32_t qp_num) +static gf_rdma_peer_t * +__gf_rdma_lookup_peer (gf_rdma_device_t *device, int32_t qp_num) { - struct _qpent *ent = NULL; - rdma_peer_t *peer = NULL; - rdma_qpreg_t *qpreg = NULL; - int32_t hash = 0; + 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; @@ -2192,34 +2854,16 @@ __rdma_lookup_peer (rdma_device_t *device, int32_t qp_num) return peer; } -/* - static rdma_peer_t * - rdma_lookup_peer (rdma_device_t *device, - int32_t qp_num) - { - rdma_qpreg_t *qpreg = NULL; - rdma_peer_t *peer = NULL; - - qpreg = &device->qpreg; - pthread_mutex_lock (&qpreg->lock); - { - peer = __rdma_lookup_peer (device, qp_num); - } - pthread_mutex_unlock (&qpreg->lock); - - return peer; - } -*/ - static void -__rdma_destroy_qp (rpc_transport_t *this) +__gf_rdma_destroy_qp (rpc_transport_t *this) { - rdma_private_t *priv = this->private; + gf_rdma_private_t *priv = NULL; + priv = this->private; if (priv->peer.qp) { - rdma_unregister_peer (priv->device, priv->peer.qp->qp_num); - ibv_destroy_qp (priv->peer.qp); + gf_rdma_unregister_peer (priv->device, priv->peer.qp->qp_num); + rdma_destroy_qp (priv->peer.cm_id); } priv->peer.qp = NULL; @@ -2228,15 +2872,38 @@ __rdma_destroy_qp (rpc_transport_t *this) static int32_t -rdma_create_qp (rpc_transport_t *this) +gf_rdma_create_qp (rpc_transport_t *this) { - rdma_private_t *priv = this->private; - rdma_options_t *options = &priv->options; - rdma_device_t *device = priv->device; - int32_t ret = 0; - rdma_peer_t *peer; + gf_rdma_private_t *priv = NULL; + gf_rdma_device_t *device = NULL; + int32_t ret = 0; + gf_rdma_peer_t *peer = NULL; + char *device_name = NULL; + + priv = this->private; peer = &priv->peer; + + device_name = (char *)ibv_get_device_name (peer->cm_id->verbs->device); + if (device_name == NULL) { + ret = -1; + gf_log (this->name, GF_LOG_WARNING, "cannot get device_name"); + goto out; + } + + device = gf_rdma_get_device (this, peer->cm_id->verbs, + device_name); + if (device == NULL) { + ret = -1; + gf_log (this->name, GF_LOG_WARNING, "cannot get device for " + "device %s", device_name); + goto out; + } + + if (priv->device == NULL) { + priv->device = device; + } + struct ibv_qp_init_attr init_attr = { .send_cq = device->send_cq, .recv_cq = device->recv_cq, @@ -2250,333 +2917,73 @@ rdma_create_qp (rpc_transport_t *this) .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 (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 (RDMA_LOG_NAME, - GF_LOG_ERROR, - "%s: failed to modify QP to INIT state", - this->name); + ret = rdma_create_qp(peer->cm_id, device->pd, &init_attr); + if (ret != 0) { + gf_log (peer->trans->name, GF_LOG_CRITICAL, + "%s: could not create QP (%s)", this->name, + strerror (errno)); ret = -1; goto out; } - peer->local_lid = rdma_get_local_lid (device->context, - options->port); - peer->local_qpn = peer->qp->qp_num; - peer->local_psn = lrand48 () & 0xffffff; + peer->qp = peer->cm_id->qp; - ret = rdma_register_peer (device, peer->qp->qp_num, peer); + ret = gf_rdma_register_peer (device, peer->qp->qp_num, peer); out: if (ret == -1) - __rdma_destroy_qp (this); + __gf_rdma_destroy_qp (this); return ret; } -static void -rdma_destroy_posts (rpc_transport_t *this) -{ - -} - - static int32_t -__rdma_create_posts (rpc_transport_t *this, int32_t count, int32_t size, - rdma_queue_t *q, rdma_post_type_t type) +__gf_rdma_teardown (rpc_transport_t *this) { - int32_t i; - int32_t ret = 0; - rdma_private_t *priv = this->private; - rdma_device_t *device = priv->device; - - for (i=0 ; i<count ; i++) { - rdma_post_t *post; - - post = rdma_new_post (device, size + 2048, type); - if (!post) { - gf_log (RDMA_LOG_NAME, - GF_LOG_ERROR, - "%s: post creation failed", - this->name); - ret = -1; - break; - } - - rdma_put_post (q, post); - } - return ret; -} - + gf_rdma_private_t *priv = NULL; + gf_rdma_peer_t *peer = NULL; -static int32_t -rdma_create_posts (rpc_transport_t *this) -{ - int32_t i, ret; - rdma_post_t *post = NULL; - rdma_private_t *priv = this->private; - rdma_options_t *options = &priv->options; - rdma_device_t *device = priv->device; - - ret = __rdma_create_posts (this, options->send_count, - options->send_size, - &device->sendq, RDMA_SEND_POST); - if (!ret) - ret = __rdma_create_posts (this, options->recv_count, - options->recv_size, - &device->recvq, RDMA_RECV_POST); + priv = this->private; + peer = &priv->peer; - if (!ret) { - for (i=0 ; i<options->recv_count ; i++) { - post = rdma_get_post (&device->recvq); - if (rdma_post_recv (device->srq, post) != 0) { - ret = -1; - break; - } - } + if (peer->cm_id->qp != NULL) { + __gf_rdma_destroy_qp (this); } - if (ret) - rdma_destroy_posts (this); - - return ret; -} - - -static int32_t -rdma_connect_qp (rpc_transport_t *this) -{ - rdma_private_t *priv = this->private; - 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 (RDMA_LOG_NAME, - GF_LOG_CRITICAL, - "Failed to modify QP to RTR\n"); - return -1; + if (!list_empty (&priv->peer.ioq)) { + __gf_rdma_ioq_flush (peer); } - /* TODO: make timeout and retry_cnt configurable from options */ - attr.qp_state = IBV_QPS_RTS; - attr.timeout = 14; - attr.retry_cnt = 7; - attr.rnr_retry = 7; - 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 (RDMA_LOG_NAME, - GF_LOG_CRITICAL, - "Failed to modify QP to RTS\n"); - return -1; + if (peer->cm_id != NULL) { + rdma_destroy_id (peer->cm_id); + peer->cm_id = NULL; } + /* TODO: decrement cq size */ return 0; } + static int32_t -__rdma_teardown (rpc_transport_t *this) +gf_rdma_teardown (rpc_transport_t *this) { - rdma_private_t *priv = this->private; - - __rdma_destroy_qp (this); + int32_t ret = 0; + gf_rdma_private_t *priv = NULL; - if (!list_empty (&priv->peer.ioq)) { - __rdma_ioq_flush (&priv->peer); + if (this == NULL) { + goto out; } - /* 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) -{ - rdma_private_t *priv = NULL; - int sock = -1; - int ret = -1; - struct iovec *opvector = vector; - int opcount = count; - int moved = 0; - priv = this->private; - sock = priv->sock; - while (opcount) + pthread_mutex_lock (&priv->write_mutex); { - 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; - rdma_private_t *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); + ret = __gf_rdma_teardown (this); } + pthread_mutex_unlock (&priv->write_mutex); +out: return ret; } @@ -2588,12 +2995,12 @@ __tcp_writev (rpc_transport_t *this, struct iovec *vector, int count, * event is sent to upper layers. */ int32_t -rdma_get_write_chunklist (char **ptr, rdma_write_array_t **write_ary) +gf_rdma_get_write_chunklist (char **ptr, gf_rdma_write_array_t **write_ary) { - rdma_write_array_t *from = NULL, *to = NULL; - int32_t ret = -1, size = 0, i = 0; + gf_rdma_write_array_t *from = NULL, *to = NULL; + int32_t ret = -1, size = 0, i = 0; - from = (rdma_write_array_t *) *ptr; + from = (gf_rdma_write_array_t *) *ptr; if (from->wc_discrim == 0) { ret = 0; goto out; @@ -2602,7 +3009,7 @@ rdma_get_write_chunklist (char **ptr, rdma_write_array_t **write_ary) from->wc_nchunks = ntoh32 (from->wc_nchunks); size = sizeof (*from) - + (sizeof (rdma_write_chunk_t) * from->wc_nchunks); + + (sizeof (gf_rdma_write_chunk_t) * from->wc_nchunks); to = GF_CALLOC (1, size, gf_common_mt_char); if (to == NULL) { @@ -2636,13 +3043,13 @@ out: * rdma-reads and hence readchunk-list can point to memory held by post. */ int32_t -rdma_get_read_chunklist (char **ptr, rdma_read_chunk_t **readch) +gf_rdma_get_read_chunklist (char **ptr, gf_rdma_read_chunk_t **readch) { - int32_t ret = -1; - rdma_read_chunk_t *chunk = NULL; - int i = 0; + int32_t ret = -1; + gf_rdma_read_chunk_t *chunk = NULL; + int i = 0; - chunk = (rdma_read_chunk_t *)*ptr; + chunk = (gf_rdma_read_chunk_t *)*ptr; if (chunk[0].rc_discrim == 0) { ret = 0; goto out; @@ -2668,25 +3075,30 @@ out: inline int32_t -rdma_decode_error_msg (rdma_peer_t *peer, rdma_post_t *post, - size_t bytes_in_post) +gf_rdma_decode_error_msg (gf_rdma_peer_t *peer, gf_rdma_post_t *post, + size_t bytes_in_post) { - rdma_header_t *header = NULL; - struct iobuf *iobuf = NULL; - struct iobref *iobref = NULL; - int32_t ret = -1; + gf_rdma_header_t *header = NULL; + struct iobuf *iobuf = NULL; + struct iobref *iobref = NULL; + int32_t ret = -1; + struct rpc_msg rpc_msg = {0, }; - header = (rdma_header_t *)post->buf; + 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.rdma_vers_low = - ntoh32 (header->rm_body.rm_error.rm_version.rdma_vers_low); - header->rm_body.rm_error.rm_version.rdma_vers_high = - ntoh32 (header->rm_body.rm_error.rm_version.rdma_vers_high); + 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); + rpc_msg.rm_xid = header->rm_xid; + rpc_msg.rm_direction = REPLY; + rpc_msg.rm_reply.rp_stat = MSG_DENIED; + + iobuf = iobuf_get2 (peer->trans->ctx->iobuf_pool, bytes_in_post); if (iobuf == NULL) { ret = -1; goto out; @@ -2700,15 +3112,15 @@ rdma_decode_error_msg (rdma_peer_t *peer, rdma_post_t *post, 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); + + ret = rpc_reply_to_xdr (&rpc_msg, iobuf_ptr (iobuf), + iobuf_pagesize (iobuf), &post->ctx.vector[0]); + if (ret == -1) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "Failed to create RPC reply"); + goto out; + } + post->ctx.count = 1; iobuf = NULL; @@ -2730,30 +3142,34 @@ out: int32_t -rdma_decode_msg (rdma_peer_t *peer, rdma_post_t *post, - rdma_read_chunk_t **readch, size_t bytes_in_post) +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; - rdma_header_t *header = NULL; - rdma_reply_info_t *reply_info = NULL; - char *ptr = NULL; - rdma_write_array_t *write_ary = NULL; - size_t header_len = 0; + 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 = (rdma_header_t *)post->buf; + header = (gf_rdma_header_t *)post->buf; ptr = (char *)&header->rm_body.rm_chunks[0]; - ret = rdma_get_read_chunklist (&ptr, readch); + ret = gf_rdma_get_read_chunklist (&ptr, readch); if (ret == -1) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "cannot get read chunklist from msg"); goto out; } /* skip terminator of read-chunklist */ ptr = ptr + sizeof (uint32_t); - ret = rdma_get_write_chunklist (&ptr, &write_ary); + ret = gf_rdma_get_write_chunklist (&ptr, &write_ary); if (ret == -1) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "cannot get write chunklist from msg"); goto out; } @@ -2761,29 +3177,35 @@ rdma_decode_msg (rdma_peer_t *peer, rdma_post_t *post, ptr = ptr + sizeof (uint32_t); if (write_ary != NULL) { - reply_info = rdma_reply_info_alloc (peer); + reply_info = gf_rdma_reply_info_alloc (peer); if (reply_info == NULL) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "reply_info_alloc failed"); ret = -1; goto out; } - reply_info->type = rdma_writech; + reply_info->type = gf_rdma_writech; reply_info->wc_array = write_ary; reply_info->rm_xid = header->rm_xid; } else { - ret = rdma_get_write_chunklist (&ptr, &write_ary); + ret = gf_rdma_get_write_chunklist (&ptr, &write_ary); if (ret == -1) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "cannot get reply chunklist from msg"); goto out; } if (write_ary != NULL) { - reply_info = rdma_reply_info_alloc (peer); + reply_info = gf_rdma_reply_info_alloc (peer); if (reply_info == NULL) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "reply_info_alloc_failed"); ret = -1; goto out; } - reply_info->type = rdma_replych; + reply_info->type = gf_rdma_replych; reply_info->wc_array = write_ary; reply_info->rm_xid = header->rm_xid; } @@ -2791,16 +3213,18 @@ rdma_decode_msg (rdma_peer_t *peer, rdma_post_t *post, /* skip terminator of reply chunk */ ptr = ptr + sizeof (uint32_t); - if (header->rm_type != RDMA_NOMSG) { - post->ctx.hdr_iobuf = iobuf_get (peer->trans->ctx->iobuf_pool); + if (header->rm_type != GF_RDMA_NOMSG) { + header_len = (long)ptr - (long)post->buf; + post->ctx.vector[0].iov_len = (bytes_in_post - header_len); + + post->ctx.hdr_iobuf = iobuf_get2 (peer->trans->ctx->iobuf_pool, + (bytes_in_post - header_len)); if (post->ctx.hdr_iobuf == NULL) { ret = -1; goto out; } - 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; @@ -2814,9 +3238,7 @@ out: *readch = NULL; } - if (write_ary != NULL) { - GF_FREE (write_ary); - } + GF_FREE (write_ary); } return ret; @@ -2825,13 +3247,13 @@ out: /* Assumes only one of either write-chunklist or a reply chunk is present */ int32_t -rdma_decode_header (rdma_peer_t *peer, rdma_post_t *post, - rdma_read_chunk_t **readch, size_t bytes_in_post) +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; - rdma_header_t *header = NULL; + int32_t ret = -1; + gf_rdma_header_t *header = NULL; - header = (rdma_header_t *)post->buf; + header = (gf_rdma_header_t *)post->buf; header->rm_xid = ntoh32 (header->rm_xid); header->rm_vers = ntoh32 (header->rm_vers); @@ -2839,31 +3261,39 @@ rdma_decode_header (rdma_peer_t *peer, rdma_post_t *post, header->rm_type = ntoh32 (header->rm_type); switch (header->rm_type) { - case RDMA_MSG: - case RDMA_NOMSG: - ret = rdma_decode_msg (peer, post, readch, bytes_in_post); + case GF_RDMA_MSG: + case GF_RDMA_NOMSG: + ret = gf_rdma_decode_msg (peer, post, readch, bytes_in_post); + if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "cannot decode msg of type (%d)", + header->rm_type); + } + break; - case RDMA_MSGP: - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, - "rdma msg of msg-type RDMA_MSGP should not have been " - "received"); + case GF_RDMA_MSGP: + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "rdma msg of msg-type GF_RDMA_MSGP should not have " + "been received"); ret = -1; break; - case RDMA_DONE: - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, - "rdma msg of msg-type RDMA_DONE should not have been " - "received"); + case GF_RDMA_DONE: + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "rdma msg of msg-type GF_RDMA_DONE should not have " + "been received"); ret = -1; break; - case RDMA_ERROR: - /* ret = rdma_decode_error_msg (peer, post, bytes_in_post); */ + case GF_RDMA_ERROR: + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "received a msg of type RDMA_ERROR"); + ret = gf_rdma_decode_error_msg (peer, post, bytes_in_post); break; default: - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "unknown rdma msg-type (%d)", header->rm_type); } @@ -2872,15 +3302,17 @@ rdma_decode_header (rdma_peer_t *peer, rdma_post_t *post, int32_t -__rdma_read (rdma_peer_t *peer, rdma_post_t *post, struct iovec *to, - rdma_read_chunk_t *readch) +__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; + int32_t ret = -1; struct ibv_sge list = {0, }; - struct ibv_send_wr wr = {0, }, *bad_wr = NULL; + struct ibv_send_wr wr = {0, }, *bad_wr = NULL; - ret = __rdma_register_local_mr_for_rdma (peer, to, 1, &post->ctx); + ret = __gf_rdma_register_local_mr_for_rdma (peer, to, 1, &post->ctx); if (ret == -1) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "registering local memory for rdma read failed"); goto out; } @@ -2888,7 +3320,7 @@ __rdma_read (rdma_peer_t *peer, rdma_post_t *post, struct iovec *to, list.length = to->iov_len; list.lkey = post->ctx.mr[post->ctx.mr_count - 1]->lkey; - wr.wr_id = (unsigned long) rdma_post_ref (post); + wr.wr_id = (unsigned long) gf_rdma_post_ref (post); wr.sg_list = &list; wr.num_sge = 1; wr.opcode = IBV_WR_RDMA_READ; @@ -2898,12 +3330,13 @@ __rdma_read (rdma_peer_t *peer, rdma_post_t *post, struct iovec *to, ret = ibv_post_send (peer->qp, &wr, &bad_wr); if (ret) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, "rdma read from client " + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "rdma read from client " "(%s) failed with ret = %d (%s)", peer->trans->peerinfo.identifier, ret, (ret > 0) ? strerror (ret) : ""); ret = -1; - rdma_post_unref (post); + gf_rdma_post_unref (post); } out: return ret; @@ -2911,13 +3344,14 @@ out: int32_t -rdma_do_reads (rdma_peer_t *peer, rdma_post_t *post, rdma_read_chunk_t *readch) +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; - rdma_private_t *priv = NULL; + 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; @@ -2926,24 +3360,15 @@ rdma_do_reads (rdma_peer_t *peer, rdma_post_t *post, rdma_read_chunk_t *readch) } if (i == 0) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "message type specified as rdma-read but there are no " "rdma read-chunks present"); goto out; } - post->ctx.rdma_reads = i; + post->ctx.gf_rdma_reads = i; - if (size > peer->trans->ctx->page_size) { - gf_log (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); + iobuf = iobuf_get2 (peer->trans->ctx->iobuf_pool, size); if (iobuf == NULL) { goto out; } @@ -2965,6 +3390,10 @@ rdma_do_reads (rdma_peer_t *peer, rdma_post_t *post, rdma_read_chunk_t *readch) pthread_mutex_lock (&priv->write_mutex); { if (!priv->connected) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "transport not connected to peer (%s), " + "not doing rdma reads", + peer->trans->peerinfo.identifier); goto unlock; } @@ -2974,10 +3403,13 @@ rdma_do_reads (rdma_peer_t *peer, rdma_post_t *post, rdma_read_chunk_t *readch) post->ctx.vector[count].iov_len = readch[i].rc_target.rs_length; - ret = __rdma_read (peer, post, - &post->ctx.vector[count], - &readch[i]); + ret = __gf_rdma_read (peer, post, + &post->ctx.vector[count], + &readch[i]); if (ret == -1) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "rdma read from peer (%s) failed", + peer->trans->peerinfo.identifier); goto unlock; } @@ -3001,16 +3433,16 @@ out: int32_t -rdma_pollin_notify (rdma_peer_t *peer, rdma_post_t *post) +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; - rdma_request_context_t *request_context = NULL; - rpc_request_info_t request_info = {0, }; - rdma_private_t *priv = NULL; - uint32_t *ptr = NULL; - rpc_transport_pollin_t *pollin = NULL; + 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; @@ -3051,7 +3483,7 @@ rdma_pollin_notify (rdma_peer_t *peer, rdma_post_t *post) RPC_TRANSPORT_MAP_XID_REQUEST, &request_info); if (ret == -1) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, "cannot get request information from rpc " "layer"); goto out; @@ -3059,7 +3491,7 @@ rdma_pollin_notify (rdma_peer_t *peer, rdma_post_t *post) rpc_req = request_info.rpc_req; if (rpc_req == NULL) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, "rpc request structure not found"); ret = -1; goto out; @@ -3072,11 +3504,11 @@ rdma_pollin_notify (rdma_peer_t *peer, rdma_post_t *post) if (request_context != NULL) { pthread_mutex_lock (&priv->write_mutex); { - __rdma_request_context_destroy (request_context); + __gf_rdma_request_context_destroy (request_context); } pthread_mutex_unlock (&priv->write_mutex); } else { - rdma_quota_put (peer); + gf_rdma_quota_put (peer); } pollin->is_reply = 1; @@ -3084,6 +3516,10 @@ rdma_pollin_notify (rdma_peer_t *peer, rdma_post_t *post) ret = rpc_transport_notify (peer->trans, RPC_TRANSPORT_MSG_RECEIVED, pollin); + if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "transport_notify failed"); + } out: if (pollin != NULL) { @@ -3096,19 +3532,19 @@ out: int32_t -rdma_recv_reply (rdma_peer_t *peer, rdma_post_t *post) +gf_rdma_recv_reply (gf_rdma_peer_t *peer, gf_rdma_post_t *post) { - int32_t ret = -1; - rdma_header_t *header = NULL; - rdma_reply_info_t *reply_info = NULL; - rdma_write_array_t *wc_array = NULL; - int i = 0; - uint32_t *ptr = NULL; - rdma_request_context_t *ctx = NULL; - rpc_request_info_t request_info = {0, }; - struct rpc_req *rpc_req = NULL; - - header = (rdma_header_t *)post->buf; + 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 */ @@ -3119,7 +3555,7 @@ rdma_recv_reply (rdma_peer_t *peer, rdma_post_t *post) wc_array = reply_info->wc_array; - if (header->rm_type == RDMA_NOMSG) { + 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 @@ -3144,15 +3580,15 @@ rdma_recv_reply (rdma_peer_t *peer, rdma_post_t *post) RPC_TRANSPORT_MAP_XID_REQUEST, &request_info); if (ret == -1) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, - "cannot get request information from rpc " - "layer"); + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "cannot get request information (peer:%s) from rpc " + "layer", peer->trans->peerinfo.identifier); goto out; } rpc_req = request_info.rpc_req; if (rpc_req == NULL) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "rpc request structure not found"); ret = -1; goto out; @@ -3165,11 +3601,15 @@ rdma_recv_reply (rdma_peer_t *peer, rdma_post_t *post) ret = 0; - rdma_reply_info_destroy (reply_info); + gf_rdma_reply_info_destroy (reply_info); out: if (ret == 0) { - ret = rdma_pollin_notify (peer, post); + ret = gf_rdma_pollin_notify (peer, post); + if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "pollin notify failed"); + } } return ret; @@ -3177,17 +3617,22 @@ out: inline int32_t -rdma_recv_request (rdma_peer_t *peer, rdma_post_t *post, - rdma_read_chunk_t *readch) +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 = rdma_do_reads (peer, post, readch); + ret = gf_rdma_do_reads (peer, post, readch); + if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "rdma read from peer (%s) failed", + peer->trans->peerinfo.identifier); + } } else { - ret = rdma_pollin_notify (peer, post); + ret = gf_rdma_pollin_notify (peer, post); if (ret == -1) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "pollin notification failed"); } } @@ -3196,38 +3641,59 @@ rdma_recv_request (rdma_peer_t *peer, rdma_post_t *post, } void -rdma_process_recv (rdma_peer_t *peer, struct ibv_wc *wc) +gf_rdma_process_recv (gf_rdma_peer_t *peer, struct ibv_wc *wc) { - rdma_post_t *post = NULL; - rdma_read_chunk_t *readch = NULL; - int ret = -1; - uint32_t *ptr = NULL; - enum msg_type msg_type = 0; - rdma_header_t *header = NULL; - - post = (rdma_post_t *) (long) wc->wr_id; + gf_rdma_post_t *post = NULL; + gf_rdma_read_chunk_t *readch = NULL; + int ret = -1; + uint32_t *ptr = NULL; + enum msg_type msg_type = 0; + gf_rdma_header_t *header = NULL; + gf_rdma_private_t *priv = NULL; + + post = (gf_rdma_post_t *) (long) wc->wr_id; if (post == NULL) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "no post found in successful work completion element"); goto out; } - ret = rdma_decode_header (peer, post, &readch, wc->byte_len); + ret = gf_rdma_decode_header (peer, post, &readch, wc->byte_len); if (ret == -1) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "decoding of header failed"); goto out; } - header = (rdma_header_t *)post->buf; + header = (gf_rdma_header_t *)post->buf; + + priv = peer->trans->private; + + pthread_mutex_lock (&priv->write_mutex); + { + if (!priv->peer.quota_set) { + priv->peer.quota_set = 1; + + /* Initially peer.quota is set to 1 as per RFC 5666. We + * have to account for the quota used while sending + * first msg (which may or may not be returned to pool + * at this point) while deriving peer.quota from + * header->rm_credit. Hence the arithmatic below, + * instead of directly setting it to header->rm_credit. + */ + priv->peer.quota = header->rm_credit + - ( 1 - priv->peer.quota); + } + } + pthread_mutex_unlock (&priv->write_mutex); switch (header->rm_type) { - case RDMA_MSG: + case GF_RDMA_MSG: ptr = (uint32_t *)post->ctx.vector[0].iov_base; msg_type = ntoh32 (*(ptr + 1)); break; - case RDMA_NOMSG: + case GF_RDMA_NOMSG: if (readch != NULL) { msg_type = CALL; } else { @@ -3235,31 +3701,49 @@ rdma_process_recv (rdma_peer_t *peer, struct ibv_wc *wc) } break; - case RDMA_ERROR: - gf_log (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 = rdma_pollin_notify (peer, post); - if (ret == -1) { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, - "pollin notification failed"); - } - goto out; -*/ + case GF_RDMA_ERROR: + if (header->rm_body.rm_error.rm_type == ERR_CHUNK) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "peer (%s), couldn't encode or decode the msg " + "properly or write chunks were not provided " + "for replies that were bigger than " + "RDMA_INLINE_THRESHOLD (%d)", + peer->trans->peerinfo.identifier, + GLUSTERFS_RDMA_INLINE_THRESHOLD); + ret = gf_rdma_pollin_notify (peer, post); + if (ret == -1) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, + "pollin notification failed"); + } + goto out; + } else { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, + "an error has happened while transmission of " + "msg, disconnecting the transport"); + ret = -1; + goto out; + } default: - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "invalid rdma msg-type (%d)", header->rm_type); - break; + goto out; } if (msg_type == CALL) { - ret = rdma_recv_request (peer, post, readch); + ret = gf_rdma_recv_request (peer, post, readch); + if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "receiving a request from peer (%s) failed", + peer->trans->peerinfo.identifier); + } } else { - ret = rdma_recv_reply (peer, post); + ret = gf_rdma_recv_reply (peer, post); + if (ret < 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "receiving a reply from peer (%s) failed", + peer->trans->peerinfo.identifier); + } } out: @@ -3270,14 +3754,50 @@ out: return; } +void * +gf_rdma_async_event_thread (void *context) +{ + struct ibv_async_event event; + int ret; + + while (1) { + do { + ret = ibv_get_async_event((struct ibv_context *)context, + &event); + + if (ret && errno != EINTR) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "Error getting event (%s)", + strerror (errno)); + } + } while(ret && errno == EINTR); + + switch (event.event_type) { + case IBV_EVENT_SRQ_LIMIT_REACHED: + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "recieved srq_limit reached"); + break; + + default: + gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, + "event (%d) recieved", event.event_type); + break; + } + + ibv_ack_async_event(&event); + } + + return 0; +} + static void * -rdma_recv_completion_proc (void *data) +gf_rdma_recv_completion_proc (void *data) { struct ibv_comp_channel *chan = NULL; - rdma_device_t *device = NULL;; - rdma_post_t *post = NULL; - rdma_peer_t *peer = 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; @@ -3288,7 +3808,7 @@ rdma_recv_completion_proc (void *data) while (1) { ret = ibv_get_cq_event (chan, &event_cq, &event_ctx); if (ret) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, "ibv_get_cq_event failed, terminating recv " "thread %d (%d)", ret, errno); continue; @@ -3298,26 +3818,26 @@ rdma_recv_completion_proc (void *data) ret = ibv_req_notify_cq (event_cq, 0); if (ret) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, + 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 = (rdma_device_t *) event_ctx; + device = (gf_rdma_device_t *) event_ctx; while ((ret = ibv_poll_cq (event_cq, 1, &wc)) > 0) { - post = (rdma_post_t *) (long) wc.wr_id; + post = (gf_rdma_post_t *) (long) wc.wr_id; pthread_mutex_lock (&device->qpreg.lock); { - peer = __rdma_lookup_peer (device, - wc.qp_num); + peer = __gf_rdma_lookup_peer (device, + wc.qp_num); /* * keep a refcount on transport so that it - * doesnot get freed because of some error + * 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. */ @@ -3328,7 +3848,7 @@ rdma_recv_completion_proc (void *data) pthread_mutex_unlock (&device->qpreg.lock); if (wc.status != IBV_WC_SUCCESS) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, "recv work request on `%s' returned " "error (%d)", device->device_name, wc.status); @@ -3338,26 +3858,26 @@ rdma_recv_completion_proc (void *data) } if (post) { - rdma_post_unref (post); + gf_rdma_post_unref (post); } continue; } if (peer) { - rdma_process_recv (peer, &wc); + gf_rdma_process_recv (peer, &wc); rpc_transport_unref (peer->trans); } else { - gf_log (RDMA_LOG_NAME, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_DEBUG, "could not lookup peer for qp_num: %d", wc.qp_num); } - rdma_post_unref (post); + gf_rdma_post_unref (post); } if (ret < 0) { - gf_log (RDMA_LOG_NAME, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, "ibv_poll_cq on `%s' returned error " "(ret = %d, errno = %d)", @@ -3372,11 +3892,11 @@ rdma_recv_completion_proc (void *data) void -rdma_handle_failed_send_completion (rdma_peer_t *peer, struct ibv_wc *wc) +gf_rdma_handle_failed_send_completion (gf_rdma_peer_t *peer, struct ibv_wc *wc) { - rdma_post_t *post = NULL; - rdma_device_t *device = NULL; - rdma_private_t *priv = NULL; + 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; @@ -3386,9 +3906,9 @@ rdma_handle_failed_send_completion (rdma_peer_t *peer, struct ibv_wc *wc) } - post = (rdma_post_t *) (long) wc->wr_id; + post = (gf_rdma_post_t *) (long) wc->wr_id; - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, "send work request on `%s' returned error " "wc.status = %d, wc.vendor_err = %d, post->buf = %p, " "wc.byte_len = %d, post->reused = %d", @@ -3413,20 +3933,22 @@ rdma_handle_failed_send_completion (rdma_peer_t *peer, struct ibv_wc *wc) void -rdma_handle_successful_send_completion (rdma_peer_t *peer, struct ibv_wc *wc) +gf_rdma_handle_successful_send_completion (gf_rdma_peer_t *peer, + struct ibv_wc *wc) { - rdma_post_t *post = NULL; - int reads = 0, ret = 0; + 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 = (rdma_post_t *)(long) wc->wr_id; + post = (gf_rdma_post_t *)(long) wc->wr_id; pthread_mutex_lock (&post->lock); { - reads = --post->ctx.rdma_reads; + reads = --post->ctx.gf_rdma_reads; } pthread_mutex_unlock (&post->lock); @@ -3435,7 +3957,14 @@ rdma_handle_successful_send_completion (rdma_peer_t *peer, struct ibv_wc *wc) goto out; } - ret = rdma_pollin_notify (peer, post); + 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); } @@ -3446,14 +3975,14 @@ out: static void * -rdma_send_completion_proc (void *data) +gf_rdma_send_completion_proc (void *data) { struct ibv_comp_channel *chan = NULL; - rdma_post_t *post = NULL; - rdma_peer_t *peer = NULL; + gf_rdma_post_t *post = NULL; + gf_rdma_peer_t *peer = NULL; struct ibv_cq *event_cq = NULL; void *event_ctx = NULL; - rdma_device_t *device = NULL; + gf_rdma_device_t *device = NULL; struct ibv_wc wc = {0, }; char is_request = 0; int32_t ret = 0, quota_ret = 0; @@ -3462,7 +3991,7 @@ rdma_send_completion_proc (void *data) while (1) { ret = ibv_get_cq_event (chan, &event_cq, &event_ctx); if (ret) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_ERROR, "ibv_get_cq_event on failed, terminating " "send thread: %d (%d)", ret, errno); continue; @@ -3472,7 +4001,7 @@ rdma_send_completion_proc (void *data) ret = ibv_req_notify_cq (event_cq, 0); if (ret) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, + 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); @@ -3480,11 +4009,11 @@ rdma_send_completion_proc (void *data) } while ((ret = ibv_poll_cq (event_cq, 1, &wc)) > 0) { - post = (rdma_post_t *) (long) wc.wr_id; + post = (gf_rdma_post_t *) (long) wc.wr_id; pthread_mutex_lock (&device->qpreg.lock); { - peer = __rdma_lookup_peer (device, wc.qp_num); + peer = __gf_rdma_lookup_peer (device, wc.qp_num); /* * keep a refcount on transport so that it @@ -3499,32 +4028,32 @@ rdma_send_completion_proc (void *data) pthread_mutex_unlock (&device->qpreg.lock); if (wc.status != IBV_WC_SUCCESS) { - rdma_handle_failed_send_completion (peer, &wc); + gf_rdma_handle_failed_send_completion (peer, &wc); } else { - rdma_handle_successful_send_completion (peer, - &wc); + gf_rdma_handle_successful_send_completion (peer, + &wc); } if (post) { is_request = post->ctx.is_request; - ret = rdma_post_unref (post); + ret = gf_rdma_post_unref (post); if ((ret == 0) && (wc.status == IBV_WC_SUCCESS) && !is_request - && (post->type == RDMA_SEND_POST) + && (post->type == GF_RDMA_SEND_POST) && (peer != NULL)) { - /* An RDMA_RECV_POST can end up in - * rdma_send_completion_proc for + /* 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 RDMA_RECV_POST. + * quota for getting an GF_RDMA_RECV_POST. */ /* * if it is request, quota is returned * after reply has come. */ - quota_ret = rdma_quota_put (peer); + quota_ret = gf_rdma_quota_put (peer); if (quota_ret < 0) { gf_log ("rdma", GF_LOG_DEBUG, "failed to send " @@ -3536,14 +4065,14 @@ rdma_send_completion_proc (void *data) if (peer) { rpc_transport_unref (peer->trans); } else { - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, + 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 (RDMA_LOG_NAME, GF_LOG_ERROR, + 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); @@ -3558,19 +4087,24 @@ rdma_send_completion_proc (void *data) static void -rdma_options_init (rpc_transport_t *this) +gf_rdma_options_init (rpc_transport_t *this) { - rdma_private_t *priv = this->private; - rdma_options_t *options = &priv->options; - int32_t mtu; - data_t *temp; + 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"); @@ -3580,7 +4114,22 @@ rdma_options_init (rpc_transport_t *this) temp = dict_get (this->options, "transport.rdma.work-request-recv-count"); if (temp) - options->recv_count = data_to_int32 (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, @@ -3606,12 +4155,12 @@ rdma_options_init (rpc_transport_t *this) break; default: if (temp) - gf_log (RDMA_LOG_NAME, GF_LOG_WARNING, + 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 (RDMA_LOG_NAME, GF_LOG_TRACE, + gf_log (GF_RDMA_LOG_NAME, GF_LOG_TRACE, "%s: defaulting MTU to '2048'", this->name); options->mtu = IBV_MTU_2048; @@ -3626,875 +4175,129 @@ rdma_options_init (rpc_transport_t *this) return; } -static void -rdma_queue_init (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 rdma_device_t * -rdma_get_device (rpc_transport_t *this, - struct ibv_context *ibctx) +gf_rdma_ctx_t * +__gf_rdma_ctx_create (void) { - glusterfs_ctx_t *ctx = NULL; - rdma_private_t *priv = NULL; - 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; - - 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; + gf_rdma_ctx_t *rdma_ctx = NULL; + int ret = -1; - while (trav) { - if ((!strcmp (trav->device_name, device_name)) && - (trav->port == port)) - break; - trav = trav->next; + rdma_ctx = GF_CALLOC (1, sizeof (*rdma_ctx), gf_common_mt_char); + if (rdma_ctx == NULL) { + goto out; } - 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 (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 (rdma_request_context_t, - RDMA_POOL_SIZE); - if (trav->request_ctx_pool == NULL) { - return NULL; - } - - trav->ioq_pool = mem_pool_new (rdma_ioq_t, RDMA_POOL_SIZE); - if (trav->ioq_pool == NULL) { - mem_pool_destroy (trav->request_ctx_pool); - return NULL; - } - - trav->reply_info_pool = mem_pool_new (rdma_reply_info_t, - 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 (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 (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 (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 (RDMA_LOG_NAME, GF_LOG_ERROR, - "could not create recv completion channel"); - /* TODO: cleanup current mess */ - return NULL; - } - - if (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 (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); - 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 (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); - 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 (RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: could not create SRQ", - this->name); - return NULL; - } - - /* queue init */ - rdma_queue_init (&trav->sendq); - rdma_queue_init (&trav->recvq); - - if (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); - 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 (RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: could not allocate posts", - this->name); - return NULL; - } + rdma_ctx->rdma_cm_event_channel = rdma_create_event_channel (); + if (rdma_ctx->rdma_cm_event_channel == NULL) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "rdma_cm event channel creation failed (%s)", + strerror (errno)); + goto out; + } - /* completion threads */ - ret = pthread_create (&trav->send_thread, - NULL, - rdma_send_completion_proc, - trav->send_chan); - if (ret) { - 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); - 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 (RDMA_LOG_NAME, GF_LOG_ERROR, - "could not create send completion thread"); - return NULL; - } + ret = gf_thread_create (&rdma_ctx->rdma_cm_thread, NULL, + gf_rdma_cm_event_handler, + rdma_ctx->rdma_cm_event_channel); + if (ret != 0) { + gf_log (GF_RDMA_LOG_NAME, GF_LOG_WARNING, + "creation of thread to handle rdma-cm events " + "failed (%s)", strerror (ret)); + goto out; + } - ret = pthread_create (&trav->recv_thread, - NULL, - rdma_recv_completion_proc, - trav->recv_chan); - if (ret) { - 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); - 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 (RDMA_LOG_NAME, GF_LOG_ERROR, - "could not create recv completion thread"); - return NULL; +out: + if (ret < 0) { + if (rdma_ctx->rdma_cm_event_channel != NULL) { + rdma_destroy_event_channel (rdma_ctx->rdma_cm_event_channel); } - /* 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]; - } + GF_FREE (rdma_ctx); + rdma_ctx = NULL; } - return trav; + + return rdma_ctx; } static int32_t -rdma_init (rpc_transport_t *this) +gf_rdma_init (rpc_transport_t *this) { - rdma_private_t *priv = this->private; - rdma_options_t *options = &priv->options; - struct ibv_device **dev_list; - struct ibv_context *ib_ctx = NULL; - int32_t ret = 0; - - ibv_fork_init (); - rdma_options_init (this); - - { - dev_list = ibv_get_device_list (NULL); - - if (!dev_list) { - gf_log (RDMA_LOG_NAME, - GF_LOG_CRITICAL, - "Failed to get IB devices"); - ret = -1; - goto cleanup; - } - - if (!*dev_list) { - gf_log (RDMA_LOG_NAME, - GF_LOG_CRITICAL, - "No IB devices found"); - ret = -1; - goto cleanup; - } + gf_rdma_private_t *priv = NULL; + int32_t ret = 0; + glusterfs_ctx_t *ctx = NULL; + gf_rdma_options_t *options = NULL; - if (!options->device_name) { - if (*dev_list) { - options->device_name = - gf_strdup (ibv_get_device_name (*dev_list)); - } else { - gf_log (RDMA_LOG_NAME, GF_LOG_CRITICAL, - "IB device list is empty. Check for " - "'ib_uverbs' module"); - return -1; - goto cleanup; - } - } + ctx= this->ctx; - 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 (RDMA_LOG_NAME, - GF_LOG_ERROR, - "Failed to get infiniband" - "device context"); - ret = -1; - goto cleanup; - } - break; - } - ++dev_list; - } + priv = this->private; - priv->device = rdma_get_device (this, ib_ctx); + ibv_fork_init (); + gf_rdma_options_init (this); - if (!priv->device) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, - "could not create rdma device for %s", - options->device_name); - ret = -1; - goto cleanup; - } - } + options = &priv->options; + priv->peer.send_count = options->send_count; + priv->peer.recv_count = options->recv_count; + priv->peer.send_size = options->send_size; + priv->peer.recv_size = options->recv_size; priv->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 -rdma_disconnect (rpc_transport_t *this) -{ - rdma_private_t *priv = this->private; - int32_t ret = 0; - - pthread_mutex_lock (&priv->write_mutex); - { - ret = __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 -rdma_fill_handshake_data (char *buf, struct rdma_nbio *nbio, - 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 -rdma_fill_handshake_ack (char *buf, struct 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 -rdma_handshake_pollin (rpc_transport_t *this) -{ - int ret = 0; - rdma_private_t *priv = this->private; - char *buf = priv->handshake.incoming.buf; - int32_t recv_buf_size, send_buf_size; - socklen_t sock_len; - - if (priv->handshake.incoming.state == RDMA_HANDSHAKE_COMPLETE) { - return -1; - } - - pthread_mutex_lock (&priv->write_mutex); + pthread_mutex_lock (&ctx->lock); { - while (priv->handshake.incoming.state != RDMA_HANDSHAKE_COMPLETE) - { - switch (priv->handshake.incoming.state) - { - case RDMA_HANDSHAKE_START: - buf = priv->handshake.incoming.buf = GF_CALLOC (1, 256, gf_common_mt_char); - rdma_fill_handshake_data (buf, &priv->handshake.incoming, priv); - buf[0] = 0; - priv->handshake.incoming.state = RDMA_HANDSHAKE_RECEIVING_DATA; - break; - - case 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 = RDMA_HANDSHAKE_RECEIVED_DATA; - } - break; - - case 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 (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 (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 (rdma_connect_qp (this)) { - gf_log (RDMA_LOG_NAME, - GF_LOG_ERROR, - "%s: failed to connect with " - "remote QP", this->name); - ret = -1; - goto unlock; - } - rdma_fill_handshake_ack (buf, &priv->handshake.incoming); - buf[0] = 0; - priv->handshake.incoming.state = RDMA_HANDSHAKE_RECEIVING_ACK; - break; - - case 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 = RDMA_HANDSHAKE_RECEIVED_ACK; - } - break; - - case RDMA_HANDSHAKE_RECEIVED_ACK: - if (strncmp (buf, "DONE", 4)) { - gf_log (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 = RDMA_HANDSHAKE_COMPLETE; + if (ctx->ib == NULL) { + ctx->ib = __gf_rdma_ctx_create (); + if (ctx->ib == NULL) { + ret = -1; } } } -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); - } - } + pthread_mutex_unlock (&ctx->lock); return ret; } -static int -rdma_handshake_pollout (rpc_transport_t *this) -{ - rdma_private_t *priv = this->private; - char *buf = priv->handshake.outgoing.buf; - int32_t ret = 0; - - if (priv->handshake.outgoing.state == RDMA_HANDSHAKE_COMPLETE) { - return 0; - } - - pthread_mutex_unlock (&priv->write_mutex); - { - while (priv->handshake.outgoing.state != RDMA_HANDSHAKE_COMPLETE) - { - switch (priv->handshake.outgoing.state) - { - case RDMA_HANDSHAKE_START: - buf = priv->handshake.outgoing.buf = GF_CALLOC (1, 256, gf_common_mt_char); - rdma_fill_handshake_data (buf, &priv->handshake.outgoing, priv); - priv->handshake.outgoing.state = RDMA_HANDSHAKE_SENDING_DATA; - break; - case 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 = RDMA_HANDSHAKE_SENT_DATA; - } - break; - - case RDMA_HANDSHAKE_SENT_DATA: - rdma_fill_handshake_ack (buf, &priv->handshake.outgoing); - priv->handshake.outgoing.state = RDMA_HANDSHAKE_SENDING_ACK; - break; - - case 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 = 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 -rdma_handshake_pollerr (rpc_transport_t *this) +static int32_t +gf_rdma_disconnect (rpc_transport_t *this) { - rdma_private_t *priv = this->private; - char need_unref = 0, connected = 0; + gf_rdma_private_t *priv = NULL; + int32_t ret = 0; - gf_log (RDMA_LOG_NAME, GF_LOG_DEBUG, - "%s: peer disconnected, cleaning up", - this->name); - - pthread_mutex_lock (&priv->write_mutex); - { - __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 (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 = RDMA_HANDSHAKE_START; - - if (priv->handshake.outgoing.buf) { - GF_FREE (priv->handshake.outgoing.buf); - priv->handshake.outgoing.buf = NULL; - } - - priv->handshake.outgoing.state = 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) -{ - rdma_private_t *priv = this->private; - int error = 0, ret = 0; + priv = this->private; + gf_log_callingfn (this->name, GF_LOG_WARNING, + "disconnect called (peer:%s)", + this->peerinfo.identifier); 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; - } + ret = __gf_rdma_disconnect (this); } -unlock: pthread_mutex_unlock (&priv->write_mutex); - if (error) { - rpc_transport_disconnect (this); - } - return ret; } -static int -rdma_event_handler (int fd, int idx, void *data, - int poll_in, int poll_out, int poll_err) -{ - rpc_transport_t *this = data; - rdma_private_t *priv = this->private; - rdma_options_t *options = NULL; - int ret = 0; - - 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 = rdma_create_qp (this)) < 0) { - gf_log (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 = rdma_handshake_pollout (this); - } - - if (!ret && !poll_err && poll_in && priv->tcp_connected) { - if (priv->handshake.incoming.state == RDMA_HANDSHAKE_COMPLETE) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: pollin received on tcp socket (peer: %s) " - "after handshake is complete", - this->name, this->peerinfo.identifier); - rdma_handshake_pollerr (this); - return 0; - } - ret = rdma_handshake_pollin (this); - } - - if (ret < 0 || poll_err) { - ret = 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 -rdma_connect (struct rpc_transport *this, int port) +gf_rdma_connect (struct rpc_transport *this, int port) { - dict_t *options = this->options; - - rdma_private_t *priv = this->private; + gf_rdma_private_t *priv = NULL; + int32_t ret = 0; + union gf_sock_union sock_union = {{0, }, }; + socklen_t sockaddr_len = 0; + gf_rdma_peer_t *peer = NULL; + gf_rdma_ctx_t *rdma_ctx = NULL; + gf_boolean_t connected = _gf_false; - int32_t ret = 0; - gf_boolean_t non_blocking = 1; - union gf_sock_union sock_union; - socklen_t sockaddr_len = 0; + priv = this->private; - if (dict_get (options, "non-blocking-io")) { - char *nb_connect = data_to_str (dict_get (this->options, - "non-blocking-io")); + peer = &priv->peer; - if (gf_string2boolean (nb_connect, &non_blocking) == -1) { - gf_log (this->name, GF_LOG_ERROR, - "'non-blocking-io' takes only boolean " - "options, not taking any action"); - non_blocking = 1; - } - } + rpc_transport_ref (this); ret = gf_rdma_client_get_remote_sockaddr (this, &sock_union.sa, @@ -4502,28 +4305,32 @@ rdma_connect (struct rpc_transport *this, int port) if (ret != 0) { gf_log (this->name, GF_LOG_DEBUG, "cannot get remote address to connect"); - return ret; + goto out; } + rdma_ctx = this->ctx->ib; + pthread_mutex_lock (&priv->write_mutex); { - if (priv->sock != -1) { - ret = 0; + if (peer->cm_id != NULL) { + ret = -1; + errno = EINPROGRESS; + connected = _gf_true; goto unlock; } - priv->sock = socket (sock_union.sa.sa_family, SOCK_STREAM, 0); + priv->entity = GF_RDMA_CLIENT; - if (priv->sock == -1) { + ret = rdma_create_id (rdma_ctx->rdma_cm_event_channel, + &peer->cm_id, this, RDMA_PS_TCP); + if (ret != 0) { gf_log (this->name, GF_LOG_ERROR, - "socket () - error: %s", strerror (errno)); + "creation of rdma_cm_id failed (%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; @@ -4534,196 +4341,84 @@ rdma_connect (struct rpc_transport *this, int 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) - { + &this->myinfo.sockaddr_len, + peer->cm_id); + if (ret != 0) { 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)", + ret = rdma_resolve_addr (peer->cm_id, NULL, &sock_union.sa, + 2000); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "rdma_resolve_addr 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 = RDMA_HANDSHAKE_START; - priv->handshake.outgoing.state = RDMA_HANDSHAKE_START; - - priv->idx = event_register (this->ctx->event_pool, - priv->sock, rdma_event_handler, - this, 1, 1); + priv->connected = 0; } unlock: pthread_mutex_unlock (&priv->write_mutex); - return ret; -} - -static int -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, *trans = data; - rdma_private_t *priv = NULL; - rdma_private_t *trans_priv = (rdma_private_t *) trans->private; - rdma_options_t *options = NULL; - - if (!poll_in) { - return 0; - } - - 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 (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; +out: + if (ret != 0) { + if (!connected) { + gf_rdma_teardown (this); + } - 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; + rpc_transport_unref (this); } - priv->peer.trans = this; - rpc_transport_ref (this); - - gf_rdma_get_transport_identifiers (this); + return ret; +} - priv->tcp_connected = 1; - priv->handshake.incoming.state = RDMA_HANDSHAKE_START; - priv->handshake.outgoing.state = 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); +static int32_t +gf_rdma_listen (rpc_transport_t *this) +{ + union gf_sock_union sock_union = {{0, }, }; + socklen_t sockaddr_len = 0; + gf_rdma_private_t *priv = NULL; + gf_rdma_peer_t *peer = NULL; + int ret = 0; + gf_rdma_ctx_t *rdma_ctx = NULL; + char service[NI_MAXSERV], host[NI_MAXHOST]; - if (rdma_create_qp (this) < 0) { - gf_log (RDMA_LOG_NAME, GF_LOG_ERROR, - "%s: could not create QP", - this->name); - rpc_transport_disconnect (this); - return -1; - } + priv = this->private; + peer = &priv->peer; - priv->idx = event_register (this->ctx->event_pool, priv->sock, - rdma_event_handler, this, 1, 1); + priv->entity = GF_RDMA_SERVER_LISTENER; - 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; -} + rdma_ctx = this->ctx->ib; -static int32_t -rdma_listen (rpc_transport_t *this) -{ - union gf_sock_union sock_union; - socklen_t sockaddr_len; - rdma_private_t *priv = this->private; - int opt = 1, ret = 0; - char service[NI_MAXSERV], host[NI_MAXHOST]; - - memset (&sock_union, 0, sizeof (sock_union)); - ret = gf_rdma_server_get_local_sockaddr (this, - &sock_union.sa, + ret = gf_rdma_server_get_local_sockaddr (this, &sock_union.sa, &sockaddr_len); if (ret != 0) { - gf_log (this->name, GF_LOG_DEBUG, + gf_log (this->name, GF_LOG_WARNING, "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", + ret = rdma_create_id (rdma_ctx->rdma_cm_event_channel, + &peer->cm_id, this, RDMA_PS_TCP); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "creation of rdma_cm_id failed (%s)", strerror (errno)); - GF_FREE (this->private); - ret = -1; goto err; } - memcpy (&this->myinfo.sockaddr, &sock_union.storage, sockaddr_len); + 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), + this->myinfo.sockaddr_len, host, sizeof (host), service, sizeof (service), NI_NUMERICHOST); if (ret != 0) { @@ -4731,55 +4426,58 @@ rdma_listen (rpc_transport_t *this) "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)); + ret = rdma_bind_addr (peer->cm_id, &sock_union.sa); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "rdma_bind_addr failed (%s)", 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; + ret = rdma_listen (peer->cm_id, 10); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "rdma_listen failed (%s)", strerror (errno)); goto err; } - /* Register the main socket */ - priv->idx = event_register (this->ctx->event_pool, priv->sock, - rdma_server_event_handler, - rpc_transport_ref (this), 1, 0); + rpc_transport_ref (this); + ret = 0; err: + if (ret < 0) { + if (peer->cm_id != NULL) { + rdma_destroy_id (peer->cm_id); + peer->cm_id = NULL; + } + } + return ret; } + struct rpc_transport_ops tops = { - .submit_request = rdma_submit_request, - .submit_reply = rdma_submit_reply, - .connect = rdma_connect, - .disconnect = rdma_disconnect, - .listen = rdma_listen, + .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) { - rdma_private_t *priv = NULL; + 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 (rdma_init (this)) { + if (gf_rdma_init (this)) { gf_log (this->name, GF_LOG_ERROR, "Failed to initialize IB Device"); return -1; @@ -4792,19 +4490,15 @@ void fini (struct rpc_transport *this) { /* TODO: verify this function does graceful finish */ - rdma_private_t *priv = this->private; + 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); @@ -4844,6 +4538,18 @@ struct volume_options options[] = { "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 }, diff --git a/rpc/rpc-transport/rdma/src/rdma.h b/rpc/rpc-transport/rdma/src/rdma.h index be6957659..7f76244f0 100644 --- a/rpc/rpc-transport/rdma/src/rdma.h +++ b/rpc/rpc-transport/rdma/src/rdma.h @@ -1,20 +1,11 @@ /* - Copyright (c) 2006-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 _XPORT_RDMA_H @@ -38,53 +29,59 @@ #include <list.h> #include <arpa/inet.h> #include <infiniband/verbs.h> +#include <rdma/rdma_cma.h> /* FIXME: give appropriate values to these macros */ #define GF_DEFAULT_RDMA_LISTEN_PORT (GF_DEFAULT_BASE_PORT + 1) -/* If you are changing RDMA_MAX_SEGMENTS, please make sure to update - * GLUSTERFS_RDMA_MAX_HEADER_SIZE defined in glusterfs.h . +/* If you are changing GF_RDMA_MAX_SEGMENTS, please make sure to update + * GLUSTERFS_GF_RDMA_MAX_HEADER_SIZE defined in glusterfs.h . */ -#define RDMA_MAX_SEGMENTS 8 +#define GF_RDMA_MAX_SEGMENTS 8 -#define RDMA_VERSION 1 -#define RDMA_POOL_SIZE 512 +#define GF_RDMA_VERSION 1 +#define GF_RDMA_POOL_SIZE 512 -typedef enum rdma_errcode { +/* 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 -}rdma_errcode_t; +}gf_rdma_errcode_t; -struct rdma_err_vers { - uint32_t rdma_vers_low; /* Version range supported by peer */ - uint32_t rdma_vers_high; +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 rdma_err_vers rdma_err_vers_t; - -typedef enum rdma_proc { - RDMA_MSG = 0, /* An RPC call or reply msg */ - RDMA_NOMSG = 1, /* An RPC call or reply msg - separate body */ - RDMA_MSGP = 2, /* An RPC call or reply msg with padding */ - RDMA_DONE = 3, /* Client signals reply completion */ - RDMA_ERROR = 4 /* An RPC RDMA encoding error */ -}rdma_proc_t; - -typedef enum rdma_chunktype { - rdma_noch = 0, /* no chunk */ - rdma_readch, /* some argument through rdma read */ - rdma_areadch, /* entire request through rdma read */ - rdma_writech, /* some result through rdma write */ - rdma_replych /* entire reply through rdma write */ -}rdma_chunktype_t; - -/* If you are modifying __rdma_header, please make sure to change - * GLUSTERFS_RDMA_MAX_HEADER_SIZE defined in glusterfs.h to reflect your changes +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 __rdma_header { +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 rdma_proc) */ + uint32_t rm_type; /* Type of message (enum gf_rdma_proc) */ union { struct { /* no chunks */ uint32_t rm_empty[3]; /* 3 empty chunk lists */ @@ -98,49 +95,49 @@ struct __rdma_header { struct { uint32_t rm_type; - rdma_err_vers_t rm_version; + 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 __rdma_header rdma_header_t; +typedef struct __gf_rdma_header gf_rdma_header_t; -/* If you are modifying __rdma_segment or __rdma_read_chunk, please make sure - * to change GLUSTERFS_RDMA_MAX_HEADER_SIZE defined in glusterfs.h to reflect +/* 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 __rdma_segment { +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 __rdma_segment rdma_segment_t; +typedef struct __gf_rdma_segment gf_rdma_segment_t; /* read chunk(s), encoded as a linked list. */ -struct __rdma_read_chunk { +struct __gf_rdma_read_chunk { uint32_t rc_discrim; /* 1 indicates presence */ uint32_t rc_position; /* Position in XDR stream */ - rdma_segment_t rc_target; + gf_rdma_segment_t rc_target; } __attribute__((packed)); -typedef struct __rdma_read_chunk rdma_read_chunk_t; +typedef struct __gf_rdma_read_chunk gf_rdma_read_chunk_t; /* write chunk, and reply chunk. */ -struct __rdma_write_chunk { - rdma_segment_t wc_target; +struct __gf_rdma_write_chunk { + gf_rdma_segment_t wc_target; } __attribute__((packed)); -typedef struct __rdma_write_chunk rdma_write_chunk_t; +typedef struct __gf_rdma_write_chunk gf_rdma_write_chunk_t; /* write chunk(s), encoded as a counted array. */ -struct __rdma_write_array { +struct __gf_rdma_write_array { uint32_t wc_discrim; /* 1 indicates presence */ uint32_t wc_nchunks; /* Array count */ - struct __rdma_write_chunk wc_array[0]; + struct __gf_rdma_write_chunk wc_array[0]; } __attribute__((packed)); -typedef struct __rdma_write_array rdma_write_array_t; +typedef struct __gf_rdma_write_array gf_rdma_write_array_t; /* options per transport end point */ -struct __rdma_options { +struct __gf_rdma_options { int32_t port; char *device_name; enum ibv_mtu mtu; @@ -148,26 +145,29 @@ struct __rdma_options { 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 __rdma_options rdma_options_t; +typedef struct __gf_rdma_options gf_rdma_options_t; -struct __rdma_reply_info { +struct __gf_rdma_reply_info { uint32_t rm_xid; /* xid in network endian */ - rdma_chunktype_t type; /* - * can be either rdma_replych - * or rdma_writech. + gf_rdma_chunktype_t type; /* + * can be either gf_rdma_replych + * or gf_rdma_writech. */ - rdma_write_array_t *wc_array; + gf_rdma_write_array_t *wc_array; struct mem_pool *pool; }; -typedef struct __rdma_reply_info rdma_reply_info_t; +typedef struct __gf_rdma_reply_info gf_rdma_reply_info_t; -struct __rdma_ioq { +struct __gf_rdma_ioq { union { struct list_head list; struct { - struct __rdma_ioq *next; - struct __rdma_ioq *prev; + struct __gf_rdma_ioq *next; + struct __gf_rdma_ioq *prev; }; }; @@ -182,8 +182,8 @@ struct __rdma_ioq { struct iobref *iobref; union { - struct __rdma_ioq_request { - /* used to build reply_chunk for RDMA_NOMSG type msgs */ + 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; @@ -200,205 +200,183 @@ struct __rdma_ioq { struct iobref *rsp_iobref; }request; - rdma_reply_info_t *reply_info; + gf_rdma_reply_info_t *reply_info; }msg; struct mem_pool *pool; }; -typedef struct __rdma_ioq rdma_ioq_t; +typedef struct __gf_rdma_ioq gf_rdma_ioq_t; -typedef enum __rdma_send_post_type { - RDMA_SEND_POST_NO_CHUNKLIST, /* post which is sent using rdma-send +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. */ - RDMA_SEND_POST_READ_CHUNKLIST, /* post which is sent using rdma-send + GF_RDMA_SEND_POST_READ_CHUNKLIST, /* post which is sent using rdma-send * and the msg carries only read * chunklist. */ - RDMA_SEND_POST_WRITE_CHUNKLIST, /* post which is sent using + GF_RDMA_SEND_POST_WRITE_CHUNKLIST, /* post which is sent using * rdma-send and the msg carries * only write chunklist. */ - RDMA_SEND_POST_READ_WRITE_CHUNKLIST, /* post which is sent using + GF_RDMA_SEND_POST_READ_WRITE_CHUNKLIST, /* post which is sent using * rdma-send and the msg * carries both read and * write chunklists. */ - RDMA_SEND_POST_RDMA_READ, /* RDMA read */ - RDMA_SEND_POST_RDMA_WRITE, /* RDMA write */ -}rdma_send_post_type_t; + 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 __rdma_peer { - rpc_transport_t *trans; - struct ibv_qp *qp; +struct __gf_rdma_peer { + rpc_transport_t *trans; + struct rdma_cm_id *cm_id; + struct ibv_qp *qp; + pthread_t rdma_event_thread; + char quota_set; int32_t recv_count; int32_t send_count; int32_t recv_size; int32_t send_size; - int32_t quota; + int32_t quota; union { - struct list_head ioq; + struct list_head ioq; struct { - rdma_ioq_t *ioq_next; - rdma_ioq_t *ioq_prev; + 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; + 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 __rdma_peer rdma_peer_t; +typedef struct __gf_rdma_peer gf_rdma_peer_t; -struct __rdma_post_context { - struct ibv_mr *mr[RDMA_MAX_SEGMENTS]; +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 rdma_reads; - rdma_reply_info_t *reply_info; + int gf_rdma_reads; + gf_rdma_reply_info_t *reply_info; }; -typedef struct __rdma_post_context rdma_post_context_t; +typedef struct __gf_rdma_post_context gf_rdma_post_context_t; typedef enum { - RDMA_SEND_POST, - RDMA_RECV_POST -} rdma_post_type_t; + GF_RDMA_SEND_POST, + GF_RDMA_RECV_POST +} gf_rdma_post_type_t; -struct __rdma_post { - struct __rdma_post *next, *prev; +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 __rdma_device *device; - rdma_post_type_t type; - rdma_post_context_t ctx; + 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 __rdma_post rdma_post_t; +typedef struct __gf_rdma_post gf_rdma_post_t; -struct __rdma_queue { - rdma_post_t active_posts, passive_posts; +struct __gf_rdma_queue { + gf_rdma_post_t active_posts, passive_posts; int32_t active_count, passive_count; pthread_mutex_t lock; }; -typedef struct __rdma_queue rdma_queue_t; +typedef struct __gf_rdma_queue gf_rdma_queue_t; -struct __rdma_qpreg { +struct __gf_rdma_qpreg { pthread_mutex_t lock; int32_t count; struct _qpent { struct _qpent *next, *prev; int32_t qp_num; - rdma_peer_t *peer; + gf_rdma_peer_t *peer; } ents[42]; }; -typedef struct __rdma_qpreg rdma_qpreg_t; +typedef struct __gf_rdma_qpreg gf_rdma_qpreg_t; /* context per device, stored in global glusterfs_ctx_t->ib */ -struct __rdma_device { - struct __rdma_device *next; +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; - rdma_qpreg_t qpreg; + gf_rdma_qpreg_t qpreg; struct ibv_comp_channel *send_chan, *recv_chan; struct ibv_cq *send_cq, *recv_cq; - rdma_queue_t sendq, recvq; - pthread_t send_thread, recv_thread; + gf_rdma_queue_t sendq, recvq; + pthread_t send_thread, recv_thread, async_event_thread; struct mem_pool *request_ctx_pool; struct mem_pool *ioq_pool; struct mem_pool *reply_info_pool; }; -typedef struct __rdma_device rdma_device_t; +typedef struct __gf_rdma_device gf_rdma_device_t; -typedef enum { - RDMA_HANDSHAKE_START = 0, - RDMA_HANDSHAKE_SENDING_DATA, - RDMA_HANDSHAKE_RECEIVING_DATA, - RDMA_HANDSHAKE_SENT_DATA, - RDMA_HANDSHAKE_RECEIVED_DATA, - RDMA_HANDSHAKE_SENDING_ACK, - RDMA_HANDSHAKE_RECEIVING_ACK, - RDMA_HANDSHAKE_RECEIVED_ACK, - RDMA_HANDSHAKE_COMPLETE, -} rdma_handshake_state_t; - -struct rdma_nbio { - int state; - char *buf; - int count; - struct iovec vector; - struct iovec *pending_vector; - int pending_count; +struct __gf_rdma_ctx { + gf_rdma_device_t *device; + struct rdma_event_channel *rdma_cm_event_channel; + pthread_t rdma_cm_thread; }; +typedef struct __gf_rdma_ctx gf_rdma_ctx_t; -struct __rdma_request_context { - struct ibv_mr *mr[RDMA_MAX_SEGMENTS]; +struct __gf_rdma_request_context { + struct ibv_mr *mr[GF_RDMA_MAX_SEGMENTS]; int mr_count; struct mem_pool *pool; - rdma_peer_t *peer; + gf_rdma_peer_t *peer; struct iobref *iobref; struct iobref *rsp_iobref; }; -typedef struct __rdma_request_context rdma_request_context_t; - -struct __rdma_private { - int32_t sock; - int32_t idx; - unsigned char connected; - unsigned char tcp_connected; - unsigned char ib_connected; - in_addr_t addr; +typedef struct __gf_rdma_request_context gf_rdma_request_context_t; + +typedef enum { + GF_RDMA_SERVER_LISTENER, + GF_RDMA_SERVER, + GF_RDMA_CLIENT, +} gf_rdma_transport_entity_t; + +struct __gf_rdma_private { + int32_t idx; + unsigned char connected; + in_addr_t addr; unsigned short port; /* IB Verbs Driver specific variables, pointers */ - rdma_peer_t peer; - struct __rdma_device *device; - rdma_options_t options; + 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; + 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 rdma_handshake */ - struct { - struct rdma_nbio incoming; - struct rdma_nbio outgoing; - int state; - rdma_header_t header; - char *buf; - size_t size; - } handshake; + pthread_mutex_t write_mutex; + rpc_transport_t *listener; + pthread_mutex_t recv_mutex; + pthread_cond_t recv_cond; + gf_rdma_transport_entity_t entity; }; -typedef struct __rdma_private rdma_private_t; +typedef struct __gf_rdma_private gf_rdma_private_t; -#endif /* _XPORT_RDMA_H */ +#endif /* _XPORT_GF_RDMA_H */ diff --git a/rpc/rpc-transport/socket/src/Makefile.am b/rpc/rpc-transport/socket/src/Makefile.am index 2c918c7e3..71e6ed6ff 100644 --- a/rpc/rpc-transport/socket/src/Makefile.am +++ b/rpc/rpc-transport/socket/src/Makefile.am @@ -3,13 +3,15 @@ noinst_HEADERS = socket.h name.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 -lssl -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ +AM_CPPFLAGS = $(GF_CPPFLAGS) \ -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/rpc/rpc-lib/src/ \ - -I$(top_srcdir)/rpc/xdr/src/ -shared -nostartfiles $(GF_CFLAGS) + -I$(top_srcdir)/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 8de1c5fcd..1647d5b6b 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,12 +15,6 @@ #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 @@ -49,9 +34,17 @@ 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; + int32_t ret = -1; + uint16_t port = ceiling - 1; + // by default assume none of the ports are blocked and all are available + gf_boolean_t ports[1024] = {_gf_false,}; + int i = 0; + + ret = gf_process_reserved_ports (ports); + if (ret != 0) { + for (i = 0; i < 1024; i++) + ports[i] = _gf_false; + } while (port) { @@ -66,7 +59,11 @@ af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr, ((struct sockaddr_in *)sockaddr)->sin_port = htons (port); break; } - + // ignore the reserved ports + if (ports[port] == _gf_true) { + port--; + continue; + } ret = bind (fd, sockaddr, sockaddr_len); if (ret == 0) @@ -96,7 +93,7 @@ af_unix_client_bind (rpc_transport_t *this, char *path = data_to_str (path_data); if (!path || strlen (path) > UNIX_PATH_MAX) { gf_log (this->name, GF_LOG_TRACE, - "bind-path not specfied for unix socket, " + "bind-path not specified for unix socket, " "letting connect to assign default value"); goto err; } @@ -112,7 +109,7 @@ af_unix_client_bind (rpc_transport_t *this, } } else { gf_log (this->name, GF_LOG_TRACE, - "bind-path not specfied for unix socket, " + "bind-path not specified for unix socket, " "letting connect to assign default value"); } @@ -143,24 +140,24 @@ client_fill_address_family (rpc_transport_t *this, sa_family_t *sa_family) 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)", + "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, guessing it " - "to be inet/inet6"); - *sa_family = AF_UNSPEC; + "to be inet from (remote-host: %s)", data_to_str (remote_host_data)); + *sa_family = AF_INET; } else { gf_log (this->name, GF_LOG_DEBUG, "address-family not specified, guessing it " - "to be unix"); + "to be unix from (transport.unix.connect-path: %s)", data_to_str (connect_path_data)); *sa_family = AF_UNIX; } @@ -174,13 +171,11 @@ client_fill_address_family (rpc_transport_t *this, sa_family_t *sa_family) *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); + *sa_family = AF_UNSPEC; goto out; } } @@ -451,12 +446,12 @@ client_bind (rpc_transport_t *this, case AF_INET6: if (!this->bind_insecure) { ret = af_inet_bind_to_port_lt_ceiling (sock, sockaddr, - *sockaddr_len, CLIENT_PORT_CEILING); + *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, CLIENT_PORT_CEILING, strerror (errno)); + sock, GF_CLIENT_PORT_CEILING, strerror (errno)); ret = 0; } break; @@ -551,18 +546,16 @@ server_fill_address_family (rpc_transport_t *this, sa_family_t *sa_family) *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); + *sa_family = AF_UNSPEC; goto out; } } else { gf_log (this->name, GF_LOG_DEBUG, - "option address-family not specified, defaulting to inet/inet6"); - *sa_family = AF_UNSPEC; + "option address-family not specified, defaulting to inet"); + *sa_family = AF_INET; } ret = 0; diff --git a/rpc/rpc-transport/socket/src/name.h b/rpc/rpc-transport/socket/src/name.h index 0ca67d2e4..0a13d8a96 100644 --- a/rpc/rpc-transport/socket/src/name.h +++ b/rpc/rpc-transport/socket/src/name.h @@ -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. */ #ifndef _SOCKET_NAME_H diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c index 089afb573..93da3f296 100644 --- a/rpc/rpc-transport/socket/src/socket.c +++ b/rpc/rpc-transport/socket/src/socket.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. */ @@ -44,97 +35,401 @@ #include <errno.h> #include <netinet/tcp.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 OWN_THREAD_OPT "transport.socket.own-thread" + +/* TBD: do automake substitutions etc. (ick) to set these. */ +#if !defined(DEFAULT_CERT_PATH) +#define DEFAULT_CERT_PATH "/etc/ssl/glusterfs.pem" +#endif +#if !defined(DEFAULT_KEY_PATH) +#define DEFAULT_KEY_PATH "/etc/ssl/glusterfs.key" +#endif +#if !defined(DEFAULT_CA_PATH) +#define DEFAULT_CA_PATH "/etc/ssl/glusterfs.ca" +#endif + +#define POLL_MASK_INPUT (POLLIN | POLLPRI) +#define POLL_MASK_OUTPUT (POLLOUT) +#define POLL_MASK_ERROR (POLLERR | POLLHUP | POLLNVAL) -#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); +typedef int SSL_unary_func (SSL *); +typedef int SSL_trinary_func (SSL *, void *, int); + +#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_fragsize = 0; \ - if (priv->incoming.frag.pending_vector->iov_len == 0) { \ - remaining_fragsize = RPC_FRAGSIZE (priv->incoming.fraghdr) \ - - priv->incoming.frag.bytes_read; \ + 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); \ \ - priv->incoming.frag.pending_vector->iov_len = \ - remaining_fragsize > priv->incoming.frag.remaining_size \ - ? priv->incoming.frag.remaining_size : remaining_fragsize; \ + frag->pending_vector->iov_len = \ + (remaining > frag->remaining_size) \ + ? frag->remaining_size : remaining; \ \ - priv->incoming.frag.remaining_size -= \ - priv->incoming.frag.pending_vector->iov_len; \ + frag->remaining_size -= \ + frag->pending_vector->iov_len; \ } \ - } while (0); + } 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; \ + struct gf_sock_incoming_frag *frag; \ + frag = &priv->incoming.frag; \ \ - if ((ret > 0) || (priv->incoming.frag.remaining_size != 0)) { \ - if (priv->incoming.frag.remaining_size != 0 && ret == 0) { \ + 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"); \ + gf_log (this->name, GF_LOG_TRACE, \ + "partial read on non-blocking socket"); \ \ break; \ } \ } -#define __socket_proto_init_pending(priv, size) \ +#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; \ + 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); \ + __socket_proto_reset_pending (priv); \ \ - priv->incoming.frag.pending_vector->iov_len = \ - remaining_fragsize > size ? size : remaining_fragsize; \ + frag->pending_vector->iov_len = \ + (remaining > size) ? size : remaining; \ \ - priv->incoming.frag.remaining_size = \ - size - priv->incoming.frag.pending_vector->iov_len; \ + frag->remaining_size = (size - frag->pending_vector->iov_len); \ \ - } while (0); + } 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; \ + struct gf_sock_incoming *in; \ + in = &priv->incoming; \ \ __socket_proto_update_pending (priv); \ \ ret = __socket_readv (this, \ - priv->incoming.pending_vector, 1, \ - &priv->incoming.pending_vector, \ - &priv->incoming.pending_count, \ + 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); \ + if (ret == -1) \ break; \ - } \ __socket_proto_update_priv_after_read (priv, ret, bytes_read); \ } +static int socket_init (rpc_transport_t *this); + +static void +ssl_dump_error_stack (const char *caller) +{ + unsigned long errnum = 0; + char errbuf[120] = {0,}; + + /* OpenSSL docs explicitly give 120 as the error-string length. */ + + while ((errnum = ERR_get_error())) { + ERR_error_string(errnum,errbuf); + gf_log(caller,GF_LOG_ERROR," %s",errbuf); + } +} + +static int +ssl_do (rpc_transport_t *this, void *buf, size_t len, SSL_trinary_func *func) +{ + int r = (-1); + struct pollfd pfd = {-1,}; + socket_private_t *priv = NULL; + + GF_VALIDATE_OR_GOTO(this->name,this->private,out); + priv = this->private; + + for (;;) { + 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__); + break; + } + r = func(priv->ssl_ssl,buf,len); + } + else { + /* + * We actually need these functions to get to + * priv->connected == 1. + */ + r = ((SSL_unary_func *)func)(priv->ssl_ssl); + } + switch (SSL_get_error(priv->ssl_ssl,r)) { + case SSL_ERROR_NONE: + return r; + case SSL_ERROR_WANT_READ: + pfd.fd = priv->sock; + pfd.events = POLLIN; + if (poll(&pfd,1,-1) < 0) { + gf_log(this->name,GF_LOG_ERROR,"poll error %d", + errno); + } + break; + case SSL_ERROR_WANT_WRITE: + pfd.fd = priv->sock; + pfd.events = POLLOUT; + if (poll(&pfd,1,-1) < 0) { + gf_log(this->name,GF_LOG_ERROR,"poll error %d", + errno); + } + break; + case SSL_ERROR_SYSCALL: + /* This is what we get when remote disconnects. */ + gf_log(this->name,GF_LOG_DEBUG, + "syscall error (probably remote disconnect)"); + errno = ENODATA; + goto out; + default: + errno = EIO; + goto out; /* "break" would just loop again */ + } + } +out: + return -1; +} + +#define ssl_connect_one(t) ssl_do((t),NULL,0,(SSL_trinary_func *)SSL_connect) +#define ssl_accept_one(t) ssl_do((t),NULL,0,(SSL_trinary_func *)SSL_accept) +#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) + +static int +ssl_setup_connection (rpc_transport_t *this, int server) +{ + X509 *peer = NULL; + char peer_CN[256] = ""; + int ret = -1; + socket_private_t *priv = NULL; + + GF_VALIDATE_OR_GOTO(this->name,this->private,done); + priv = this->private; + + 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); + + if (server) { + ret = ssl_accept_one(this); + } + else { + ret = ssl_connect_one(this); + } + + /* Make sure _the call_ succeeded. */ + if (ret < 0) { + goto ssl_error; + } + + /* 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; + } + + /* 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_INFO,"peer CN = %s", peer_CN); + return 0; + + /* Error paths. */ +ssl_error: + gf_log(this->name,GF_LOG_ERROR,"SSL connect error"); + ssl_dump_error_stack(this->name); +free_ssl: + SSL_free(priv->ssl_ssl); + priv->ssl_ssl = NULL; +done: + return ret; +} + + +static void +ssl_teardown_connection (socket_private_t *priv) +{ + SSL_shutdown(priv->ssl_ssl); + SSL_clear(priv->ssl_ssl); + SSL_free(priv->ssl_ssl); + priv->ssl_ssl = NULL; +} + + +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) { + ret = ssl_read_one (this, opvector->iov_base, opvector->iov_len); + } else { + ret = readv (sock, opvector, opcount); + } + + return ret; +} + + +static ssize_t +__socket_ssl_read (rpc_transport_t *this, void *buf, size_t count) +{ + struct iovec iov = {0, }; + int ret = -1; + + iov.iov_base = buf; + iov.iov_len = count; + + 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; + int sock = -1; + struct gf_sock_incoming *in = NULL; + int req_len = -1; + int ret = -1; + + priv = this->private; + sock = priv->sock; + 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. By using this itself as our + read-ahead cache, we can avoid memory copies in iov_load + */ + in->ra_buf = iobuf_ptr (in->iobuf); + } + + /* 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; +} + +static gf_boolean_t +__does_socket_rwv_error_need_logging (socket_private_t *priv, int write) +{ + int read = !write; + + if (priv->connected == -1) /* Didn't even connect, of course it fails */ + return _gf_false; -int socket_init (rpc_transport_t *this); + if (read && (priv->read_fail_log == _gf_false)) + return _gf_false; + + return _gf_true; +} /* * return value: @@ -143,7 +438,7 @@ int socket_init (rpc_transport_t *this); * > 0 = incomplete */ -int +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) @@ -168,9 +463,22 @@ __socket_rwv (rpc_transport_t *this, struct iovec *vector, int count, *bytes = 0; } - while (opcount) { + 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 (write) { - ret = writev (sock, opvector, opcount); + if (priv->use_ssl) { + ret = ssl_write_one(this, + opvector->iov_base, opvector->iov_len); + } + else { + ret = writev (sock, opvector, opcount); + } if (ret == 0 || (ret == -1 && errno == EAGAIN)) { /* done for now */ @@ -178,7 +486,13 @@ __socket_rwv (rpc_transport_t *this, struct iovec *vector, int count, } this->total_bytes_write += ret; } else { - ret = readv (sock, opvector, opcount); + ret = __socket_cached_read (this, opvector, opcount); + + if (ret == 0) { + gf_log(this->name,GF_LOG_DEBUG,"EOF on socket"); + errno = ENODATA; + ret = -1; + } if (ret == -1 && errno == EAGAIN) { /* done for now */ break; @@ -199,9 +513,18 @@ __socket_rwv (rpc_transport_t *this, struct iovec *vector, int count, if (errno == EINTR) continue; - gf_log (this->name, GF_LOG_WARNING, - "%s failed (%s)", write ? "writev" : "readv", - strerror (errno)); + if (__does_socket_rwv_error_need_logging (priv, + write)) { + gf_log (this->name, GF_LOG_WARNING, + "%s on %s failed (%s)", + write ? "writev":"readv", + this->peerinfo.identifier, + strerror (errno)); + } + + if (priv->use_ssl) { + ssl_dump_error_stack(this->name); + } opcount = -1; break; } @@ -213,6 +536,17 @@ __socket_rwv (rpc_transport_t *this, struct iovec *vector, int count, 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++; @@ -222,13 +556,11 @@ __socket_rwv (rpc_transport_t *this, struct iovec *vector, int count, opvector[0].iov_base += (ret - moved); moved += (ret - moved); } - while (opcount && !opvector[0].iov_len) { - opvector++; - opcount--; - } } } +ran_out: + if (pending_vector) *pending_vector = opvector; @@ -240,7 +572,7 @@ out: } -int +static int __socket_readv (rpc_transport_t *this, struct iovec *vector, int count, struct iovec **pending_vector, int *pending_count, size_t *bytes) @@ -254,7 +586,7 @@ __socket_readv (rpc_transport_t *this, struct iovec *vector, int count, } -int +static int __socket_writev (rpc_transport_t *this, struct iovec *vector, int count, struct iovec **pending_vector, int *pending_count) { @@ -267,26 +599,55 @@ __socket_writev (rpc_transport_t *this, struct iovec *vector, int count, } -int +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)); + } + + return ret; +} + +static int __socket_disconnect (rpc_transport_t *this) { - socket_private_t *priv = NULL; int ret = -1; + socket_private_t *priv = NULL; GF_VALIDATE_OR_GOTO ("socket", this, out); GF_VALIDATE_OR_GOTO ("socket", this->private, out); priv = this->private; + gf_log (this->name, GF_LOG_TRACE, + "disconnecting %p, state=%u gen=%u sock=%d", this, + priv->ot_state, priv->ot_gen, priv->sock); + 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)); + ret = __socket_shutdown(this); + if (priv->own_thread) { + /* + * Without this, reconnect (= disconnect + connect) + * won't work except by accident. + */ + close(priv->sock); + priv->sock = -1; + gf_log (this->name, GF_LOG_TRACE, + "OT_PLEASE_DIE on %p", this); + priv->ot_state = OT_PLEASE_DIE; + } + else if (priv->use_ssl) { + ssl_teardown_connection(priv); } } @@ -295,7 +656,7 @@ out: } -int +static int __socket_server_bind (rpc_transport_t *this) { socket_private_t *priv = NULL; @@ -318,12 +679,12 @@ __socket_server_bind (rpc_transport_t *this) strerror (errno)); } - //reuse-address doesnt work for unix type sockets + /* 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) { + if (reuse_check_sock >= 0) { ret = connect (reuse_check_sock, SA (&unix_addr), this->myinfo.sockaddr_len); if ((ret == -1) && (ECONNREFUSED == errno)) { @@ -351,7 +712,7 @@ out: } -int +static int __socket_nonblock (int fd) { int flags = 0; @@ -365,8 +726,7 @@ __socket_nonblock (int fd) return ret; } - -int +static int __socket_nodelay (int fd) { int on = 1; @@ -383,7 +743,7 @@ __socket_nodelay (int fd) static int -__socket_keepalive (int fd, int keepalive_intvl, int keepalive_idle) +__socket_keepalive (int fd, int family, int keepalive_intvl, int keepalive_idle) { int on = 1; int ret = -1; @@ -412,18 +772,23 @@ __socket_keepalive (int fd, int keepalive_intvl, int keepalive_idle) goto err; } #else + if (family != AF_INET) + goto done; + 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); + "failed to set keep idle %d on socket %d, %s", + keepalive_idle, fd, strerror(errno)); goto err; } - ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPINTVL, &keepalive_intvl, + 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); + "failed to set keep interval %d on socket %d, %s", + keepalive_intvl, fd, strerror(errno)); goto err; } #endif @@ -437,7 +802,7 @@ err: } -int +static int __socket_connect_finish (int fd) { int ret = -1; @@ -455,7 +820,7 @@ __socket_connect_finish (int fd) } -void +static void __socket_reset (rpc_transport_t *this) { socket_private_t *priv = NULL; @@ -476,9 +841,7 @@ __socket_reset (rpc_transport_t *this) iobuf_unref (priv->incoming.iobuf); } - if (priv->incoming.request_info != NULL) { - GF_FREE (priv->incoming.request_info); - } + GF_FREE (priv->incoming.request_info); memset (&priv->incoming, 0, sizeof (priv->incoming)); @@ -494,13 +857,13 @@ out: } -void +static void socket_set_lastfrag (uint32_t *fragsize) { (*fragsize) |= 0x80000000U; } -void +static void socket_set_frag_header_size (uint32_t size, char *haddr) { size = htonl (size); @@ -508,14 +871,14 @@ socket_set_frag_header_size (uint32_t size, char *haddr) } -void +static void socket_set_last_frag_header_size (uint32_t size, char *haddr) { socket_set_lastfrag (&size); socket_set_frag_header_size (size, haddr); } -struct ioq * +static struct ioq * __socket_ioq_new (rpc_transport_t *this, rpc_transport_msg_t *msg) { struct ioq *entry = NULL; @@ -582,7 +945,7 @@ out: } -void +static void __socket_ioq_entry_free (struct ioq *entry) { GF_VALIDATE_OR_GOTO ("socket", entry, out); @@ -599,7 +962,7 @@ out: } -void +static void __socket_ioq_flush (rpc_transport_t *this) { socket_private_t *priv = NULL; @@ -620,10 +983,12 @@ out: } -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 direct) { - int ret = -1; + int ret = -1; + socket_private_t *priv = NULL; + char a_byte = 0; ret = __socket_writev (this, entry->pending_vector, entry->pending_count, @@ -634,13 +999,25 @@ __socket_ioq_churn_entry (rpc_transport_t *this, struct ioq *entry) /* current entry was completely written */ GF_ASSERT (entry->pending_count == 0); __socket_ioq_entry_free (entry); + priv = this->private; + if (priv->own_thread) { + /* + * The pipe should only remain readable if there are + * more entries after this, so drain the byte + * representing this entry. + */ + if (!direct && read(priv->pipe[0],&a_byte,1) < 1) { + gf_log(this->name,GF_LOG_WARNING, + "read error on pipe"); + } + } } return ret; } -int +static int __socket_ioq_churn (rpc_transport_t *this) { socket_private_t *priv = NULL; @@ -656,13 +1033,13 @@ __socket_ioq_churn (rpc_transport_t *this) /* pick next entry */ entry = priv->ioq_next; - ret = __socket_ioq_churn_entry (this, entry); + ret = __socket_ioq_churn_entry (this, entry, 0); if (ret != 0) break; } - if (list_empty (&priv->ioq)) { + if (!priv->own_thread && 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); @@ -673,7 +1050,7 @@ out: } -int +static int socket_event_poll_err (rpc_transport_t *this) { socket_private_t *priv = NULL; @@ -698,7 +1075,7 @@ out: } -int +static int socket_event_poll_out (rpc_transport_t *this) { socket_private_t *priv = NULL; @@ -728,43 +1105,45 @@ out: } -inline int +static inline 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); 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); - priv->incoming.frag.simple_state = - SP_STATE_READING_SIMPLE_MSG; + frag->simple_state = SP_STATE_READING_SIMPLE_MSG; /* fall through */ case SP_STATE_READING_SIMPLE_MSG: 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, + in->pending_vector, 1, + &in->pending_vector, + &in->pending_count, &bytes_read); } @@ -776,8 +1155,8 @@ __socket_read_simple_msg (rpc_transport_t *this) 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, @@ -786,8 +1165,7 @@ __socket_read_simple_msg (rpc_transport_t *this) } if (ret == 0) { - priv->incoming.frag.simple_state - = SP_STATE_SIMPLE_MSG_INIT; + frag->simple_state = SP_STATE_SIMPLE_MSG_INIT; } } @@ -796,7 +1174,7 @@ out: } -inline int +static inline int __socket_read_simple_request (rpc_transport_t *this) { return __socket_read_simple_msg (this); @@ -813,7 +1191,7 @@ __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 +static inline int __socket_read_vectored_request (rpc_transport_t *this, rpcsvc_vector_sizer vector_sizer) { socket_private_t *priv = NULL; @@ -823,16 +1201,26 @@ __socket_read_vectored_request (rpc_transport_t *this, rpcsvc_vector_sizer vecto 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; 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) { + /* 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; + + addr = rpc_cred_addr (iobuf_ptr (in->iobuf)); /* also read verf flavour and verflen */ credlen = ntoh32 (*((uint32_t *)addr)) @@ -840,99 +1228,114 @@ __socket_read_vectored_request (rpc_transport_t *this, rpcsvc_vector_sizer vecto __socket_proto_init_pending (priv, credlen); - priv->incoming.frag.call_body.request.vector_state = - SP_STATE_READING_CREDBYTES; + request->vector_state = SP_STATE_READING_CREDBYTES; /* fall through */ case SP_STATE_READING_CREDBYTES: __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 */ case SP_STATE_READ_CREDBYTES: - addr = rpc_verf_addr (priv->incoming.frag.fragcurrent); + 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; + 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 */ case SP_STATE_READING_VERFBYTES: __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 */ 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); + /* set the base_addr 'persistently' across multiple calls + into the state machine */ + in->proghdr_base_addr = frag->fragcurrent; + + request->vector_sizer_state = + vector_sizer (request->vector_sizer_state, + &readsize, in->proghdr_base_addr, + frag->fragcurrent); __socket_proto_init_pending (priv, readsize); - priv->incoming.frag.call_body.request.vector_state - = SP_STATE_READING_PROGHDR; + + request->vector_state = SP_STATE_READING_PROGHDR; /* fall through */ 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); + + request->vector_state = SP_STATE_READ_PROGHDR; + + /* fall through */ + + 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) { - 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_READ_PROGHDR_XDATA; + goto sp_state_read_proghdr_xdata; } - case SP_STATE_READ_PROGHDR: - if (priv->incoming.payload_vector.iov_base == NULL) { - iobuf = iobuf_get (this->ctx->iobuf_pool); + __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; } - if (priv->incoming.iobref == NULL) { - priv->incoming.iobref = iobref_new (); - if (priv->incoming.iobref == NULL) { + if (in->iobref == NULL) { + in->iobref = iobref_new (); + if (in->iobref == NULL) { ret = -1; iobuf_unref (iobuf); break; } } - iobref_add (priv->incoming.iobref, iobuf); + iobref_add (in->iobref, iobuf); iobuf_unref (iobuf); - priv->incoming.payload_vector.iov_base - = iobuf_ptr (iobuf); + in->payload_vector.iov_base = iobuf_ptr (iobuf); - priv->incoming.frag.fragcurrent = iobuf_ptr (iobuf); + frag->fragcurrent = iobuf_ptr (iobuf); } - priv->incoming.frag.call_body.request.vector_state = - SP_STATE_READING_PROG; + request->vector_state = SP_STATE_READING_PROG; /* fall through */ @@ -943,19 +1346,15 @@ sp_state_reading_proghdr: 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.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; + if ((ret == -1) || + ((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; } @@ -964,7 +1363,7 @@ out: return ret; } -inline int +static inline int __socket_read_request (rpc_transport_t *this) { socket_private_t *priv = NULL; @@ -973,46 +1372,53 @@ __socket_read_request (rpc_transport_t *this) 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; 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.header_state) { + /* 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); - priv->incoming.frag.call_body.request.header_state - = SP_STATE_READING_RPCHDR1; + request->header_state = SP_STATE_READING_RPCHDR1; /* fall through */ case SP_STATE_READING_RPCHDR1: __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 */ case SP_STATE_READ_RPCHDR1: - buf = rpc_prognum_addr (iobuf_ptr (priv->incoming.iobuf)); + buf = rpc_prognum_addr (iobuf_ptr (in->iobuf)); prognum = ntoh32 (*((uint32_t *)buf)); - buf = rpc_progver_addr (iobuf_ptr (priv->incoming.iobuf)); + buf = rpc_progver_addr (iobuf_ptr (in->iobuf)); progver = ntoh32 (*((uint32_t *)buf)); - buf = rpc_procnum_addr (iobuf_ptr (priv->incoming.iobuf)); + 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) { @@ -1021,15 +1427,13 @@ __socket_read_request (rpc_transport_t *this) ret = __socket_read_simple_request (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; + && (RPC_LASTFRAG (in->fraghdr)))) { + request->header_state = SP_STATE_REQUEST_HEADER_INIT; } break; @@ -1040,35 +1444,40 @@ out: } -inline int +static inline 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; + char *proghdr_buf = NULL; + XDR xdr; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; GF_VALIDATE_OR_GOTO ("socket", this, out); GF_VALIDATE_OR_GOTO ("socket", this->private, out); priv = this->private; - switch (priv->incoming.frag.call_body.reply.accepted_success_state) { + /* 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: - gluster_read_rsp_hdr_len = xdr_sizeof ((xdrproc_t) xdr_gfs3_read_rsp, - &read_rsp); + default_read_size = xdr_sizeof ((xdrproc_t) xdr_gfs3_read_rsp, + &read_rsp); - if (gluster_read_rsp_hdr_len == 0) { - gf_log (this->name, GF_LOG_ERROR, - "xdr_sizeof on gfs3_read_rsp failed"); - ret = -1; - goto out; - } - __socket_proto_init_pending (priv, gluster_read_rsp_hdr_len); + proghdr_buf = frag->fragcurrent; + + __socket_proto_init_pending (priv, default_read_size); - priv->incoming.frag.call_body.reply.accepted_success_state + frag->call_body.reply.accepted_success_state = SP_STATE_READING_PROC_HEADER; /* fall through */ @@ -1076,34 +1485,70 @@ __socket_read_accepted_successful_reply (rpc_transport_t *this) case SP_STATE_READING_PROC_HEADER: __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 */ + xdrmem_create (&xdr, proghdr_buf, default_read_size, + XDR_DECODE); + + /* 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 roof (%4), as XDR packing pads + the end of opaque object with '0' */ + size = roof (read_rsp.xdata.xdata_len, 4); - if (priv->incoming.payload_vector.iov_base == NULL) { - iobuf = iobuf_get (this->ctx->iobuf_pool); + 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; + + case SP_STATE_READING_PROC_OPAQUE: + __socket_proto_read (priv, ret); + + frag->call_body.reply.accepted_success_state + = SP_STATE_READ_PROC_OPAQUE; + + 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 (priv->incoming.iobref == NULL) { - priv->incoming.iobref = iobref_new (); - if (priv->incoming.iobref == NULL) { + if (in->iobref == NULL) { + in->iobref = iobref_new (); + if (in->iobref == NULL) { ret = -1; iobuf_unref (iobuf); goto out; } } - iobref_add (priv->incoming.iobref, iobuf); + iobref_add (in->iobref, iobuf); iobuf_unref (iobuf); - priv->incoming.payload_vector.iov_base - = iobuf_ptr (iobuf); + in->payload_vector.iov_base = iobuf_ptr (iobuf); + + in->payload_vector.iov_len = size; } - priv->incoming.frag.fragcurrent - = priv->incoming.payload_vector.iov_base; + frag->fragcurrent = in->payload_vector.iov_base; + + frag->call_body.reply.accepted_success_state + = SP_STATE_READ_PROC_HEADER; /* fall through */ @@ -1111,9 +1556,8 @@ __socket_read_accepted_successful_reply (rpc_transport_t *this) /* 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 + || ((ret == 0) && RPC_LASTFRAG (in->fraghdr))) { + frag->call_body.reply.accepted_success_state = SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT; } @@ -1127,7 +1571,7 @@ out: #define rpc_reply_verflen_addr(fragcurrent) ((char *)fragcurrent - 4) #define rpc_reply_accept_status_addr(fragcurrent) ((char *)fragcurrent - 4) -inline int +static inline int __socket_read_accepted_reply (rpc_transport_t *this) { socket_private_t *priv = NULL; @@ -1135,19 +1579,24 @@ __socket_read_accepted_reply (rpc_transport_t *this) 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; GF_VALIDATE_OR_GOTO ("socket", this, out); GF_VALIDATE_OR_GOTO ("socket", this->private, out); priv = this->private; + /* used to reduce the indirection */ + in = &priv->incoming; + frag = &in->frag; - switch (priv->incoming.frag.call_body.reply.accepted_state) { + switch (frag->call_body.reply.accepted_state) { case SP_STATE_ACCEPTED_REPLY_INIT: __socket_proto_init_pending (priv, RPC_AUTH_FLAVOUR_N_LENGTH_SIZE); - priv->incoming.frag.call_body.reply.accepted_state + frag->call_body.reply.accepted_state = SP_STATE_READING_REPLY_VERFLEN; /* fall through */ @@ -1155,13 +1604,13 @@ __socket_read_accepted_reply (rpc_transport_t *this) case SP_STATE_READING_REPLY_VERFLEN: __socket_proto_read (priv, ret); - priv->incoming.frag.call_body.reply.accepted_state + frag->call_body.reply.accepted_state = SP_STATE_READ_REPLY_VERFLEN; /* 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)); @@ -1170,7 +1619,7 @@ __socket_read_accepted_reply (rpc_transport_t *this) __socket_proto_init_pending (priv, len); - priv->incoming.frag.call_body.reply.accepted_state + frag->call_body.reply.accepted_state = SP_STATE_READING_REPLY_VERFBYTES; /* fall through */ @@ -1178,19 +1627,19 @@ __socket_read_accepted_reply (rpc_transport_t *this) case SP_STATE_READING_REPLY_VERFBYTES: __socket_proto_read (priv, ret); - priv->incoming.frag.call_body.reply.accepted_state + 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 + frag->call_body.reply.accept_status = ntoh32 (*(uint32_t *) buf); /* fall through */ case SP_STATE_READ_REPLY_VERFBYTES: - if (priv->incoming.frag.call_body.reply.accept_status + if (frag->call_body.reply.accept_status == SUCCESS) { ret = __socket_read_accepted_successful_reply (this); } else { @@ -1200,14 +1649,13 @@ __socket_read_accepted_reply (rpc_transport_t *this) 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 + || ((ret == 0) && (remaining_size == 0) + && (RPC_LASTFRAG (in->fraghdr)))) { + frag->call_body.reply.accepted_state = SP_STATE_ACCEPTED_REPLY_INIT; } @@ -1219,7 +1667,7 @@ out: } -inline int +static inline int __socket_read_denied_reply (rpc_transport_t *this) { return __socket_read_simple_msg (this); @@ -1229,25 +1677,29 @@ __socket_read_denied_reply (rpc_transport_t *this) #define rpc_reply_status_addr(fragcurrent) ((char *)fragcurrent - 4) -inline int +static inline 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; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; GF_VALIDATE_OR_GOTO ("socket", this, out); GF_VALIDATE_OR_GOTO ("socket", this->private, out); priv = this->private; + in = &priv->incoming; + frag = &in->frag; - switch (priv->incoming.frag.call_body.reply.status_state) { + switch (frag->call_body.reply.status_state) { case SP_STATE_ACCEPTED_REPLY_INIT: __socket_proto_init_pending (priv, RPC_REPLY_STATUS_SIZE); - priv->incoming.frag.call_body.reply.status_state + frag->call_body.reply.status_state = SP_STATE_READING_REPLY_STATUS; /* fall through */ @@ -1255,37 +1707,33 @@ __socket_read_vectored_reply (rpc_transport_t *this) case SP_STATE_READING_REPLY_STATUS: __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 + frag->call_body.reply.accept_status = ntoh32 (*((uint32_t *) buf)); - priv->incoming.frag.call_body.reply.status_state + frag->call_body.reply.status_state = SP_STATE_READ_REPLY_STATUS; /* fall through */ case SP_STATE_READ_REPLY_STATUS: - if (priv->incoming.frag.call_body.reply.accept_status - == MSG_ACCEPTED) { + 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 (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.status_state + || ((ret == 0) && (remaining_size == 0) + && (RPC_LASTFRAG (in->fraghdr)))) { + 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; + in->payload_vector.iov_len + = (unsigned long)frag->fragcurrent + - (unsigned long)in->payload_vector.iov_base; } break; } @@ -1295,7 +1743,7 @@ out: } -inline int +static inline int __socket_read_simple_reply (rpc_transport_t *this) { return __socket_read_simple_msg (this); @@ -1303,7 +1751,7 @@ __socket_read_simple_reply (rpc_transport_t *this) #define rpc_xid_addr(buf) (buf) -inline int +static inline int __socket_read_reply (rpc_transport_t *this) { socket_private_t *priv = NULL; @@ -1311,26 +1759,29 @@ __socket_read_reply (rpc_transport_t *this) 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; GF_VALIDATE_OR_GOTO ("socket", this, out); GF_VALIDATE_OR_GOTO ("socket", this->private, out); priv = this->private; + in = &priv->incoming; + frag = &in->frag; - buf = rpc_xid_addr (iobuf_ptr (priv->incoming.iobuf)); + buf = rpc_xid_addr (iobuf_ptr (in->iobuf)); - 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) { + 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; } map_xid = 1; } - request_info = priv->incoming.request_info; + request_info = in->request_info; if (map_xid) { request_info->xid = ntoh32 (*((uint32_t *) buf)); @@ -1342,7 +1793,7 @@ __socket_read_reply (rpc_transport_t *this) { ret = rpc_transport_notify (this, RPC_TRANSPORT_MAP_XID_REQUEST, - priv->incoming.request_info); + in->request_info); } pthread_mutex_lock (&priv->lock); @@ -1353,13 +1804,11 @@ __socket_read_reply (rpc_transport_t *this) } } - if ((request_info->prognum == GLUSTER3_1_FOP_PROGRAM) + if ((request_info->prognum == GLUSTER_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; + in->iobref = iobref_ref (request_info->rsp.rsp_iobref); + in->payload_vector = *request_info->rsp.rsp_payload; } ret = __socket_read_vectored_reply (this); @@ -1372,42 +1821,47 @@ out: /* returns the number of bytes yet to be read in a fragment */ -inline int +static inline 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; + struct gf_sock_incoming *in = NULL; + struct gf_sock_incoming_frag *frag = NULL; GF_VALIDATE_OR_GOTO ("socket", this, out); GF_VALIDATE_OR_GOTO ("socket", this->private, out); priv = this->private; + /* used to reduce the indirection */ + in = &priv->incoming; + frag = &in->frag; - switch (priv->incoming.frag.state) { + switch (frag->state) { case SP_STATE_NADA: __socket_proto_init_pending (priv, RPC_MSGTYPE_SIZE); - priv->incoming.frag.state = SP_STATE_READING_MSGTYPE; + frag->state = SP_STATE_READING_MSGTYPE; /* fall through */ case SP_STATE_READING_MSGTYPE: __socket_proto_read (priv, ret); - priv->incoming.frag.state = SP_STATE_READ_MSGTYPE; + 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)); + buf = rpc_msgtype_addr (iobuf_ptr (in->iobuf)); + in->msg_type = ntoh32 (*((uint32_t *)buf)); - if (priv->incoming.msg_type == CALL) { + if (in->msg_type == CALL) { ret = __socket_read_request (this); - } else if (priv->incoming.msg_type == REPLY) { + } else if (in->msg_type == REPLY) { ret = __socket_read_reply (this); - } else if (priv->incoming.msg_type == GF_UNIVERSAL_ANSWER) { + } else if (in->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", @@ -1415,19 +1869,17 @@ __socket_read_frag (rpc_transport_t *this) } else { gf_log ("rpc", GF_LOG_ERROR, "wrong MSG-TYPE (%d) received from %s", - priv->incoming.msg_type, + 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; + || ((ret == 0) && (remaining_size == 0) + && (RPC_LASTFRAG (in->fraghdr)))) { + frag->state = SP_STATE_NADA; } break; @@ -1438,31 +1890,36 @@ out: } -inline +static inline 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; + + /* used to reduce the indirection */ + in = &priv->incoming; + + if (in->iobref) { + iobref_unref (in->iobref); + in->iobref = NULL; } - if (priv->incoming.iobuf) { - iobuf_unref (priv->incoming.iobuf); + if (in->iobuf) { + iobuf_unref (in->iobuf); } - if (priv->incoming.request_info != NULL) { - GF_FREE (priv->incoming.request_info); - priv->incoming.request_info = NULL; + if (in->request_info != NULL) { + GF_FREE (in->request_info); + in->request_info = NULL; } - memset (&priv->incoming.payload_vector, 0, - sizeof (priv->incoming.payload_vector)); + memset (&in->payload_vector, 0, + sizeof (in->payload_vector)); - priv->incoming.iobuf = NULL; + in->iobuf = NULL; } -int +static int __socket_proto_state_machine (rpc_transport_t *this, rpc_transport_pollin_t **pollin) { @@ -1471,46 +1928,40 @@ __socket_proto_state_machine (rpc_transport_t *this, 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; 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) { + /* used to reduce the indirection */ + in = &priv->incoming; + frag = &in->frag; + + while (in->record_state != SP_STATE_COMPLETE) { + switch (in->record_state) { case SP_STATE_NADA: - priv->incoming.total_bytes_read = 0; - priv->incoming.payload_vector.iov_len = 0; + in->total_bytes_read = 0; + in->payload_vector.iov_len = 0; - priv->incoming.pending_vector = priv->incoming.vector; - priv->incoming.pending_vector->iov_base = - &priv->incoming.fraghdr; + in->pending_vector = in->vector; + in->pending_vector->iov_base = &in->fraghdr; - priv->incoming.pending_vector->iov_len = - sizeof (priv->incoming.fraghdr); + in->pending_vector->iov_len = sizeof (in->fraghdr); - priv->incoming.record_state = SP_STATE_READING_FRAGHDR; + in->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, + ret = __socket_readv (this, in->pending_vector, 1, + &in->pending_vector, + &in->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); - } + if (ret == -1) goto out; - } if (ret > 0) { gf_log (this->name, GF_LOG_TRACE, "partial " @@ -1519,44 +1970,40 @@ __socket_proto_state_machine (rpc_transport_t *this, } if (ret == 0) { - priv->incoming.record_state = - SP_STATE_READ_FRAGHDR; + in->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); + in->fraghdr = ntoh32 (in->fraghdr); + in->total_bytes_read += RPC_FRAGSIZE(in->fraghdr); iobuf = iobuf_get2 (this->ctx->iobuf_pool, - priv->incoming.total_bytes_read + - sizeof (priv->incoming.fraghdr)); + (in->total_bytes_read + + sizeof (in->fraghdr))); if (!iobuf) { ret = -ENOMEM; goto out; } - priv->incoming.iobuf = iobuf; - priv->incoming.iobuf_size = 0; - priv->incoming.frag.fragcurrent = iobuf_ptr (iobuf); + in->iobuf = iobuf; + in->iobuf_size = 0; + frag->fragcurrent = iobuf_ptr (iobuf); + in->record_state = SP_STATE_READING_FRAG; /* fall through */ case SP_STATE_READING_FRAG: ret = __socket_read_frag (this); - if ((ret == -1) - || (priv->incoming.frag.bytes_read != - RPC_FRAGSIZE (priv->incoming.fraghdr))) { + if ((ret == -1) || + (frag->bytes_read != RPC_FRAGSIZE (in->fraghdr))) { goto out; } - priv->incoming.frag.bytes_read = 0; + frag->bytes_read = 0; - if (!RPC_LASTFRAG (priv->incoming.fraghdr)) { - priv->incoming.record_state = - SP_STATE_READING_FRAGHDR; + if (!RPC_LASTFRAG (in->fraghdr)) { + in->record_state = SP_STATE_READING_FRAGHDR; break; } @@ -1565,44 +2012,39 @@ __socket_proto_state_machine (rpc_transport_t *this, */ if (pollin != NULL) { int count = 0; - priv->incoming.iobuf_size - = priv->incoming.total_bytes_read - - priv->incoming.payload_vector.iov_len; + in->iobuf_size = (in->total_bytes_read - + in->payload_vector.iov_len); memset (vector, 0, sizeof (vector)); - if (priv->incoming.iobref == NULL) { - priv->incoming.iobref = iobref_new (); - if (priv->incoming.iobref == NULL) { + if (in->iobref == NULL) { + in->iobref = iobref_new (); + if (in->iobref == NULL) { ret = -1; goto out; } } - vector[count].iov_base - = iobuf_ptr (priv->incoming.iobuf); - vector[count].iov_len - = priv->incoming.iobuf_size; + vector[count].iov_base = iobuf_ptr (in->iobuf); + vector[count].iov_len = in->iobuf_size; - iobref = priv->incoming.iobref; + iobref = in->iobref; count++; - if (priv->incoming.payload_vector.iov_base - != NULL) { - vector[count] - = priv->incoming.payload_vector; + if (in->payload_vector.iov_base != NULL) { + vector[count] = in->payload_vector; count++; } *pollin = rpc_transport_pollin_alloc (this, vector, count, - priv->incoming.iobuf, + in->iobuf, iobref, - priv->incoming.request_info); - iobuf_unref (priv->incoming.iobuf); - priv->incoming.iobuf = NULL; + in->request_info); + iobuf_unref (in->iobuf); + in->iobuf = NULL; if (*pollin == NULL) { gf_log (this->name, GF_LOG_WARNING, @@ -1610,12 +2052,12 @@ __socket_proto_state_machine (rpc_transport_t *this, ret = -1; goto out; } - if (priv->incoming.msg_type == REPLY) + if (in->msg_type == REPLY) (*pollin)->is_reply = 1; - priv->incoming.request_info = NULL; + in->request_info = NULL; } - priv->incoming.record_state = SP_STATE_COMPLETE; + in->record_state = SP_STATE_COMPLETE; break; case SP_STATE_COMPLETE: @@ -1627,8 +2069,8 @@ __socket_proto_state_machine (rpc_transport_t *this, } } - if (priv->incoming.record_state == SP_STATE_COMPLETE) { - priv->incoming.record_state = SP_STATE_NADA; + if (in->record_state == SP_STATE_COMPLETE) { + in->record_state = SP_STATE_NADA; __socket_reset_priv (priv); } @@ -1640,7 +2082,7 @@ out: } -int +static int socket_proto_state_machine (rpc_transport_t *this, rpc_transport_pollin_t **pollin) { @@ -1663,18 +2105,22 @@ out: } -int +static int socket_event_poll_in (rpc_transport_t *this) { int ret = -1; rpc_transport_pollin_t *pollin = NULL; + socket_private_t *priv = this->private; ret = socket_proto_state_machine (this, &pollin); if (pollin != NULL) { + priv->ot_state = OT_CALLBACK; ret = rpc_transport_notify (this, RPC_TRANSPORT_MSG_RECEIVED, pollin); - + if (priv->ot_state == OT_CALLBACK) { + priv->ot_state = OT_RUNNING; + } rpc_transport_pollin_destroy (pollin); } @@ -1682,7 +2128,7 @@ socket_event_poll_in (rpc_transport_t *this) } -int +static int socket_connect_finish (rpc_transport_t *this) { int ret = -1; @@ -1697,9 +2143,11 @@ socket_connect_finish (rpc_transport_t *this) pthread_mutex_lock (&priv->lock); { - if (priv->connected) + if (priv->connected != 0) goto unlock; + get_transport_identifiers (this); + ret = __socket_connect_finish (priv->sock); if (ret == -1 && errno == EINPROGRESS) @@ -1714,8 +2162,6 @@ socket_connect_finish (rpc_transport_t *this) priv->connect_finish_log = 1; } __socket_disconnect (this); - notify_rpc = 1; - event = RPC_TRANSPORT_DISCONNECT; goto unlock; } @@ -1740,7 +2186,6 @@ socket_connect_finish (rpc_transport_t *this) priv->connected = 1; priv->connect_finish_log = 0; event = RPC_TRANSPORT_CONNECT; - get_transport_identifiers (this); } } unlock: @@ -1755,13 +2200,13 @@ out: /* reads rpc_requests during pollin */ -int +static int socket_event_handler (int fd, int idx, void *data, int poll_in, int poll_out, int poll_err) { - rpc_transport_t *this = NULL; + rpc_transport_t *this = NULL; socket_private_t *priv = NULL; - int ret = 0; + int ret = -1; this = data; GF_VALIDATE_OR_GOTO ("socket", this, out); @@ -1771,16 +2216,13 @@ socket_event_handler (int fd, int idx, void *data, THIS = this->xl; priv = this->private; - pthread_mutex_lock (&priv->lock); { priv->idx = idx; } pthread_mutex_unlock (&priv->lock); - if (!priv->connected) { - ret = socket_connect_finish (this); - } + ret = (priv->connected == 1) ? 0 : socket_connect_finish(this); if (!ret && poll_out) { ret = socket_event_poll_out (this); @@ -1796,14 +2238,198 @@ socket_event_handler (int fd, int idx, void *data, "disconnecting now"); socket_event_poll_err (this); rpc_transport_unref (this); - } + } out: - return 0; + return ret; } -int +static void * +socket_poller (void *ctx) +{ + rpc_transport_t *this = ctx; + socket_private_t *priv = this->private; + struct pollfd pfd[2] = {{0,},}; + gf_boolean_t to_write = _gf_false; + int ret = 0; + uint32_t gen = 0; + + priv->ot_state = OT_RUNNING; + + if (priv->use_ssl) { + if (ssl_setup_connection(this,priv->connected) < 0) { + gf_log (this->name,GF_LOG_ERROR, "%s setup failed", + priv->connected ? "server" : "client"); + goto err; + } + } + + if (!priv->bio) { + ret = __socket_nonblock (priv->sock); + if (ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "NBIO on %d failed (%s)", + priv->sock, strerror (errno)); + goto err; + } + } + + if (priv->connected == 0) { + THIS = this->xl; + ret = socket_connect_finish (this); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "asynchronous socket_connect_finish failed"); + } + } + + ret = rpc_transport_notify (this->listener, + RPC_TRANSPORT_ACCEPT, this); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "asynchronous rpc_transport_notify failed"); + } + + gen = priv->ot_gen; + for (;;) { + pthread_mutex_lock(&priv->lock); + to_write = !list_empty(&priv->ioq); + pthread_mutex_unlock(&priv->lock); + pfd[0].fd = priv->pipe[0]; + pfd[0].events = POLL_MASK_ERROR; + pfd[0].revents = 0; + pfd[1].fd = priv->sock; + pfd[1].events = POLL_MASK_INPUT | POLL_MASK_ERROR; + pfd[1].revents = 0; + if (to_write) { + pfd[1].events |= POLL_MASK_OUTPUT; + } + else { + pfd[0].events |= POLL_MASK_INPUT; + } + if (poll(pfd,2,-1) < 0) { + gf_log(this->name,GF_LOG_ERROR,"poll failed"); + break; + } + if (pfd[0].revents & POLL_MASK_ERROR) { + gf_log(this->name,GF_LOG_ERROR, + "poll error on pipe"); + break; + } + /* Only glusterd actually seems to need this. */ + THIS = this->xl; + if (pfd[1].revents & POLL_MASK_INPUT) { + ret = socket_event_poll_in(this); + if (ret >= 0) { + /* Suppress errors while making progress. */ + pfd[1].revents &= ~POLL_MASK_ERROR; + } + else if (errno == ENOTCONN) { + ret = 0; + } + if (priv->ot_state == OT_PLEASE_DIE) { + gf_log (this->name, GF_LOG_TRACE, + "OT_IDLE on %p (input request)", + this); + priv->ot_state = OT_IDLE; + break; + } + } + else if (pfd[1].revents & POLL_MASK_OUTPUT) { + ret = socket_event_poll_out(this); + if (ret >= 0) { + /* Suppress errors while making progress. */ + pfd[1].revents &= ~POLL_MASK_ERROR; + } + else if (errno == ENOTCONN) { + ret = 0; + } + if (priv->ot_state == OT_PLEASE_DIE) { + gf_log (this->name, GF_LOG_TRACE, + "OT_IDLE on %p (output request)", + this); + priv->ot_state = OT_IDLE; + break; + } + } + else { + /* + * This usually means that we left poll() because + * somebody pushed a byte onto our pipe. That wakeup + * is why the pipe is there, but once awake we can do + * all the checking we need on the next iteration. + */ + ret = 0; + } + if (pfd[1].revents & POLL_MASK_ERROR) { + gf_log(this->name,GF_LOG_ERROR, + "poll error on socket"); + break; + } + if (ret < 0) { + gf_log(this->name,GF_LOG_ERROR, + "error in polling loop"); + break; + } + if (priv->ot_gen != gen) { + gf_log (this->name, GF_LOG_TRACE, + "generation mismatch, my %u != %u", + gen, priv->ot_gen); + return NULL; + } + } + +err: + /* All (and only) I/O errors should come here. */ + pthread_mutex_lock(&priv->lock); + if (priv->ssl_ssl) { + /* + * We're always responsible for this part, but only actually + * have to do it if we got far enough for ssl_ssl to be valid + * (i.e. errors in ssl_setup_connection don't count). + */ + ssl_teardown_connection(priv); + } + __socket_shutdown(this); + close(priv->sock); + priv->sock = -1; + priv->ot_state = OT_IDLE; + pthread_mutex_unlock(&priv->lock); + rpc_transport_notify (this->listener, RPC_TRANSPORT_DISCONNECT, + this); + rpc_transport_unref (this); + return NULL; +} + + +static void +socket_spawn (rpc_transport_t *this) +{ + socket_private_t *priv = this->private; + + switch (priv->ot_state) { + case OT_IDLE: + case OT_PLEASE_DIE: + break; + default: + gf_log (this->name, GF_LOG_WARNING, + "refusing to start redundant poller"); + return; + } + + priv->ot_gen += 7; + priv->ot_state = OT_SPAWNING; + gf_log (this->name, GF_LOG_TRACE, + "spawning %p with gen %u", this, priv->ot_gen); + + if (gf_thread_create(&priv->thread,NULL,socket_poller,this) != 0) { + gf_log (this->name, GF_LOG_ERROR, + "could not create poll thread"); + } +} + +static int socket_server_event_handler (int fd, int idx, void *data, int poll_in, int poll_out, int poll_err) { @@ -1841,20 +2467,7 @@ socket_server_event_handler (int fd, int idx, void *data, goto unlock; } - if (!priv->bio) { - ret = __socket_nonblock (new_sock); - - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "NBIO on %d failed (%s)", - new_sock, strerror (errno)); - - close (new_sock); - goto unlock; - } - } - - if (priv->nodelay) { + if (priv->nodelay && (new_sockaddr.ss_family != AF_UNIX)) { ret = __socket_nodelay (new_sock); if (ret == -1) { gf_log (this->name, GF_LOG_WARNING, @@ -1864,8 +2477,10 @@ socket_server_event_handler (int fd, int idx, void *data, } } - if (priv->keepalive) { + if (priv->keepalive && + new_sockaddr.ss_family != AF_UNIX) { ret = __socket_keepalive (new_sock, + new_sockaddr.ss_family, priv->keepaliveintvl, priv->keepaliveidle); if (ret == -1) @@ -1879,6 +2494,15 @@ socket_server_event_handler (int fd, int idx, void *data, if (!new_trans) goto unlock; + ret = pthread_mutex_init(&new_trans->lock, NULL); + if (ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "pthread_mutex_init() failed: %s", + strerror (errno)); + close (new_sock); + goto unlock; + } + new_trans->name = gf_strdup (this->name); memcpy (&new_trans->peerinfo.sockaddr, &new_sockaddr, @@ -1900,7 +2524,11 @@ socket_server_event_handler (int fd, int idx, void *data, } get_transport_identifiers (new_trans); - socket_init (new_trans); + ret = socket_init(new_trans); + if (ret != 0) { + close(new_sock); + goto unlock; + } new_trans->ops = this->ops; new_trans->init = this->init; new_trans->fini = this->fini; @@ -1911,20 +2539,62 @@ socket_server_event_handler (int fd, int idx, void *data, new_trans->listener = this; new_priv = new_trans->private; + new_priv->use_ssl = priv->use_ssl; + new_priv->sock = new_sock; + new_priv->own_thread = priv->own_thread; + + new_priv->ssl_ctx = priv->ssl_ctx; + if (priv->use_ssl && !priv->own_thread) { + if (ssl_setup_connection(new_trans,1) < 0) { + gf_log(this->name,GF_LOG_ERROR, + "server setup failed"); + close(new_sock); + goto unlock; + } + } + + if (!priv->bio && !priv->own_thread) { + ret = __socket_nonblock (new_sock); + + if (ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "NBIO on %d failed (%s)", + new_sock, strerror (errno)); + + close (new_sock); + goto unlock; + } + } + pthread_mutex_lock (&new_priv->lock); { - new_priv->sock = new_sock; + /* + * In the own_thread case, this is used to + * indicate that we're initializing a server + * connection. + */ new_priv->connected = 1; + new_priv->is_server = _gf_true; 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->own_thread) { + if (pipe(new_priv->pipe) < 0) { + gf_log(this->name,GF_LOG_ERROR, + "could not create pipe"); + } + socket_spawn(new_trans); + } + else { + new_priv->idx = + event_register (ctx->event_pool, + new_sock, + socket_event_handler, + new_trans, + 1, 0); + if (new_priv->idx == -1) + ret = -1; + } - if (new_priv->idx == -1) - ret = -1; } pthread_mutex_unlock (&new_priv->lock); if (ret == -1) { @@ -1933,8 +2603,10 @@ socket_server_event_handler (int fd, int idx, void *data, goto unlock; } - ret = rpc_transport_notify (this, RPC_TRANSPORT_ACCEPT, - new_trans); + if (!priv->own_thread) { + ret = rpc_transport_notify (this, + RPC_TRANSPORT_ACCEPT, new_trans); + } } } unlock: @@ -1945,7 +2617,7 @@ out: } -int +static int socket_disconnect (rpc_transport_t *this) { socket_private_t *priv = NULL; @@ -1967,7 +2639,7 @@ out: } -int +static int socket_connect (rpc_transport_t *this, int port) { int ret = -1; @@ -1976,7 +2648,9 @@ socket_connect (rpc_transport_t *this, int port) 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_VALIDATE_OR_GOTO ("socket", this, err); GF_VALIDATE_OR_GOTO ("socket", this->private, err); @@ -2004,6 +2678,10 @@ socket_connect (rpc_transport_t *this, int port) goto err; } + gf_log (this->name, GF_LOG_TRACE, + "connecting %p, state=%u gen=%u sock=%d", this, + priv->ot_state, priv->ot_gen, priv->sock); + ret = socket_client_get_remote_sockaddr (this, &sock_union.sa, &sockaddr_len, &sa_family); if (ret == -1) { @@ -2014,6 +2692,20 @@ socket_connect (rpc_transport_t *this, int port) if (port > 0) { sock_union.sin.sin_port = htons (port); } + if (ntohs(sock_union.sin.sin_port) == GF_DEFAULT_SOCKET_LISTEN_PORT) { + if (priv->use_ssl) { + gf_log(this->name,GF_LOG_DEBUG, + "disabling SSL for portmapper connection"); + priv->use_ssl = _gf_false; + } + } + 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; + } + } pthread_mutex_lock (&priv->lock); { if (priv->sock != -1) { @@ -2037,49 +2729,41 @@ socket_connect (rpc_transport_t *this, int port) /* 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 (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)); - } - + 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 (priv->nodelay) { - ret = __socket_nodelay (priv->sock); - if (ret == -1) { + if (setsockopt (priv->sock, SOL_SOCKET, SO_SNDBUF, + &priv->windowsize, + sizeof (priv->windowsize)) < 0) { gf_log (this->name, GF_LOG_ERROR, - "setsockopt() failed for NODELAY (%s)", + "setting send window size " + "failed: %d: %d: %s", + priv->sock, priv->windowsize, strerror (errno)); } } - if (!priv->bio) { - ret = __socket_nonblock (priv->sock); + if (priv->nodelay && (sa_family != AF_UNIX)) { + ret = __socket_nodelay (priv->sock); if (ret == -1) { gf_log (this->name, GF_LOG_ERROR, - "NBIO on %d failed (%s)", + "NODELAY on %d failed (%s)", priv->sock, strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; } } - if (priv->keepalive) { + if (priv->keepalive && sa_family != AF_UNIX) { ret = __socket_keepalive (priv->sock, + sa_family, priv->keepaliveintvl, priv->keepaliveidle); if (ret == -1) @@ -2091,6 +2775,15 @@ socket_connect (rpc_transport_t *this, int port) SA (&this->myinfo.sockaddr)->sa_family = SA (&this->peerinfo.sockaddr)->sa_family; + /* If a source addr is explicitly specified, use it */ + ret = dict_get_str (this->options, + "transport.socket.source-addr", + &local_addr); + 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)); + } + ret = client_bind (this, SA (&this->myinfo.sockaddr), &this->myinfo.sockaddr_len, priv->sock); if (ret == -1) { @@ -2101,29 +2794,86 @@ socket_connect (rpc_transport_t *this, int port) goto unlock; } + if (!priv->use_ssl && !priv->bio && !priv->own_thread) { + ret = __socket_nonblock (priv->sock); + 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; + } + } + ret = connect (priv->sock, SA (&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)); + if (ret == -1 && ((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)); close (priv->sock); priv->sock = -1; goto unlock; } - priv->connected = 0; + if (priv->use_ssl && !priv->own_thread) { + ret = ssl_setup_connection(this,0); + if (ret < 0) { + gf_log(this->name,GF_LOG_ERROR, + "client setup failed"); + close(priv->sock); + priv->sock = -1; + goto unlock; + } + } - rpc_transport_ref (this); + if (!priv->bio && !priv->own_thread) { + ret = __socket_nonblock (priv->sock); - 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; + 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; + } } + + /* + * In the own_thread case, this is used to indicate that we're + * initializing a client connection. + */ + priv->connected = 0; + priv->is_server = _gf_false; + rpc_transport_ref (this); + + if (priv->own_thread) { + if (pipe(priv->pipe) < 0) { + gf_log(this->name,GF_LOG_ERROR, + "could not create pipe"); + } + + this->listener = this; + socket_spawn(this); + } + else { + priv->idx = event_register (ctx->event_pool, priv->sock, + socket_event_handler, + this, 1, 1); + if (priv->idx == -1) { + gf_log ("", GF_LOG_WARNING, + "failed to register the event"); + ret = -1; + } + } } unlock: pthread_mutex_unlock (&priv->lock); @@ -2133,7 +2883,7 @@ err: } -int +static int socket_listen (rpc_transport_t *this) { socket_private_t * priv = NULL; @@ -2160,7 +2910,7 @@ socket_listen (rpc_transport_t *this) if (sock != -1) { gf_log_callingfn (this->name, GF_LOG_DEBUG, - "alreading listening"); + "already listening"); return ret; } @@ -2193,25 +2943,29 @@ socket_listen (rpc_transport_t *this) /* 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 (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)); + 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)); + } } - if (priv->nodelay) { + if (priv->nodelay && (sa_family != AF_UNIX)) { ret = __socket_nodelay (priv->sock); if (ret == -1) { gf_log (this->name, GF_LOG_ERROR, @@ -2280,7 +3034,7 @@ out: } -int32_t +static int32_t socket_submit_request (rpc_transport_t *this, rpc_transport_req_t *req) { socket_private_t *priv = NULL; @@ -2289,6 +3043,7 @@ socket_submit_request (rpc_transport_t *this, rpc_transport_req_t *req) char need_append = 1; struct ioq *entry = NULL; glusterfs_ctx_t *ctx = NULL; + char a_byte = 'j'; GF_VALIDATE_OR_GOTO ("socket", this, out); GF_VALIDATE_OR_GOTO ("socket", this->private, out); @@ -2314,21 +3069,31 @@ socket_submit_request (rpc_transport_t *this, rpc_transport_req_t *req) goto unlock; if (list_empty (&priv->ioq)) { - ret = __socket_ioq_churn_entry (this, entry); + ret = __socket_ioq_churn_entry (this, entry, 1); - if (ret == 0) + if (ret == 0) { need_append = 0; - - if (ret > 0) + } + if (ret > 0) { need_poll_out = 1; + } } if (need_append) { list_add_tail (&entry->list, &priv->ioq); + if (priv->own_thread) { + /* + * Make sure the polling thread wakes up, by + * writing a byte to represent this entry. + */ + if (write(priv->pipe[1],&a_byte,1) < 1) { + gf_log(this->name,GF_LOG_WARNING, + "write error on pipe"); + } + } ret = 0; } - - if (need_poll_out) { + if (!priv->own_thread && need_poll_out) { /* first entry to wait. continue writing on POLLOUT */ priv->idx = event_select_on (ctx->event_pool, priv->sock, @@ -2343,7 +3108,7 @@ out: } -int32_t +static int32_t socket_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply) { socket_private_t *priv = NULL; @@ -2352,6 +3117,7 @@ socket_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply) char need_append = 1; struct ioq *entry = NULL; glusterfs_ctx_t *ctx = NULL; + char a_byte = 'd'; GF_VALIDATE_OR_GOTO ("socket", this, out); GF_VALIDATE_OR_GOTO ("socket", this->private, out); @@ -2370,33 +3136,44 @@ socket_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply) } 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); + ret = __socket_ioq_churn_entry (this, entry, 1); - if (ret == 0) + if (ret == 0) { need_append = 0; - - if (ret > 0) + } + if (ret > 0) { need_poll_out = 1; + } } if (need_append) { list_add_tail (&entry->list, &priv->ioq); + if (priv->own_thread) { + /* + * Make sure the polling thread wakes up, by + * writing a byte to represent this entry. + */ + if (write(priv->pipe[1],&a_byte,1) < 1) { + gf_log(this->name,GF_LOG_WARNING, + "write error on pipe"); + } + } ret = 0; } - - if (need_poll_out) { + if (!priv->own_thread && 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); } } - unlock: pthread_mutex_unlock (&priv->lock); @@ -2405,7 +3182,7 @@ out: } -int32_t +static int32_t socket_getpeername (rpc_transport_t *this, char *hostname, int hostlen) { int32_t ret = -1; @@ -2424,7 +3201,7 @@ out: } -int32_t +static int32_t socket_getpeeraddr (rpc_transport_t *this, char *peeraddr, int addrlen, struct sockaddr_storage *sa, socklen_t salen) { @@ -2445,7 +3222,7 @@ out: } -int32_t +static int32_t socket_getmyname (rpc_transport_t *this, char *hostname, int hostlen) { int32_t ret = -1; @@ -2464,7 +3241,7 @@ out: } -int32_t +static int32_t socket_getmyaddr (rpc_transport_t *this, char *myaddr, int addrlen, struct sockaddr_storage *sa, socklen_t salen) { @@ -2484,6 +3261,25 @@ out: } +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. + */ + priv->idx = event_select_on (this->ctx->event_pool, priv->sock, + priv->idx, (int) !onoff, -1); + return 0; +} + + struct rpc_transport_ops tops = { .listen = socket_listen, .connect = socket_connect, @@ -2494,15 +3290,17 @@ struct rpc_transport_ops tops = { .get_peeraddr = socket_getpeeraddr, .get_myname = socket_getmyname, .get_myaddr = socket_getmyaddr, + .throttle = socket_throttle, }; int 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 = 0; + uint64_t windowsize = 0; GF_VALIDATE_OR_GOTO ("socket", this, out); GF_VALIDATE_OR_GOTO ("socket", this->private, out); @@ -2530,13 +3328,26 @@ reconfigure (rpc_transport_t *this, dict_t *options) } else priv->keepalive = 1; + + optstr = NULL; + if (dict_get_str (this->options, "tcp-window-size", + &optstr) == 0) { + if (gf_string2bytesize (optstr, &windowsize) != 0) { + gf_log (this->name, GF_LOG_ERROR, + "invalid number format: %s", optstr); + goto out; + } + } + + priv->windowsize = (int)windowsize; + ret = 0; out: return ret; } -int +static int socket_init (rpc_transport_t *this) { socket_private_t *priv = NULL; @@ -2545,6 +3356,7 @@ socket_init (rpc_transport_t *this) char *optstr = NULL; uint32_t keepalive = 0; uint32_t backlog = 0; + int session_id = 0; if (this->private) { gf_log_callingfn (this->name, GF_LOG_ERROR, @@ -2556,6 +3368,7 @@ socket_init (rpc_transport_t *this) if (!priv) { return -1; } + memset(priv,0,sizeof(*priv)); pthread_mutex_init (&priv->lock, NULL); @@ -2609,9 +3422,8 @@ socket_init (rpc_transport_t *this) } } - optstr = NULL; - if (dict_get_str (this->options, "transport.window-size", + if (dict_get_str (this->options, "tcp-window-size", &optstr) == 0) { if (gf_string2bytesize (optstr, &windowsize) != 0) { gf_log (this->name, GF_LOG_ERROR, @@ -2620,8 +3432,9 @@ socket_init (rpc_transport_t *this) } } - optstr = NULL; + priv->windowsize = (int)windowsize; + optstr = NULL; /* Enable Keep-alive by default. */ priv->keepalive = 1; priv->keepaliveintvl = 2; @@ -2674,10 +3487,133 @@ socket_init (rpc_transport_t *this) } priv->windowsize = (int)windowsize; + + priv->ssl_enabled = _gf_false; + if (dict_get_str(this->options,SSL_ENABLED_OPT,&optstr) == 0) { + if (gf_string2boolean (optstr, &priv->ssl_enabled) != 0) { + gf_log (this->name, GF_LOG_ERROR, + "invalid value given for ssl-enabled boolean"); + } + } + + priv->ssl_own_cert = DEFAULT_CERT_PATH; + if (dict_get_str(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(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(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); + + gf_log(this->name,GF_LOG_INFO,"SSL support is %s", + priv->ssl_enabled ? "ENABLED" : "NOT enabled"); + /* + * This might get overridden temporarily in socket_connect (q.v.) + * if we're using the glusterd portmapper. + */ + priv->use_ssl = priv->ssl_enabled; + + priv->own_thread = priv->use_ssl; + if (dict_get_str(this->options,OWN_THREAD_OPT,&optstr) == 0) { + if (gf_string2boolean (optstr, &priv->own_thread) != 0) { + gf_log (this->name, GF_LOG_ERROR, + "invalid value given for own-thread boolean"); + } + } + gf_log(this->name,GF_LOG_INFO,"using %s polling thread", + priv->own_thread ? "private" : "system"); + + if (priv->use_ssl) { + SSL_library_init(); + SSL_load_error_strings(); + priv->ssl_meth = (SSL_METHOD *)TLSv1_method(); + priv->ssl_ctx = SSL_CTX_new(priv->ssl_meth); + + if (SSL_CTX_set_cipher_list(priv->ssl_ctx, + "HIGH:-SSLv2") == 0) { + gf_log(this->name,GF_LOG_ERROR, + "failed to find any valid ciphers"); + goto err; + } + + 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"); + goto err; + } + + 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"); + goto err; + } + + if (!SSL_CTX_load_verify_locations(priv->ssl_ctx, + priv->ssl_ca_list,0)) { + gf_log(this->name,GF_LOG_ERROR, + "could not load CA list"); + goto err; + } + +#if (OPENSSL_VERSION_NUMBER < 0x00905100L) + SSL_CTX_set_verify_depth(ctx,1); +#endif + + 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); + } + + if (priv->own_thread) { + priv->ot_state = OT_IDLE; + } + out: this->private = priv; - return 0; + +err: + if (priv->ssl_own_cert) { + GF_FREE(priv->ssl_own_cert); + } + if (priv->ssl_private_key) { + GF_FREE(priv->ssl_private_key); + } + if (priv->ssl_ca_list) { + GF_FREE(priv->ssl_ca_list); + } + GF_FREE(priv); + return -1; } @@ -2703,6 +3639,15 @@ fini (rpc_transport_t *this) "transport %p destroyed", this); pthread_mutex_destroy (&priv->lock); + 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); } @@ -2747,18 +3692,17 @@ struct volume_options options[] = { }, { .key = { "transport.address-family", "address-family" }, - .value = {"inet", "inet6", "inet/inet6", "inet6/inet", - "unix", "inet-sdp" }, + .value = {"inet", "inet6", "unix", "inet-sdp" }, .type = GF_OPTION_TYPE_STR }, { .key = {"non-blocking-io"}, .type = GF_OPTION_TYPE_BOOL }, - { .key = {"transport.window-size"}, + { .key = {"tcp-window-size"}, .type = GF_OPTION_TYPE_SIZET, .min = GF_MIN_SOCKET_WINDOW_SIZE, - .max = GF_MAX_SOCKET_WINDOW_SIZE, + .max = GF_MAX_SOCKET_WINDOW_SIZE }, { .key = {"transport.socket.nodelay"}, .type = GF_OPTION_TYPE_BOOL @@ -2781,5 +3725,20 @@ struct volume_options options[] = { { .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 = {OWN_THREAD_OPT}, + .type = GF_OPTION_TYPE_BOOL + }, { .key = {NULL} } }; diff --git a/rpc/rpc-transport/socket/src/socket.h b/rpc/rpc-transport/socket/src/socket.h index 7f0fb6bc3..e0b412fcc 100644 --- a/rpc/rpc-transport/socket/src/socket.h +++ b/rpc/rpc-transport/socket/src/socket.h @@ -1,25 +1,18 @@ /* - 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 +#include <openssl/ssl.h> +#include <openssl/err.h> #ifndef _CONFIG_H #define _CONFIG_H @@ -41,19 +34,17 @@ #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_DEFAULT_SOCKET_WINDOW_SIZE (0) #define GF_MAX_SOCKET_WINDOW_SIZE (1 * GF_UNIT_MB) -#define GF_MIN_SOCKET_WINDOW_SIZE (128 * GF_UNIT_KB) +#define GF_MIN_SOCKET_WINDOW_SIZE (0) #define GF_USE_DEFAULT_KEEPALIVE (-1) typedef enum { @@ -83,6 +74,12 @@ typedef enum { 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; @@ -126,6 +123,8 @@ typedef enum { typedef enum { 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; @@ -144,10 +143,60 @@ typedef struct { 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 { + sp_rpcrecord_state_t record_state; + struct gf_sock_incoming_frag frag; + char *proghdr_base_addr; + 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; + + size_t ra_read; + size_t ra_max; + size_t ra_served; + char *ra_buf; +}; + +typedef enum { + OT_IDLE, /* Uninitialized or termination complete. */ + OT_SPAWNING, /* Past pthread_create but not in thread yet. */ + OT_RUNNING, /* Poller thread running normally. */ + OT_CALLBACK, /* Poller thread in the middle of a callback. */ + OT_PLEASE_DIE, /* Poller termination requested. */ +} ot_state_t; + typedef struct { int32_t sock; int32_t idx; - unsigned char connected; // -1 = not connected. 0 = in progress. 1 = connected + /* -1 = not connected. 0 = in progress. 1 = connected */ + char connected; char bio; char connect_finish_log; char submit_log; @@ -158,36 +207,7 @@ typedef struct { struct ioq *ioq_prev; }; }; - 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; + struct gf_sock_incoming incoming; pthread_mutex_t lock; int windowsize; char lowlat; @@ -197,6 +217,22 @@ typedef struct { int keepaliveintvl; uint32_t backlog; gf_boolean_t read_fail_log; + gf_boolean_t ssl_enabled; + gf_boolean_t use_ssl; + SSL_METHOD *ssl_meth; + SSL_CTX *ssl_ctx; + int ssl_session_id; + BIO *ssl_sbio; + SSL *ssl_ssl; + char *ssl_own_cert; + char *ssl_private_key; + char *ssl_ca_list; + pthread_t thread; + int pipe[2]; + gf_boolean_t own_thread; + ot_state_t ot_state; + uint32_t ot_gen; + gf_boolean_t is_server; } socket_private_t; diff --git a/rpc/xdr/src/Makefile.am b/rpc/xdr/src/Makefile.am index cabab3db6..949e75e8d 100644 --- a/rpc/xdr/src/Makefile.am +++ b/rpc/xdr/src/Makefile.am @@ -1,24 +1,25 @@ 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 = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 \ - -D_GNU_SOURCE -D$(GF_HOST_OS) \ +libgfxdr_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 \ -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/rpc/rpc-lib/src libgfxdr_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ $(top_builddir)/rpc/rpc-lib/src/libgfrpc.la -libgfxdr_la_SOURCES = xdr-generic.c \ +libgfxdr_la_SOURCES = xdr-generic.c rpc-common-xdr.c \ glusterfs3-xdr.c \ cli1-xdr.c \ glusterd1-xdr.c \ portmap-xdr.c \ - xdr-nfs3.c msg-nfs3.c + nlm4-xdr.c xdr-nfs3.c msg-nfs3.c nsm-xdr.c \ + nlmcbk-xdr.c acl3-xdr.c -noinst_HEADERS = xdr-generic.h \ +noinst_HEADERS = xdr-generic.h rpc-common-xdr.h \ glusterfs3-xdr.h glusterfs3.h \ cli1-xdr.h \ glusterd1-xdr.h \ portmap-xdr.h \ - xdr-nfs3.h msg-nfs3.h + nlm4-xdr.h xdr-nfs3.h msg-nfs3.h nsm-xdr.h \ + nlmcbk-xdr.h acl3-xdr.h diff --git a/rpc/xdr/src/acl.x b/rpc/xdr/src/acl.x new file mode 100644 index 000000000..6cf4f1d3b --- /dev/null +++ b/rpc/xdr/src/acl.x @@ -0,0 +1,48 @@ +/* + * 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. + */ + + +struct aclentry { + int type; + int uid; + int perm; +}; + +struct getaclargs { + netobj fh; + int mask; +}; + +struct getaclreply { + int status; + int attr_follows; + struct fattr3 attr; + int mask; + int aclcount; + struct aclentry aclentry<>; + int daclcount; + struct aclentry daclentry<>; +}; + +struct setaclargs { + netobj fh; + int mask; + int aclcount; + struct aclentry aclentry<>; + int daclcount; + struct aclentry daclentry<>; +}; + +struct setaclreply { + int status; + int attr_follows; + struct fattr3 attr; +}; + diff --git a/rpc/xdr/src/acl3-xdr.c b/rpc/xdr/src/acl3-xdr.c new file mode 100644 index 000000000..8fbaeff16 --- /dev/null +++ b/rpc/xdr/src/acl3-xdr.c @@ -0,0 +1,94 @@ +/* + * 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. + */ + +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include "acl3-xdr.h" + +bool_t +xdr_aclentry (XDR *xdrs, aclentry *objp) +{ + if (!xdr_int (xdrs, &objp->type)) + return FALSE; + if (!xdr_int (xdrs, &objp->uid)) + return FALSE; + if (!xdr_int (xdrs, &objp->perm)) + return FALSE; + return TRUE; +} + +bool_t +xdr_getaclargs (XDR *xdrs, getaclargs *objp) +{ + if (!xdr_netobj (xdrs, &objp->fh)) + return FALSE; + if (!xdr_int (xdrs, &objp->mask)) + return FALSE; + return TRUE; +} + +bool_t +xdr_getaclreply (XDR *xdrs, getaclreply *objp) +{ + if (!xdr_int (xdrs, &objp->status)) + return FALSE; + if (!xdr_int (xdrs, &objp->attr_follows)) + return FALSE; + if (!xdr_fattr3 (xdrs, &objp->attr)) + return FALSE; + if (!xdr_int (xdrs, &objp->mask)) + return FALSE; + if (!xdr_int (xdrs, &objp->aclcount)) + return FALSE; + if (!xdr_array (xdrs, (char **)&objp->aclentry.aclentry_val, (u_int *) &objp->aclentry.aclentry_len, ~0, + sizeof (aclentry), (xdrproc_t) xdr_aclentry)) + return FALSE; + if (!xdr_int (xdrs, &objp->daclcount)) + return FALSE; + if (!xdr_array (xdrs, (char **)&objp->daclentry.daclentry_val, (u_int *) &objp->daclentry.daclentry_len, ~0, + sizeof (aclentry), (xdrproc_t) xdr_aclentry)) + return FALSE; + return TRUE; +} + +bool_t +xdr_setaclargs (XDR *xdrs, setaclargs *objp) +{ + if (!xdr_netobj (xdrs, &objp->fh)) + return FALSE; + if (!xdr_int (xdrs, &objp->mask)) + return FALSE; + if (!xdr_int (xdrs, &objp->aclcount)) + return FALSE; + if (!xdr_array (xdrs, (char **)&objp->aclentry.aclentry_val, (u_int *) &objp->aclentry.aclentry_len, ~0, + sizeof (aclentry), (xdrproc_t) xdr_aclentry)) + return FALSE; + if (!xdr_int (xdrs, &objp->daclcount)) + return FALSE; + if (!xdr_array (xdrs, (char **)&objp->daclentry.daclentry_val, (u_int *) &objp->daclentry.daclentry_len, ~0, + sizeof (aclentry), (xdrproc_t) xdr_aclentry)) + return FALSE; + return TRUE; +} + +bool_t +xdr_setaclreply (XDR *xdrs, setaclreply *objp) +{ + if (!xdr_int (xdrs, &objp->status)) + return FALSE; + if (!xdr_int (xdrs, &objp->attr_follows)) + return FALSE; + if (!xdr_fattr3 (xdrs, &objp->attr)) + return FALSE; + return TRUE; +} diff --git a/rpc/xdr/src/acl3-xdr.h b/rpc/xdr/src/acl3-xdr.h new file mode 100644 index 000000000..7cebaed69 --- /dev/null +++ b/rpc/xdr/src/acl3-xdr.h @@ -0,0 +1,107 @@ +/* + * 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. + */ + +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#ifndef _ACL_H_RPCGEN +#define _ACL_H_RPCGEN + +#include <rpc/rpc.h> +#include "xdr-nfs3.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +struct aclentry { + int type; + int uid; + int perm; +}; +typedef struct aclentry aclentry; + +struct getaclargs { + netobj fh; + int mask; +}; +typedef struct getaclargs getaclargs; + +struct getaclreply { + int status; + int attr_follows; + struct fattr3 attr; + int mask; + int aclcount; + struct { + u_int aclentry_len; + struct aclentry *aclentry_val; + } aclentry; + int daclcount; + struct { + u_int daclentry_len; + struct aclentry *daclentry_val; + } daclentry; +}; +typedef struct getaclreply getaclreply; + +struct setaclargs { + netobj fh; + int mask; + int aclcount; + struct { + u_int aclentry_len; + struct aclentry *aclentry_val; + } aclentry; + int daclcount; + struct { + u_int daclentry_len; + struct aclentry *daclentry_val; + } daclentry; +}; +typedef struct setaclargs setaclargs; + +struct setaclreply { + int status; + int attr_follows; + struct fattr3 attr; +}; +typedef struct setaclreply setaclreply; + +#define ACL3_NULL 0 +#define ACL3_GETACL 1 +#define ACL3_SETACL 2 +#define ACL3_PROC_COUNT 3 +/* the xdr functions */ + +#if defined(__STDC__) || defined(__cplusplus) +extern bool_t xdr_aclentry (XDR *, aclentry*); +extern bool_t xdr_getaclargs (XDR *, getaclargs*); +extern bool_t xdr_getaclreply (XDR *, getaclreply*); +extern bool_t xdr_setaclargs (XDR *, setaclargs*); +extern bool_t xdr_setaclreply (XDR *, setaclreply*); + +#else /* K&R C */ +extern bool_t xdr_aclentry (); +extern bool_t xdr_getaclargs (); +extern bool_t xdr_getaclreply (); +extern bool_t xdr_setaclargs (); +extern bool_t xdr_setaclreply (); + +#endif /* K&R C */ + +#ifdef __cplusplus +} +#endif + +#endif /* !_ACL_H_RPCGEN */ diff --git a/rpc/xdr/src/cli1-xdr.c b/rpc/xdr/src/cli1-xdr.c index d325ac42a..97b210e14 100644 --- a/rpc/xdr/src/cli1-xdr.c +++ b/rpc/xdr/src/cli1-xdr.c @@ -1,20 +1,11 @@ /* - 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-common.h" @@ -177,510 +168,51 @@ xdr_gf1_cli_top_op (XDR *xdrs, gf1_cli_top_op *objp) } 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_get_vol_req (XDR *xdrs, gf1_cli_get_vol_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_get_vol_rsp (XDR *xdrs, gf1_cli_get_vol_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->volumes.volumes_val, (u_int *) &objp->volumes.volumes_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_create_vol_req (XDR *xdrs, gf1_cli_create_vol_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_gf1_cluster_type (xdrs, &objp->type)) - return FALSE; - if (!xdr_int (xdrs, &objp->count)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->bricks.bricks_val, (u_int *) &objp->bricks.bricks_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_create_vol_rsp (XDR *xdrs, gf1_cli_create_vol_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->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_delete_vol_req (XDR *xdrs, gf1_cli_delete_vol_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_delete_vol_rsp (XDR *xdrs, gf1_cli_delete_vol_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->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_start_vol_req (XDR *xdrs, gf1_cli_start_vol_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->flags)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_start_vol_rsp (XDR *xdrs, gf1_cli_start_vol_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->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_stop_vol_req (XDR *xdrs, gf1_cli_stop_vol_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->flags)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_stop_vol_rsp (XDR *xdrs, gf1_cli_stop_vol_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->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_rename_vol_req (XDR *xdrs, gf1_cli_rename_vol_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->old_volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->new_volname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_rename_vol_rsp (XDR *xdrs, gf1_cli_rename_vol_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->volname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_defrag_vol_req (XDR *xdrs, gf1_cli_defrag_vol_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->cmd)) - return FALSE; - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_defrag_vol_rsp (XDR *xdrs, gf1_cli_defrag_vol_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->volname, ~0)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->files)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->size)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->lookedup_files)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf2_cli_defrag_vol_rsp (XDR *xdrs, gf2_cli_defrag_vol_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_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->files)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->size)) - return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->lookedup_files)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_add_brick_req (XDR *xdrs, gf1_cli_add_brick_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->count)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->bricks.bricks_val, (u_int *) &objp->bricks.bricks_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_add_brick_rsp (XDR *xdrs, gf1_cli_add_brick_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->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_remove_brick_req (XDR *xdrs, gf1_cli_remove_brick_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->count)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->bricks.bricks_val, (u_int *) &objp->bricks.bricks_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_remove_brick_rsp (XDR *xdrs, gf1_cli_remove_brick_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->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_replace_brick_req (XDR *xdrs, gf1_cli_replace_brick_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_gf1_cli_replace_op (xdrs, &objp->op)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->bricks.bricks_val, (u_int *) &objp->bricks.bricks_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_replace_brick_rsp (XDR *xdrs, gf1_cli_replace_brick_rsp *objp) +xdr_gf_cli_status_type (XDR *xdrs, gf_cli_status_type *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_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->status, ~0)) + if (!xdr_enum (xdrs, (enum_t *) objp)) return FALSE; return TRUE; } bool_t -xdr_gf1_cli_reset_vol_req (XDR *xdrs, gf1_cli_reset_vol_req *objp) +xdr_gf1_cli_snapshot (XDR *xdrs, gf1_cli_snapshot *objp) { register int32_t *buf; buf = NULL; - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + if (!xdr_enum (xdrs, (enum_t *) objp)) return FALSE; return TRUE; } bool_t -xdr_gf1_cli_reset_vol_rsp (XDR *xdrs, gf1_cli_reset_vol_rsp *objp) +xdr_gf1_cli_snapshot_config (XDR *xdrs, gf1_cli_snapshot_config *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->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) + if (!xdr_enum (xdrs, (enum_t *) objp)) return FALSE; return TRUE; } bool_t -xdr_gf1_cli_set_vol_req (XDR *xdrs, gf1_cli_set_vol_req *objp) +xdr_gf_cli_req (XDR *xdrs, gf_cli_req *objp) { register int32_t *buf; buf = NULL; - if (!xdr_string (xdrs, &objp->volname, ~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_set_vol_rsp (XDR *xdrs, gf1_cli_set_vol_rsp *objp) +xdr_gf_cli_rsp (XDR *xdrs, gf_cli_rsp *objp) { register int32_t *buf; buf = NULL; @@ -689,8 +221,6 @@ xdr_gf1_cli_set_vol_rsp (XDR *xdrs, gf1_cli_set_vol_rsp *objp) return FALSE; if (!xdr_int (xdrs, &objp->op_errno)) return FALSE; - if (!xdr_string (xdrs, &objp->volname, ~0)) - 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)) @@ -699,108 +229,20 @@ xdr_gf1_cli_set_vol_rsp (XDR *xdrs, gf1_cli_set_vol_rsp *objp) } bool_t -xdr_gf1_cli_log_filename_req (XDR *xdrs, gf1_cli_log_filename_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->brick, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_log_filename_rsp (XDR *xdrs, gf1_cli_log_filename_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->errstr, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_log_locate_req (XDR *xdrs, gf1_cli_log_locate_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->brick, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_sync_volume_req (XDR *xdrs, gf1_cli_sync_volume_req *objp) +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_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_log_locate_rsp (XDR *xdrs, gf1_cli_log_locate_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_log_rotate_req (XDR *xdrs, gf1_cli_log_rotate_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->brick, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_log_rotate_rsp (XDR *xdrs, gf1_cli_log_rotate_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->errstr, ~0)) + 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_sync_volume_rsp (XDR *xdrs, gf1_cli_sync_volume_rsp *objp) +xdr_gf1_cli_peer_list_rsp (XDR *xdrs, gf1_cli_peer_list_rsp *objp) { register int32_t *buf; buf = NULL; @@ -809,7 +251,7 @@ xdr_gf1_cli_sync_volume_rsp (XDR *xdrs, gf1_cli_sync_volume_rsp *objp) return FALSE; if (!xdr_int (xdrs, &objp->op_errno)) return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) + if (!xdr_bytes (xdrs, (char **)&objp->friends.friends_val, (u_int *) &objp->friends.friends_len, ~0)) return FALSE; return TRUE; } @@ -843,102 +285,6 @@ xdr_gf1_cli_fsm_log_rsp (XDR *xdrs, gf1_cli_fsm_log_rsp *objp) } bool_t -xdr_gf1_cli_gsync_set_req (XDR *xdrs, gf1_cli_gsync_set_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_gf1_cli_gsync_set_rsp (XDR *xdrs, gf1_cli_gsync_set_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_int (xdrs, &objp->type)) - 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_stats_volume_req (XDR *xdrs, gf1_cli_stats_volume_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_gf1_cli_stats_op (xdrs, &objp->op)) - return FALSE; - if (!xdr_bytes (xdrs, (char **)&objp->dict_req.dict_req_val, (u_int *) &objp->dict_req.dict_req_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_stats_volume_rsp (XDR *xdrs, gf1_cli_stats_volume_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->stats_info.stats_info_val, (u_int *) &objp->stats_info.stats_info_len, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_quota_req (XDR *xdrs, gf1_cli_quota_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~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_quota_rsp (XDR *xdrs, gf1_cli_quota_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->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->limit_list, ~0)) - return FALSE; - if (!xdr_gf_quota_type (xdrs, &objp->type)) - return FALSE; - return TRUE; -} - -bool_t xdr_gf1_cli_getwd_req (XDR *xdrs, gf1_cli_getwd_req *objp) { register int32_t *buf; @@ -965,66 +311,6 @@ xdr_gf1_cli_getwd_rsp (XDR *xdrs, gf1_cli_getwd_rsp *objp) } bool_t -xdr_gf1_cli_log_level_req (XDR *xdrs, gf1_cli_log_level_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->xlator, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->loglevel, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_log_level_rsp (XDR *xdrs, gf1_cli_log_level_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; - return TRUE; -} - -bool_t -xdr_gf1_cli_status_volume_req (XDR *xdrs, gf1_cli_status_volume_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~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_status_volume_rsp (XDR *xdrs, gf1_cli_status_volume_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_mount_req (XDR *xdrs, gf1_cli_mount_req *objp) { register int32_t *buf; @@ -1077,67 +363,3 @@ xdr_gf1_cli_umount_rsp (XDR *xdrs, gf1_cli_umount_rsp *objp) return FALSE; return TRUE; } - -bool_t -xdr_gf1_cli_heal_vol_req (XDR *xdrs, gf1_cli_heal_vol_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_heal_vol_rsp (XDR *xdrs, gf1_cli_heal_vol_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->volname, ~0)) - 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_statedump_vol_req (XDR *xdrs, gf1_cli_statedump_vol_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->volname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->options, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->option_cnt)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_statedump_vol_rsp (XDR *xdrs, gf1_cli_statedump_vol_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->volname, ~0)) - 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; -} diff --git a/rpc/xdr/src/cli1-xdr.h b/rpc/xdr/src/cli1-xdr.h index b92c707bb..5e8c29fbb 100644 --- a/rpc/xdr/src/cli1-xdr.h +++ b/rpc/xdr/src/cli1-xdr.h @@ -1,20 +1,11 @@ /* - 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-common.h" @@ -47,22 +38,20 @@ enum gf_cli_defrag_type { 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, + GF_DEFRAG_CMD_START_FORCE = 1 + 4, }; 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, + GF_DEFRAG_STATUS_STARTED = 1, + GF_DEFRAG_STATUS_STOPPED = 2, + GF_DEFRAG_STATUS_COMPLETE = 3, + GF_DEFRAG_STATUS_FAILED = 4, + GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED = 5, + GF_DEFRAG_STATUS_LAYOUT_FIX_STOPPED = 6, + GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE = 7, + GF_DEFRAG_STATUS_LAYOUT_FIX_FAILED = 8, }; typedef enum gf_defrag_status_t gf_defrag_status_t; @@ -89,10 +78,9 @@ 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, + GF_OP_CMD_STOP = 0 + 3, + GF_OP_CMD_STATUS = 0 + 4, + GF_OP_CMD_COMMIT_FORCE = 0 + 5, }; typedef enum gf1_op_commands gf1_op_commands; @@ -108,7 +96,8 @@ enum gf_quota_type { typedef enum gf_quota_type gf_quota_type; enum gf1_cli_friends_list { - GF_CLI_LIST_ALL = 1, + GF_CLI_LIST_PEERS = 1, + GF_CLI_LIST_POOL_NODES = 2, }; typedef enum gf1_cli_friends_list gf1_cli_friends_list; @@ -135,6 +124,9 @@ enum gf1_cli_gsync_set { GF_GSYNC_OPTION_TYPE_STOP = 2, GF_GSYNC_OPTION_TYPE_CONFIG = 3, GF_GSYNC_OPTION_TYPE_STATUS = 4, + GF_GSYNC_OPTION_TYPE_ROTATE = 5, + GF_GSYNC_OPTION_TYPE_CREATE = 6, + GF_GSYNC_OPTION_TYPE_DELETE = 7, }; typedef enum gf1_cli_gsync_set gf1_cli_gsync_set; @@ -159,318 +151,96 @@ enum gf1_cli_top_op { }; typedef enum gf1_cli_top_op gf1_cli_top_op; -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; +enum gf_cli_status_type { + GF_CLI_STATUS_NONE = 0x0000, + GF_CLI_STATUS_MEM = 0x0001, + GF_CLI_STATUS_CLIENTS = 0x0002, + GF_CLI_STATUS_INODE = 0x0004, + GF_CLI_STATUS_FD = 0x0008, + GF_CLI_STATUS_CALLPOOL = 0x0010, + GF_CLI_STATUS_DETAIL = 0x0020, + GF_CLI_STATUS_TASKS = 0x0040, + GF_CLI_STATUS_MASK = 0x00FF, + GF_CLI_STATUS_VOL = 0x0100, + GF_CLI_STATUS_ALL = 0x0200, + GF_CLI_STATUS_BRICK = 0x0400, + GF_CLI_STATUS_NFS = 0x0800, + GF_CLI_STATUS_SHD = 0x1000, +}; +typedef enum gf_cli_status_type gf_cli_status_type; + +enum gf1_cli_snapshot { + GF_SNAP_OPTION_TYPE_NONE = 0, + GF_SNAP_OPTION_TYPE_CREATE = 1, + GF_SNAP_OPTION_TYPE_DELETE = 2, + GF_SNAP_OPTION_TYPE_RESTORE = 3, + GF_SNAP_OPTION_TYPE_START = 4, + GF_SNAP_OPTION_TYPE_STOP = 5, + GF_SNAP_OPTION_TYPE_LIST = 6, + GF_SNAP_OPTION_TYPE_STATUS = 7, + GF_SNAP_OPTION_TYPE_CONFIG = 8, + GF_SNAP_OPTION_TYPE_INFO = 9, +}; +typedef enum gf1_cli_snapshot gf1_cli_snapshot; + +enum gf1_cli_snapshot_info { + GF_SNAP_INFO_TYPE_ALL = 0, + GF_SNAP_INFO_TYPE_SNAP = 1, + GF_SNAP_INFO_TYPE_VOL = 2, +}; +typedef enum gf1_cli_snapshot_info gf1_cli_snapshot_info; + +enum gf1_cli_snapshot_config { + GF_SNAP_CONFIG_TYPE_NONE = 0, + GF_SNAP_CONFIG_TYPE_SET = 1, + GF_SNAP_CONFIG_DISPLAY = 2, +}; +typedef enum gf1_cli_snapshot_config gf1_cli_snapshot_config; + +enum gf1_cli_snapshot_status { + GF_SNAP_STATUS_TYPE_ALL = 0, + GF_SNAP_STATUS_TYPE_SNAP = 1, + GF_SNAP_STATUS_TYPE_VOL = 2, +}; +typedef enum gf1_cli_snapshot_status gf1_cli_snapshot_status; + +struct gf_cli_req { struct { u_int dict_len; char *dict_val; } dict; }; -typedef struct gf1_cli_peer_list_req gf1_cli_peer_list_req; +typedef struct gf_cli_req gf_cli_req; -struct gf1_cli_peer_list_rsp { +struct gf_cli_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_get_vol_req { - int flags; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf1_cli_get_vol_req gf1_cli_get_vol_req; - -struct gf1_cli_get_vol_rsp { - int op_ret; - int op_errno; - struct { - u_int volumes_len; - char *volumes_val; - } volumes; -}; -typedef struct gf1_cli_get_vol_rsp gf1_cli_get_vol_rsp; - -struct gf1_cli_create_vol_req { - char *volname; - gf1_cluster_type type; - int count; - struct { - u_int bricks_len; - char *bricks_val; - } bricks; -}; -typedef struct gf1_cli_create_vol_req gf1_cli_create_vol_req; - -struct gf1_cli_create_vol_rsp { - int op_ret; - int op_errno; - char *volname; char *op_errstr; -}; -typedef struct gf1_cli_create_vol_rsp gf1_cli_create_vol_rsp; - -struct gf1_cli_delete_vol_req { - char *volname; -}; -typedef struct gf1_cli_delete_vol_req gf1_cli_delete_vol_req; - -struct gf1_cli_delete_vol_rsp { - int op_ret; - int op_errno; - char *volname; - char *op_errstr; -}; -typedef struct gf1_cli_delete_vol_rsp gf1_cli_delete_vol_rsp; - -struct gf1_cli_start_vol_req { - char *volname; - int flags; -}; -typedef struct gf1_cli_start_vol_req gf1_cli_start_vol_req; - -struct gf1_cli_start_vol_rsp { - int op_ret; - int op_errno; - char *volname; - char *op_errstr; -}; -typedef struct gf1_cli_start_vol_rsp gf1_cli_start_vol_rsp; - -struct gf1_cli_stop_vol_req { - char *volname; - int flags; -}; -typedef struct gf1_cli_stop_vol_req gf1_cli_stop_vol_req; - -struct gf1_cli_stop_vol_rsp { - int op_ret; - int op_errno; - char *volname; - char *op_errstr; -}; -typedef struct gf1_cli_stop_vol_rsp gf1_cli_stop_vol_rsp; - -struct gf1_cli_rename_vol_req { - char *old_volname; - char *new_volname; -}; -typedef struct gf1_cli_rename_vol_req gf1_cli_rename_vol_req; - -struct gf1_cli_rename_vol_rsp { - int op_ret; - int op_errno; - char *volname; -}; -typedef struct gf1_cli_rename_vol_rsp gf1_cli_rename_vol_rsp; - -struct gf1_cli_defrag_vol_req { - int cmd; - char *volname; -}; -typedef struct gf1_cli_defrag_vol_req gf1_cli_defrag_vol_req; - -struct gf1_cli_defrag_vol_rsp { - int op_ret; - int op_errno; - char *volname; - u_quad_t files; - u_quad_t size; - u_quad_t lookedup_files; -}; -typedef struct gf1_cli_defrag_vol_rsp gf1_cli_defrag_vol_rsp; - -struct gf2_cli_defrag_vol_rsp { - int op_ret; - int op_errno; - char *op_errstr; - char *volname; - u_quad_t files; - u_quad_t size; - u_quad_t lookedup_files; -}; -typedef struct gf2_cli_defrag_vol_rsp gf2_cli_defrag_vol_rsp; - -struct gf1_cli_add_brick_req { - char *volname; - int count; - struct { - u_int bricks_len; - char *bricks_val; - } bricks; -}; -typedef struct gf1_cli_add_brick_req gf1_cli_add_brick_req; - -struct gf1_cli_add_brick_rsp { - int op_ret; - int op_errno; - char *volname; - char *op_errstr; -}; -typedef struct gf1_cli_add_brick_rsp gf1_cli_add_brick_rsp; - -struct gf1_cli_remove_brick_req { - char *volname; - int count; - struct { - u_int bricks_len; - char *bricks_val; - } bricks; -}; -typedef struct gf1_cli_remove_brick_req gf1_cli_remove_brick_req; - -struct gf1_cli_remove_brick_rsp { - int op_ret; - int op_errno; - char *volname; - char *op_errstr; -}; -typedef struct gf1_cli_remove_brick_rsp gf1_cli_remove_brick_rsp; - -struct gf1_cli_replace_brick_req { - char *volname; - gf1_cli_replace_op op; - struct { - u_int bricks_len; - char *bricks_val; - } bricks; -}; -typedef struct gf1_cli_replace_brick_req gf1_cli_replace_brick_req; - -struct gf1_cli_replace_brick_rsp { - int op_ret; - int op_errno; - char *op_errstr; - char *volname; - char *status; -}; -typedef struct gf1_cli_replace_brick_rsp gf1_cli_replace_brick_rsp; - -struct gf1_cli_reset_vol_req { - char *volname; struct { u_int dict_len; char *dict_val; } dict; }; -typedef struct gf1_cli_reset_vol_req gf1_cli_reset_vol_req; - -struct gf1_cli_reset_vol_rsp { - int op_ret; - int op_errno; - char *volname; - char *op_errstr; -}; -typedef struct gf1_cli_reset_vol_rsp gf1_cli_reset_vol_rsp; +typedef struct gf_cli_rsp gf_cli_rsp; -struct gf1_cli_set_vol_req { - char *volname; +struct gf1_cli_peer_list_req { + int flags; struct { u_int dict_len; char *dict_val; } dict; }; -typedef struct gf1_cli_set_vol_req gf1_cli_set_vol_req; +typedef struct gf1_cli_peer_list_req gf1_cli_peer_list_req; -struct gf1_cli_set_vol_rsp { +struct gf1_cli_peer_list_rsp { int op_ret; int op_errno; - char *volname; - char *op_errstr; struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf1_cli_set_vol_rsp gf1_cli_set_vol_rsp; - -struct gf1_cli_log_filename_req { - char *volname; - char *brick; - char *path; -}; -typedef struct gf1_cli_log_filename_req gf1_cli_log_filename_req; - -struct gf1_cli_log_filename_rsp { - int op_ret; - int op_errno; - char *errstr; -}; -typedef struct gf1_cli_log_filename_rsp gf1_cli_log_filename_rsp; - -struct gf1_cli_log_locate_req { - char *volname; - char *brick; -}; -typedef struct gf1_cli_log_locate_req gf1_cli_log_locate_req; - -struct gf1_cli_sync_volume_req { - int flags; - char *volname; - char *hostname; -}; -typedef struct gf1_cli_sync_volume_req gf1_cli_sync_volume_req; - -struct gf1_cli_log_locate_rsp { - int op_ret; - int op_errno; - char *path; -}; -typedef struct gf1_cli_log_locate_rsp gf1_cli_log_locate_rsp; - -struct gf1_cli_log_rotate_req { - char *volname; - char *brick; -}; -typedef struct gf1_cli_log_rotate_req gf1_cli_log_rotate_req; - -struct gf1_cli_log_rotate_rsp { - int op_ret; - int op_errno; - char *errstr; -}; -typedef struct gf1_cli_log_rotate_rsp gf1_cli_log_rotate_rsp; - -struct gf1_cli_sync_volume_rsp { - int op_ret; - int op_errno; - char *op_errstr; + u_int friends_len; + char *friends_val; + } friends; }; -typedef struct gf1_cli_sync_volume_rsp gf1_cli_sync_volume_rsp; +typedef struct gf1_cli_peer_list_rsp gf1_cli_peer_list_rsp; struct gf1_cli_fsm_log_req { char *name; @@ -488,66 +258,6 @@ struct gf1_cli_fsm_log_rsp { }; typedef struct gf1_cli_fsm_log_rsp gf1_cli_fsm_log_rsp; -struct gf1_cli_gsync_set_req { - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf1_cli_gsync_set_req gf1_cli_gsync_set_req; - -struct gf1_cli_gsync_set_rsp { - int op_ret; - int op_errno; - char *op_errstr; - int type; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf1_cli_gsync_set_rsp gf1_cli_gsync_set_rsp; - -struct gf1_cli_stats_volume_req { - char *volname; - gf1_cli_stats_op op; - struct { - u_int dict_req_len; - char *dict_req_val; - } dict_req; -}; -typedef struct gf1_cli_stats_volume_req gf1_cli_stats_volume_req; - -struct gf1_cli_stats_volume_rsp { - int op_ret; - int op_errno; - char *op_errstr; - struct { - u_int stats_info_len; - char *stats_info_val; - } stats_info; -}; -typedef struct gf1_cli_stats_volume_rsp gf1_cli_stats_volume_rsp; - -struct gf1_cli_quota_req { - char *volname; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf1_cli_quota_req gf1_cli_quota_req; - -struct gf1_cli_quota_rsp { - int op_ret; - int op_errno; - char *volname; - char *op_errstr; - char *limit_list; - gf_quota_type type; -}; -typedef struct gf1_cli_quota_rsp gf1_cli_quota_rsp; - struct gf1_cli_getwd_req { int unused; }; @@ -560,40 +270,6 @@ struct gf1_cli_getwd_rsp { }; typedef struct gf1_cli_getwd_rsp gf1_cli_getwd_rsp; -struct gf1_cli_log_level_req { - char *volname; - char *xlator; - char *loglevel; -}; -typedef struct gf1_cli_log_level_req gf1_cli_log_level_req; - -struct gf1_cli_log_level_rsp { - int op_ret; - int op_errno; - char *op_errstr; -}; -typedef struct gf1_cli_log_level_rsp gf1_cli_log_level_rsp; - -struct gf1_cli_status_volume_req { - char *volname; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf1_cli_status_volume_req gf1_cli_status_volume_req; - -struct gf1_cli_status_volume_rsp { - int op_ret; - int op_errno; - char *op_errstr; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf1_cli_status_volume_rsp gf1_cli_status_volume_rsp; - struct gf1_cli_mount_req { char *label; struct { @@ -622,42 +298,6 @@ struct gf1_cli_umount_rsp { }; typedef struct gf1_cli_umount_rsp gf1_cli_umount_rsp; -struct gf1_cli_heal_vol_req { - char *volname; -}; -typedef struct gf1_cli_heal_vol_req gf1_cli_heal_vol_req; - -struct gf1_cli_heal_vol_rsp { - int op_ret; - int op_errno; - char *volname; - char *op_errstr; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf1_cli_heal_vol_rsp gf1_cli_heal_vol_rsp; - -struct gf1_cli_statedump_vol_req { - char *volname; - char *options; - int option_cnt; -}; -typedef struct gf1_cli_statedump_vol_req gf1_cli_statedump_vol_req; - -struct gf1_cli_statedump_vol_rsp { - int op_ret; - int op_errno; - char *volname; - char *op_errstr; - struct { - u_int dict_len; - char *dict_val; - } dict; -}; -typedef struct gf1_cli_statedump_vol_rsp gf1_cli_statedump_vol_rsp; - /* the xdr functions */ #if defined(__STDC__) || defined(__cplusplus) @@ -674,67 +314,21 @@ 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_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_gf_cli_status_type (XDR *, gf_cli_status_type*); +extern bool_t xdr_gf1_cli_snapshot (XDR *, gf1_cli_snapshot*); +extern bool_t xdr_gf1_cli_snapshot_config (XDR *, gf1_cli_snapshot_config*); +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_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_get_vol_req (XDR *, gf1_cli_get_vol_req*); -extern bool_t xdr_gf1_cli_get_vol_rsp (XDR *, gf1_cli_get_vol_rsp*); -extern bool_t xdr_gf1_cli_create_vol_req (XDR *, gf1_cli_create_vol_req*); -extern bool_t xdr_gf1_cli_create_vol_rsp (XDR *, gf1_cli_create_vol_rsp*); -extern bool_t xdr_gf1_cli_delete_vol_req (XDR *, gf1_cli_delete_vol_req*); -extern bool_t xdr_gf1_cli_delete_vol_rsp (XDR *, gf1_cli_delete_vol_rsp*); -extern bool_t xdr_gf1_cli_start_vol_req (XDR *, gf1_cli_start_vol_req*); -extern bool_t xdr_gf1_cli_start_vol_rsp (XDR *, gf1_cli_start_vol_rsp*); -extern bool_t xdr_gf1_cli_stop_vol_req (XDR *, gf1_cli_stop_vol_req*); -extern bool_t xdr_gf1_cli_stop_vol_rsp (XDR *, gf1_cli_stop_vol_rsp*); -extern bool_t xdr_gf1_cli_rename_vol_req (XDR *, gf1_cli_rename_vol_req*); -extern bool_t xdr_gf1_cli_rename_vol_rsp (XDR *, gf1_cli_rename_vol_rsp*); -extern bool_t xdr_gf1_cli_defrag_vol_req (XDR *, gf1_cli_defrag_vol_req*); -extern bool_t xdr_gf1_cli_defrag_vol_rsp (XDR *, gf1_cli_defrag_vol_rsp*); -extern bool_t xdr_gf2_cli_defrag_vol_rsp (XDR *, gf2_cli_defrag_vol_rsp*); -extern bool_t xdr_gf1_cli_add_brick_req (XDR *, gf1_cli_add_brick_req*); -extern bool_t xdr_gf1_cli_add_brick_rsp (XDR *, gf1_cli_add_brick_rsp*); -extern bool_t xdr_gf1_cli_remove_brick_req (XDR *, gf1_cli_remove_brick_req*); -extern bool_t xdr_gf1_cli_remove_brick_rsp (XDR *, gf1_cli_remove_brick_rsp*); -extern bool_t xdr_gf1_cli_replace_brick_req (XDR *, gf1_cli_replace_brick_req*); -extern bool_t xdr_gf1_cli_replace_brick_rsp (XDR *, gf1_cli_replace_brick_rsp*); -extern bool_t xdr_gf1_cli_reset_vol_req (XDR *, gf1_cli_reset_vol_req*); -extern bool_t xdr_gf1_cli_reset_vol_rsp (XDR *, gf1_cli_reset_vol_rsp*); -extern bool_t xdr_gf1_cli_set_vol_req (XDR *, gf1_cli_set_vol_req*); -extern bool_t xdr_gf1_cli_set_vol_rsp (XDR *, gf1_cli_set_vol_rsp*); -extern bool_t xdr_gf1_cli_log_filename_req (XDR *, gf1_cli_log_filename_req*); -extern bool_t xdr_gf1_cli_log_filename_rsp (XDR *, gf1_cli_log_filename_rsp*); -extern bool_t xdr_gf1_cli_log_locate_req (XDR *, gf1_cli_log_locate_req*); -extern bool_t xdr_gf1_cli_sync_volume_req (XDR *, gf1_cli_sync_volume_req*); -extern bool_t xdr_gf1_cli_log_locate_rsp (XDR *, gf1_cli_log_locate_rsp*); -extern bool_t xdr_gf1_cli_log_rotate_req (XDR *, gf1_cli_log_rotate_req*); -extern bool_t xdr_gf1_cli_log_rotate_rsp (XDR *, gf1_cli_log_rotate_rsp*); -extern bool_t xdr_gf1_cli_sync_volume_rsp (XDR *, gf1_cli_sync_volume_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_gsync_set_req (XDR *, gf1_cli_gsync_set_req*); -extern bool_t xdr_gf1_cli_gsync_set_rsp (XDR *, gf1_cli_gsync_set_rsp*); -extern bool_t xdr_gf1_cli_stats_volume_req (XDR *, gf1_cli_stats_volume_req*); -extern bool_t xdr_gf1_cli_stats_volume_rsp (XDR *, gf1_cli_stats_volume_rsp*); -extern bool_t xdr_gf1_cli_quota_req (XDR *, gf1_cli_quota_req*); -extern bool_t xdr_gf1_cli_quota_rsp (XDR *, gf1_cli_quota_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_log_level_req (XDR *, gf1_cli_log_level_req*); -extern bool_t xdr_gf1_cli_log_level_rsp (XDR *, gf1_cli_log_level_rsp*); -extern bool_t xdr_gf1_cli_status_volume_req (XDR *, gf1_cli_status_volume_req*); -extern bool_t xdr_gf1_cli_status_volume_rsp (XDR *, gf1_cli_status_volume_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*); -extern bool_t xdr_gf1_cli_heal_vol_req (XDR *, gf1_cli_heal_vol_req*); -extern bool_t xdr_gf1_cli_heal_vol_rsp (XDR *, gf1_cli_heal_vol_rsp*); -extern bool_t xdr_gf1_cli_statedump_vol_req (XDR *, gf1_cli_statedump_vol_req*); -extern bool_t xdr_gf1_cli_statedump_vol_rsp (XDR *, gf1_cli_statedump_vol_rsp*); #else /* K&R C */ extern bool_t xdr_gf_cli_defrag_type (); @@ -750,67 +344,21 @@ 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_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_gf_cli_status_type (); +extern bool_t xdr_gf1_cli_snapshot (); +extern bool_t xdr_gf1_cli_snapshot_config (); +extern bool_t xdr_gf_cli_req (); +extern bool_t xdr_gf_cli_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_get_vol_req (); -extern bool_t xdr_gf1_cli_get_vol_rsp (); -extern bool_t xdr_gf1_cli_create_vol_req (); -extern bool_t xdr_gf1_cli_create_vol_rsp (); -extern bool_t xdr_gf1_cli_delete_vol_req (); -extern bool_t xdr_gf1_cli_delete_vol_rsp (); -extern bool_t xdr_gf1_cli_start_vol_req (); -extern bool_t xdr_gf1_cli_start_vol_rsp (); -extern bool_t xdr_gf1_cli_stop_vol_req (); -extern bool_t xdr_gf1_cli_stop_vol_rsp (); -extern bool_t xdr_gf1_cli_rename_vol_req (); -extern bool_t xdr_gf1_cli_rename_vol_rsp (); -extern bool_t xdr_gf1_cli_defrag_vol_req (); -extern bool_t xdr_gf1_cli_defrag_vol_rsp (); -extern bool_t xdr_gf2_cli_defrag_vol_rsp (); -extern bool_t xdr_gf1_cli_add_brick_req (); -extern bool_t xdr_gf1_cli_add_brick_rsp (); -extern bool_t xdr_gf1_cli_remove_brick_req (); -extern bool_t xdr_gf1_cli_remove_brick_rsp (); -extern bool_t xdr_gf1_cli_replace_brick_req (); -extern bool_t xdr_gf1_cli_replace_brick_rsp (); -extern bool_t xdr_gf1_cli_reset_vol_req (); -extern bool_t xdr_gf1_cli_reset_vol_rsp (); -extern bool_t xdr_gf1_cli_set_vol_req (); -extern bool_t xdr_gf1_cli_set_vol_rsp (); -extern bool_t xdr_gf1_cli_log_filename_req (); -extern bool_t xdr_gf1_cli_log_filename_rsp (); -extern bool_t xdr_gf1_cli_log_locate_req (); -extern bool_t xdr_gf1_cli_sync_volume_req (); -extern bool_t xdr_gf1_cli_log_locate_rsp (); -extern bool_t xdr_gf1_cli_log_rotate_req (); -extern bool_t xdr_gf1_cli_log_rotate_rsp (); -extern bool_t xdr_gf1_cli_sync_volume_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_gsync_set_req (); -extern bool_t xdr_gf1_cli_gsync_set_rsp (); -extern bool_t xdr_gf1_cli_stats_volume_req (); -extern bool_t xdr_gf1_cli_stats_volume_rsp (); -extern bool_t xdr_gf1_cli_quota_req (); -extern bool_t xdr_gf1_cli_quota_rsp (); extern bool_t xdr_gf1_cli_getwd_req (); extern bool_t xdr_gf1_cli_getwd_rsp (); -extern bool_t xdr_gf1_cli_log_level_req (); -extern bool_t xdr_gf1_cli_log_level_rsp (); -extern bool_t xdr_gf1_cli_status_volume_req (); -extern bool_t xdr_gf1_cli_status_volume_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 (); -extern bool_t xdr_gf1_cli_heal_vol_req (); -extern bool_t xdr_gf1_cli_heal_vol_rsp (); -extern bool_t xdr_gf1_cli_statedump_vol_req (); -extern bool_t xdr_gf1_cli_statedump_vol_rsp (); #endif /* K&R C */ diff --git a/rpc/xdr/src/cli1-xdr.x b/rpc/xdr/src/cli1-xdr.x index 146ed68d3..f9d29b7e1 100644 --- a/rpc/xdr/src/cli1-xdr.x +++ b/rpc/xdr/src/cli1-xdr.x @@ -3,21 +3,19 @@ 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 */ } ; 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 } ; enum gf1_cluster_type { @@ -41,8 +39,7 @@ 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 } ; @@ -58,7 +55,8 @@ enum gf_quota_type { }; 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 { @@ -80,7 +78,10 @@ enum gf1_cli_gsync_set { GF_GSYNC_OPTION_TYPE_START, GF_GSYNC_OPTION_TYPE_STOP, GF_GSYNC_OPTION_TYPE_CONFIG, - GF_GSYNC_OPTION_TYPE_STATUS + GF_GSYNC_OPTION_TYPE_STATUS, + GF_GSYNC_OPTION_TYPE_ROTATE, + GF_GSYNC_OPTION_TYPE_CREATE, + GF_GSYNC_OPTION_TYPE_DELETE }; enum gf1_cli_stats_op { @@ -102,28 +103,54 @@ enum gf1_cli_top_op { GF_CLI_TOP_WRITE_PERF }; - struct gf1_cli_probe_req { - string hostname<>; - int port; -} ; - - struct gf1_cli_probe_rsp { - int op_ret; - int op_errno; - int port; - string hostname<>; -} ; - - struct gf1_cli_deprobe_req { - string hostname<>; - int port; - int flags; +/* 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_MEM = 0x0001, /*0000000000001*/ + GF_CLI_STATUS_CLIENTS = 0x0002, /*0000000000010*/ + GF_CLI_STATUS_INODE = 0x0004, /*0000000000100*/ + GF_CLI_STATUS_FD = 0x0008, /*0000000001000*/ + GF_CLI_STATUS_CALLPOOL = 0x0010, /*0000000010000*/ + GF_CLI_STATUS_DETAIL = 0x0020, /*0000000100000*/ + GF_CLI_STATUS_TASKS = 0x0040, /*0000001000000*/ + GF_CLI_STATUS_MASK = 0x00FF, /*0000011111111 Used to get the op*/ + GF_CLI_STATUS_VOL = 0x0100, /*0000100000000*/ + GF_CLI_STATUS_ALL = 0x0200, /*0001000000000*/ + GF_CLI_STATUS_BRICK = 0x0400, /*0010000000000*/ + GF_CLI_STATUS_NFS = 0x0800, /*0100000000000*/ + GF_CLI_STATUS_SHD = 0x1000 /*1000000000000*/ +}; + +/* 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_START, + GF_SNAP_OPTION_TYPE_STOP, + GF_SNAP_OPTION_TYPE_LIST, + GF_SNAP_OPTION_TYPE_STATUS, + GF_SNAP_OPTION_TYPE_CONFIG +}; + +enum gf1_cli_snapshot_config { + GF_SNAP_CONFIG_TYPE_NONE = 0, + GF_SNAP_CONFIG_TYPE_SET, + GF_SNAP_CONFIG_DISPLAY, + +}; + + struct gf_cli_req { + opaque dict<>; } ; - struct gf1_cli_deprobe_rsp { + struct gf_cli_rsp { int op_ret; int op_errno; - string hostname<>; + string op_errstr<>; + opaque dict<>; } ; struct gf1_cli_peer_list_req { @@ -137,221 +164,6 @@ struct gf1_cli_peer_list_rsp { opaque friends<>; } ; -struct gf1_cli_get_vol_req { - int flags; - opaque dict<>; -} ; - -struct gf1_cli_get_vol_rsp { - int op_ret; - int op_errno; - opaque volumes<>; -} ; - - struct gf1_cli_create_vol_req { - string volname<>; - gf1_cluster_type type; - int count; - opaque bricks<>; -} ; - - struct gf1_cli_create_vol_rsp { - int op_ret; - int op_errno; - string volname<>; - string op_errstr<>; -} ; - - struct gf1_cli_delete_vol_req { - string volname<>; -} ; - - struct gf1_cli_delete_vol_rsp { - int op_ret; - int op_errno; - string volname<>; - string op_errstr<>; -} ; - - struct gf1_cli_start_vol_req { - string volname<>; - int flags; -} ; - - - struct gf1_cli_start_vol_rsp { - int op_ret; - int op_errno; - string volname<>; - string op_errstr<>; -} ; - - struct gf1_cli_stop_vol_req { - string volname<>; - int flags; -} ; - - - struct gf1_cli_stop_vol_rsp { - int op_ret; - int op_errno; - string volname<>; - string op_errstr<>; -} ; - - - struct gf1_cli_rename_vol_req { - string old_volname<>; - string new_volname<>; -} ; - - struct gf1_cli_rename_vol_rsp { - int op_ret; - int op_errno; - string volname<>; -} ; - - struct gf1_cli_defrag_vol_req { - int cmd; - string volname<>; -} ; - - struct gf1_cli_defrag_vol_rsp { - int op_ret; - int op_errno; - string volname<>; - unsigned hyper files; - unsigned hyper size; - unsigned hyper lookedup_files; -} ; - - - struct gf2_cli_defrag_vol_rsp { - int op_ret; - int op_errno; - string op_errstr<>; - string volname<>; - unsigned hyper files; - unsigned hyper size; - unsigned hyper lookedup_files; -} ; - - struct gf1_cli_add_brick_req { - string volname<>; - int count; - opaque bricks<>; -} ; - - struct gf1_cli_add_brick_rsp { - int op_ret; - int op_errno; - string volname<>; - string op_errstr<>; -} ; - - struct gf1_cli_remove_brick_req { - string volname<>; - int count; - opaque bricks<>; -} ; - - - struct gf1_cli_remove_brick_rsp { - int op_ret; - int op_errno; - string volname<>; - string op_errstr<>; -} ; - - struct gf1_cli_replace_brick_req { - string volname<>; - gf1_cli_replace_op op; - opaque bricks<>; -} ; - - struct gf1_cli_replace_brick_rsp { - int op_ret; - int op_errno; - string op_errstr<>; - string volname<>; - string status<>; -} ; - -struct gf1_cli_reset_vol_req { - string volname<>; - opaque dict<>; -} ; - - - struct gf1_cli_reset_vol_rsp { - int op_ret; - int op_errno; - string volname<>; - string op_errstr<>; -} ; - - - -struct gf1_cli_set_vol_req { - string volname<>; - opaque dict<>; -} ; - - - struct gf1_cli_set_vol_rsp { - int op_ret; - int op_errno; - string volname<>; - string op_errstr<>; - opaque dict<>; -} ; - -struct gf1_cli_log_filename_req { - string volname<>; - string brick<>; - string path<>; -}; - -struct gf1_cli_log_filename_rsp { - int op_ret; - int op_errno; - string errstr<>; -}; - -struct gf1_cli_log_locate_req { - string volname<>; - string brick<>; -}; - -struct gf1_cli_sync_volume_req { - int flags; - string volname<>; - string hostname<>; -}; - -struct gf1_cli_log_locate_rsp { - int op_ret; - int op_errno; - string path<>; -}; - -struct gf1_cli_log_rotate_req { - string volname<>; - string brick<>; -}; - -struct gf1_cli_log_rotate_rsp { - int op_ret; - int op_errno; - string errstr<>; -}; - -struct gf1_cli_sync_volume_rsp { - int op_ret; - int op_errno; - string op_errstr<>; -}; - struct gf1_cli_fsm_log_req { string name<>; }; @@ -363,45 +175,6 @@ struct gf1_cli_fsm_log_rsp { opaque fsm_log<>; }; -struct gf1_cli_gsync_set_req { - opaque dict<>; -}; - -struct gf1_cli_gsync_set_rsp { - int op_ret; - int op_errno; - string op_errstr<>; - int type; - opaque dict<>; -}; - -struct gf1_cli_stats_volume_req { - string volname<>; - gf1_cli_stats_op op; - opaque dict_req<>; -}; - -struct gf1_cli_stats_volume_rsp { - int op_ret; - int op_errno; - string op_errstr<>; - opaque stats_info<>; -}; - -struct gf1_cli_quota_req { - string volname<>; - opaque dict<>; -} ; - -struct gf1_cli_quota_rsp { - int op_ret; - int op_errno; - string volname<>; - string op_errstr<>; - string limit_list<>; - gf_quota_type type; -}; - struct gf1_cli_getwd_req { int unused; } ; @@ -412,30 +185,6 @@ struct gf1_cli_getwd_rsp { string wd<>; }; -struct gf1_cli_log_level_req { - string volname<>; - string xlator<>; - string loglevel<>; -}; - -struct gf1_cli_log_level_rsp { - int op_ret; - int op_errno; - string op_errstr<>; -}; - -struct gf1_cli_status_volume_req { - string volname<>; - opaque dict<>; -}; - -struct gf1_cli_status_volume_rsp { - int op_ret; - int op_errno; - string op_errstr<>; - opaque dict<>; -}; - struct gf1_cli_mount_req { string label<>; opaque dict<>; @@ -456,28 +205,3 @@ struct gf1_cli_umount_rsp { int op_ret; int op_errno; }; - -struct gf1_cli_heal_vol_req { - string volname<>; -} ; - -struct gf1_cli_heal_vol_rsp { - int op_ret; - int op_errno; - string volname<>; - string op_errstr<>; - opaque dict<>; -}; -struct gf1_cli_statedump_vol_req { - string volname<>; - string options<>; - int option_cnt; -}; - -struct gf1_cli_statedump_vol_rsp { - int op_ret; - int op_errno; - string volname<>; - string op_errstr<>; - opaque dict<>; -}; diff --git a/rpc/xdr/src/glusterd1-xdr.c b/rpc/xdr/src/glusterd1-xdr.c index a5438d23e..7fa98aaeb 100644 --- a/rpc/xdr/src/glusterd1-xdr.c +++ b/rpc/xdr/src/glusterd1-xdr.c @@ -1,20 +1,11 @@ /* - 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-common.h" @@ -66,6 +57,55 @@ xdr_gd1_mgmt_probe_rsp (XDR *xdrs, gd1_mgmt_probe_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; + if (!xdr_string (xdrs, &objp->hostname, ~0)) + return FALSE; + buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); + if (buf == NULL) { + 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; + + } else { + IXDR_PUT_LONG(buf, objp->port); + IXDR_PUT_LONG(buf, objp->op_ret); + IXDR_PUT_LONG(buf, objp->op_errno); + } + 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; + if (!xdr_string (xdrs, &objp->hostname, ~0)) + return FALSE; + buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); + if (buf == NULL) { + 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; + + } else { + objp->port = 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; + return TRUE; + } + if (!xdr_vector (xdrs, (char *)objp->uuid, 16, sizeof (u_char), (xdrproc_t) xdr_u_char)) return FALSE; @@ -77,6 +117,8 @@ xdr_gd1_mgmt_probe_rsp (XDR *xdrs, gd1_mgmt_probe_rsp *objp) return FALSE; if (!xdr_int (xdrs, &objp->op_errno)) return FALSE; + if (!xdr_string (xdrs, &objp->op_errstr, ~0)) + return FALSE; return TRUE; } @@ -449,3 +491,433 @@ xdr_gd1_mgmt_brick_op_rsp (XDR *xdrs, gd1_mgmt_brick_op_rsp *objp) return FALSE; return TRUE; } + +bool_t +xdr_gd1_mgmt_v3_lock_req (XDR *xdrs, gd1_mgmt_v3_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; + if (!xdr_vector (xdrs, (char *)objp->txn_id, 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->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gd1_mgmt_v3_lock_rsp (XDR *xdrs, gd1_mgmt_v3_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_vector (xdrs, (char *)objp->txn_id, 16, + sizeof (u_char), (xdrproc_t) xdr_u_char)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + 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_v3_pre_val_req (XDR *xdrs, gd1_mgmt_v3_pre_val_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->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gd1_mgmt_v3_pre_val_rsp (XDR *xdrs, gd1_mgmt_v3_pre_val_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_v3_brick_op_req (XDR *xdrs, gd1_mgmt_v3_brick_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->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gd1_mgmt_v3_brick_op_rsp (XDR *xdrs, gd1_mgmt_v3_brick_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_v3_commit_req (XDR *xdrs, gd1_mgmt_v3_commit_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->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gd1_mgmt_v3_commit_rsp (XDR *xdrs, gd1_mgmt_v3_commit_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_v3_post_val_req (XDR *xdrs, gd1_mgmt_v3_post_val_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_int (xdrs, &objp->op_ret)) + 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_v3_post_val_rsp (XDR *xdrs, gd1_mgmt_v3_post_val_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_v3_unlock_req (XDR *xdrs, gd1_mgmt_v3_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; + if (!xdr_vector (xdrs, (char *)objp->txn_id, 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->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gd1_mgmt_v3_unlock_rsp (XDR *xdrs, gd1_mgmt_v3_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_vector (xdrs, (char *)objp->txn_id, 16, + sizeof (u_char), (xdrproc_t) xdr_u_char)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; + 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/glusterd1-xdr.h b/rpc/xdr/src/glusterd1-xdr.h index 14c41baff..b6be23d06 100644 --- a/rpc/xdr/src/glusterd1-xdr.h +++ b/rpc/xdr/src/glusterd1-xdr.h @@ -1,20 +1,11 @@ /* - 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-common.h" @@ -62,6 +53,7 @@ struct gd1_mgmt_probe_rsp { int port; int op_ret; int op_errno; + char *op_errstr; }; typedef struct gd1_mgmt_probe_rsp gd1_mgmt_probe_rsp; @@ -210,6 +202,145 @@ struct gd1_mgmt_brick_op_rsp { }; typedef struct gd1_mgmt_brick_op_rsp gd1_mgmt_brick_op_rsp; +struct gd1_mgmt_v3_lock_req { + u_char uuid[16]; + u_char txn_id[16]; + int op; + struct { + u_int dict_len; + char *dict_val; + } dict; +}; +typedef struct gd1_mgmt_v3_lock_req gd1_mgmt_v3_lock_req; + +struct gd1_mgmt_v3_lock_rsp { + u_char uuid[16]; + u_char txn_id[16]; + struct { + u_int dict_len; + char *dict_val; + } dict; + int op_ret; + int op_errno; +}; +typedef struct gd1_mgmt_v3_lock_rsp gd1_mgmt_v3_lock_rsp; + +struct gd1_mgmt_v3_pre_val_req { + u_char uuid[16]; + int op; + struct { + u_int dict_len; + char *dict_val; + } dict; +}; +typedef struct gd1_mgmt_v3_pre_val_req gd1_mgmt_v3_pre_val_req; + +struct gd1_mgmt_v3_pre_val_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_v3_pre_val_rsp gd1_mgmt_v3_pre_val_rsp; + +struct gd1_mgmt_v3_brick_op_req { + u_char uuid[16]; + int op; + struct { + u_int dict_len; + char *dict_val; + } dict; +}; +typedef struct gd1_mgmt_v3_brick_op_req gd1_mgmt_v3_brick_op_req; + +struct gd1_mgmt_v3_brick_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_v3_brick_op_rsp gd1_mgmt_v3_brick_op_rsp; + +struct gd1_mgmt_v3_commit_req { + u_char uuid[16]; + int op; + struct { + u_int dict_len; + char *dict_val; + } dict; +}; +typedef struct gd1_mgmt_v3_commit_req gd1_mgmt_v3_commit_req; + +struct gd1_mgmt_v3_commit_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_v3_commit_rsp gd1_mgmt_v3_commit_rsp; + +struct gd1_mgmt_v3_post_val_req { + u_char uuid[16]; + int op; + int op_ret; + struct { + u_int dict_len; + char *dict_val; + } dict; +}; +typedef struct gd1_mgmt_v3_post_val_req gd1_mgmt_v3_post_val_req; + +struct gd1_mgmt_v3_post_val_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_v3_post_val_rsp gd1_mgmt_v3_post_val_rsp; + +struct gd1_mgmt_v3_unlock_req { + u_char uuid[16]; + u_char txn_id[16]; + int op; + struct { + u_int dict_len; + char *dict_val; + } dict; +}; +typedef struct gd1_mgmt_v3_unlock_req gd1_mgmt_v3_unlock_req; + +struct gd1_mgmt_v3_unlock_rsp { + u_char uuid[16]; + u_char txn_id[16]; + struct { + u_int dict_len; + char *dict_val; + } dict; + int op_ret; + int op_errno; +}; +typedef struct gd1_mgmt_v3_unlock_rsp gd1_mgmt_v3_unlock_rsp; + /* the xdr functions */ #if defined(__STDC__) || defined(__cplusplus) @@ -232,6 +363,18 @@ 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*); +extern bool_t xdr_gd1_mgmt_v3_lock_req (XDR *, gd1_mgmt_v3_lock_req*); +extern bool_t xdr_gd1_mgmt_v3_lock_rsp (XDR *, gd1_mgmt_v3_lock_rsp*); +extern bool_t xdr_gd1_mgmt_v3_pre_val_req (XDR *, gd1_mgmt_v3_pre_val_req*); +extern bool_t xdr_gd1_mgmt_v3_pre_val_rsp (XDR *, gd1_mgmt_v3_pre_val_rsp*); +extern bool_t xdr_gd1_mgmt_v3_brick_op_req (XDR *, gd1_mgmt_v3_brick_op_req*); +extern bool_t xdr_gd1_mgmt_v3_brick_op_rsp (XDR *, gd1_mgmt_v3_brick_op_rsp*); +extern bool_t xdr_gd1_mgmt_v3_commit_req (XDR *, gd1_mgmt_v3_commit_req*); +extern bool_t xdr_gd1_mgmt_v3_commit_rsp (XDR *, gd1_mgmt_v3_commit_rsp*); +extern bool_t xdr_gd1_mgmt_v3_post_val_req (XDR *, gd1_mgmt_v3_post_val_req*); +extern bool_t xdr_gd1_mgmt_v3_post_val_rsp (XDR *, gd1_mgmt_v3_post_val_rsp*); +extern bool_t xdr_gd1_mgmt_v3_unlock_req (XDR *, gd1_mgmt_v3_unlock_req*); +extern bool_t xdr_gd1_mgmt_v3_unlock_rsp (XDR *, gd1_mgmt_v3_unlock_rsp*); #else /* K&R C */ extern bool_t xdr_glusterd_volume_status (); @@ -253,6 +396,18 @@ 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 (); +extern bool_t xdr_gd1_mgmt_v3_lock_req (); +extern bool_t xdr_gd1_mgmt_v3_lock_rsp (); +extern bool_t xdr_gd1_mgmt_v3_pre_val_req (); +extern bool_t xdr_gd1_mgmt_v3_pre_val_rsp (); +extern bool_t xdr_gd1_mgmt_v3_brick_op_req (); +extern bool_t xdr_gd1_mgmt_v3_brick_op_rsp (); +extern bool_t xdr_gd1_mgmt_v3_commit_req (); +extern bool_t xdr_gd1_mgmt_v3_commit_rsp (); +extern bool_t xdr_gd1_mgmt_v3_post_val_req (); +extern bool_t xdr_gd1_mgmt_v3_post_val_rsp (); +extern bool_t xdr_gd1_mgmt_v3_unlock_req (); +extern bool_t xdr_gd1_mgmt_v3_unlock_rsp (); #endif /* K&R C */ diff --git a/rpc/xdr/src/glusterd1-xdr.x b/rpc/xdr/src/glusterd1-xdr.x index c30c71e02..f5c45c9e4 100644 --- a/rpc/xdr/src/glusterd1-xdr.x +++ b/rpc/xdr/src/glusterd1-xdr.x @@ -16,6 +16,7 @@ int port; int op_ret; int op_errno; + string op_errstr<>; } ; struct gd1_mgmt_friend_req { @@ -124,3 +125,94 @@ 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_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 index 64e504f46..3205c551e 100644 --- a/rpc/xdr/src/glusterfs3-xdr.c +++ b/rpc/xdr/src/glusterfs3-xdr.c @@ -1,20 +1,11 @@ /* - 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-common.h" @@ -80,7 +71,7 @@ xdr_gf_proto_flock (XDR *xdrs, gf_proto_flock *objp) return FALSE; if (!xdr_u_int (xdrs, &objp->pid)) return FALSE; - if (!xdr_u_quad_t (xdrs, &objp->owner)) + if (!xdr_bytes (xdrs, (char **)&objp->lk_owner.lk_owner_val, (u_int *) &objp->lk_owner.lk_owner_len, ~0)) return FALSE; return TRUE; } @@ -249,7 +240,7 @@ xdr_gfs3_stat_req (XDR *xdrs, gfs3_stat_req *objp) if (!xdr_opaque (xdrs, objp->gfid, 16)) return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -266,6 +257,8 @@ xdr_gfs3_stat_rsp (XDR *xdrs, gfs3_stat_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->stat)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -279,7 +272,7 @@ xdr_gfs3_readlink_req (XDR *xdrs, gfs3_readlink_req *objp) return FALSE; if (!xdr_u_int (xdrs, &objp->size)) return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -298,6 +291,8 @@ xdr_gfs3_readlink_rsp (XDR *xdrs, gfs3_readlink_rsp *objp) return FALSE; if (!xdr_string (xdrs, &objp->path, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -313,11 +308,11 @@ xdr_gfs3_mknod_req (XDR *xdrs, gfs3_mknod_req *objp) return FALSE; if (!xdr_u_int (xdrs, &objp->mode)) return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) + if (!xdr_u_int (xdrs, &objp->umask)) 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)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -338,6 +333,8 @@ xdr_gfs3_mknod_rsp (XDR *xdrs, gfs3_mknod_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->postparent)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -351,11 +348,11 @@ xdr_gfs3_mkdir_req (XDR *xdrs, gfs3_mkdir_req *objp) return FALSE; if (!xdr_u_int (xdrs, &objp->mode)) return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) + if (!xdr_u_int (xdrs, &objp->umask)) 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)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -376,6 +373,8 @@ xdr_gfs3_mkdir_rsp (XDR *xdrs, gfs3_mkdir_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->postparent)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -387,10 +386,12 @@ xdr_gfs3_unlink_req (XDR *xdrs, gfs3_unlink_req *objp) 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_u_int (xdrs, &objp->xflags)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -408,6 +409,8 @@ xdr_gfs3_unlink_rsp (XDR *xdrs, gfs3_unlink_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->postparent)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -419,12 +422,12 @@ xdr_gfs3_rmdir_req (XDR *xdrs, gfs3_rmdir_req *objp) if (!xdr_opaque (xdrs, objp->pargfid, 16)) return FALSE; - if (!xdr_int (xdrs, &objp->flags)) - return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) + if (!xdr_int (xdrs, &objp->xflags)) return FALSE; if (!xdr_string (xdrs, &objp->bname, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -442,6 +445,8 @@ xdr_gfs3_rmdir_rsp (XDR *xdrs, gfs3_rmdir_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->postparent)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -453,13 +458,13 @@ xdr_gfs3_symlink_req (XDR *xdrs, gfs3_symlink_req *objp) 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_u_int (xdrs, &objp->umask)) + 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)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -480,6 +485,8 @@ xdr_gfs3_symlink_rsp (XDR *xdrs, gfs3_symlink_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->postparent)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -493,14 +500,12 @@ xdr_gfs3_rename_req (XDR *xdrs, gfs3_rename_req *objp) 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; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -524,6 +529,8 @@ xdr_gfs3_rename_rsp (XDR *xdrs, gfs3_rename_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->postnewparent)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -537,12 +544,10 @@ xdr_gfs3_link_req (XDR *xdrs, gfs3_link_req *objp) 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; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -562,6 +567,8 @@ xdr_gfs3_link_rsp (XDR *xdrs, gfs3_link_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->postparent)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -575,7 +582,7 @@ xdr_gfs3_truncate_req (XDR *xdrs, gfs3_truncate_req *objp) return FALSE; if (!xdr_u_quad_t (xdrs, &objp->offset)) return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -594,6 +601,8 @@ xdr_gfs3_truncate_rsp (XDR *xdrs, gfs3_truncate_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->poststat)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -607,9 +616,7 @@ xdr_gfs3_open_req (XDR *xdrs, gfs3_open_req *objp) 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)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -626,6 +633,8 @@ xdr_gfs3_open_rsp (XDR *xdrs, gfs3_open_rsp *objp) return FALSE; if (!xdr_quad_t (xdrs, &objp->fd)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -643,6 +652,10 @@ xdr_gfs3_read_req (XDR *xdrs, gfs3_read_req *objp) return FALSE; if (!xdr_u_int (xdrs, &objp->size)) return FALSE; + if (!xdr_u_int (xdrs, &objp->flag)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -660,6 +673,8 @@ xdr_gfs3_read_rsp (XDR *xdrs, gfs3_read_rsp *objp) return FALSE; if (!xdr_u_int (xdrs, &objp->size)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -675,11 +690,9 @@ xdr_gfs3_lookup_req (XDR *xdrs, gfs3_lookup_req *objp) 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)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -698,7 +711,7 @@ xdr_gfs3_lookup_rsp (XDR *xdrs, gfs3_lookup_rsp *objp) 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)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -717,6 +730,10 @@ xdr_gfs3_write_req (XDR *xdrs, gfs3_write_req *objp) return FALSE; if (!xdr_u_int (xdrs, &objp->size)) return FALSE; + if (!xdr_u_int (xdrs, &objp->flag)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -734,6 +751,8 @@ xdr_gfs3_write_rsp (XDR *xdrs, gfs3_write_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->poststat)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -745,7 +764,7 @@ xdr_gfs3_statfs_req (XDR *xdrs, gfs3_statfs_req *objp) if (!xdr_opaque (xdrs, objp->gfid, 16)) return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -762,6 +781,8 @@ xdr_gfs3_statfs_rsp (XDR *xdrs, gfs3_statfs_rsp *objp) return FALSE; if (!xdr_gf_statfs (xdrs, &objp->statfs)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -781,6 +802,8 @@ xdr_gfs3_lk_req (XDR *xdrs, gfs3_lk_req *objp) return FALSE; if (!xdr_gf_proto_flock (xdrs, &objp->flock)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -796,6 +819,8 @@ xdr_gfs3_lk_rsp (XDR *xdrs, gfs3_lk_rsp *objp) return FALSE; if (!xdr_gf_proto_flock (xdrs, &objp->flock)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -813,10 +838,10 @@ xdr_gfs3_inodelk_req (XDR *xdrs, gfs3_inodelk_req *objp) 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; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -838,6 +863,8 @@ xdr_gfs3_finodelk_req (XDR *xdrs, gfs3_finodelk_req *objp) return FALSE; if (!xdr_string (xdrs, &objp->volume, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -851,6 +878,8 @@ xdr_gfs3_flush_req (XDR *xdrs, gfs3_flush_req *objp) return FALSE; if (!xdr_quad_t (xdrs, &objp->fd)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -866,6 +895,8 @@ xdr_gfs3_fsync_req (XDR *xdrs, gfs3_fsync_req *objp) return FALSE; if (!xdr_u_int (xdrs, &objp->data)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -883,6 +914,8 @@ xdr_gfs3_fsync_rsp (XDR *xdrs, gfs3_fsync_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->poststat)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -898,7 +931,7 @@ xdr_gfs3_setxattr_req (XDR *xdrs, gfs3_setxattr_req *objp) 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)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -917,6 +950,8 @@ xdr_gfs3_fsetxattr_req (XDR *xdrs, gfs3_fsetxattr_req *objp) return FALSE; if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -932,7 +967,7 @@ xdr_gfs3_xattrop_req (XDR *xdrs, gfs3_xattrop_req *objp) 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)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -949,6 +984,8 @@ xdr_gfs3_xattrop_rsp (XDR *xdrs, gfs3_xattrop_rsp *objp) return FALSE; if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -966,6 +1003,8 @@ xdr_gfs3_fxattrop_req (XDR *xdrs, gfs3_fxattrop_req *objp) return FALSE; if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -981,6 +1020,8 @@ xdr_gfs3_fxattrop_rsp (XDR *xdrs, gfs3_fxattrop_rsp *objp) return FALSE; if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -994,10 +1035,10 @@ xdr_gfs3_getxattr_req (XDR *xdrs, gfs3_getxattr_req *objp) 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; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1013,6 +1054,8 @@ xdr_gfs3_getxattr_rsp (XDR *xdrs, gfs3_getxattr_rsp *objp) return FALSE; if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1030,6 +1073,8 @@ xdr_gfs3_fgetxattr_req (XDR *xdrs, gfs3_fgetxattr_req *objp) return FALSE; if (!xdr_string (xdrs, &objp->name, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1045,6 +1090,8 @@ xdr_gfs3_fgetxattr_rsp (XDR *xdrs, gfs3_fgetxattr_rsp *objp) return FALSE; if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1056,10 +1103,27 @@ xdr_gfs3_removexattr_req (XDR *xdrs, gfs3_removexattr_req *objp) if (!xdr_opaque (xdrs, objp->gfid, 16)) return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) + if (!xdr_string (xdrs, &objp->name, ~0)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gfs3_fremovexattr_req (XDR *xdrs, gfs3_fremovexattr_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_string (xdrs, &objp->name, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1071,7 +1135,7 @@ xdr_gfs3_opendir_req (XDR *xdrs, gfs3_opendir_req *objp) if (!xdr_opaque (xdrs, objp->gfid, 16)) return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -1088,6 +1152,8 @@ xdr_gfs3_opendir_rsp (XDR *xdrs, gfs3_opendir_rsp *objp) return FALSE; if (!xdr_quad_t (xdrs, &objp->fd)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1103,6 +1169,8 @@ xdr_gfs3_fsyncdir_req (XDR *xdrs, gfs3_fsyncdir_req *objp) return FALSE; if (!xdr_int (xdrs, &objp->data)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1120,6 +1188,8 @@ xdr_gfs3_readdir_req (XDR *xdrs, gfs3_readdir_req *objp) return FALSE; if (!xdr_u_int (xdrs, &objp->size)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1137,30 +1207,6 @@ xdr_gfs3_readdirp_req (XDR *xdrs, gfs3_readdirp_req *objp) 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; @@ -1176,7 +1222,7 @@ xdr_gfs3_access_req (XDR *xdrs, gfs3_access_req *objp) return FALSE; if (!xdr_u_int (xdrs, &objp->mask)) return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -1187,17 +1233,64 @@ xdr_gfs3_create_req (XDR *xdrs, gfs3_create_req *objp) register int32_t *buf; buf = NULL; + + if (xdrs->x_op == XDR_ENCODE) { + if (!xdr_opaque (xdrs, objp->pargfid, 16)) + return FALSE; + buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); + if (buf == NULL) { + if (!xdr_u_int (xdrs, &objp->flags)) + return FALSE; + if (!xdr_u_int (xdrs, &objp->mode)) + return FALSE; + if (!xdr_u_int (xdrs, &objp->umask)) + return FALSE; + + } else { + IXDR_PUT_U_LONG(buf, objp->flags); + IXDR_PUT_U_LONG(buf, objp->mode); + IXDR_PUT_U_LONG(buf, objp->umask); + } + if (!xdr_string (xdrs, &objp->bname, ~0)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; + return TRUE; + } else if (xdrs->x_op == XDR_DECODE) { + if (!xdr_opaque (xdrs, objp->pargfid, 16)) + return FALSE; + buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); + if (buf == NULL) { + if (!xdr_u_int (xdrs, &objp->flags)) + return FALSE; + if (!xdr_u_int (xdrs, &objp->mode)) + return FALSE; + if (!xdr_u_int (xdrs, &objp->umask)) + return FALSE; + + } else { + objp->flags = IXDR_GET_U_LONG(buf); + objp->mode = IXDR_GET_U_LONG(buf); + objp->umask = IXDR_GET_U_LONG(buf); + } + if (!xdr_string (xdrs, &objp->bname, ~0)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; + return TRUE; + } + 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)) + if (!xdr_u_int (xdrs, &objp->umask)) 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)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -1220,6 +1313,8 @@ xdr_gfs3_create_rsp (XDR *xdrs, gfs3_create_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->postparent)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1235,6 +1330,8 @@ xdr_gfs3_ftruncate_req (XDR *xdrs, gfs3_ftruncate_req *objp) return FALSE; if (!xdr_u_quad_t (xdrs, &objp->offset)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1252,6 +1349,8 @@ xdr_gfs3_ftruncate_rsp (XDR *xdrs, gfs3_ftruncate_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->poststat)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1265,6 +1364,8 @@ xdr_gfs3_fstat_req (XDR *xdrs, gfs3_fstat_req *objp) return FALSE; if (!xdr_quad_t (xdrs, &objp->fd)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1280,6 +1381,8 @@ xdr_gfs3_fstat_rsp (XDR *xdrs, gfs3_fstat_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->stat)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1297,12 +1400,12 @@ xdr_gfs3_entrylk_req (XDR *xdrs, gfs3_entrylk_req *objp) 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; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1326,6 +1429,8 @@ xdr_gfs3_fentrylk_req (XDR *xdrs, gfs3_fentrylk_req *objp) return FALSE; if (!xdr_string (xdrs, &objp->volume, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1341,7 +1446,7 @@ xdr_gfs3_setattr_req (XDR *xdrs, gfs3_setattr_req *objp) return FALSE; if (!xdr_int (xdrs, &objp->valid)) return FALSE; - if (!xdr_string (xdrs, &objp->path, ~0)) + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) return FALSE; return TRUE; } @@ -1360,6 +1465,8 @@ xdr_gfs3_setattr_rsp (XDR *xdrs, gfs3_setattr_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->statpost)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1375,6 +1482,8 @@ xdr_gfs3_fsetattr_req (XDR *xdrs, gfs3_fsetattr_req *objp) return FALSE; if (!xdr_int (xdrs, &objp->valid)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1392,10 +1501,131 @@ xdr_gfs3_fsetattr_rsp (XDR *xdrs, gfs3_fsetattr_rsp *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->statpost)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } bool_t +xdr_gfs3_fallocate_req (XDR *xdrs, gfs3_fallocate_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_u_quad_t (xdrs, &objp->offset)) + return FALSE; + if (!xdr_u_quad_t (xdrs, &objp->size)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gfs3_fallocate_rsp (XDR *xdrs, gfs3_fallocate_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; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gfs3_discard_req (XDR *xdrs, gfs3_discard_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_quad_t (xdrs, &objp->size)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gfs3_discard_rsp (XDR *xdrs, gfs3_discard_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; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gfs3_zerofill_req (XDR *xdrs, gfs3_zerofill_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_quad_t (xdrs, &objp->size)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, + (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gfs3_zerofill_rsp (XDR *xdrs, gfs3_zerofill_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; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, + (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; + return TRUE; +} + + +bool_t xdr_gfs3_rchecksum_req (XDR *xdrs, gfs3_rchecksum_req *objp) { register int32_t *buf; @@ -1407,6 +1637,8 @@ xdr_gfs3_rchecksum_req (XDR *xdrs, gfs3_rchecksum_req *objp) return FALSE; if (!xdr_u_int (xdrs, &objp->len)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1434,6 +1666,8 @@ xdr_gfs3_rchecksum_rsp (XDR *xdrs, gfs3_rchecksum_rsp *objp) } if (!xdr_bytes (xdrs, (char **)&objp->strong_checksum.strong_checksum_val, (u_int *) &objp->strong_checksum.strong_checksum_len, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } else if (xdrs->x_op == XDR_DECODE) { buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); @@ -1452,6 +1686,8 @@ xdr_gfs3_rchecksum_rsp (XDR *xdrs, gfs3_rchecksum_rsp *objp) } if (!xdr_bytes (xdrs, (char **)&objp->strong_checksum.strong_checksum_val, (u_int *) &objp->strong_checksum.strong_checksum_len, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1463,6 +1699,34 @@ xdr_gfs3_rchecksum_rsp (XDR *xdrs, gfs3_rchecksum_rsp *objp) return FALSE; if (!xdr_bytes (xdrs, (char **)&objp->strong_checksum.strong_checksum_val, (u_int *) &objp->strong_checksum.strong_checksum_len, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + 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; } @@ -1476,6 +1740,8 @@ xdr_gf_getspec_req (XDR *xdrs, gf_getspec_req *objp) return FALSE; if (!xdr_string (xdrs, &objp->key, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1491,6 +1757,34 @@ xdr_gf_getspec_rsp (XDR *xdrs, gf_getspec_rsp *objp) return FALSE; if (!xdr_string (xdrs, &objp->spec, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gf_mgmt_hndsk_req (XDR *xdrs, gf_mgmt_hndsk_req *objp) +{ + register int32_t *buf; + buf = NULL; + + if (!xdr_bytes (xdrs, (char **)&objp->hndsk.hndsk_val, (u_int *) &objp->hndsk.hndsk_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gf_mgmt_hndsk_rsp (XDR *xdrs, gf_mgmt_hndsk_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->hndsk.hndsk_val, (u_int *) &objp->hndsk.hndsk_len, ~0)) + return FALSE; return TRUE; } @@ -1515,6 +1809,8 @@ xdr_gf_notify_req (XDR *xdrs, gf_notify_req *objp) return FALSE; if (!xdr_string (xdrs, &objp->buf, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1542,6 +1838,8 @@ xdr_gf_notify_rsp (XDR *xdrs, gf_notify_rsp *objp) } if (!xdr_string (xdrs, &objp->buf, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } else if (xdrs->x_op == XDR_DECODE) { buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); @@ -1560,6 +1858,8 @@ xdr_gf_notify_rsp (XDR *xdrs, gf_notify_rsp *objp) } if (!xdr_string (xdrs, &objp->buf, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1571,6 +1871,8 @@ xdr_gf_notify_rsp (XDR *xdrs, gf_notify_rsp *objp) return FALSE; if (!xdr_string (xdrs, &objp->buf, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1584,6 +1886,8 @@ xdr_gfs3_releasedir_req (XDR *xdrs, gfs3_releasedir_req *objp) return FALSE; if (!xdr_quad_t (xdrs, &objp->fd)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1597,6 +1901,8 @@ xdr_gfs3_release_req (XDR *xdrs, gfs3_release_req *objp) return FALSE; if (!xdr_quad_t (xdrs, &objp->fd)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1610,6 +1916,8 @@ xdr_gf_common_rsp (XDR *xdrs, gf_common_rsp *objp) return FALSE; if (!xdr_int (xdrs, &objp->op_errno)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1646,6 +1954,8 @@ xdr_gfs3_readdir_rsp (XDR *xdrs, gfs3_readdir_rsp *objp) return FALSE; if (!xdr_pointer (xdrs, (char **)&objp->reply, sizeof (gfs3_dirlist), (xdrproc_t) xdr_gfs3_dirlist)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; return TRUE; } @@ -1667,6 +1977,8 @@ xdr_gfs3_dirplist (XDR *xdrs, gfs3_dirplist *objp) return FALSE; if (!xdr_gf_iatt (xdrs, &objp->stat)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; if (!xdr_pointer (xdrs, (char **)&objp->nextentry, sizeof (gfs3_dirplist), (xdrproc_t) xdr_gfs3_dirplist)) return FALSE; return TRUE; @@ -1684,5 +1996,63 @@ xdr_gfs3_readdirp_rsp (XDR *xdrs, gfs3_readdirp_rsp *objp) return FALSE; if (!xdr_pointer (xdrs, (char **)&objp->reply, sizeof (gfs3_dirplist), (xdrproc_t) xdr_gfs3_dirplist)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->xdata.xdata_val, (u_int *) &objp->xdata.xdata_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gf_set_lk_ver_rsp (XDR *xdrs, gf_set_lk_ver_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_int (xdrs, &objp->lk_ver)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gf_set_lk_ver_req (XDR *xdrs, gf_set_lk_ver_req *objp) +{ + register int32_t *buf; + buf = NULL; + + if (!xdr_string (xdrs, &objp->uid, ~0)) + return FALSE; + if (!xdr_int (xdrs, &objp->lk_ver)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gf_event_notify_req (XDR *xdrs, gf_event_notify_req *objp) +{ + register int32_t *buf; + buf = NULL; + + if (!xdr_int (xdrs, &objp->op)) + 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_gf_event_notify_rsp (XDR *xdrs, gf_event_notify_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; } diff --git a/rpc/xdr/src/glusterfs3-xdr.h b/rpc/xdr/src/glusterfs3-xdr.h index 0c8af17d2..13566e694 100644 --- a/rpc/xdr/src/glusterfs3-xdr.h +++ b/rpc/xdr/src/glusterfs3-xdr.h @@ -1,20 +1,11 @@ /* - 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-common.h" @@ -63,7 +54,10 @@ struct gf_proto_flock { u_quad_t start; u_quad_t len; u_int pid; - u_quad_t owner; + struct { + u_int lk_owner_len; + char *lk_owner_val; + } lk_owner; }; typedef struct gf_proto_flock gf_proto_flock; @@ -90,7 +84,10 @@ typedef struct gf_iatt gf_iatt; struct gfs3_stat_req { char gfid[16]; - char *path; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_stat_req gfs3_stat_req; @@ -98,13 +95,20 @@ struct gfs3_stat_rsp { int op_ret; int op_errno; struct gf_iatt stat; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_stat_rsp gfs3_stat_rsp; struct gfs3_readlink_req { char gfid[16]; u_int size; - char *path; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_readlink_req gfs3_readlink_req; @@ -113,6 +117,10 @@ struct gfs3_readlink_rsp { int op_errno; struct gf_iatt buf; char *path; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_readlink_rsp gfs3_readlink_rsp; @@ -120,12 +128,12 @@ struct gfs3_mknod_req { char pargfid[16]; u_quad_t dev; u_int mode; - char *path; + u_int umask; char *bname; struct { - u_int dict_len; - char *dict_val; - } dict; + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_mknod_req gfs3_mknod_req; @@ -135,18 +143,22 @@ struct gfs3_mknod_rsp { struct gf_iatt stat; struct gf_iatt preparent; struct gf_iatt postparent; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_mknod_rsp gfs3_mknod_rsp; struct gfs3_mkdir_req { char pargfid[16]; u_int mode; - char *path; + u_int umask; char *bname; struct { - u_int dict_len; - char *dict_val; - } dict; + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_mkdir_req gfs3_mkdir_req; @@ -156,13 +168,21 @@ struct gfs3_mkdir_rsp { struct gf_iatt stat; struct gf_iatt preparent; struct gf_iatt postparent; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_mkdir_rsp gfs3_mkdir_rsp; struct gfs3_unlink_req { char pargfid[16]; - char *path; char *bname; + u_int xflags; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_unlink_req gfs3_unlink_req; @@ -171,14 +191,21 @@ struct gfs3_unlink_rsp { int op_errno; struct gf_iatt preparent; struct gf_iatt postparent; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_unlink_rsp gfs3_unlink_rsp; struct gfs3_rmdir_req { char pargfid[16]; - int flags; - char *path; + int xflags; char *bname; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_rmdir_req gfs3_rmdir_req; @@ -187,18 +214,22 @@ struct gfs3_rmdir_rsp { int op_errno; struct gf_iatt preparent; struct gf_iatt postparent; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_rmdir_rsp gfs3_rmdir_rsp; struct gfs3_symlink_req { char pargfid[16]; - char *path; char *bname; + u_int umask; char *linkname; struct { - u_int dict_len; - char *dict_val; - } dict; + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_symlink_req gfs3_symlink_req; @@ -208,16 +239,22 @@ struct gfs3_symlink_rsp { struct gf_iatt stat; struct gf_iatt preparent; struct gf_iatt postparent; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; 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; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_rename_req gfs3_rename_req; @@ -229,15 +266,21 @@ struct gfs3_rename_rsp { struct gf_iatt postoldparent; struct gf_iatt prenewparent; struct gf_iatt postnewparent; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_rename_rsp gfs3_rename_rsp; struct gfs3_link_req { char oldgfid[16]; char newgfid[16]; - char *oldpath; - char *newpath; char *newbname; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_link_req gfs3_link_req; @@ -247,13 +290,20 @@ struct gfs3_link_rsp { struct gf_iatt stat; struct gf_iatt preparent; struct gf_iatt postparent; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_link_rsp gfs3_link_rsp; struct gfs3_truncate_req { char gfid[16]; u_quad_t offset; - char *path; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_truncate_req gfs3_truncate_req; @@ -262,14 +312,20 @@ struct gfs3_truncate_rsp { int op_errno; struct gf_iatt prestat; struct gf_iatt poststat; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_truncate_rsp gfs3_truncate_rsp; struct gfs3_open_req { char gfid[16]; u_int flags; - u_int wbflags; - char *path; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_open_req gfs3_open_req; @@ -277,6 +333,10 @@ struct gfs3_open_rsp { int op_ret; int op_errno; quad_t fd; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_open_rsp gfs3_open_rsp; @@ -285,6 +345,11 @@ struct gfs3_read_req { quad_t fd; u_quad_t offset; u_int size; + u_int flag; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_read_req gfs3_read_req; @@ -293,6 +358,10 @@ struct gfs3_read_rsp { int op_errno; struct gf_iatt stat; u_int size; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_read_rsp gfs3_read_rsp; @@ -300,12 +369,11 @@ 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; + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_lookup_req gfs3_lookup_req; @@ -315,9 +383,9 @@ struct gfs3_lookup_rsp { struct gf_iatt stat; struct gf_iatt postparent; struct { - u_int dict_len; - char *dict_val; - } dict; + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_lookup_rsp gfs3_lookup_rsp; @@ -326,6 +394,11 @@ struct gfs3_write_req { quad_t fd; u_quad_t offset; u_int size; + u_int flag; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_write_req gfs3_write_req; @@ -334,12 +407,19 @@ struct gfs3_write_rsp { int op_errno; struct gf_iatt prestat; struct gf_iatt poststat; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_write_rsp gfs3_write_rsp; struct gfs3_statfs_req { char gfid[16]; - char *path; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_statfs_req gfs3_statfs_req; @@ -347,6 +427,10 @@ struct gfs3_statfs_rsp { int op_ret; int op_errno; struct gf_statfs statfs; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_statfs_rsp gfs3_statfs_rsp; @@ -356,6 +440,10 @@ struct gfs3_lk_req { u_int cmd; u_int type; struct gf_proto_flock flock; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_lk_req gfs3_lk_req; @@ -363,6 +451,10 @@ struct gfs3_lk_rsp { int op_ret; int op_errno; struct gf_proto_flock flock; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_lk_rsp gfs3_lk_rsp; @@ -371,8 +463,11 @@ struct gfs3_inodelk_req { u_int cmd; u_int type; struct gf_proto_flock flock; - char *path; char *volume; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_inodelk_req gfs3_inodelk_req; @@ -383,12 +478,20 @@ struct gfs3_finodelk_req { u_int type; struct gf_proto_flock flock; char *volume; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_finodelk_req gfs3_finodelk_req; struct gfs3_flush_req { char gfid[16]; quad_t fd; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_flush_req gfs3_flush_req; @@ -396,6 +499,10 @@ struct gfs3_fsync_req { char gfid[16]; quad_t fd; u_int data; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fsync_req gfs3_fsync_req; @@ -404,6 +511,10 @@ struct gfs3_fsync_rsp { int op_errno; struct gf_iatt prestat; struct gf_iatt poststat; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fsync_rsp gfs3_fsync_rsp; @@ -414,7 +525,10 @@ struct gfs3_setxattr_req { u_int dict_len; char *dict_val; } dict; - char *path; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_setxattr_req gfs3_setxattr_req; @@ -426,6 +540,10 @@ struct gfs3_fsetxattr_req { u_int dict_len; char *dict_val; } dict; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fsetxattr_req gfs3_fsetxattr_req; @@ -436,7 +554,10 @@ struct gfs3_xattrop_req { u_int dict_len; char *dict_val; } dict; - char *path; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_xattrop_req gfs3_xattrop_req; @@ -447,6 +568,10 @@ struct gfs3_xattrop_rsp { u_int dict_len; char *dict_val; } dict; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_xattrop_rsp gfs3_xattrop_rsp; @@ -458,6 +583,10 @@ struct gfs3_fxattrop_req { u_int dict_len; char *dict_val; } dict; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fxattrop_req gfs3_fxattrop_req; @@ -468,14 +597,21 @@ struct gfs3_fxattrop_rsp { u_int dict_len; char *dict_val; } dict; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fxattrop_rsp gfs3_fxattrop_rsp; struct gfs3_getxattr_req { char gfid[16]; u_int namelen; - char *path; char *name; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_getxattr_req gfs3_getxattr_req; @@ -486,6 +622,10 @@ struct gfs3_getxattr_rsp { u_int dict_len; char *dict_val; } dict; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_getxattr_rsp gfs3_getxattr_rsp; @@ -494,6 +634,10 @@ struct gfs3_fgetxattr_req { quad_t fd; u_int namelen; char *name; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fgetxattr_req gfs3_fgetxattr_req; @@ -504,19 +648,40 @@ struct gfs3_fgetxattr_rsp { u_int dict_len; char *dict_val; } dict; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fgetxattr_rsp gfs3_fgetxattr_rsp; struct gfs3_removexattr_req { char gfid[16]; - char *path; char *name; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_removexattr_req gfs3_removexattr_req; +struct gfs3_fremovexattr_req { + char gfid[16]; + quad_t fd; + char *name; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; +}; +typedef struct gfs3_fremovexattr_req gfs3_fremovexattr_req; + struct gfs3_opendir_req { char gfid[16]; - char *path; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_opendir_req gfs3_opendir_req; @@ -524,6 +689,10 @@ struct gfs3_opendir_rsp { int op_ret; int op_errno; quad_t fd; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_opendir_rsp gfs3_opendir_rsp; @@ -531,6 +700,10 @@ struct gfs3_fsyncdir_req { char gfid[16]; quad_t fd; int data; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fsyncdir_req gfs3_fsyncdir_req; @@ -539,6 +712,10 @@ struct gfs3_readdir_req { quad_t fd; u_quad_t offset; u_int size; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_readdir_req gfs3_readdir_req; @@ -547,31 +724,20 @@ struct gfs3_readdirp_req { 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; +typedef struct gfs3_readdirp_req gfs3_readdirp_req; struct gfs3_access_req { char gfid[16]; u_int mask; - char *path; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_access_req gfs3_access_req; @@ -579,12 +745,12 @@ struct gfs3_create_req { char pargfid[16]; u_int flags; u_int mode; - char *path; + u_int umask; char *bname; struct { - u_int dict_len; - char *dict_val; - } dict; + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_create_req gfs3_create_req; @@ -595,6 +761,10 @@ struct gfs3_create_rsp { u_quad_t fd; struct gf_iatt preparent; struct gf_iatt postparent; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_create_rsp gfs3_create_rsp; @@ -602,6 +772,10 @@ struct gfs3_ftruncate_req { char gfid[16]; quad_t fd; u_quad_t offset; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_ftruncate_req gfs3_ftruncate_req; @@ -610,12 +784,20 @@ struct gfs3_ftruncate_rsp { int op_errno; struct gf_iatt prestat; struct gf_iatt poststat; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_ftruncate_rsp gfs3_ftruncate_rsp; struct gfs3_fstat_req { char gfid[16]; quad_t fd; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fstat_req gfs3_fstat_req; @@ -623,6 +805,10 @@ struct gfs3_fstat_rsp { int op_ret; int op_errno; struct gf_iatt stat; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fstat_rsp gfs3_fstat_rsp; @@ -631,9 +817,12 @@ struct gfs3_entrylk_req { u_int cmd; u_int type; u_quad_t namelen; - char *path; char *name; char *volume; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_entrylk_req gfs3_entrylk_req; @@ -645,6 +834,10 @@ struct gfs3_fentrylk_req { u_quad_t namelen; char *name; char *volume; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fentrylk_req gfs3_fentrylk_req; @@ -652,7 +845,10 @@ struct gfs3_setattr_req { char gfid[16]; struct gf_iatt stbuf; int valid; - char *path; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_setattr_req gfs3_setattr_req; @@ -661,6 +857,10 @@ struct gfs3_setattr_rsp { int op_errno; struct gf_iatt statpre; struct gf_iatt statpost; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_setattr_rsp gfs3_setattr_rsp; @@ -668,6 +868,10 @@ struct gfs3_fsetattr_req { quad_t fd; struct gf_iatt stbuf; int valid; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fsetattr_req gfs3_fsetattr_req; @@ -676,13 +880,95 @@ struct gfs3_fsetattr_rsp { int op_errno; struct gf_iatt statpre; struct gf_iatt statpost; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_fsetattr_rsp gfs3_fsetattr_rsp; +struct gfs3_fallocate_req { + char gfid[16]; + quad_t fd; + u_int flags; + u_quad_t offset; + u_quad_t size; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; +}; +typedef struct gfs3_fallocate_req gfs3_fallocate_req; + +struct gfs3_fallocate_rsp { + int op_ret; + int op_errno; + struct gf_iatt statpre; + struct gf_iatt statpost; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; +}; +typedef struct gfs3_fallocate_rsp gfs3_fallocate_rsp; + +struct gfs3_discard_req { + char gfid[16]; + quad_t fd; + u_quad_t offset; + u_quad_t size; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; +}; +typedef struct gfs3_discard_req gfs3_discard_req; + +struct gfs3_discard_rsp { + int op_ret; + int op_errno; + struct gf_iatt statpre; + struct gf_iatt statpost; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; +}; +typedef struct gfs3_discard_rsp gfs3_discard_rsp; + +struct gfs3_zerofill_req { + char gfid[16]; + quad_t fd; + u_quad_t offset; + u_quad_t size; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; +}; +typedef struct gfs3_zerofill_req gfs3_zerofill_req; + +struct gfs3_zerofill_rsp { + int op_ret; + int op_errno; + struct gf_iatt statpre; + struct gf_iatt statpost; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; +}; +typedef struct gfs3_zerofill_rsp gfs3_zerofill_rsp; + + struct gfs3_rchecksum_req { quad_t fd; u_quad_t offset; u_int len; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_rchecksum_req gfs3_rchecksum_req; @@ -694,12 +980,38 @@ struct gfs3_rchecksum_rsp { u_int strong_checksum_len; char *strong_checksum_val; } strong_checksum; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_rchecksum_rsp gfs3_rchecksum_rsp; +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 gf_getspec_req { u_int flags; char *key; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gf_getspec_req gf_getspec_req; @@ -707,9 +1019,31 @@ struct gf_getspec_rsp { int op_ret; int op_errno; char *spec; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gf_getspec_rsp gf_getspec_rsp; +struct gf_mgmt_hndsk_req { + struct { + u_int hndsk_len; + char *hndsk_val; + } hndsk; +}; +typedef struct gf_mgmt_hndsk_req gf_mgmt_hndsk_req; + +struct gf_mgmt_hndsk_rsp { + int op_ret; + int op_errno; + struct { + u_int hndsk_len; + char *hndsk_val; + } hndsk; +}; +typedef struct gf_mgmt_hndsk_rsp gf_mgmt_hndsk_rsp; + struct gf_log_req { struct { u_int msg_len; @@ -721,6 +1055,10 @@ typedef struct gf_log_req gf_log_req; struct gf_notify_req { u_int flags; char *buf; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gf_notify_req gf_notify_req; @@ -729,24 +1067,40 @@ struct gf_notify_rsp { int op_errno; u_int flags; char *buf; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gf_notify_rsp gf_notify_rsp; struct gfs3_releasedir_req { char gfid[16]; quad_t fd; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_releasedir_req gfs3_releasedir_req; struct gfs3_release_req { char gfid[16]; quad_t fd; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_release_req gfs3_release_req; struct gf_common_rsp { int op_ret; int op_errno; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gf_common_rsp gf_common_rsp; @@ -764,6 +1118,10 @@ struct gfs3_readdir_rsp { int op_ret; int op_errno; struct gfs3_dirlist *reply; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_readdir_rsp gfs3_readdir_rsp; @@ -774,6 +1132,10 @@ struct gfs3_dirplist { u_int d_type; char *name; struct gf_iatt stat; + struct { + u_int dict_len; + char *dict_val; + } dict; struct gfs3_dirplist *nextentry; }; typedef struct gfs3_dirplist gfs3_dirplist; @@ -782,9 +1144,45 @@ struct gfs3_readdirp_rsp { int op_ret; int op_errno; struct gfs3_dirplist *reply; + struct { + u_int xdata_len; + char *xdata_val; + } xdata; }; typedef struct gfs3_readdirp_rsp gfs3_readdirp_rsp; +struct gf_set_lk_ver_rsp { + int op_ret; + int op_errno; + int lk_ver; +}; +typedef struct gf_set_lk_ver_rsp gf_set_lk_ver_rsp; + +struct gf_set_lk_ver_req { + char *uid; + int lk_ver; +}; +typedef struct gf_set_lk_ver_req gf_set_lk_ver_req; + +struct gf_event_notify_req { + int op; + struct { + u_int dict_len; + char *dict_val; + } dict; +}; +typedef struct gf_event_notify_req gf_event_notify_req; + +struct gf_event_notify_rsp { + int op_ret; + int op_errno; + struct { + u_int dict_len; + char *dict_val; + } dict; +}; +typedef struct gf_event_notify_rsp gf_event_notify_rsp; + /* the xdr functions */ #if defined(__STDC__) || defined(__cplusplus) @@ -839,13 +1237,12 @@ 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_fremovexattr_req (XDR *, gfs3_fremovexattr_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*); @@ -859,10 +1256,20 @@ 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_fallocate_req (XDR *, gfs3_fallocate_req*); +extern bool_t xdr_gfs3_fallocate_rsp (XDR *, gfs3_fallocate_rsp*); +extern bool_t xdr_gfs3_discard_req (XDR *, gfs3_discard_req*); +extern bool_t xdr_gfs3_discard_rsp (XDR *, gfs3_discard_rsp*); +extern bool_t xdr_gfs3_zerofill_req (XDR *, gfs3_zerofill_req*); +extern bool_t xdr_gfs3_zerofill_rsp (XDR *, gfs3_zerofill_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_setvolume_req (XDR *, gf_setvolume_req*); +extern bool_t xdr_gf_setvolume_rsp (XDR *, gf_setvolume_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_mgmt_hndsk_req (XDR *, gf_mgmt_hndsk_req*); +extern bool_t xdr_gf_mgmt_hndsk_rsp (XDR *, gf_mgmt_hndsk_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*); @@ -873,6 +1280,10 @@ 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*); +extern bool_t xdr_gf_set_lk_ver_rsp (XDR *, gf_set_lk_ver_rsp*); +extern bool_t xdr_gf_set_lk_ver_req (XDR *, gf_set_lk_ver_req*); +extern bool_t xdr_gf_event_notify_req (XDR *, gf_event_notify_req*); +extern bool_t xdr_gf_event_notify_rsp (XDR *, gf_event_notify_rsp*); #else /* K&R C */ extern bool_t xdr_gf_statfs (); @@ -926,13 +1337,12 @@ 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_fremovexattr_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 (); @@ -946,10 +1356,20 @@ 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_fallocate_req (); +extern bool_t xdr_gfs3_fallocate_rsp (); +extern bool_t xdr_gfs3_discard_req (); +extern bool_t xdr_gfs3_discard_rsp (); +extern bool_t xdr_gfs3_zerofill_req (); +extern bool_t xdr_gfs3_zerofill_rsp (); extern bool_t xdr_gfs3_rchecksum_req (); extern bool_t xdr_gfs3_rchecksum_rsp (); +extern bool_t xdr_gf_setvolume_req (); +extern bool_t xdr_gf_setvolume_rsp (); extern bool_t xdr_gf_getspec_req (); extern bool_t xdr_gf_getspec_rsp (); +extern bool_t xdr_gf_mgmt_hndsk_req (); +extern bool_t xdr_gf_mgmt_hndsk_rsp (); extern bool_t xdr_gf_log_req (); extern bool_t xdr_gf_notify_req (); extern bool_t xdr_gf_notify_rsp (); @@ -960,6 +1380,10 @@ 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 (); +extern bool_t xdr_gf_set_lk_ver_rsp (); +extern bool_t xdr_gf_set_lk_ver_req (); +extern bool_t xdr_gf_event_notify_req (); +extern bool_t xdr_gf_event_notify_rsp (); #endif /* K&R C */ diff --git a/rpc/xdr/src/glusterfs3-xdr.x b/rpc/xdr/src/glusterfs3-xdr.x index 592f7ed70..1edbda3ad 100644 --- a/rpc/xdr/src/glusterfs3-xdr.x +++ b/rpc/xdr/src/glusterfs3-xdr.x @@ -19,7 +19,7 @@ struct gf_proto_flock { unsigned hyper start; unsigned hyper len; unsigned int pid; - unsigned hyper owner; + opaque lk_owner<>; } ; @@ -45,26 +45,27 @@ struct gf_iatt { 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; + 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; string path<>; /* NULL terminated */ + opaque xdata<>; /* Extra data */ } ; @@ -72,9 +73,9 @@ struct gfs3_readlink_req { opaque pargfid[16]; unsigned hyper 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; @@ -82,15 +83,16 @@ struct gfs3_readlink_req { struct gf_iatt stat; struct gf_iatt preparent; struct 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; @@ -98,42 +100,46 @@ struct gfs3_readlink_req { struct gf_iatt stat; struct gf_iatt preparent; struct 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; + 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; + 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; @@ -141,16 +147,16 @@ struct gfs3_readlink_req { struct gf_iatt stat; struct gf_iatt preparent; struct 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; @@ -160,15 +166,15 @@ struct gfs3_readlink_req { struct gf_iatt postoldparent; struct gf_iatt prenewparent; struct 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; @@ -176,31 +182,33 @@ struct gfs3_readlink_req { struct gf_iatt stat; struct gf_iatt preparent; struct gf_iatt postparent; + opaque xdata<>; /* Extra data */ }; struct gfs3_truncate_req { opaque gfid[16]; unsigned hyper offset; - string path<>; + opaque xdata<>; /* Extra data */ }; struct gfs3_truncate_rsp { int op_ret; int op_errno; struct gf_iatt prestat; struct 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; + opaque xdata<>; /* Extra data */ }; @@ -209,28 +217,30 @@ struct gfs3_readlink_req { hyper fd; unsigned hyper 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; 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<>; + opaque xdata<>; /* Extra data */ } ; @@ -240,23 +250,27 @@ struct gfs3_lookup_req { hyper fd; unsigned hyper 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; + 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; + opaque xdata<>; /* Extra data */ } ; struct gfs3_lk_req { @@ -265,11 +279,13 @@ struct gfs3_lookup_req { unsigned int cmd; unsigned int type; struct gf_proto_flock flock; + opaque xdata<>; /* Extra data */ } ; struct gfs3_lk_rsp { int op_ret; int op_errno; struct gf_proto_flock flock; + opaque xdata<>; /* Extra data */ } ; struct gfs3_inodelk_req { @@ -277,8 +293,8 @@ struct gfs3_lookup_req { unsigned int cmd; unsigned int type; struct gf_proto_flock flock; - string path<>; string volume<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_finodelk_req { @@ -288,12 +304,14 @@ struct gfs3_finodelk_req { unsigned int type; struct gf_proto_flock flock; string volume<>; + opaque xdata<>; /* Extra data */ } ; struct gfs3_flush_req { opaque gfid[16]; hyper fd; + opaque xdata<>; /* Extra data */ } ; @@ -301,12 +319,14 @@ struct gfs3_finodelk_req { opaque gfid[16]; hyper 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; + opaque xdata<>; /* Extra data */ } ; @@ -314,7 +334,7 @@ struct gfs3_finodelk_req { opaque gfid[16]; unsigned int flags; opaque dict<>; - string path<>; + opaque xdata<>; /* Extra data */ } ; @@ -324,6 +344,7 @@ struct gfs3_finodelk_req { hyper fd; unsigned int flags; opaque dict<>; + opaque xdata<>; /* Extra data */ } ; @@ -332,13 +353,14 @@ 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 */ } ; @@ -347,25 +369,28 @@ struct gfs3_finodelk_req { hyper 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 */ } ; @@ -374,30 +399,40 @@ struct gfs3_finodelk_req { hyper 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]; + hyper 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; + opaque xdata<>; /* Extra data */ } ; @@ -405,6 +440,7 @@ struct gfs3_finodelk_req { opaque gfid[16]; hyper fd; int data; + opaque xdata<>; /* Extra data */ } ; struct gfs3_readdir_req { @@ -412,6 +448,7 @@ struct gfs3_finodelk_req { hyper fd; unsigned hyper offset; unsigned int size; + opaque xdata<>; /* Extra data */ }; struct gfs3_readdirp_req { @@ -419,22 +456,14 @@ struct gfs3_finodelk_req { hyper fd; unsigned hyper 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,9 +471,9 @@ 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; @@ -453,6 +482,7 @@ struct gfs3_create_rsp { unsigned hyper fd; struct gf_iatt preparent; struct gf_iatt postparent; + opaque xdata<>; /* Extra data */ } ; @@ -461,23 +491,27 @@ struct gfs3_ftruncate_req { opaque gfid[16]; hyper fd; unsigned hyper offset; + opaque xdata<>; /* Extra data */ } ; struct gfs3_ftruncate_rsp { int op_ret; int op_errno; struct gf_iatt prestat; struct gf_iatt poststat; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fstat_req { opaque gfid[16]; hyper fd; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fstat_rsp { int op_ret; int op_errno; struct gf_iatt stat; + opaque xdata<>; /* Extra data */ } ; @@ -487,9 +521,9 @@ struct gfs3_fstat_req { unsigned int cmd; unsigned int type; unsigned hyper namelen; - string path<>; string name<>; string volume<>; + opaque xdata<>; /* Extra data */ }; struct gfs3_fentrylk_req { @@ -500,6 +534,7 @@ struct gfs3_fstat_req { unsigned hyper namelen; string name<>; string volume<>; + opaque xdata<>; /* Extra data */ }; @@ -507,79 +542,160 @@ struct gfs3_fstat_req { opaque gfid[16]; struct 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; + opaque xdata<>; /* Extra data */ } ; struct gfs3_fsetattr_req { hyper fd; struct 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; + opaque xdata<>; /* Extra data */ +} ; + + struct gfs3_fallocate_req { + opaque gfid[16]; + hyper fd; + unsigned int flags; + unsigned hyper offset; + unsigned hyper size; + opaque xdata<>; /* Extra data */ +} ; + + struct gfs3_fallocate_rsp { + int op_ret; + int op_errno; + struct gf_iatt statpre; + struct gf_iatt statpost; + opaque xdata<>; /* Extra data */ +} ; + + struct gfs3_discard_req { + opaque gfid[16]; + hyper fd; + unsigned hyper offset; + unsigned hyper size; + opaque xdata<>; /* Extra data */ +} ; + + struct gfs3_discard_rsp { + int op_ret; + int op_errno; + struct gf_iatt statpre; + struct gf_iatt statpost; + opaque xdata<>; /* Extra data */ } ; + struct gfs3_zerofill_req { + opaque gfid[16]; + hyper fd; + unsigned hyper offset; + unsigned hyper size; + opaque xdata<>; +} ; + + struct gfs3_zerofill_rsp { + int op_ret; + int op_errno; + struct gf_iatt statpre; + struct gf_iatt statpost; + opaque xdata<>; +} ; + + struct gfs3_rchecksum_req { hyper fd; unsigned hyper 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 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_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; + opaque xdata<>; /* Extra data */ } ; struct gfs3_release_req { opaque gfid[16]; hyper fd; + opaque xdata<>; /* Extra data */ } ; struct gf_common_rsp { int op_ret; int op_errno; + opaque xdata<>; /* Extra data */ } ; struct gfs3_dirlist { @@ -596,6 +712,7 @@ struct gfs3_readdir_rsp { int op_ret; int op_errno; struct gfs3_dirlist *reply; + opaque xdata<>; /* Extra data */ }; struct gfs3_dirplist { @@ -605,6 +722,7 @@ struct gfs3_dirplist { unsigned int d_type; string name<>; struct gf_iatt stat; + opaque dict<>; struct gfs3_dirplist *nextentry; }; @@ -612,5 +730,27 @@ struct gfs3_readdirp_rsp { int op_ret; int op_errno; struct 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<>; +}; diff --git a/rpc/xdr/src/glusterfs3.h b/rpc/xdr/src/glusterfs3.h index ba64a0b45..798413e31 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 @@ -54,6 +44,8 @@ #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; \ @@ -112,6 +104,7 @@ gf_flags_from_flags (uint32_t flags) XLATE_BIT (flags, gf_flags, O_CLOEXEC); #endif XLATE_BIT (flags, gf_flags, O_LARGEFILE); + XLATE_BIT (flags, gf_flags, O_FMODE_EXEC); return gf_flags; } @@ -142,6 +135,7 @@ gf_flags_to_flags (uint32_t gf_flags) UNXLATE_BIT (gf_flags, flags, O_CLOEXEC); #endif UNXLATE_BIT (gf_flags, flags, O_LARGEFILE); + UNXLATE_BIT (gf_flags, flags, O_FMODE_EXEC); return flags; } @@ -197,7 +191,11 @@ gf_proto_flock_to_flock (struct gf_proto_flock *gf_proto_flock, struct gf_flock 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; + 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); } @@ -212,7 +210,9 @@ gf_proto_flock_from_flock (struct gf_proto_flock *gf_proto_flock, struct gf_floc 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); + 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 diff --git a/rpc/xdr/src/mount3udp.x b/rpc/xdr/src/mount3udp.x new file mode 100644 index 000000000..888c53120 --- /dev/null +++ b/rpc/xdr/src/mount3udp.x @@ -0,0 +1,25 @@ +/* + 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. +*/ + +/* This is used by rpcgen to auto generate the rpc stubs. + * mount3udp_svc.c is heavily modified though + */ + +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 d760d43b5..6cdb5d37e 100644 --- a/rpc/xdr/src/msg-nfs3.c +++ b/rpc/xdr/src/msg-nfs3.c @@ -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 _CONFIG_H @@ -63,84 +54,6 @@ ret: return ret; } -/* -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)) { - 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)) { - ret = -1; - goto ret; - } - - ret = xdr_decoded_length (xdr); -ret: - return ret; -} - - -ssize_t -xdr_to_generic_payload (struct iovec inmsg, void *args, xdrproc_t proc, - struct iovec *pendingpayload) -{ - 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; -} -*/ - /* 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. @@ -552,4 +465,108 @@ xdr_serialize_nfsstat3 (struct iovec outmsg, nfsstat3 *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_serialize_nlm4_testres (struct iovec outmsg, nlm4_testres *res) +{ + 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_nlm4_res (struct iovec outmsg, nlm4_res *res) +{ + 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_to_nlm4_unlockargs (struct iovec inmsg, nlm4_unlockargs *args) +{ + return xdr_to_generic (inmsg, (void*)args, + (xdrproc_t)xdr_nlm4_unlockargs); +} + +ssize_t +xdr_to_nlm4_shareargs (struct iovec inmsg, nlm4_shareargs *args) +{ + return xdr_to_generic (inmsg, (void*)args, + (xdrproc_t)xdr_nlm4_shareargs); +} + +ssize_t +xdr_serialize_nlm4_shareres (struct iovec outmsg, nlm4_shareres *res) +{ + return xdr_serialize_generic (outmsg, (void *)res, + (xdrproc_t)xdr_nlm4_shareres); +} + +ssize_t +xdr_serialize_nlm4_testargs (struct iovec outmsg, nlm4_testargs *args) +{ + return xdr_serialize_generic (outmsg, (void*)args, + (xdrproc_t)xdr_nlm4_testargs); +} + +ssize_t +xdr_to_nlm4_res (struct iovec inmsg, nlm4_res *args) +{ + return xdr_to_generic (inmsg, (void*)args, + (xdrproc_t)xdr_nlm4_res); +} + +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_to_setaclargs (struct iovec inmsg, setaclargs *args) +{ + 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 f828979e7..b8e2c9694 100644 --- a/rpc/xdr/src/msg-nfs3.h +++ b/rpc/xdr/src/msg-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 _MSG_NFS3_H_ @@ -26,7 +17,8 @@ #endif #include "xdr-nfs3.h" - +#include "nlm4-xdr.h" +#include "acl3-xdr.h" #include <sys/types.h> #include <sys/uio.h> @@ -183,4 +175,50 @@ xdr_serialize_mountstat3 (struct iovec outmsg, mountstat3 *m); extern ssize_t xdr_serialize_nfsstat3 (struct iovec outmsg, nfsstat3 *s); + +extern ssize_t +xdr_to_nlm4_testargs (struct iovec inmsg, nlm4_testargs *args); + +extern ssize_t +xdr_serialize_nlm4_testres (struct iovec outmsg, nlm4_testres *res); + +extern ssize_t +xdr_to_nlm4_lockargs (struct iovec inmsg, nlm4_lockargs *args); + +extern ssize_t +xdr_serialize_nlm4_res (struct iovec outmsg, nlm4_res *res); + +extern ssize_t +xdr_to_nlm4_cancelargs (struct iovec inmsg, nlm4_cancargs *args); + +extern ssize_t +xdr_to_nlm4_unlockargs (struct iovec inmsg, nlm4_unlockargs *args); + +extern ssize_t +xdr_to_nlm4_shareargs (struct iovec inmsg, nlm4_shareargs *args); + +extern ssize_t +xdr_serialize_nlm4_shareres (struct iovec outmsg, nlm4_shareres *res); + +extern ssize_t +xdr_serialize_nlm4_testargs (struct iovec outmsg, nlm4_testargs *args); + +extern ssize_t +xdr_to_nlm4_res (struct iovec inmsg, nlm4_res *args); + +extern ssize_t +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.c b/rpc/xdr/src/nlm4-xdr.c new file mode 100644 index 000000000..caba05f58 --- /dev/null +++ b/rpc/xdr/src/nlm4-xdr.c @@ -0,0 +1,245 @@ +/* + 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. +*/ + +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include "nlm4-xdr.h" + +bool_t +xdr_netobj (XDR *xdrs, netobj *objp) +{ + if (!xdr_bytes (xdrs, (char **)&objp->n_bytes, (u_int *) &objp->n_len, MAXNETOBJ_SZ)) + return FALSE; + return TRUE; +} + +bool_t +xdr_fsh_mode (XDR *xdrs, fsh_mode *objp) +{ + if (!xdr_enum (xdrs, (enum_t *) objp)) + return FALSE; + return TRUE; +} + +bool_t +xdr_fsh_access (XDR *xdrs, fsh_access *objp) +{ + if (!xdr_enum (xdrs, (enum_t *) objp)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_stats (XDR *xdrs, nlm4_stats *objp) +{ + if (!xdr_enum (xdrs, (enum_t *) objp)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_stat (XDR *xdrs, nlm4_stat *objp) +{ + if (!xdr_nlm4_stats (xdrs, &objp->stat)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_holder (XDR *xdrs, nlm4_holder *objp) +{ + if (!xdr_bool (xdrs, &objp->exclusive)) + return FALSE; + if (!xdr_uint32_t (xdrs, &objp->svid)) + return FALSE; + if (!xdr_netobj (xdrs, &objp->oh)) + return FALSE; + if (!xdr_uint64_t (xdrs, &objp->l_offset)) + return FALSE; + if (!xdr_uint64_t (xdrs, &objp->l_len)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_lock (XDR *xdrs, nlm4_lock *objp) +{ + if (!xdr_string (xdrs, &objp->caller_name, MAXNAMELEN)) + return FALSE; + if (!xdr_netobj (xdrs, &objp->fh)) + return FALSE; + if (!xdr_netobj (xdrs, &objp->oh)) + return FALSE; + if (!xdr_uint32_t (xdrs, &objp->svid)) + return FALSE; + if (!xdr_uint64_t (xdrs, &objp->l_offset)) + return FALSE; + if (!xdr_uint64_t (xdrs, &objp->l_len)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_share (XDR *xdrs, nlm4_share *objp) +{ + if (!xdr_string (xdrs, &objp->caller_name, MAXNAMELEN)) + return FALSE; + if (!xdr_netobj (xdrs, &objp->fh)) + return FALSE; + if (!xdr_netobj (xdrs, &objp->oh)) + return FALSE; + if (!xdr_fsh_mode (xdrs, &objp->mode)) + return FALSE; + if (!xdr_fsh_access (xdrs, &objp->access)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_testrply (XDR *xdrs, nlm4_testrply *objp) +{ + if (!xdr_nlm4_stats (xdrs, &objp->stat)) + return FALSE; + switch (objp->stat) { + case nlm4_denied: + if (!xdr_nlm4_holder (xdrs, &objp->nlm4_testrply_u.holder)) + return FALSE; + break; + default: + break; + } + return TRUE; +} + +bool_t +xdr_nlm4_testres (XDR *xdrs, nlm4_testres *objp) +{ + if (!xdr_netobj (xdrs, &objp->cookie)) + return FALSE; + if (!xdr_nlm4_testrply (xdrs, &objp->stat)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_testargs (XDR *xdrs, nlm4_testargs *objp) +{ + if (!xdr_netobj (xdrs, &objp->cookie)) + return FALSE; + if (!xdr_bool (xdrs, &objp->exclusive)) + return FALSE; + if (!xdr_nlm4_lock (xdrs, &objp->alock)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_res (XDR *xdrs, nlm4_res *objp) +{ + if (!xdr_netobj (xdrs, &objp->cookie)) + return FALSE; + if (!xdr_nlm4_stat (xdrs, &objp->stat)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_lockargs (XDR *xdrs, nlm4_lockargs *objp) +{ + if (!xdr_netobj (xdrs, &objp->cookie)) + return FALSE; + if (!xdr_bool (xdrs, &objp->block)) + return FALSE; + if (!xdr_bool (xdrs, &objp->exclusive)) + return FALSE; + if (!xdr_nlm4_lock (xdrs, &objp->alock)) + return FALSE; + if (!xdr_bool (xdrs, &objp->reclaim)) + return FALSE; + if (!xdr_int (xdrs, &objp->state)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_cancargs (XDR *xdrs, nlm4_cancargs *objp) +{ + if (!xdr_netobj (xdrs, &objp->cookie)) + return FALSE; + if (!xdr_bool (xdrs, &objp->block)) + return FALSE; + if (!xdr_bool (xdrs, &objp->exclusive)) + return FALSE; + if (!xdr_nlm4_lock (xdrs, &objp->alock)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_unlockargs (XDR *xdrs, nlm4_unlockargs *objp) +{ + if (!xdr_netobj (xdrs, &objp->cookie)) + return FALSE; + if (!xdr_nlm4_lock (xdrs, &objp->alock)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_shareargs (XDR *xdrs, nlm4_shareargs *objp) +{ + if (!xdr_netobj (xdrs, &objp->cookie)) + return FALSE; + if (!xdr_nlm4_share (xdrs, &objp->share)) + return FALSE; + if (!xdr_bool (xdrs, &objp->reclaim)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_shareres (XDR *xdrs, nlm4_shareres *objp) +{ + if (!xdr_netobj (xdrs, &objp->cookie)) + return FALSE; + if (!xdr_nlm4_stats (xdrs, &objp->stat)) + return FALSE; + if (!xdr_int (xdrs, &objp->sequence)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nlm4_freeallargs (XDR *xdrs, nlm4_freeallargs *objp) +{ + if (!xdr_string (xdrs, &objp->name, LM_MAXSTRLEN)) + return FALSE; + if (!xdr_uint32_t (xdrs, &objp->state)) + return FALSE; + return TRUE; +} + + +/* +bool_t +xdr_nlm_sm_status (XDR *xdrs, nlm_sm_status *objp) +{ + if (!xdr_string (xdrs, &objp->mon_name, LM_MAXSTRLEN)) + return FALSE; + if (!xdr_int (xdrs, &objp->state)) + return FALSE; + if (!xdr_opaque (xdrs, objp->priv, 16)) + return FALSE; + return TRUE; +} +*/ diff --git a/rpc/xdr/src/nlm4-xdr.h b/rpc/xdr/src/nlm4-xdr.h new file mode 100644 index 000000000..4391a4790 --- /dev/null +++ b/rpc/xdr/src/nlm4-xdr.h @@ -0,0 +1,258 @@ +/* + 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. +*/ + +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#ifndef _NLM_H_RPCGEN +#define _NLM_H_RPCGEN + +#include <rpc/rpc.h> + +#if defined(__NetBSD__) +#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 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAXNETOBJ_SZ 1024 +#define LM_MAXSTRLEN 1024 +#define MAXNAMELEN 1025 + +#if defined(__NetBSD__) +#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 +#endif + +/* + * The following enums are actually bit encoded for efficient + * boolean algebra.... DON'T change them..... + */ + +enum fsh_mode { + fsm_DN = 0, + fsm_DR = 1, + fsm_DW = 2, + fsm_DRW = 3, +}; +typedef enum fsh_mode fsh_mode; + +enum fsh_access { + fsa_NONE = 0, + fsa_R = 1, + fsa_W = 2, + fsa_RW = 3, +}; +typedef enum fsh_access fsh_access; +/* definitions for NLM version 4 */ + +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, +}; +typedef enum nlm4_stats nlm4_stats; + +struct nlm4_stat { + nlm4_stats stat; +}; +typedef struct nlm4_stat nlm4_stat; + +struct nlm4_holder { + bool_t exclusive; + u_int32_t svid; + netobj oh; + u_int64_t l_offset; + u_int64_t l_len; +}; +typedef struct nlm4_holder nlm4_holder; + +struct nlm4_lock { + char *caller_name; + netobj fh; + netobj oh; + u_int32_t svid; + u_int64_t l_offset; + u_int64_t l_len; +}; +typedef struct nlm4_lock nlm4_lock; + +struct nlm4_share { + char *caller_name; + netobj fh; + netobj oh; + fsh_mode mode; + fsh_access access; +}; +typedef struct nlm4_share nlm4_share; + +struct nlm4_testrply { + nlm4_stats stat; + union { + struct nlm4_holder holder; + } nlm4_testrply_u; +}; +typedef struct nlm4_testrply nlm4_testrply; + +struct nlm4_testres { + netobj cookie; + nlm4_testrply stat; +}; +typedef struct nlm4_testres nlm4_testres; + +struct nlm4_testargs { + netobj cookie; + bool_t exclusive; + struct nlm4_lock alock; +}; +typedef struct nlm4_testargs nlm4_testargs; + +struct nlm4_res { + netobj cookie; + nlm4_stat stat; +}; +typedef struct nlm4_res nlm4_res; + +struct nlm4_lockargs { + netobj cookie; + bool_t block; + bool_t exclusive; + struct nlm4_lock alock; + bool_t reclaim; + int state; +}; +typedef struct nlm4_lockargs nlm4_lockargs; + +struct nlm4_cancargs { + netobj cookie; + bool_t block; + bool_t exclusive; + struct nlm4_lock alock; +}; +typedef struct nlm4_cancargs nlm4_cancargs; + +struct nlm4_unlockargs { + netobj cookie; + struct nlm4_lock alock; +}; +typedef struct nlm4_unlockargs nlm4_unlockargs; + +struct nlm4_shareargs { + netobj cookie; + nlm4_share share; + bool_t reclaim; +}; +typedef struct nlm4_shareargs nlm4_shareargs; + +struct nlm4_shareres { + netobj cookie; + nlm4_stats stat; + int sequence; +}; +typedef struct nlm4_shareres nlm4_shareres; + +struct nlm4_freeallargs { + char *name; + u_int32_t state; +}; +typedef struct nlm4_freeallargs nlm4_freeallargs; + + +#define NLM4_NULL 0 +#define NLM4_TEST 1 +#define NLM4_LOCK 2 +#define NLM4_CANCEL 3 +#define NLM4_UNLOCK 4 +#define NLM4_GRANTED 5 +#define NLM4_TEST_MSG 6 +#define NLM4_LOCK_MSG 7 +#define NLM4_CANCEL_MSG 8 +#define NLM4_UNLOCK_MSG 9 +#define NLM4_GRANTED_MSG 10 +#define NLM4_TEST_RES 11 +#define NLM4_LOCK_RES 12 +#define NLM4_CANCEL_RES 13 +#define NLM4_UNLOCK_RES 14 +#define NLM4_GRANTED_RES 15 +#define NLM4_SM_NOTIFY 16 +#define NLM4_SEVENTEEN 17 +#define NLM4_EIGHTEEN 18 +#define NLM4_NINETEEN 19 +#define NLM4_SHARE 20 +#define NLM4_UNSHARE 21 +#define NLM4_NM_LOCK 22 +#define NLM4_FREE_ALL 23 +#define NLM4_PROC_COUNT 24 + +/* the xdr functions */ + +#if defined(__STDC__) || defined(__cplusplus) +extern bool_t xdr_netobj (XDR *, netobj*); +extern bool_t xdr_fsh_mode (XDR *, fsh_mode*); +extern bool_t xdr_fsh_access (XDR *, fsh_access*); +extern bool_t xdr_nlm4_stats (XDR *, nlm4_stats*); +extern bool_t xdr_nlm4_stat (XDR *, nlm4_stat*); +extern bool_t xdr_nlm4_holder (XDR *, nlm4_holder*); +extern bool_t xdr_nlm4_lock (XDR *, nlm4_lock*); +extern bool_t xdr_nlm4_share (XDR *, nlm4_share*); +extern bool_t xdr_nlm4_testrply (XDR *, nlm4_testrply*); +extern bool_t xdr_nlm4_testres (XDR *, nlm4_testres*); +extern bool_t xdr_nlm4_testargs (XDR *, nlm4_testargs*); +extern bool_t xdr_nlm4_res (XDR *, nlm4_res*); +extern bool_t xdr_nlm4_lockargs (XDR *, nlm4_lockargs*); +extern bool_t xdr_nlm4_cancargs (XDR *, nlm4_cancargs*); +extern bool_t xdr_nlm4_unlockargs (XDR *, nlm4_unlockargs*); +extern bool_t xdr_nlm4_shareargs (XDR *, nlm4_shareargs*); +extern bool_t xdr_nlm4_shareres (XDR *, nlm4_shareres*); +extern bool_t xdr_nlm4_freeallargs (XDR *, nlm4_freeallargs*); + +#else /* K&R C */ +extern bool_t xdr_netobj (); +extern bool_t xdr_fsh_mode (); +extern bool_t xdr_fsh_access (); +extern bool_t xdr_nlm4_stats (); +extern bool_t xdr_nlm4_stat (); +extern bool_t xdr_nlm4_holder (); +extern bool_t xdr_nlm4_lock (); +extern bool_t xdr_nlm4_share (); +extern bool_t xdr_nlm4_testrply (); +extern bool_t xdr_nlm4_testres (); +extern bool_t xdr_nlm4_testargs (); +extern bool_t xdr_nlm4_res (); +extern bool_t xdr_nlm4_lockargs (); +extern bool_t xdr_nlm4_cancargs (); +extern bool_t xdr_nlm4_unlockargs (); +extern bool_t xdr_nlm4_shareargs (); +extern bool_t xdr_nlm4_shareres (); +extern bool_t xdr_nlm4_freeallargs (); + +#endif /* K&R C */ + +#ifdef __cplusplus +} +#endif + +#endif /* !_NLM_H_RPCGEN */ diff --git a/rpc/xdr/src/nlm4.x b/rpc/xdr/src/nlm4.x new file mode 100644 index 000000000..e22ac99f2 --- /dev/null +++ b/rpc/xdr/src/nlm4.x @@ -0,0 +1,154 @@ +/* + 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. +*/ + +/* .x file defined as according to the RFC */ + +const MAXNETOBJ_SZ = 1024; +const LM_MAXSTRLEN = 1024; +const MAXNAMELEN = 1025; + +typedef opaque 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; + netobj oh; + u_int64_t l_offset; + u_int64_t l_len; +}; + +struct nlm4_lock { + string caller_name<LM_MAXSTRLEN>; + netobj fh; + netobj oh; + u_int32_t svid; + u_int64_t l_offset; + u_int64_t l_len; +}; + +struct nlm4_share { + string caller_name<LM_MAXSTRLEN>; + netobj fh; + netobj oh; + fsh_mode mode; + fsh_access access; +}; + +union nlm4_testrply switch (nlm4_stats stat) { + case nlm_denied: + struct nlm4_holder holder; + default: + void; +}; + +struct nlm4_testres { + netobj cookie; + nlm4_testrply stat; +}; + +struct nlm4_testargs { + netobj cookie; + bool exclusive; + struct nlm4_lock alock; +}; + +struct nlm4_res { + netobj cookie; + nlm4_stat stat; +}; + +struct nlm4_lockargs { + netobj cookie; + bool block; + bool exclusive; + struct nlm4_lock alock; + bool reclaim; /* used for recovering locks */ + int state; /* specify local status monitor state */ +}; + +struct nlm4_cancargs { + netobj cookie; + bool block; + bool exclusive; + struct nlm4_lock alock; +}; + +struct nlm4_unlockargs { + netobj cookie; + struct nlm4_lock alock; +}; + +struct nlm4_shareargs { + netobj cookie; + nlm4_share share; + bool reclaim; +}; + +struct nlm4_shareres { + netobj cookie; + nlm4_stats stat; + int sequence; +}; + +struct nlm4_freeallargs { + string name<LM_MAXSTRLEN>; /* client hostname */ + uint32 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 */ +}; diff --git a/rpc/xdr/src/nlmcbk-xdr.c b/rpc/xdr/src/nlmcbk-xdr.c new file mode 100644 index 000000000..3d75acc55 --- /dev/null +++ b/rpc/xdr/src/nlmcbk-xdr.c @@ -0,0 +1,28 @@ +/* + 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. +*/ + +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include "nlmcbk-xdr.h" + +bool_t +xdr_nlm_sm_status (XDR *xdrs, nlm_sm_status *objp) +{ + if (!xdr_string (xdrs, &objp->mon_name, LM_MAXSTRLEN)) + return FALSE; + if (!xdr_int (xdrs, &objp->state)) + return FALSE; + if (!xdr_opaque (xdrs, objp->priv, 16)) + return FALSE; + return TRUE; +} diff --git a/rpc/xdr/src/nlmcbk-xdr.h b/rpc/xdr/src/nlmcbk-xdr.h new file mode 100644 index 000000000..ad8421857 --- /dev/null +++ b/rpc/xdr/src/nlmcbk-xdr.h @@ -0,0 +1,65 @@ +/* + 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. +*/ + +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#ifndef _NLMCBK_H_RPCGEN +#define _NLMCBK_H_RPCGEN + +#include <rpc/rpc.h> + + +#ifdef __cplusplus +extern "C" { +#endif + +#define LM_MAXSTRLEN 1024 + +struct nlm_sm_status { + char *mon_name; + int state; + char priv[16]; +}; +typedef struct nlm_sm_status nlm_sm_status; + +#define NLMCBK_PROGRAM 100021 +#define NLMCBK_V1 1 + +#if defined(__STDC__) || defined(__cplusplus) +#define NLMCBK_SM_NOTIFY 16 +extern void * nlmcbk_sm_notify_0(struct nlm_sm_status *, CLIENT *); +extern void * nlmcbk_sm_notify_0_svc(struct nlm_sm_status *, struct svc_req *); +extern int nlmcbk_program_0_freeresult (SVCXPRT *, xdrproc_t, caddr_t); + +#else /* K&R C */ +#define NLMCBK_SM_NOTIFY 16 +extern void * nlmcbk_sm_notify_0(); +extern void * nlmcbk_sm_notify_0_svc(); +extern int nlmcbk_program_0_freeresult (); +#endif /* K&R C */ + +/* the xdr functions */ + +#if defined(__STDC__) || defined(__cplusplus) +extern bool_t xdr_nlm_sm_status (XDR *, nlm_sm_status*); + +#else /* K&R C */ +extern bool_t xdr_nlm_sm_status (); + +#endif /* K&R C */ + +#ifdef __cplusplus +} +#endif + +#endif /* !_NLMCBK_H_RPCGEN */ diff --git a/rpc/xdr/src/nlmcbk.x b/rpc/xdr/src/nlmcbk.x new file mode 100644 index 000000000..1d3746c9a --- /dev/null +++ b/rpc/xdr/src/nlmcbk.x @@ -0,0 +1,24 @@ +/* + 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. +*/ + +const LM_MAXSTRLEN = 1024; + +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_V0 { + void NLMCBK_SM_NOTIFY(struct nlm_sm_status) = 1; + } = 0; +} = 1238477; + diff --git a/rpc/xdr/src/nsm-xdr.c b/rpc/xdr/src/nsm-xdr.c new file mode 100644 index 000000000..58712737b --- /dev/null +++ b/rpc/xdr/src/nsm-xdr.c @@ -0,0 +1,96 @@ +/* + 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. +*/ + +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include "nsm-xdr.h" + +bool_t +xdr_sm_name (XDR *xdrs, sm_name *objp) +{ + if (!xdr_string (xdrs, &objp->mon_name, SM_MAXSTRLEN)) + return FALSE; + return TRUE; +} + +bool_t +xdr_res (XDR *xdrs, res *objp) +{ + if (!xdr_enum (xdrs, (enum_t *) objp)) + return FALSE; + return TRUE; +} + +bool_t +xdr_sm_stat_res (XDR *xdrs, sm_stat_res *objp) +{ + if (!xdr_res (xdrs, &objp->res_stat)) + return FALSE; + if (!xdr_int (xdrs, &objp->state)) + return FALSE; + return TRUE; +} + +bool_t +xdr_sm_stat (XDR *xdrs, sm_stat *objp) +{ + if (!xdr_int (xdrs, &objp->state)) + return FALSE; + return TRUE; +} + +bool_t +xdr_my_id (XDR *xdrs, my_id *objp) +{ + if (!xdr_string (xdrs, &objp->my_name, SM_MAXSTRLEN)) + return FALSE; + if (!xdr_int (xdrs, &objp->my_prog)) + return FALSE; + if (!xdr_int (xdrs, &objp->my_vers)) + return FALSE; + if (!xdr_int (xdrs, &objp->my_proc)) + return FALSE; + return TRUE; +} + +bool_t +xdr_mon_id (XDR *xdrs, mon_id *objp) +{ + if (!xdr_string (xdrs, &objp->mon_name, SM_MAXSTRLEN)) + return FALSE; + if (!xdr_my_id (xdrs, &objp->my_id)) + return FALSE; + return TRUE; +} + +bool_t +xdr_mon (XDR *xdrs, mon *objp) +{ + if (!xdr_mon_id (xdrs, &objp->mon_id)) + return FALSE; + if (!xdr_opaque (xdrs, objp->priv, 16)) + return FALSE; + return TRUE; +} + +bool_t +xdr_nsm_callback_status (XDR *xdrs, nsm_callback_status *objp) +{ + if (!xdr_string (xdrs, &objp->mon_name, SM_MAXSTRLEN)) + return FALSE; + if (!xdr_int (xdrs, &objp->state)) + return FALSE; + if (!xdr_opaque (xdrs, objp->priv, 16)) + return FALSE; + return TRUE; +} diff --git a/rpc/xdr/src/nsm-xdr.h b/rpc/xdr/src/nsm-xdr.h new file mode 100644 index 000000000..9de642c15 --- /dev/null +++ b/rpc/xdr/src/nsm-xdr.h @@ -0,0 +1,95 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#ifndef _NSM_H_RPCGEN +#define _NSM_H_RPCGEN + +#include <rpc/rpc.h> + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SM_MAXSTRLEN 1024 + +struct sm_name { + char *mon_name; +}; +typedef struct sm_name sm_name; + +enum res { + STAT_SUCC = 0, + STAT_FAIL = 1, +}; +typedef enum res res; + +struct sm_stat_res { + res res_stat; + int state; +}; +typedef struct sm_stat_res sm_stat_res; + +struct sm_stat { + int state; +}; +typedef struct sm_stat sm_stat; + +struct my_id { + char *my_name; + int my_prog; + int my_vers; + int my_proc; +}; +typedef struct my_id my_id; + +struct mon_id { + char *mon_name; + struct my_id my_id; +}; +typedef struct mon_id mon_id; + +struct mon { + struct mon_id mon_id; + char priv[16]; +}; +typedef struct mon mon; + +struct nsm_callback_status { + char *mon_name; + int state; + char priv[16]; +}; +typedef struct nsm_callback_status nsm_callback_status; + +/* the xdr functions */ + +#if defined(__STDC__) || defined(__cplusplus) +extern bool_t xdr_sm_name (XDR *, sm_name*); +extern bool_t xdr_res (XDR *, res*); +extern bool_t xdr_sm_stat_res (XDR *, sm_stat_res*); +extern bool_t xdr_sm_stat (XDR *, sm_stat*); +extern bool_t xdr_my_id (XDR *, my_id*); +extern bool_t xdr_mon_id (XDR *, mon_id*); +extern bool_t xdr_mon (XDR *, mon*); +extern bool_t xdr_nsm_callback_status (XDR *, nsm_callback_status*); + +#else /* K&R C */ +extern bool_t xdr_sm_name (); +extern bool_t xdr_res (); +extern bool_t xdr_sm_stat_res (); +extern bool_t xdr_sm_stat (); +extern bool_t xdr_my_id (); +extern bool_t xdr_mon_id (); +extern bool_t xdr_mon (); +extern bool_t xdr_nsm_callback_status (); + +#endif /* K&R C */ + +#ifdef __cplusplus +} +#endif + +#endif /* !_NSM_H_RPCGEN */ diff --git a/rpc/xdr/src/nsm.x b/rpc/xdr/src/nsm.x new file mode 100644 index 000000000..8f97b1aaa --- /dev/null +++ b/rpc/xdr/src/nsm.x @@ -0,0 +1,47 @@ +/* + * 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 */ + struct my_id my_id; +}; + +struct mon { + struct 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 index 7033213c0..4766122e6 100644 --- a/rpc/xdr/src/portmap-xdr.c +++ b/rpc/xdr/src/portmap-xdr.c @@ -1,20 +1,11 @@ /* - 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-common.h" diff --git a/rpc/xdr/src/portmap-xdr.h b/rpc/xdr/src/portmap-xdr.h index 2686da287..8e4ff4f45 100644 --- a/rpc/xdr/src/portmap-xdr.h +++ b/rpc/xdr/src/portmap-xdr.h @@ -1,20 +1,11 @@ /* - 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-common.h" diff --git a/rpc/xdr/src/rpc-common-xdr.c b/rpc/xdr/src/rpc-common-xdr.c new file mode 100644 index 000000000..6cb48a923 --- /dev/null +++ b/rpc/xdr/src/rpc-common-xdr.c @@ -0,0 +1,223 @@ +/* + 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. +*/ + +#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 "rpc-common-xdr.h" + +bool_t +xdr_auth_glusterfs_parms_v2 (XDR *xdrs, auth_glusterfs_parms_v2 *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->pid)) + return FALSE; + if (!xdr_u_int (xdrs, &objp->uid)) + return FALSE; + if (!xdr_u_int (xdrs, &objp->gid)) + return FALSE; + + } else { + IXDR_PUT_LONG(buf, objp->pid); + IXDR_PUT_U_LONG(buf, objp->uid); + IXDR_PUT_U_LONG(buf, objp->gid); + } + if (!xdr_array (xdrs, (char **)&objp->groups.groups_val, (u_int *) &objp->groups.groups_len, ~0, + sizeof (u_int), (xdrproc_t) xdr_u_int)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->lk_owner.lk_owner_val, (u_int *) &objp->lk_owner.lk_owner_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->pid)) + return FALSE; + if (!xdr_u_int (xdrs, &objp->uid)) + return FALSE; + if (!xdr_u_int (xdrs, &objp->gid)) + return FALSE; + + } else { + objp->pid = IXDR_GET_LONG(buf); + objp->uid = IXDR_GET_U_LONG(buf); + objp->gid = IXDR_GET_U_LONG(buf); + } + if (!xdr_array (xdrs, (char **)&objp->groups.groups_val, (u_int *) &objp->groups.groups_len, ~0, + sizeof (u_int), (xdrproc_t) xdr_u_int)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->lk_owner.lk_owner_val, (u_int *) &objp->lk_owner.lk_owner_len, ~0)) + return FALSE; + return TRUE; + } + + if (!xdr_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_array (xdrs, (char **)&objp->groups.groups_val, (u_int *) &objp->groups.groups_len, ~0, + sizeof (u_int), (xdrproc_t) xdr_u_int)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->lk_owner.lk_owner_val, (u_int *) &objp->lk_owner.lk_owner_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_auth_glusterfs_parms (XDR *xdrs, auth_glusterfs_parms *objp) +{ + register int32_t *buf; + int i; + buf = NULL; + + + 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; +} + +bool_t +xdr_gf_dump_req (XDR *xdrs, gf_dump_req *objp) +{ + register int32_t *buf; + buf = NULL; + + 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) +{ + register int32_t *buf; + buf = NULL; + + 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) +{ + register int32_t *buf; + buf = NULL; + + 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; +} diff --git a/rpc/xdr/src/rpc-common-xdr.h b/rpc/xdr/src/rpc-common-xdr.h new file mode 100644 index 000000000..c43eab315 --- /dev/null +++ b/rpc/xdr/src/rpc-common-xdr.h @@ -0,0 +1,104 @@ +/* + 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. +*/ + +#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 _RPC_COMMON_XDR_H_RPCGEN +#define _RPC_COMMON_XDR_H_RPCGEN + +#include <rpc/rpc.h> + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct auth_glusterfs_parms_v2 { + int pid; + u_int uid; + u_int gid; + struct { + u_int groups_len; + u_int *groups_val; + } groups; + struct { + u_int lk_owner_len; + char *lk_owner_val; + } lk_owner; +}; +typedef struct auth_glusterfs_parms_v2 auth_glusterfs_parms_v2; + +struct auth_glusterfs_parms { + u_quad_t lk_owner; + u_int pid; + u_int uid; + u_int gid; + u_int ngrps; + u_int groups[16]; +}; +typedef struct auth_glusterfs_parms auth_glusterfs_parms; + +struct gf_dump_req { + u_quad_t gfs_id; +}; +typedef struct gf_dump_req gf_dump_req; + +struct gf_prog_detail { + char *progname; + u_quad_t prognum; + u_quad_t progver; + struct gf_prog_detail *next; +}; +typedef struct gf_prog_detail gf_prog_detail; + +struct gf_dump_rsp { + u_quad_t gfs_id; + int op_ret; + int op_errno; + struct gf_prog_detail *prog; +}; +typedef struct gf_dump_rsp gf_dump_rsp; + +/* the xdr functions */ + +#if defined(__STDC__) || defined(__cplusplus) +extern bool_t xdr_auth_glusterfs_parms_v2 (XDR *, auth_glusterfs_parms_v2*); +extern bool_t xdr_auth_glusterfs_parms (XDR *, auth_glusterfs_parms*); +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*); + +#else /* K&R C */ +extern bool_t xdr_auth_glusterfs_parms_v2 (); +extern bool_t xdr_auth_glusterfs_parms (); +extern bool_t xdr_gf_dump_req (); +extern bool_t xdr_gf_prog_detail (); +extern bool_t xdr_gf_dump_rsp (); + +#endif /* K&R C */ + +#ifdef __cplusplus +} +#endif + +#endif /* !_RPC_COMMON_XDR_H_RPCGEN */ diff --git a/rpc/xdr/src/rpc-common-xdr.x b/rpc/xdr/src/rpc-common-xdr.x new file mode 100644 index 000000000..ca28f38b5 --- /dev/null +++ b/rpc/xdr/src/rpc-common-xdr.x @@ -0,0 +1,39 @@ +/* This file has definition of few XDR structures which are + * not captured in any section specific file */ + +struct auth_glusterfs_parms_v2 { + int pid; + unsigned int uid; + unsigned int gid; + unsigned int groups<>; + opaque lk_owner<>; +}; + +struct auth_glusterfs_parms { + unsigned hyper lk_owner; + unsigned int pid; + unsigned int uid; + unsigned int gid; + unsigned int ngrps; + unsigned groups[16]; +}; + +struct gf_dump_req { + unsigned hyper gfs_id; +}; + + +struct gf_prog_detail { + string progname<>; + unsigned hyper prognum; + unsigned hyper progver; + struct gf_prog_detail *next; +}; + + +struct gf_dump_rsp { + unsigned hyper gfs_id; + int op_ret; + int op_errno; + struct gf_prog_detail *prog; +}; diff --git a/rpc/xdr/src/xdr-generic.c b/rpc/xdr/src/xdr-generic.c index 5d5cf7197..58d1ee77e 100644 --- a/rpc/xdr/src/xdr-generic.c +++ b/rpc/xdr/src/xdr-generic.c @@ -1,20 +1,11 @@ /* - 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. */ @@ -127,7 +118,7 @@ xdr_vector_round_up (struct iovec *vec, int vcount, uint32_t count) round_count = xdr_length_round_up (count, 1048576); round_count -= count; - if (round_count == 0) + if (round_count == 0 || vcount <= 0) return; vec[vcount-1].iov_len += round_count; diff --git a/rpc/xdr/src/xdr-generic.h b/rpc/xdr/src/xdr-generic.h index 24054e11c..bb3759bbe 100644 --- a/rpc/xdr/src/xdr-generic.h +++ b/rpc/xdr/src/xdr-generic.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 _XDR_GENERIC_H #define _XDR_GENERIC_H diff --git a/rpc/xdr/src/xdr-nfs3.c b/rpc/xdr/src/xdr-nfs3.c index 2b2b1049c..a497e9f54 100644 --- a/rpc/xdr/src/xdr-nfs3.c +++ b/rpc/xdr/src/xdr-nfs3.c @@ -1,24 +1,16 @@ /* - 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" +#include "xdr-common.h" #if GF_DARWIN_HOST_OS #define xdr_u_quad_t xdr_u_int64_t @@ -1847,12 +1839,10 @@ xdr_free_exports_list (struct exportnode *first) while (first) { elist = first->ex_next; - if (first->ex_dir) - GF_FREE (first->ex_dir); + GF_FREE (first->ex_dir); if (first->ex_groups) { - if (first->ex_groups->gr_name) - GF_FREE (first->ex_groups->gr_name); + GF_FREE (first->ex_groups->gr_name); GF_FREE (first->ex_groups); } diff --git a/rpc/xdr/src/xdr-nfs3.h b/rpc/xdr/src/xdr-nfs3.h index 9e5ccd186..6f6b0e1f9 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 @@ -1048,8 +1039,10 @@ typedef struct exportnode exportnode; #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 */ |
