summaryrefslogtreecommitdiffstats
path: root/sbin/ggate/shared/ggate.c
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2005-07-08 21:28:26 +0000
committerpjd <pjd@FreeBSD.org>2005-07-08 21:28:26 +0000
commit48406acfafebf9020783e0c2d8a8b79be9e465d6 (patch)
tree36a5f3303e7dcfeb9f092f43b6c42199acf5ea18 /sbin/ggate/shared/ggate.c
parent9ef3d97ebe1d220afd368af05a870dd6fb7896b4 (diff)
downloadFreeBSD-src-48406acfafebf9020783e0c2d8a8b79be9e465d6.zip
FreeBSD-src-48406acfafebf9020783e0c2d8a8b79be9e465d6.tar.gz
Reimplement ggatec/ggated applications.
Change communication protocol to be much more resistant on network problems and to allow for much better performance. Better performance is achieved by creating two connections between ggatec and ggated one for sending the data and one for receiving it. Every connection is handled by separeted thread, so there is no more synchronous data flow (send and wait for response), now one threads sends all requests and another receives the data. Use two threads in ggatec(8): - sendtd, which takes I/O requests from the kernel and sends them to the ggated daemon on the other end; - recvtd, which waits for ggated responses and forwards them to the kernel. Use three threads in ggated(8): - recvtd, which waits for I/O requests and puts them onto incoming queue; - disktd, which takes requests from the incoming queue, does disk operations and puts finished requests onto outgoing queue; - sendtd, which takes finished requests from the outgoing queue and sends responses back to ggatec. Because there were major changes in communication protocol, there is no backward compatibility, from now on, both client and server has to run on 5.x or 6.x (or at least ggated should be from the same FreeBSD version on which ggatec is running). For Gbit networks some buffers need to be increased. I use those settings: kern.ipc.maxsockbuf=16777216 net.inet.tcp.sendspace=8388608 net.inet.tcp.recvspace=8388608 and I use '-S 4194304 -R 4194304' options for both, ggatec and ggated. Approved by: re (scottl)
Diffstat (limited to 'sbin/ggate/shared/ggate.c')
-rw-r--r--sbin/ggate/shared/ggate.c82
1 files changed, 71 insertions, 11 deletions
diff --git a/sbin/ggate/shared/ggate.c b/sbin/ggate/shared/ggate.c
index 08f13d7..c8428a6 100644
--- a/sbin/ggate/shared/ggate.c
+++ b/sbin/ggate/shared/ggate.c
@@ -38,6 +38,7 @@
#include <sys/linker.h>
#include <sys/module.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <signal.h>
#include <err.h>
@@ -206,17 +207,6 @@ g_gate_destroy(int unit, int force)
g_gate_ioctl(G_GATE_CMD_DESTROY, &ggio);
}
-int
-g_gate_openflags(unsigned ggflags)
-{
-
- if ((ggflags & G_GATE_FLAG_READONLY) != 0)
- return (O_RDONLY);
- else if ((ggflags & G_GATE_FLAG_WRITEONLY) != 0)
- return (O_WRONLY);
- return (O_RDWR);
-}
-
void
g_gate_load_module(void)
{
@@ -232,6 +222,76 @@ g_gate_load_module(void)
}
}
+ssize_t
+g_gate_send(int s, const void *buf, size_t len, int flags)
+{
+ ssize_t done = 0, done2;
+ const unsigned char *p = buf;
+
+ while (len > 0) {
+ done2 = send(s, p, len, flags);
+ if (done2 == 0)
+ break;
+ else if (done2 == -1) {
+ if (errno == EAGAIN) {
+ printf("%s: EAGAIN\n", __func__);
+ continue;
+ }
+ done = -1;
+ break;
+ }
+ done += done2;
+ p += done2;
+ len -= done2;
+ }
+ return (done);
+}
+
+ssize_t
+g_gate_recv(int s, void *buf, size_t len, int flags)
+{
+
+ return (recv(s, buf, len, flags));
+}
+
+int nagle = 1;
+unsigned rcvbuf = G_GATE_RCVBUF;
+unsigned sndbuf = G_GATE_SNDBUF;
+
+void
+g_gate_socket_settings(int sfd)
+{
+ struct timeval tv;
+ int bsize, on;
+
+ /* Socket settings. */
+ on = 1;
+ if (nagle) {
+ if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &on,
+ sizeof(on)) == -1) {
+ g_gate_xlog("setsockopt() error: %s.", strerror(errno));
+ }
+ }
+ if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1)
+ g_gate_xlog("setsockopt(SO_REUSEADDR): %s.", strerror(errno));
+ bsize = rcvbuf;
+ if (setsockopt(sfd, SOL_SOCKET, SO_RCVBUF, &bsize, sizeof(bsize)) == -1)
+ g_gate_xlog("setsockopt(SO_RCVBUF): %s.", strerror(errno));
+ bsize = sndbuf;
+ if (setsockopt(sfd, SOL_SOCKET, SO_SNDBUF, &bsize, sizeof(bsize)) == -1)
+ g_gate_xlog("setsockopt(SO_SNDBUF): %s.", strerror(errno));
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ if (setsockopt(sfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1) {
+ g_gate_log(LOG_ERR, "setsockopt(SO_SNDTIMEO) error: %s.",
+ strerror(errno));
+ }
+ if (setsockopt(sfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) {
+ g_gate_log(LOG_ERR, "setsockopt(SO_RCVTIMEO) error: %s.",
+ strerror(errno));
+ }
+}
+
#ifdef LIBGEOM
static struct gclass *
find_class(struct gmesh *mesh, const char *name)
OpenPOWER on IntegriCloud