summaryrefslogtreecommitdiffstats
path: root/rpc/rpc-lib/src/rpc-clnt.h
diff options
context:
space:
mode:
Diffstat (limited to 'rpc/rpc-lib/src/rpc-clnt.h')
-rw-r--r--rpc/rpc-lib/src/rpc-clnt.h150
1 files changed, 104 insertions, 46 deletions
diff --git a/rpc/rpc-lib/src/rpc-clnt.h b/rpc/rpc-lib/src/rpc-clnt.h
index b9d39b332..584963ad0 100644
--- a/rpc/rpc-lib/src/rpc-clnt.h
+++ b/rpc/rpc-lib/src/rpc-clnt.h
@@ -1,24 +1,15 @@
/*
- Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
This file is part of GlusterFS.
- GlusterFS is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- GlusterFS is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see
- <http://www.gnu.org/licenses/>.
+ This file is licensed to you under your choice of the GNU Lesser
+ General Public License, version 3 or any later version (LGPLv3 or
+ later), or the GNU General Public License, version 2 (GPLv2), in all
+ cases as published by the Free Software Foundation.
*/
-#ifndef _RPC_CLNT_H
-#define _RPC_CLNT_H
+#ifndef __RPC_CLNT_H
+#define __RPC_CLNT_H
#include "stack.h"
#include "rpc-transport.h"
@@ -31,7 +22,10 @@ typedef enum {
RPC_CLNT_MSG
} rpc_clnt_event_t;
-#define AUTH_GLUSTERFS 5
+
+#define SFRAME_GET_PROGNUM(sframe) (sframe->rpcreq->prog->prognum)
+#define SFRAME_GET_PROGVER(sframe) (sframe->rpcreq->prog->progver)
+#define SFRAME_GET_PROCNUM(sframe) (sframe->rpcreq->procnum)
struct xptr_clnt;
struct rpc_req;
@@ -65,6 +59,7 @@ struct saved_frame {
struct saved_frames {
int64_t count;
struct saved_frame sf;
+ struct saved_frame lk_sf;
};
@@ -83,28 +78,71 @@ typedef struct rpc_clnt_program {
int numproc;
} rpc_clnt_prog_t;
-#define RPC_MAX_AUTH_BYTES 400
+typedef int (*rpcclnt_cb_fn) (struct rpc_clnt *rpc, void *mydata, void *data);
+
+/* The descriptor for each procedure/actor that runs
+ * over the RPC service.
+ */
+typedef struct rpcclnt_actor_desc {
+ char procname[32];
+ int procnum;
+ rpcclnt_cb_fn actor;
+} rpcclnt_cb_actor_t;
+
+/* Describes a program and its version along with the function pointers
+ * required to handle the procedures/actors of each program/version.
+ * Never changed ever by any thread so no need for a lock.
+ */
+typedef struct rpcclnt_cb_program {
+ char progname[32];
+ int prognum;
+ int progver;
+ rpcclnt_cb_actor_t *actors; /* All procedure handlers */
+ int numactors; /* Num actors in actor array */
+
+ /* Program specific state handed to actors */
+ void *private;
+
+
+ /* list member to link to list of registered services with rpc_clnt */
+ struct list_head program;
+
+ /* Needed for passing back in cb_actor */
+ void *mydata;
+} rpcclnt_cb_program_t;
+
+
+
typedef struct rpc_auth_data {
- int flavour;
- int datalen;
- char authdata[RPC_MAX_AUTH_BYTES];
+ int flavour;
+ int datalen;
+ char authdata[GF_MAX_AUTH_BYTES];
} rpc_auth_data_t;
+
+struct rpc_clnt_config {
+ int rpc_timeout;
+ int remote_port;
+ char * remote_host;
+};
+
+
#define rpc_auth_flavour(au) ((au).flavour)
struct rpc_clnt_connection {
- pthread_mutex_t lock;
- rpc_transport_t *trans;
- gf_timer_t *reconnect;
- gf_timer_t *timer;
- gf_timer_t *ping_timer;
- struct rpc_clnt *rpc_clnt;
- char connected;
- struct saved_frames *saved_frames;
- int32_t frame_timeout;
- struct timeval last_sent;
- struct timeval last_received;
- int32_t ping_started;
+ pthread_mutex_t lock;
+ rpc_transport_t *trans;
+ struct rpc_clnt_config config;
+ gf_timer_t *reconnect;
+ gf_timer_t *timer;
+ gf_timer_t *ping_timer;
+ struct rpc_clnt *rpc_clnt;
+ char connected;
+ struct saved_frames *saved_frames;
+ int32_t frame_timeout;
+ struct timeval last_sent;
+ struct timeval last_received;
+ int32_t ping_started;
};
typedef struct rpc_clnt_connection rpc_clnt_connection_t;
@@ -125,31 +163,32 @@ 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;
void *mydata;
uint64_t xid;
+ /* list of cb programs registered with rpc-clnt */
+ struct list_head programs;
+
/* Memory pool for rpc_req_t */
struct mem_pool *reqpool;
struct mem_pool *saved_frames_pool;
glusterfs_ctx_t *ctx;
-};
+ int refcount;
+ int auth_null;
+ char disabled;
+} rpc_clnt_t;
-struct rpc_clnt_config {
- int rpc_timeout;
- int remote_port;
- char * remote_host;
-};
+struct rpc_clnt *rpc_clnt_new (dict_t *options, glusterfs_ctx_t *ctx,
+ char *name, uint32_t reqpool_size);
-struct rpc_clnt * rpc_clnt_init (struct rpc_clnt_config *config,
- dict_t *options, glusterfs_ctx_t *ctx,
- char *name);
+int rpc_clnt_start (struct rpc_clnt *rpc);
int rpc_clnt_register_notify (struct rpc_clnt *rpc, rpc_clnt_notify_t fn,
void *mydata);
@@ -168,7 +207,7 @@ int rpc_clnt_register_notify (struct rpc_clnt *rpc, rpc_clnt_notify_t fn,
* also be filled with pointer to buffer to hold header and length
* of the header.
*/
-
+
int rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog,
int procnum, fop_cbk_fn_t cbkfn,
struct iovec *proghdr, int proghdrcount,
@@ -177,12 +216,31 @@ int rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog,
int rsphdr_count, struct iovec *rsp_payload,
int rsp_payload_count, struct iobref *rsp_iobref);
-void rpc_clnt_destroy (struct rpc_clnt *rpc);
+struct rpc_clnt *
+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);
+
+/* All users of RPC services should use this API to register their
+ * procedure handlers.
+ */
+int rpcclnt_cbk_program_register (struct rpc_clnt *svc,
+ rpcclnt_cb_program_t *program, void *mydata);
+
+void
+rpc_clnt_disable (struct rpc_clnt *rpc);
+
+char
+rpc_clnt_is_disabled (struct rpc_clnt *rpc);
+
#endif /* !_RPC_CLNT_H */