summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore27
-rw-r--r--Makefile69
-rw-r--r--Makefile.am40
-rwxr-xr-xautogen.sh82
-rw-r--r--cli/Makefile.am11
-rw-r--r--cli/gluster-block.c (renamed from gluster-block.c)25
-rw-r--r--configure.ac75
-rw-r--r--daemon/Makefile.am12
-rw-r--r--daemon/gluster-blockd.c120
-rw-r--r--gluster-block.spec.in42
-rw-r--r--rpc/Makefile.am15
-rw-r--r--rpc/block.h21
-rw-r--r--rpc/block_svc.c114
-rw-r--r--rpc/block_svc_routines.c (renamed from gluster-blockd.c)23
-rw-r--r--rpc/glfs-operations.c (renamed from glfs-operations.c)0
-rw-r--r--rpc/glfs-operations.h (renamed from glfs-operations.h)2
-rw-r--r--rpc/rpcl/block.x (renamed from rpc/block.x)0
-rw-r--r--systemd/Makefile.am10
-rw-r--r--systemd/gluster-blockd.service.in (renamed from systemd/gluster-blockd.service)2
-rw-r--r--utils/Makefile.am11
-rw-r--r--utils/common.c (renamed from common.c)1
-rw-r--r--utils/common.h (renamed from common.h)1
-rw-r--r--utils/utils.c (renamed from utils.c)4
-rw-r--r--utils/utils.h (renamed from utils.h)2
24 files changed, 484 insertions, 225 deletions
diff --git a/.gitignore b/.gitignore
index 93d006a..c4f04a6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,29 @@
-gluster-block
-gluster-blockd
+ar-lib
+aclocal.m4
+autom4te.cache
+build
+config.*
+configure
+depcomp
+install-sh
+ltmain.sh
+Makefile
+Makefile.in
+missing
+.deps
+compile
+libtool
+m4/
+*.libs
*.o
+*.lo
+*.la
+stamp-h1
+.deps
+*.spec
+*.service
+*.tar.gz
+
cscope.*
tags
TAGS
diff --git a/Makefile b/Makefile
deleted file mode 100644
index cb9e5a2..0000000
--- a/Makefile
+++ /dev/null
@@ -1,69 +0,0 @@
-########################################################################
-# #
-# 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. #
-# #
-########################################################################
-
-
-CC = gcc
-
-COMMON = utils.o common.o rpc/block_xdr.o
-
-CLIENT = gluster-block
-CDEP = rpc/block_clnt.o gluster-block.o
-
-SERVER = gluster-blockd
-SDEP = glfs-operations.o rpc/block_svc.o rpc/block_clnt.o gluster-blockd.o
-
-CFLAGS = -g -ggdb -Wall -lpthread
-LIBS := $(shell pkg-config --libs uuid glusterfs-api)
-
-DEPS_LIST = gcc tcmu-runner targetcli
-
-PREFIX ?= /usr/local/sbin
-MKDIR_P = mkdir -p
-INSTALL = /usr/bin/install -c
-INSTALLDATA = /usr/bin/install -c -m 644
-SYSTEMD_DIR = /usr/lib/systemd/system
-LOGDIR = /var/log/gluster-block
-
-
-all: $(SERVER) $(CLIENT)
-
-$(CLIENT): $(CDEP) $(COMMON)
- @$(MKDIR_P) $(LOGDIR)$@
- $(CC) $(CFLAGS) $(LIBS) $^ -o $@
-
-$(SERVER): $(SDEP) $(COMMON)
- $(CC) $(CFLAGS) $(LIBS) $^ -o $@
-
-glfs-operations.o: glfs-operations.c glfs-operations.h
- $(foreach x, $(DEPS_LIST),\
- $(if $(shell which $x), \
- $(info -- found $x),\
- $(else, \
- $(error "No $x in PATH, install '$x' and continue ..."))))
- $(CC) $(CFLAGS) -c $< -o $@
-
-$(CLIENT).o: $(CLIENT).c
- $(CC) $(CFLAGS) -c $< -o $@
-
-install: $(SERVER) $(CLIENT)
- $(INSTALL) $^ $(PREFIX)/
- @if [ -d $(SYSTEMD_DIR) ]; then \
- $(MKDIR_P) $(SYSTEMD_DIR); \
- $(INSTALLDATA) systemd/$(SERVER).service $(SYSTEMD_DIR)/; \
- fi
-
-.PHONY: clean distclean
-clean distclean:
- $(RM) ./*.o ./rpc/*.o $(CLIENT) $(SERVER)
-
-uninstall:
- $(RM) $(PREFIX)/$(CLIENT) $(PREFIX)/$(SERVER) $(SYSTEMD_DIR)/$(SERVER).service
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..a07333b
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,40 @@
+ACLOCAL_AMFLAGS = -I m4
+
+SUBDIRS = rpc utils cli daemon systemd
+
+DISTCLEANFILES = Makefile.in gluster-block.spec autom4te.cache
+
+CLEANFILES = *~ gluster-block.spec
+
+EXTRA_DIST = autogen.sh README.md
+
+rpms: prep
+ QA_RPATHS=17 rpmbuild --define '_topdir $(abs_top_builddir)/build/rpmbuild' \
+ -ba $(abs_top_builddir)/build/rpmbuild/SPECS/gluster-block.spec
+
+prep: dist
+ mkdir -p build/rpmbuild && cd build/rpmbuild \
+ && mkdir BUILD SPECS RPMS SRPM SOURCES && cd ../..
+ rm -rf rpmbuild/SOURCES/*
+ cp *.tar.gz build/rpmbuild/SOURCES
+ cp gluster-block.spec build/rpmbuild/SPECS
+
+uninstall-local:
+ cd $(DESTDIR)$(bindir) && rm -f gluster-block gluster-blockd
+
+clean-local:
+ rm -rf build rpmbuild *.rpm
+
+gitclean: clean distclean
+ find . -path gnulib -prune -name Makefile.in -exec rm -f {} \;
+ find . -path gnulib -prune -name Makefile -exec rm -f {} \;
+ rm -f aclocal.m4 compile config.* configure depcomp install-sh libtool \
+ ltmain.sh missing stamp-h1
+ rm -rf autom4te.cache ar-lib *.tar.gz m4
+
+dist-hook: gen-ChangeLog
+
+.PHONY: gen-ChangeLog
+
+gen-ChangeLog:
+ (cd $(srcdir) && git diff && echo ===== git log ==== && git log) > $(distdir)/ChangeLog
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..4bc5af7
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+
+set -e
+
+chmod +x $0
+
+case "$(uname)" in
+ Darwin)
+ LIBTOOLIZE=${LIBTOOLIZE:-glibtoolize}
+ ;;
+ *)
+ LIBTOOLIZE=${LIBTOOLIZE:-libtoolize}
+ ;;
+esac
+AUTORECONF=${AUTORECONF:-autoreconf}
+ACLOCAL=${ACLOCAL:-aclocal}
+AUTOCONF=${AUTOCONF:-autoconf}
+AUTOHEADER=${AUTOHEADER:-autoheader}
+AUTOMAKE=${AUTOMAKE:-automake}
+
+# Check we have all tools installed
+check_command() {
+ command -v "${1}" > /dev/null 2>&1 || {
+ >&2 echo "autogen.sh: could not find \`$1'. \`$1' is required to run autogen.sh."
+ exit 1
+ }
+}
+check_command "$LIBTOOLIZE"
+check_command "$AUTORECONF"
+check_command "$ACLOCAL"
+check_command "$AUTOCONF"
+check_command "$AUTOHEADER"
+check_command "$AUTOMAKE"
+
+# Absence of pkg-config or misconfiguration can make some odd error
+# messages, we check if it is installed correctly. See:
+# https://blogs.oracle.com/mandy/entry/autoconf_weirdness
+#
+# We cannot just check for pkg-config command, we need to check for
+# PKG_* macros. The pkg-config command can be defined in ./configure,
+# we cannot tell anything when not present.
+check_pkg_config() {
+ grep -q '^AC_DEFUN.*PKG_CHECK_MODULES' aclocal.m4 || {
+ cat <<EOF >&2
+autogen.sh: could not find PKG_CHECK_MODULES macro.
+
+ Either pkg-config is not installed on your system or
+ \`pkg.m4' is missing or not found by aclocal.
+
+ If \`pkg.m4' is installed at an unusual location, re-run
+ \`autogen.sh' by setting \`ACLOCAL_FLAGS':
+
+ ACLOCAL_FLAGS="-I <prefix>/share/aclocal" ./autogen.sh
+
+EOF
+ exit 1
+ }
+}
+
+
+echo "autogen.sh: start libtoolize to get ltmain.sh"
+${LIBTOOLIZE} --copy --force
+echo "autogen.sh: reconfigure with autoreconf"
+${AUTORECONF} -vif -I m4 || {
+ echo "autogen.sh: autoreconf has failed ($?), let's do it manually"
+ for dir in $PWD *; do
+ [ -d "$dir" ] || continue
+ [ -f "$dir"/configure.ac ] || [ -f "$dir"/configure.in ] || continue
+ echo "autogen.sh: configure `basename $dir`"
+ (cd "$dir" && ${ACLOCAL} -I m4 ${ACLOCAL_FLAGS})
+ (cd "$dir" && check_pkg_config)
+ (cd "$dir" && ${LIBTOOLIZE} --automake --copy --force)
+ (cd "$dir" && ${ACLOCAL} -I m4 ${ACLOCAL_FLAGS})
+ (cd "$dir" && ${AUTOCONF} --force)
+ (cd "$dir" && ${AUTOHEADER})
+ (cd "$dir" && ${AUTOMAKE} --add-missing --copy --force-missing)
+ done
+}
+
+echo "autogen.sh: for the next step, run ./configure"
+
+exit 0
diff --git a/cli/Makefile.am b/cli/Makefile.am
new file mode 100644
index 0000000..4d908a9
--- /dev/null
+++ b/cli/Makefile.am
@@ -0,0 +1,11 @@
+sbin_PROGRAMS = gluster-block
+
+gluster_block_SOURCES = gluster-block.c
+
+gluster_block_LDADD = $(top_srcdir)/rpc/libgbxdr.la $(top_srcdir)/utils/libgb.la
+
+gluster_block_CFLAGS = -I$(top_srcdir)/utils/ -I$(top_srcdir)/rpc
+
+DISTCLEANFILES = Makefile.in
+
+CLEANFILES = *~
diff --git a/gluster-block.c b/cli/gluster-block.c
index b9d21c2..0605ef7 100644
--- a/gluster-block.c
+++ b/cli/gluster-block.c
@@ -9,32 +9,17 @@
*/
-# define _GNU_SOURCE /* See feature_test_macros(7) */
-
-# include <unistd.h>
-# include <getopt.h>
-
# include "common.h"
-# include "rpc/block.h"
-
-
-# define LIST "list"
-# define CREATE "create"
-# define DELETE "delete"
-# define INFO "info"
-# define MODIFY "modify"
-# define BLOCKHOST "block-host"
-# define VOLUME "volume"
-# define HELP "help"
+# include "block.h"
-typedef enum operations {
+typedef enum clioperations {
CREATE_CLI = 1,
LIST_CLI = 2,
INFO_CLI = 3,
DELETE_CLI = 4
-} operations;
+} clioperations;
static int
@@ -174,7 +159,6 @@ glusterBlockCreate(int argcount, char **options)
return -1;
}
-
switch (opt) {
case GB_CLI_CREATE_VOLUME:
strcpy(cobj.volume, options[optind++]);
@@ -290,6 +274,7 @@ glusterBlockDelete(int argcount, char **options)
char *out = NULL;
int ret = -1;
+
if(argcount <= optind) {
MSG("%s\n", "Insufficient options for delete");
return -1;
@@ -331,6 +316,7 @@ glusterBlockInfo(int argcount, char **options)
char *out = NULL;
int ret = -1;
+
if(argcount <= optind) {
MSG("%s\n", "Insufficient options for info");
return -1;
@@ -369,6 +355,7 @@ glusterBlockParseArgs(int count, char **options)
int ret = 0;
size_t opt = 0;
+
opt = glusterBlockCLIOptEnumParse(options[1]);
if (!opt || opt >= GB_CLI_OPT_MAX) {
MSG("unknow option: %s\n", options[1]);
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..e18b3e2
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,75 @@
+dnl Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
+dnl This file is part of gluster-block.
+dnl
+dnl This file is licensed to you under your choice of the GNU Lesser
+dnl General Public License, version 3 or any later version (LGPLv3 or
+dnl later), or the GNU General Public License, version 2 (GPLv2), in all
+dnl cases as published by the Free Software Foundation.
+
+
+AC_PREREQ([2.69])
+AC_INIT([glusterfs-block],
+ m4_esyscmd(echo -n `git describe --always --tags`),
+ [pkalever@redhat.com],,
+ [https://github.com/pkalever/gluster-block.git])
+
+AC_SUBST([PACKAGE_RELEASE], 1)
+
+AC_ARG_WITH(systemddir,
+ [ --with-systemddir=DIR systemd service files in DIR @<:@PREFIX/lib/systemd/system@:>@],
+ [systemddir=$withval],
+ [systemddir='${prefix}/lib/systemd/system'])
+AC_SUBST(systemddir)
+AM_CONDITIONAL([USE_SYSTEMD], test [ -d '/usr/lib/systemd/system' ])
+
+AM_INIT_AUTOMAKE([-Wall -Werror foreign nostdinc silent-rules])
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_FILES([gluster-block.spec
+ Makefile
+ rpc/Makefile
+ cli/Makefile
+ daemon/Makefile
+ utils/Makefile
+ systemd/Makefile
+ systemd/gluster-blockd.service])
+AC_CONFIG_MACRO_DIR([m4])
+m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+
+AM_MAINTAINER_MODE
+
+# Configure libtool
+LT_INIT
+
+# Checks for programs.
+AC_PROG_CC
+
+# Checks for header files.
+AC_CHECK_HEADERS([memory.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h])
+
+# Checks for libraries.
+AC_CHECK_LIB([gfapi], [glfs_init])
+PKG_CHECK_MODULES([GLFS], [glusterfs-api >= 3])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_CHECK_HEADER_STDBOOL
+AC_TYPE_SIZE_T
+AC_TYPE_SSIZE_T
+
+# Checks for library functions.
+AC_FUNC_STRTOD
+AC_CHECK_FUNCS([bzero gethostbyname memset socket strchr strdup strerror])
+AC_OUTPUT
+
+cat <<EOF
+
+------------------ Summary ------------------
+ $PACKAGE_NAME version $PACKAGE_VERSION
+ Prefix.........: $prefix
+ C Compiler.....: $CC $CFLAGS $CPPFLAGS
+ Linker.........: $LD $MORE_LDFLAGS $LDFLAGS $LIBS
+---------------------------------------------
+
+Check the above options and compile with:
+ ${MAKE-make}
+
+EOF
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 */
+}
diff --git a/gluster-block.spec.in b/gluster-block.spec.in
new file mode 100644
index 0000000..c0a2ea9
--- /dev/null
+++ b/gluster-block.spec.in
@@ -0,0 +1,42 @@
+
+Summary: Gluster block storage utility
+Name: @PACKAGE_NAME@
+Version: @PACKAGE_VERSION@
+Vendor: Gluster Community
+Release: @PACKAGE_RELEASE@
+License: GPLv2 or LGPLv3+
+Group: System Environment/Base
+BuildRequires: glusterfs-api-devel >= 3.6.0
+BuildRequires: help2man >= 1.36
+Requires: glusterfs-api >= 3.6.0
+%if ( 0%{?_with_systemd:1} )
+BuildRequires: systemd
+%endif
+URL: http://www.gluster.org/docs/index.php/GlusterFS
+Source0: @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz
+
+%description
+gluster-block is a CLI utility, which aims at making gluster backed
+block storage creation and maintenance as simple as possible.
+
+%prep
+rm -rf %{_topdir}/BUILD/*
+
+%setup
+
+%build
+%configure
+make
+
+%install
+make DESTDIR=${RPM_BUILD_ROOT} install
+
+%clean
+rm -rf ${RPM_BUILD_ROOT}
+
+%files
+%{_sbindir}/gluster-block
+%{_sbindir}/gluster-blockd
+%if ( 0%{?_with_systemd:1} )
+%{_unitdir}/gluster-blockd.service
+%endif
diff --git a/rpc/Makefile.am b/rpc/Makefile.am
new file mode 100644
index 0000000..20ed49d
--- /dev/null
+++ b/rpc/Makefile.am
@@ -0,0 +1,15 @@
+noinst_LTLIBRARIES = libgbxdr.la
+
+libgbxdr_la_SOURCES = block_clnt.c block_xdr.c block_svc.c block_svc_routines.c glfs-operations.c
+
+noinst_HEADERS = block.h glfs-operations.h
+
+libgbxdr_la_CFLAGS = -I$(top_srcdir)/utils/
+
+libgbxdr_la_LIBADD = -lgfapi
+
+libgbxdr_ladir = $(includedir)/gluster-block/rpc
+
+DISTCLEANFILES = Makefile.in
+
+CLEANFILES = *~
diff --git a/rpc/block.h b/rpc/block.h
index 03d0ec4..7122632 100644
--- a/rpc/block.h
+++ b/rpc/block.h
@@ -69,6 +69,27 @@ struct blockResponse {
};
typedef struct blockResponse blockResponse;
+typedef struct blockServerDef {
+ size_t nhosts;
+ char **hosts;
+} blockServerDef;
+typedef blockServerDef *blockServerDefPtr;
+
+typedef enum operations {
+ CREATE_SRV = 1,
+ DELETE_SRV = 2,
+} operations;
+
+void
+gluster_block_cli_1(struct svc_req *rqstp, register SVCXPRT *transp);
+
+void
+gluster_block_1(struct svc_req *rqstp, register SVCXPRT *transp);
+
+
+int
+glusterBlockCallRPC_1(char *host, void *cobj, operations opt, char **out);
+
#define GLUSTER_BLOCK_CLI 212153113
#define GLUSTER_BLOCK_CLI_VERS 1
diff --git a/rpc/block_svc.c b/rpc/block_svc.c
index 3722d51..8c94d30 100644
--- a/rpc/block_svc.c
+++ b/rpc/block_svc.c
@@ -4,23 +4,12 @@
*/
#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>
-#include <sys/socket.h>
-#include <netinet/in.h>
#ifndef SIG_PF
#define SIG_PF void(*)(int)
#endif
-
-
-static void
+void
gluster_block_cli_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
union {
@@ -82,7 +71,7 @@ gluster_block_cli_1(struct svc_req *rqstp, register SVCXPRT *transp)
return;
}
-static void
+void
gluster_block_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
union {
@@ -129,102 +118,3 @@ gluster_block_1(struct svc_req *rqstp, register SVCXPRT *transp)
}
return;
}
-
-void *
-cli_thread_proc (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 *
-server_thread_proc(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, cli_thread_proc , NULL);
- pthread_create(&server_thread, NULL, server_thread_proc , NULL);
-
- pthread_join(cli_thread, NULL);
- pthread_join(server_thread, NULL);
-
-
- fprintf (stderr, "%s", "svc_run returned");
- exit (0);
- /* NOTREACHED */
-}
diff --git a/gluster-blockd.c b/rpc/block_svc_routines.c
index 9d1ace8..91ad630 100644
--- a/gluster-blockd.c
+++ b/rpc/block_svc_routines.c
@@ -9,17 +9,12 @@
*/
-# define _GNU_SOURCE /* See feature_test_macros(7) */
+# include "common.h"
+# include "glfs-operations.h"
-# include <stdio.h>
# include <netdb.h>
-# include <sys/socket.h>
# include <uuid/uuid.h>
-# include "rpc/block.h"
-# include "common.h"
-# include "glfs-operations.h"
-
# define UUID_BUF_SIZE 38
@@ -37,19 +32,7 @@
-typedef struct blockServerDef {
- size_t nhosts;
- char **hosts;
-} blockServerDef;
-typedef blockServerDef *blockServerDefPtr;
-
-typedef enum operations {
- CREATE_SRV = 1,
- DELETE_SRV = 2,
-} operations;
-
-
-static int
+int
glusterBlockCallRPC_1(char *host, void *cobj,
operations opt, char **out)
{
diff --git a/glfs-operations.c b/rpc/glfs-operations.c
index 9712f64..9712f64 100644
--- a/glfs-operations.c
+++ b/rpc/glfs-operations.c
diff --git a/glfs-operations.h b/rpc/glfs-operations.h
index 214a71c..8ba12f5 100644
--- a/glfs-operations.h
+++ b/rpc/glfs-operations.h
@@ -19,7 +19,7 @@
# include <glusterfs/api/glfs.h>
-# include "rpc/block.h"
+# include "block.h"
diff --git a/rpc/block.x b/rpc/rpcl/block.x
index 0bc988c..0bc988c 100644
--- a/rpc/block.x
+++ b/rpc/rpcl/block.x
diff --git a/systemd/Makefile.am b/systemd/Makefile.am
new file mode 100644
index 0000000..605e1f8
--- /dev/null
+++ b/systemd/Makefile.am
@@ -0,0 +1,10 @@
+DISTCLEANFILES = Makefile.in gluster-blockd.service
+
+CLEANFILES = *~ gluster-blockd.service
+
+EXTRA_DIST = gluster-blockd.service.in
+
+if USE_SYSTEMD
+# systemddir is already defined through configure.ac
+systemd_DATA = gluster-blockd.service
+endif
diff --git a/systemd/gluster-blockd.service b/systemd/gluster-blockd.service.in
index d1fc67c..a92c10c 100644
--- a/systemd/gluster-blockd.service
+++ b/systemd/gluster-blockd.service.in
@@ -5,7 +5,7 @@ After=rpcbind.service target.service tcmu-runner.service
[Service]
Type=simple
-ExecStart=/usr/local/sbin/gluster-blockd
+ExecStart=@prefix@/sbin/gluster-blockd
KillMode=process
[Install]
diff --git a/utils/Makefile.am b/utils/Makefile.am
new file mode 100644
index 0000000..461c73c
--- /dev/null
+++ b/utils/Makefile.am
@@ -0,0 +1,11 @@
+noinst_LTLIBRARIES = libgb.la
+
+libgb_la_SOURCES = common.c utils.c
+
+noinst_HEADERS = common.h utils.h
+
+libgb_ladir = $(includedir)/gluster-block/utils
+
+DISTCLEANFILES = Makefile.in
+
+CLEANFILES = *~
diff --git a/common.c b/utils/common.c
index 2efc127..dfa6bc8 100644
--- a/common.c
+++ b/utils/common.c
@@ -20,6 +20,7 @@ glusterBlockCreateParseSize(char *value)
char *tmp;
ssize_t sizef;
+
if (!value)
return -1;
diff --git a/common.h b/utils/common.h
index c230df8..6b0983d 100644
--- a/common.h
+++ b/utils/common.h
@@ -21,7 +21,6 @@
# define GFAPI_LOG_LEVEL 7
-
ssize_t glusterBlockCreateParseSize(char *value);
# endif /* _COMMON_H */
diff --git a/utils.c b/utils/utils.c
index 059fb6b..a43a347 100644
--- a/utils.c
+++ b/utils/utils.c
@@ -32,6 +32,7 @@ glusterBlockCLIOptEnumParse(const char *opt)
return i;
}
+
int
glusterBlockCLICreateOptEnumParse(const char *opt)
{
@@ -52,6 +53,7 @@ glusterBlockCLICreateOptEnumParse(const char *opt)
return i;
}
+
int
glusterBlockCLICommonOptEnumParse(const char *opt)
{
@@ -72,6 +74,7 @@ glusterBlockCLICommonOptEnumParse(const char *opt)
return i;
}
+
int
blockMetaKeyEnumParse(const char *opt)
{
@@ -147,6 +150,7 @@ gbFree(void *ptrptr)
{
int save_errno = errno;
+
if(*(void**)ptrptr == NULL) {
return;
}
diff --git a/utils.h b/utils/utils.h
index 4cc1347..f9763eb 100644
--- a/utils.h
+++ b/utils/utils.h
@@ -12,7 +12,9 @@
# ifndef _UTILS_H
# define _UTILS_H 1
+# define _GNU_SOURCE /* See feature_test_macros(7) */
# include <stdio.h>
+
# include <stdlib.h>
# include <stdbool.h>
# include <string.h>