summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorAravinda VK <avishwan@redhat.com>2016-08-17 13:46:00 +0530
committerAtin Mukherjee <amukherj@redhat.com>2016-08-30 18:34:59 -0700
commitb71ae7d77d7ab1581d266f6435d134958844d0db (patch)
tree1e2044ee1c7d7ec4dc5a620693484fb091ffb2c9 /libglusterfs/src
parentc1f5cf0bda47fc34725084ee3988b0efe2dcfc8a (diff)
eventsapi: Add support for Client side Events
Client side gf_event uses ctx->cmd_args.volfile_server to push notifications to the eventsd. Socket server changed from Unix domain socket to UDP to support external events. Following to be addressed in different patch - Port used for eventsd is 24009. Make it configurable Already configurable in Server side. Configurable in gf_event API is required. - Auth Token yet to be added as discussed in https://www.gluster.org/pipermail/gluster-devel/2016-August/050324.html Change-Id: I159acf80b681d10b82d52cfb3ffdf85cb896542d BUG: 1367774 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/15189 Smoke: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Prashanth Pai <ppai@redhat.com> Reviewed-by: Atin Mukherjee <amukherj@redhat.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/events.c90
1 files changed, 62 insertions, 28 deletions
diff --git a/libglusterfs/src/events.c b/libglusterfs/src/events.c
index f93934de0fb..b7b513eb39a 100644
--- a/libglusterfs/src/events.c
+++ b/libglusterfs/src/events.c
@@ -16,73 +16,107 @@
#include <time.h>
#include <stdarg.h>
#include <string.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
#include "syscall.h"
#include "mem-pool.h"
+#include "glusterfs.h"
+#include "globals.h"
#include "events.h"
-#define EVENT_PATH DATADIR "/run/gluster/events.sock"
-#define EVENTS_MSG_MAX 2048
+#define EVENT_HOST "127.0.0.1"
+#define EVENT_PORT 24009
int
gf_event (eventtypes_t event, char *fmt, ...)
{
- int ret = 0;
- int sock = -1;
- char eventstr[EVENTS_MSG_MAX] = "";
- struct sockaddr_un server;
- va_list arguments;
- char *msg = NULL;
- size_t eventstr_size = 0;
+ int ret = 0;
+ int sock = -1;
+ char *eventstr = NULL;
+ struct sockaddr_in server;
+ va_list arguments;
+ char *msg = NULL;
+ glusterfs_ctx_t *ctx = NULL;
+ struct hostent *host_data;
+ char *host = NULL;
+
+ /* Global context */
+ ctx = THIS->ctx;
if (event < 0 || event >= EVENT_LAST) {
ret = EVENT_ERROR_INVALID_INPUTS;
goto out;
}
- sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ /* Initialize UDP socket */
+ sock = socket (AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
ret = EVENT_ERROR_SOCKET;
goto out;
}
- server.sun_family = AF_UNIX;
- strcpy(server.sun_path, EVENT_PATH);
- if (connect(sock,
- (struct sockaddr *) &server,
- sizeof(struct sockaddr_un)) < 0) {
- ret = EVENT_ERROR_CONNECT;
- goto out;
+ /* Get Host name to send message */
+ if (ctx && ctx->cmd_args.volfile_server) {
+ /* If it is client code then volfile_server is set
+ use that information to push the events. */
+ host_data = gethostbyname (ctx->cmd_args.volfile_server);
+ if (host_data == NULL) {
+ ret = EVENT_ERROR_RESOLVE;
+ goto out;
+ }
+ host = inet_ntoa (*(struct in_addr *)(host_data->h_addr));
+ } else {
+ /* Localhost, Use the defined IP for localhost */
+ host = EVENT_HOST;
}
+ /* Socket Configurations */
+ server.sin_family = AF_INET;
+ server.sin_port = htons (EVENT_PORT);
+ server.sin_addr.s_addr = inet_addr (host);
+ memset (&server.sin_zero, '\0', sizeof (server.sin_zero));
+
va_start (arguments, fmt);
ret = gf_vasprintf (&msg, fmt, arguments);
va_end (arguments);
+
if (ret < 0) {
ret = EVENT_ERROR_INVALID_INPUTS;
goto out;
}
- eventstr_size = snprintf(NULL, 0, "%u %d %s", (unsigned)time(NULL),
- event, msg);
+ ret = gf_asprintf (&eventstr, "%u %d %s",
+ (unsigned)time(NULL), event, msg);
- if (eventstr_size + 1 > EVENTS_MSG_MAX) {
- eventstr_size = EVENTS_MSG_MAX - 1;
+ if (ret <= 0) {
+ ret = EVENT_ERROR_MSG_FORMAT;
+ goto out;
}
- snprintf(eventstr, eventstr_size+1, "%u %d %s",
- (unsigned)time(NULL), event, msg);
-
- if (sys_write(sock, eventstr, strlen(eventstr)) <= 0) {
+ /* Send Message */
+ if (sendto (sock, eventstr, strlen (eventstr),
+ 0, (struct sockaddr *)&server, sizeof (server)) <= 0) {
ret = EVENT_ERROR_SEND;
- goto out;
}
ret = EVENT_SEND_OK;
out:
- sys_close(sock);
- GF_FREE(msg);
+ if (sock >= 0) {
+ sys_close (sock);
+ }
+
+ /* Allocated by gf_vasprintf */
+ if (msg)
+ GF_FREE (msg);
+
+ /* Allocated by gf_asprintf */
+ if (eventstr)
+ GF_FREE (eventstr);
+
return ret;
}