summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-02-05 20:23:20 +0530
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-02-07 13:29:05 +0530
commit23b12455796ec453ca35e94ab49e7629d7f9aced (patch)
tree0d69ce51ad68b56a753fa8e4a021bec2a3cc5f4a /daemon
parentbbcbaf494ad406ceea4f0175b91cf67966d32a27 (diff)
gluster-block: migrate build to libtoolz and create rpm
Till now we had simple makefile for checking dependencies and building. Using libtoolz will give more control on dependency checks and flexibility. This patch also introduce rpm build feature. Compiling: $ ./autogen.sh $ ./configure $ make -j $ make install Building RPMS: $ make rpms Running: $ systemctl start gluster-blockd.service Using CLI: $ gluster-block help Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Diffstat (limited to 'daemon')
-rw-r--r--daemon/Makefile.am12
-rw-r--r--daemon/gluster-blockd.c120
2 files changed, 132 insertions, 0 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
new file mode 100644
index 0000000..0b04f74
--- /dev/null
+++ b/daemon/Makefile.am
@@ -0,0 +1,12 @@
+sbin_PROGRAMS = gluster-blockd
+
+gluster_blockd_SOURCES = gluster-blockd.c
+
+gluster_blockd_CFLAGS = -I$(top_srcdir)/utils/ -I$(top_srcdir)/rpc
+
+gluster_blockd_LDADD = $(top_srcdir)/rpc/libgbxdr.la $(top_srcdir)/utils/libgb.la
+
+DISTCLEANFILES = Makefile.in
+
+CLEANFILES = *~
+
diff --git a/daemon/gluster-blockd.c b/daemon/gluster-blockd.c
new file mode 100644
index 0000000..f998d97
--- /dev/null
+++ b/daemon/gluster-blockd.c
@@ -0,0 +1,120 @@
+/*
+ Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
+ This file is part of gluster-block.
+
+ 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 <unistd.h>
+# include <pthread.h>
+# include <rpc/pmap_clnt.h>
+
+# include "block.h"
+
+
+
+void *
+glusterBlockCliThreadProc (void *vargp)
+{
+ register SVCXPRT *transp;
+ struct sockaddr_un saun;
+ int sockfd, len;
+
+
+ if ((sockfd = socket(AF_UNIX, SOCK_STREAM, IPPROTO_IP)) < 0) {
+ perror("server: socket");
+ exit(1);
+ }
+
+ 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 = 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 *
+glusterBlockServerThreadProc(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 (GLUSTER_BLOCK, GLUSTER_BLOCK_VERS, tcp).");
+ exit(1);
+ }
+
+ svc_run ();
+
+ return NULL;
+}
+
+
+int
+main (int argc, char **argv)
+{
+ pthread_t cli_thread;
+ pthread_t server_thread;
+
+
+ pmap_unset (GLUSTER_BLOCK_CLI, GLUSTER_BLOCK_CLI_VERS);
+ pmap_unset (GLUSTER_BLOCK, GLUSTER_BLOCK_VERS);
+
+ pthread_create(&cli_thread, NULL, glusterBlockCliThreadProc , NULL);
+ pthread_create(&server_thread, NULL, glusterBlockServerThreadProc , NULL);
+
+ pthread_join(cli_thread, NULL);
+ pthread_join(server_thread, NULL);
+
+
+ fprintf (stderr, "%s", "svc_run returned");
+ exit (0);
+ /* NOTREACHED */
+}