summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--Makefile6
-rw-r--r--glfs-operations.c12
-rw-r--r--glfs-operations.h6
-rw-r--r--gluster-block.c104
-rw-r--r--gluster-blockd.c133
-rw-r--r--rpc/block.h64
-rw-r--r--rpc/block.x31
-rw-r--r--rpc/block_clnt.c27
-rw-r--r--rpc/block_svc.c159
-rw-r--r--rpc/block_xdr.c45
10 files changed, 485 insertions, 102 deletions
diff --git a/Makefile b/Makefile
index 5bce7b2..e713ee7 100644
--- a/Makefile
+++ b/Makefile
@@ -16,9 +16,9 @@ CLIENT = gluster-block
CDEP = glfs-operations.o utils.o rpc/block_clnt.c rpc/block_xdr.c gluster-block.o
SERVER = gluster-blockd
-SDEP = rpc/block_svc.o rpc/block_xdr.o gluster-blockd.o utils.o
+SDEP = rpc/block_svc.o rpc/block_clnt.c rpc/block_xdr.o gluster-blockd.o utils.o glfs-operations.o
-CFLAGS = -g -ggdb -Wall
+CFLAGS = -g -ggdb -Wall -lpthread
LIBS := $(shell pkg-config --libs uuid glusterfs-api)
DEPS_LIST = gcc tcmu-runner targetcli
@@ -38,7 +38,7 @@ $(CLIENT): $(CDEP)
$(CC) $(CFLAGS) $(LIBS) $^ -o $@
$(SERVER): $(SDEP)
- $(CC) $(CFLAGS) $^ -o $@
+ $(CC) $(CFLAGS) $(LIBS) $^ -o $@
glfs-operations.o: glfs-operations.c glfs-operations.h
$(foreach x, $(DEPS_LIST),\
diff --git a/glfs-operations.c b/glfs-operations.c
index 3a6bd32..fecc315 100644
--- a/glfs-operations.c
+++ b/glfs-operations.c
@@ -18,7 +18,7 @@
int
-glusterBlockCreateEntry(glusterBlockDefPtr blk)
+glusterBlockCreateEntry(blockCreateCli *blk, char *gbid)
{
struct glfs *glfs;
struct glfs_fd *fd;
@@ -30,7 +30,7 @@ glusterBlockCreateEntry(glusterBlockDefPtr blk)
return -1;
}
- ret = glfs_set_volfile_server(glfs, "tcp", blk->host, 24007);
+ ret = glfs_set_volfile_server(glfs, "tcp", blk->volfileserver, 24007);
if (ret) {
ERROR("%s", "glfs_set_volfile_server: failed");
goto out;
@@ -48,7 +48,7 @@ glusterBlockCreateEntry(glusterBlockDefPtr blk)
goto out;
}
- fd = glfs_creat(glfs, blk->filename,
+ fd = glfs_creat(glfs, gbid,
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR);
if (!fd) {
@@ -74,7 +74,7 @@ glusterBlockCreateEntry(glusterBlockDefPtr blk)
int
-glusterBlockDeleteEntry(glusterBlockDefPtr blk)
+glusterBlockDeleteEntry(blockCreateCli *blk, char *gbid)
{
struct glfs *glfs;
int ret = 0;
@@ -85,7 +85,7 @@ glusterBlockDeleteEntry(glusterBlockDefPtr blk)
return -1;
}
- ret = glfs_set_volfile_server(glfs, "tcp", blk->host, 24007);
+ ret = glfs_set_volfile_server(glfs, "tcp", blk->volfileserver, 24007);
if (ret) {
ERROR("%s", "glfs_set_volfile_server: failed");
goto out;
@@ -103,7 +103,7 @@ glusterBlockDeleteEntry(glusterBlockDefPtr blk)
goto out;
}
- ret = glfs_unlink(glfs, blk->filename);
+ ret = glfs_unlink(glfs, gbid);
if (ret) {
ERROR("%s", "glfs_unlink: failed");
goto out;
diff --git a/glfs-operations.h b/glfs-operations.h
index dd3992b..1a1208d 100644
--- a/glfs-operations.h
+++ b/glfs-operations.h
@@ -19,6 +19,8 @@
# include <glusterfs/api/glfs.h>
+# include "rpc/block.h"
+
typedef struct glusterBlockDef {
@@ -31,8 +33,8 @@ typedef struct glusterBlockDef {
typedef glusterBlockDef *glusterBlockDefPtr;
-int glusterBlockCreateEntry(glusterBlockDefPtr blk);
+int glusterBlockCreateEntry(blockCreateCli *blk, char *gbid);
-int glusterBlockDeleteEntry(glusterBlockDefPtr blk);
+int glusterBlockDeleteEntry(blockCreateCli *blk, char *gbid);
#endif /* _GLFS_OPERATIONS_H */
diff --git a/gluster-block.c b/gluster-block.c
index 9a2564e..e6dc0fc 100644
--- a/gluster-block.c
+++ b/gluster-block.c
@@ -12,6 +12,7 @@
# define _GNU_SOURCE /* See feature_test_macros(7) */
# include <string.h>
+# include <unistd.h>
# include <getopt.h>
# include <uuid/uuid.h>
@@ -53,21 +54,40 @@ typedef blockServerDef *blockServerDefPtr;
static void
-gluster_block_1(char *host, char *cmd, blockTrans **reply)
+gluster_block_cli_1(blockCreateCli cobj, blockResponse **reply)
{
CLIENT *clnt;
+ int sockfd, len;
+ struct sockaddr_un saun;
- clnt = clnt_create (host, GLUSTER_BLOCK, GLUSTER_BLOCK_VERS, "tcp");
+ if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ perror("client: socket");
+ exit(1);
+ }
+
+ saun.sun_family = AF_UNIX;
+ strcpy(saun.sun_path, ADDRESS);
+
+ len = sizeof(saun.sun_family) + strlen(saun.sun_path);
+
+ if (connect(sockfd, (struct sockaddr *) &saun, len) < 0) {
+ perror("client: connect");
+ exit(1);
+ }
+
+ clnt = clntunix_create ((struct sockaddr_un *) &saun, GLUSTER_BLOCK_CLI, GLUSTER_BLOCK_CLI_VERS, &sockfd, 0, 0);
if (clnt == NULL) {
- clnt_pcreateerror (host);
+ clnt_pcreateerror ("localhost");
exit (1);
}
- *reply = block_exec_1(&cmd, clnt);
+ *reply = block_create_cli_1(&cobj, clnt);
if (*reply == NULL) {
- clnt_perror (clnt, "call failed");
+ clnt_perror (clnt, "call failed gluster-block");
}
+ printf("%s\n", (*reply)->out);
+
clnt_destroy (clnt);
}
@@ -249,16 +269,20 @@ glusterBlockCreate(int count, char **options, char *name)
{
int c;
int ret = 0;
- char *cmd = NULL;
- char *exec = NULL;
- char *iqn = NULL;
- char *blkServers = NULL;
- blockServerDefPtr list;
- uuid_t out;
- glusterBlockDefPtr blk;
- blockTrans *reply;
- size_t i;
+// char *cmd = NULL;
+// char *exec = NULL;
+// char *iqn = NULL;
+// char *blkServers = NULL;
+// blockServerDefPtr list;
+// uuid_t out;
+// glusterBlockDefPtr blk;
+ blockResponse *reply;
+ static blockCreateCli cobj;
+// size_t i;
+/*
+ if (GB_ALLOC(&cobj) < 0)
+ return -1;
if (GB_ALLOC(blk) < 0)
return -1;
@@ -266,6 +290,7 @@ glusterBlockCreate(int count, char **options, char *name)
uuid_generate(out);
uuid_unparse(out, blk->filename);
+*/
if (!name) {
ERROR("%s", "Insufficient arguments supplied for"
@@ -274,6 +299,8 @@ glusterBlockCreate(int count, char **options, char *name)
goto out;
}
+ strcpy(cobj.block_name, name);
+
while (1) {
static const struct option long_options[] = {
{"volume", required_argument, 0, 'v'},
@@ -294,22 +321,23 @@ glusterBlockCreate(int count, char **options, char *name)
switch (c) {
case 'b':
- blkServers = optarg;
+ //blkServers = optarg;
+ GB_STRDUP(cobj.block_hosts, optarg);
break;
case 'v':
- GB_STRDUP(blk->volume, optarg);
+ strcpy(cobj.volume, optarg);
ret++;
break;
case 'h':
- GB_STRDUP(blk->host, optarg);
+ strcpy(cobj.volfileserver, optarg);
ret++;
break;
case 's':
- blk->size = glusterBlockCreateParseSize(optarg);
- if (blk->size < 0) {
+ cobj.size = glusterBlockCreateParseSize(optarg);
+ if (cobj.size < 0) {
ERROR("%s", "failed while parsing size");
ret = -1;
goto out;
@@ -326,13 +354,13 @@ glusterBlockCreate(int count, char **options, char *name)
break;
}
}
-
+/*
if (blkServers) {
list = blockServerParse(blkServers);
} else {
list = blockServerParse("localhost");
}
-
+*/
/* Print any remaining command line arguments (not options). */
if (optind < count) {
ERROR("%s", "non-option ARGV-elements: ");
@@ -351,6 +379,13 @@ glusterBlockCreate(int count, char **options, char *name)
goto out;
}
+ gluster_block_cli_1(cobj, &reply);
+
+
+
+
+
+/*
ret = glusterBlockCreateEntry(blk);
if (ret) {
ERROR("%s volume: %s host: %s",
@@ -363,7 +398,6 @@ glusterBlockCreate(int count, char **options, char *name)
blk->filename, blk->filename) < 0)
goto out;
- /* Created user-backed storage object LUN size 2147483648. */
for (i = 0; i < list->nhosts; i++) {
MSG("[OnHost: %s]", list->hosts[i]);
gluster_block_1(list->hosts[i], cmd, &reply);
@@ -429,8 +463,10 @@ glusterBlockCreate(int count, char **options, char *name)
GB_FREE(iqn);
glusterBlockDefFree(blk);
blockServerDefFree(list);
+*/
- return ret;
+ out:
+ return 0;
}
@@ -527,12 +563,12 @@ getCfgstring(char* name, char *blkServer)
char *cmd;
char *exec;
char *buf = NULL;
- blockTrans *reply;
+ blockResponse *reply = NULL;
asprintf(&cmd, "%s %s", TARGETCLI_GLFS, BACKEND_CFGSTR);
asprintf(&exec, cmd, name);
- gluster_block_1(blkServer, exec, &reply);
+ //gluster_block_1(blkServer, exec, &reply);
if (!reply || reply->exit) {
ERROR("%s on host: %s",
FAILED_GATHERING_CFGSTR, blkServer);
@@ -559,7 +595,7 @@ glusterBlockList(blockServerDefPtr blkServers)
char *size;
char *cfgstring = NULL;
glusterBlockDefPtr blk = NULL;
- blockTrans *reply;
+ blockResponse *reply = NULL;
MSG("%s", "BlockName Volname Host Size Status");
@@ -567,7 +603,7 @@ glusterBlockList(blockServerDefPtr blkServers)
for (i = 0; i < blkServers->nhosts; i++) {
MSG("[OnHost: %s]", blkServers->hosts[i]);
- gluster_block_1(blkServers->hosts[i], cmd, &reply);
+ //gluster_block_1(blkServers->hosts[i], cmd, &reply);
if (!reply || reply->exit) {
ERROR("%s on host: %s",
FAILED_LIST_BACKEND, blkServers->hosts[i]);
@@ -632,7 +668,7 @@ glusterBlockDelete(char* name, blockServerDefPtr blkServers)
char *cfgstring = NULL;
char *iqn = NULL;
glusterBlockDefPtr blk = NULL;
- blockTrans *reply;
+ blockResponse *reply = NULL;
asprintf(&cmd, "%s %s %s", TARGETCLI_GLFS, DELETE, name);
@@ -647,7 +683,7 @@ glusterBlockDelete(char* name, blockServerDefPtr blkServers)
goto fail;
}
- gluster_block_1(blkServers->hosts[i], cmd, &reply);
+ //gluster_block_1(blkServers->hosts[i], cmd, &reply);
if (!reply || reply->exit) {
ERROR("%s on host: %s",
FAILED_DELETING_BACKEND, blkServers->hosts[i]);
@@ -669,7 +705,7 @@ glusterBlockDelete(char* name, blockServerDefPtr blkServers)
asprintf(&iqn, "%s%s", IQN_PREFIX, blk->filename);
asprintf(&exec, "%s %s %s", TARGETCLI_ISCSI, DELETE, iqn);
- gluster_block_1(blkServers->hosts[i], exec, &reply);
+ //gluster_block_1(blkServers->hosts[i], exec, &reply);
if (!reply || reply->exit) {
ERROR("%s on host: %s",
FAILED_DELETING_IQN, blkServers->hosts[i]);
@@ -680,7 +716,7 @@ glusterBlockDelete(char* name, blockServerDefPtr blkServers)
GB_FREE(exec);
GB_FREE(iqn);
- gluster_block_1(blkServers->hosts[i], TARGETCLI_SAVE, &reply);
+ //gluster_block_1(blkServers->hosts[i], TARGETCLI_SAVE, &reply);
if (!reply || reply->exit) {
ERROR("%s on host: %s",
FAILED_SAVEING_CONFIG, blkServers->hosts[i]);
@@ -691,7 +727,7 @@ glusterBlockDelete(char* name, blockServerDefPtr blkServers)
putchar('\n');
}
- ret = glusterBlockDeleteEntry(blk);
+ //ret = glusterBlockDeleteEntry(blk);
if (ret) {
ERROR("%s volume: %s host: %s",
FAILED_DELETING_FILE, blk->volume, blk->host);
@@ -713,13 +749,13 @@ glusterBlockInfo(char* name, blockServerDefPtr blkServers)
size_t i;
int ret = 0;
char *cmd;
- blockTrans *reply;
+ blockResponse *reply = NULL;
asprintf(&cmd, "%s/%s %s", TARGETCLI_GLFS, name, INFO);
for (i = 0; i < blkServers->nhosts; i++) {
MSG("[OnHost: %s]", blkServers->hosts[i]);
- gluster_block_1(blkServers->hosts[i], cmd, &reply);
+ //gluster_block_1(blkServers->hosts[i], cmd, &reply);
if (!reply || reply->exit) {
ret = -1;
ERROR("%s on host: %s",
diff --git a/gluster-blockd.c b/gluster-blockd.c
index 18506ac..6b73c8b 100644
--- a/gluster-blockd.c
+++ b/gluster-blockd.c
@@ -1,15 +1,135 @@
#define _GNU_SOURCE /* See feature_test_macros(7) */
-#include <stdio.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <sys/socket.h>
+# include <uuid/uuid.h>
#include "rpc/block.h"
#include "utils.h"
+#include "glfs-operations.h"
+# define UUID_BUF_SIZE 256
+# define CFG_STRING_SIZE 256
-blockTrans *
-block_exec_1_svc(char **cmd, struct svc_req *rqstp)
+# define LIST "list"
+# define CREATE "create"
+# define DELETE "delete"
+# define INFO "info"
+# define MODIFY "modify"
+# define BLOCKHOST "block-host"
+# define HELP "help"
+
+# define GLFS_PATH "/backstores/user:glfs"
+# define TARGETCLI_GLFS "targetcli "GLFS_PATH
+# define TARGETCLI_ISCSI "targetcli /iscsi"
+# define TARGETCLI_SAVE "targetcli / saveconfig"
+# define ATTRIBUTES "generate_node_acls=1 demo_mode_write_protect=0"
+# define BACKEND_CFGSTR "ls | grep ' %s ' | cut -d'[' -f2 | cut -d']' -f1"
+# define LUNS_LIST "ls | grep -v user:glfs | cut -d'-' -f2 | cut -d' ' -f2"
+
+# define IQN_PREFIX "iqn.2016-12.org.gluster-block:"
+
+# define MSERVER_DELIMITER ","
+
+blockResponse *
+block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
+{
+ //FILE *fp;
+ CLIENT *clnt;
+ int sockfd;
+ struct hostent *server;
+ struct sockaddr_in sain;
+ int ret;
+ uuid_t out;
+ static blockCreate *cobj;
+ static blockResponse *reply;
+ char *gbid = CALLOC(UUID_BUF_SIZE);
+
+ uuid_generate(out);
+ uuid_unparse(out,gbid);
+
+ ret = glusterBlockCreateEntry(blk, gbid);
+ if (ret) {
+ ERROR("%s volume: %s host: %s",
+ FAILED_CREATING_FILE, blk->volume, blk->volfileserver);
+ goto out;
+ }
+
+ if(GB_ALLOC(cobj) < 0)
+ goto out;
+
+ strcpy(cobj->volume, blk->volume);
+ strcpy(cobj->volfileserver, blk->volfileserver);
+ strcpy(cobj->block_name, blk->block_name);
+ cobj->size = blk->size;
+ strcpy(cobj->gbid, gbid);
+
+ //for
+
+ if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+ perror("gluster-blockd: socket");
+ exit(1);
+ }
+ server = gethostbyname(blk->block_hosts);
+ if (server == NULL) {
+ fprintf(stderr,"ERROR, no such host\n");
+ exit(0);
+ }
+
+ bzero((char *) &sain, sizeof(sain));
+ sain.sin_family = AF_INET;
+ bcopy((char *)server->h_addr, (char *)&sain.sin_addr.s_addr, server->h_length);
+ sain.sin_port = htons(24006);
+
+ if (connect(sockfd, (struct sockaddr *) &sain, sizeof(sain)) < 0) {
+ perror("gluster-blockd: connect");
+ exit(1);
+ }
+
+ clnt = clnttcp_create ((struct sockaddr_in *) &sain, GLUSTER_BLOCK, GLUSTER_BLOCK_VERS, &sockfd, 0, 0);
+ if (clnt == NULL) {
+ clnt_pcreateerror ("localhost");
+ exit (1);
+ }
+
+ reply = block_create_1(cobj, clnt);
+ if (reply == NULL) {
+ clnt_perror (clnt, "call failed gluster-blockd");
+ }
+
+ clnt_destroy (clnt);
+
+out:
+ return reply;
+}
+
+
+blockResponse *
+block_create_1_svc(blockCreate *blk, struct svc_req *rqstp)
{
FILE *fp;
- static blockTrans *obj;
+ char *backstore = NULL;
+ char *iqn = NULL;
+ char *lun = NULL;
+ char *attr = NULL;
+ char *exec = NULL;
+ blockResponse *obj = NULL;
+
+ asprintf(&backstore, "%s %s %s %zu %s@%s/%s %s", TARGETCLI_GLFS,
+ CREATE, blk->block_name, blk->size, blk->volume, blk->volfileserver,
+ blk->gbid, blk->gbid);
+
+ asprintf(&iqn, "%s %s %s%s", TARGETCLI_ISCSI, CREATE, IQN_PREFIX, blk->gbid);
+
+
+ asprintf(&lun, "%s/%s%s/tpg1/luns %s %s/%s",
+ TARGETCLI_ISCSI, IQN_PREFIX, blk->gbid, CREATE, GLFS_PATH, blk->block_name);
+
+ asprintf(&attr, "%s/%s%s/tpg1 set attribute %s",
+ TARGETCLI_ISCSI, IQN_PREFIX, blk->gbid, ATTRIBUTES);
+
+
+ asprintf(&exec, "%s && %s && %s && %s && %s", backstore, iqn, lun, attr, TARGETCLI_SAVE);
if(GB_ALLOC(obj) < 0)
return NULL;
@@ -19,9 +139,9 @@ block_exec_1_svc(char **cmd, struct svc_req *rqstp)
return NULL;
}
- fp = popen(*cmd, "r");
+ fp = popen(exec, "r");
if (fp != NULL) {
- size_t newLen = fread(obj->out, sizeof(char), 4996, fp);
+ size_t newLen = fread(obj->out, sizeof(char), 4096, fp);
if (ferror( fp ) != 0) {
ERROR("%s", "Error reading command output\n");
} else {
@@ -32,3 +152,4 @@ block_exec_1_svc(char **cmd, struct svc_req *rqstp)
return obj;
}
+
diff --git a/rpc/block.h b/rpc/block.h
index 54315b7..d939057 100644
--- a/rpc/block.h
+++ b/rpc/block.h
@@ -8,41 +8,85 @@
#include <rpc/rpc.h>
+#define ADDRESS "/var/run/gluster-block.socket"
#ifdef __cplusplus
extern "C" {
#endif
-struct blockTrans {
+struct blockCreate {
+ char volume[255];
+ char volfileserver[255];
+ char gbid[127];
+ u_quad_t size;
+ char block_name[255];
+};
+typedef struct blockCreate blockCreate;
+
+struct blockCreateCli {
+ char volume[255];
+ char volfileserver[255];
+ u_quad_t size;
+ char block_name[255];
+ char *block_hosts;
+};
+typedef struct blockCreateCli blockCreateCli;
+
+struct blockResponse {
int exit;
char *out;
+ u_quad_t offset;
+ struct {
+ u_int xdata_len;
+ char *xdata_val;
+ } xdata;
};
-typedef struct blockTrans blockTrans;
+typedef struct blockResponse blockResponse;
+
+#define GLUSTER_BLOCK_CLI 212153113
+#define GLUSTER_BLOCK_CLI_VERS 1
+
+#if defined(__STDC__) || defined(__cplusplus)
+#define BLOCK_CREATE_CLI 1
+extern blockResponse * block_create_cli_1(blockCreateCli *, CLIENT *);
+extern blockResponse * block_create_cli_1_svc(blockCreateCli *, struct svc_req *);
+extern int gluster_block_cli_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
+
+#else /* K&R C */
+#define BLOCK_CREATE_CLI 1
+extern blockResponse * block_create_cli_1();
+extern blockResponse * block_create_cli_1_svc();
+extern int gluster_block_cli_1_freeresult ();
+#endif /* K&R C */
#define GLUSTER_BLOCK 21215311
#define GLUSTER_BLOCK_VERS 1
#if defined(__STDC__) || defined(__cplusplus)
-#define BLOCK_EXEC 1
-extern blockTrans * block_exec_1(char **, CLIENT *);
-extern blockTrans * block_exec_1_svc(char **, struct svc_req *);
+#define BLOCK_CREATE 1
+extern blockResponse * block_create_1(blockCreate *, CLIENT *);
+extern blockResponse * block_create_1_svc(blockCreate *, struct svc_req *);
extern int gluster_block_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
#else /* K&R C */
-#define BLOCK_EXEC 1
-extern blockTrans * block_exec_1();
-extern blockTrans * block_exec_1_svc();
+#define BLOCK_CREATE 1
+extern blockResponse * block_create_1();
+extern blockResponse * block_create_1_svc();
extern int gluster_block_1_freeresult ();
#endif /* K&R C */
/* the xdr functions */
#if defined(__STDC__) || defined(__cplusplus)
-extern bool_t xdr_blockTrans (XDR *, blockTrans*);
+extern bool_t xdr_blockCreate (XDR *, blockCreate*);
+extern bool_t xdr_blockCreateCli (XDR *, blockCreateCli*);
+extern bool_t xdr_blockResponse (XDR *, blockResponse*);
#else /* K&R C */
-extern bool_t xdr_blockTrans ();
+extern bool_t xdr_blockCreate ();
+extern bool_t xdr_blockCreateCli ();
+extern bool_t xdr_blockResponse ();
#endif /* K&R C */
diff --git a/rpc/block.x b/rpc/block.x
index c88fdf2..b563c9e 100644
--- a/rpc/block.x
+++ b/rpc/block.x
@@ -1,12 +1,35 @@
+struct blockCreate {
+ char volume[255];
+ char volfileserver[255];
+ char gbid[127]; /* uuid */
+ u_quad_t size;
+ char block_name[255];
+};
+
+struct blockCreateCli {
+ char volume[255];
+ char volfileserver[255];
+ u_quad_t size;
+ char block_name[255];
+ string block_hosts<>;
+};
-struct blockTrans {
- int exit; /* exit code of the command */
- string out<>; /* stdout of the command */
+struct blockResponse {
+ int exit; /* exit code of the command */
+ string out<>; /* json output */
+ u_quad_t offset; /* dentry d_name offset */
+ opaque xdata<>; /* future reserve */
};
+program GLUSTER_BLOCK_CLI {
+ version GLUSTER_BLOCK_CLI_VERS {
+ blockResponse BLOCK_CREATE_CLI(blockCreateCli) = 1;
+ } = 1;
+} = 212153113; /* B2 L12 O15 C3 K11 C3 */
+
program GLUSTER_BLOCK {
version GLUSTER_BLOCK_VERS {
- blockTrans BLOCK_EXEC(string) = 1;
+ blockResponse BLOCK_CREATE(blockCreate) = 1;
} = 1;
} = 21215311; /* B2 L12 O15 C3 K11 */
diff --git a/rpc/block_clnt.c b/rpc/block_clnt.c
index 9e5b585..ae95d9a 100644
--- a/rpc/block_clnt.c
+++ b/rpc/block_clnt.c
@@ -9,15 +9,30 @@
/* Default timeout can be changed using clnt_control() */
static struct timeval TIMEOUT = { 25, 0 };
-blockTrans *
-block_exec_1(char **argp, CLIENT *clnt)
+blockResponse *
+block_create_cli_1(blockCreateCli *argp, CLIENT *clnt)
{
- static blockTrans clnt_res;
+ static blockResponse clnt_res;
memset((char *)&clnt_res, 0, sizeof(clnt_res));
- if (clnt_call (clnt, BLOCK_EXEC,
- (xdrproc_t) xdr_wrapstring, (caddr_t) argp,
- (xdrproc_t) xdr_blockTrans, (caddr_t) &clnt_res,
+ if (clnt_call (clnt, BLOCK_CREATE_CLI,
+ (xdrproc_t) xdr_blockCreateCli, (caddr_t) argp,
+ (xdrproc_t) xdr_blockResponse, (caddr_t) &clnt_res,
+ TIMEOUT) != RPC_SUCCESS) {
+ return (NULL);
+ }
+ return (&clnt_res);
+}
+
+blockResponse *
+block_create_1(blockCreate *argp, CLIENT *clnt)
+{
+ static blockResponse clnt_res;
+
+ memset((char *)&clnt_res, 0, sizeof(clnt_res));
+ if (clnt_call (clnt, BLOCK_CREATE,
+ (xdrproc_t) xdr_blockCreate, (caddr_t) argp,
+ (xdrproc_t) xdr_blockResponse, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
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 */
}
diff --git a/rpc/block_xdr.c b/rpc/block_xdr.c
index cd8400e..91775fa 100644
--- a/rpc/block_xdr.c
+++ b/rpc/block_xdr.c
@@ -6,11 +6,54 @@
#include "block.h"
bool_t
-xdr_blockTrans (XDR *xdrs, blockTrans *objp)
+xdr_blockCreate (XDR *xdrs, blockCreate *objp)
+{
+ if (!xdr_vector (xdrs, (char *)objp->volume, 255,
+ sizeof (char), (xdrproc_t) xdr_char))
+ return FALSE;
+ if (!xdr_vector (xdrs, (char *)objp->volfileserver, 255,
+ sizeof (char), (xdrproc_t) xdr_char))
+ return FALSE;
+ if (!xdr_vector (xdrs, (char *)objp->gbid, 127,
+ sizeof (char), (xdrproc_t) xdr_char))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->size))
+ return FALSE;
+ if (!xdr_vector (xdrs, (char *)objp->block_name, 255,
+ sizeof (char), (xdrproc_t) xdr_char))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_blockCreateCli (XDR *xdrs, blockCreateCli *objp)
+{
+ if (!xdr_vector (xdrs, (char *)objp->volume, 255,
+ sizeof (char), (xdrproc_t) xdr_char))
+ return FALSE;
+ if (!xdr_vector (xdrs, (char *)objp->volfileserver, 255,
+ sizeof (char), (xdrproc_t) xdr_char))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->size))
+ return FALSE;
+ if (!xdr_vector (xdrs, (char *)objp->block_name, 255,
+ sizeof (char), (xdrproc_t) xdr_char))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->block_hosts, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_blockResponse (XDR *xdrs, blockResponse *objp)
{
if (!xdr_int (xdrs, &objp->exit))
return FALSE;
if (!xdr_string (xdrs, &objp->out, ~0))
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;
}