summaryrefslogtreecommitdiffstats
path: root/rpc/block_svc.c
diff options
context:
space:
mode:
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-01-20 12:13:37 +0530
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-01-30 19:31:50 +0530
commit683b6ba3f17a9bbf876c66f5d4b7a9d573d8853f (patch)
treea2bf7cbcda416818d663613284b29e16b2b533c3 /rpc/block_svc.c
parent4ef14866295c1328a11f9a06cfc3bc1db9b1e7b6 (diff)
gluster-block: listen on unix and inet
from now We basically have 2 RPC connections, 1. Between gluster block CLI and local gluster-blockd This connection is basically UNIX/local netid ,listening on /var/run/gluster-blockd.socket file. The CLI always Send/Receive the commands to/from the local gluster-blockd via local rpc. 2. Between gluster-blockd's, i.e local (to cli) gluster-blockd and the gluster-blockd's running on remote(blockhost) This is the tcp connection. The rpc requests are listening on 24006 Also from now gluster-blockd is multi threaded (As of now 2 threads) Lets consider the Create Request to understand what each thread solves Thread1 (THE CLI THREAD) * Listening on local RPC * Generate the GBID (UUID) and create the entry with name GBID in the given volume with a requested size. * And Send the Configuration requests to remote hosts, waits for the replies (HINt: after this point Read Thread2 and come back) * Return to CLI. Thread 2 (THE SERVER THREAD) * Listens on 24006 * On Receiving an event, read the structure. * Executes the required "targetcli bla bla bla" command locally * Fills the command exitcode and the output in the RPC reply structure and send reply Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Diffstat (limited to 'rpc/block_svc.c')
-rw-r--r--rpc/block_svc.c159
1 files changed, 129 insertions, 30 deletions
diff --git a/rpc/block_svc.c b/rpc/block_svc.c
index 144b7e1..4c054f5 100644
--- a/rpc/block_svc.c
+++ b/rpc/block_svc.c
@@ -6,6 +6,8 @@
#include "block.h"
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
+#include <pthread.h>
#include <rpc/pmap_clnt.h>
#include <string.h>
#include <memory.h>
@@ -16,11 +18,16 @@
#define SIG_PF void(*)(int)
#endif
+
+
+pthread_t p_thread1, p_thread2;
+
+
static void
-gluster_block_1(struct svc_req *rqstp, register SVCXPRT *transp)
+gluster_block_cli_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
union {
- char *block_exec_1_arg;
+ blockCreateCli block_create_cli_1_arg;
} argument;
char *result;
xdrproc_t _xdr_argument, _xdr_result;
@@ -31,10 +38,10 @@ gluster_block_1(struct svc_req *rqstp, register SVCXPRT *transp)
(void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
return;
- case BLOCK_EXEC:
- _xdr_argument = (xdrproc_t) xdr_wrapstring;
- _xdr_result = (xdrproc_t) xdr_blockTrans;
- local = (char *(*)(char *, struct svc_req *)) block_exec_1_svc;
+ case BLOCK_CREATE_CLI:
+ _xdr_argument = (xdrproc_t) xdr_blockCreateCli;
+ _xdr_result = (xdrproc_t) xdr_blockResponse;
+ local = (char *(*)(char *, struct svc_req *)) block_create_cli_1_svc;
break;
default:
@@ -57,46 +64,138 @@ gluster_block_1(struct svc_req *rqstp, register SVCXPRT *transp)
return;
}
-int
-main (int argc, char **argv)
+static void
+gluster_block_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
- register SVCXPRT *transp;
- struct sockaddr_in addr;
- int sockfd;
+ union {
+ blockCreate block_create_1_arg;
+ } argument;
+ char *result;
+ xdrproc_t _xdr_argument, _xdr_result;
+ char *(*local)(char *, struct svc_req *);
- pmap_unset (GLUSTER_BLOCK, GLUSTER_BLOCK_VERS);
+ switch (rqstp->rq_proc) {
+ case NULLPROC:
+ (void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
+ return;
- if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
- fprintf (stderr, "%s", "socket failed");
- }
+ case BLOCK_CREATE:
+ _xdr_argument = (xdrproc_t) xdr_blockCreate;
+ _xdr_result = (xdrproc_t) xdr_blockResponse;
+ local = (char *(*)(char *, struct svc_req *)) block_create_1_svc;
+ break;
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = INADDR_ANY;
- addr.sin_port = htons(24009);
+ default:
+ svcerr_noproc (transp);
+ return;
+ }
+ memset ((char *)&argument, 0, sizeof (argument));
+ if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
+ svcerr_decode (transp);
+ return;
+ }
+ result = (*local)((char *)&argument, rqstp);
+ if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
+ svcerr_systemerr (transp);
+ }
+ if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
+ fprintf (stderr, "%s", "unable to free arguments");
+ exit (1);
+ }
+ return;
+}
+
+void *
+cli_thread(void *vargp)
+{
+ register SVCXPRT *transp;
+ struct sockaddr_un saun;
+ int sockfd, len;
- if (bind(sockfd, (struct sockaddr *)&addr, sizeof (addr)) < 0) {
- fprintf (stderr, "%s", "bind failed");
+ if ((sockfd = socket(AF_UNIX, SOCK_STREAM, IPPROTO_IP)) < 0) {
+ perror("server: socket");
+ exit(1);
}
- if (listen(sockfd, 10) < 0) {
- fprintf (stderr, "%s", "server: listen failed");
+ saun.sun_family = AF_UNIX;
+ strcpy(saun.sun_path, ADDRESS);
+
+ unlink(ADDRESS);
+ len = sizeof(saun.sun_family) + strlen(saun.sun_path);
+
+ if (bind(sockfd, (struct sockaddr *) &saun, len) < 0) {
+ perror("server: bind");
exit(1);
}
- transp = svctcp_create(sockfd, 0, 0);
- if (transp == NULL) {
- fprintf (stderr, "%s", "cannot create tcp service");
+ transp = svcunix_create(sockfd, 0, 0, ADDRESS);
+ if (transp == NULL) {
+ fprintf (stderr, "%s", "cannot create tcp service");
+ exit(1);
+ }
+
+ if (!svc_register(transp, GLUSTER_BLOCK_CLI, GLUSTER_BLOCK_CLI_VERS, gluster_block_cli_1, IPPROTO_IP)) {
+ fprintf (stderr, "%s", "unable to register (GLUSTER_BLOCK_CLI, GLUSTER_BLOCK_CLI_VERS, unix|local).");
exit(1);
}
+ svc_run ();
+
+ return NULL;
+}
+
+void *
+server_thread(void *vargp)
+{
+ register SVCXPRT *transp;
+ struct sockaddr_in sain;
+ int sockfd;
+
+ if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+ perror("server: socket");
+ exit(1);
+ }
+
+ sain.sin_family = AF_INET;
+ sain.sin_addr.s_addr = INADDR_ANY;
+ sain.sin_port = htons(24006);
+
+ if (bind(sockfd, (struct sockaddr *) &sain, sizeof (sain)) < 0) {
+ perror("server: bind");
+ exit(1);
+ }
+
+ transp = svctcp_create(sockfd, 0, 0);
+ if (transp == NULL) {
+ fprintf (stderr, "%s", "cannot create tcp service");
+ exit(1);
+ }
+
if (!svc_register(transp, GLUSTER_BLOCK, GLUSTER_BLOCK_VERS, gluster_block_1, IPPROTO_TCP)) {
- fprintf (stderr, "%s", "unable to register (BLOCK_PROG, GLUSTER_BLOCK_VERS, tcp).");
+ fprintf (stderr, "%s", "unable to register (GLUSTER_BLOCK, GLUSTER_BLOCK_VERS, tcp).");
exit(1);
}
- svc_run ();
+ svc_run ();
+
+ return NULL;
+}
+
+
+int
+main (int argc, char **argv)
+{
+ pmap_unset (GLUSTER_BLOCK_CLI, GLUSTER_BLOCK_CLI_VERS);
+ pmap_unset (GLUSTER_BLOCK, GLUSTER_BLOCK_VERS);
+
+ pthread_create(&p_thread1, NULL, cli_thread, NULL);
+ pthread_create(&p_thread2, NULL, server_thread, NULL);
+
+ pthread_join(p_thread1, NULL);
+ pthread_join(p_thread2, NULL);
+
- fprintf (stderr, "%s", "svc_run returned");
- exit (1);
- /* NOTREACHED */
+ fprintf (stderr, "%s", "svc_run returned");
+ exit (0);
+ /* NOTREACHED */
}