summaryrefslogtreecommitdiffstats
path: root/sbin/ggate/shared
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
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')
-rw-r--r--sbin/ggate/shared/ggate.c82
-rw-r--r--sbin/ggate/shared/ggate.h78
2 files changed, 136 insertions, 24 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)
diff --git a/sbin/ggate/shared/ggate.h b/sbin/ggate/shared/ggate.h
index 12dfe6d..acbdaaa 100644
--- a/sbin/ggate/shared/ggate.h
+++ b/sbin/ggate/shared/ggate.h
@@ -32,22 +32,49 @@
#include <sys/endian.h>
#include <stdarg.h>
-#define G_GATE_BUFSIZE_START 65536
#define G_GATE_PORT 3080
#define G_GATE_RCVBUF 131072
#define G_GATE_SNDBUF 131072
#define G_GATE_QUEUE_SIZE 1024
-#define G_GATE_TIMEOUT 30
+#define G_GATE_TIMEOUT 0
+
+#define GGATE_MAGIC "GEOM_GATE "
+#define GGATE_VERSION 0
+
+#define GGATE_FLAG_RDONLY 0x0001
+#define GGATE_FLAG_WRONLY 0x0002
+/*
+ * If GGATE_FLAG_SEND not GGATE_FLAG_RECV flag is set, this is initial
+ * connection.
+ * If GGATE_FLAG_SEND flag is set - this is socket to send data.
+ * If GGATE_FLAG_RECV flag is set - this is socket to receive data.
+ */
+#define GGATE_FLAG_SEND 0x0004
+#define GGATE_FLAG_RECV 0x0008
+
+#define GGATE_CMD_READ 0
+#define GGATE_CMD_WRITE 1
extern int g_gate_devfd;
extern int g_gate_verbose;
+extern int nagle;
+extern unsigned rcvbuf, sndbuf;
+
+struct g_gate_version {
+ char gv_magic[16];
+ uint16_t gv_version;
+ uint16_t gv_error;
+} __packed;
+
/* Client's initial packet. */
struct g_gate_cinit {
- char gc_path[PATH_MAX + 1];
- uint8_t gc_flags;
-};
+ char gc_path[PATH_MAX + 1];
+ uint64_t gc_flags;
+ uint16_t gc_nconn;
+ uint32_t gc_token;
+} __packed;
/* Server's initial packet. */
struct g_gate_sinit {
@@ -55,15 +82,16 @@ struct g_gate_sinit {
uint64_t gs_mediasize;
uint32_t gs_sectorsize;
uint16_t gs_error;
-};
+} __packed;
/* Control struct. */
struct g_gate_hdr {
uint8_t gh_cmd; /* command */
uint64_t gh_offset; /* device offset */
uint32_t gh_length; /* size of block */
- int16_t gh_error; /* error value (0 if ok) */
-};
+ uint64_t gh_seq; /* request number */
+ uint16_t gh_error; /* error value (0 if ok) */
+} __packed;
void g_gate_vlog(int priority, const char *message, va_list ap);
void g_gate_log(int priority, const char *message, ...);
@@ -75,8 +103,10 @@ void g_gate_open_device(void);
void g_gate_close_device(void);
void g_gate_ioctl(unsigned long req, void *data);
void g_gate_destroy(int unit, int force);
-int g_gate_openflags(unsigned ggflags);
void g_gate_load_module(void);
+ssize_t g_gate_recv(int s, void *buf, size_t len, int flags);
+ssize_t g_gate_send(int s, const void *buf, size_t len, int flags);
+void g_gate_socket_settings(int sfd);
#ifdef LIBGEOM
void g_gate_list(int unit, int verbose);
#endif
@@ -89,17 +119,37 @@ in_addr_t g_gate_str2ip(const char *str);
*/
static __inline void
-g_gate_swap2h_cinit(struct g_gate_cinit *cinit __unused)
+g_gate_swap2h_version(struct g_gate_version *ver)
+{
+
+ ver->gv_version = be16toh(ver->gv_version);
+ ver->gv_error = be16toh(ver->gv_error);
+}
+
+static __inline void
+g_gate_swap2n_version(struct g_gate_version *ver)
+{
+
+ ver->gv_version = htobe16(ver->gv_version);
+ ver->gv_error = htobe16(ver->gv_error);
+}
+
+static __inline void
+g_gate_swap2h_cinit(struct g_gate_cinit *cinit)
{
- /* Nothing here for now. */
+ cinit->gc_flags = be64toh(cinit->gc_flags);
+ cinit->gc_nconn = be16toh(cinit->gc_nconn);
+ cinit->gc_token = be32toh(cinit->gc_token);
}
static __inline void
-g_gate_swap2n_cinit(struct g_gate_cinit *cinit __unused)
+g_gate_swap2n_cinit(struct g_gate_cinit *cinit)
{
- /* Nothing here for now. */
+ cinit->gc_flags = htobe64(cinit->gc_flags);
+ cinit->gc_nconn = htobe16(cinit->gc_nconn);
+ cinit->gc_token = htobe32(cinit->gc_token);
}
static __inline void
@@ -129,6 +179,7 @@ g_gate_swap2h_hdr(struct g_gate_hdr *hdr)
/* Swap only used fields. */
hdr->gh_offset = be64toh(hdr->gh_offset);
hdr->gh_length = be32toh(hdr->gh_length);
+ hdr->gh_seq = be64toh(hdr->gh_seq);
hdr->gh_error = be16toh(hdr->gh_error);
}
@@ -139,6 +190,7 @@ g_gate_swap2n_hdr(struct g_gate_hdr *hdr)
/* Swap only used fields. */
hdr->gh_offset = htobe64(hdr->gh_offset);
hdr->gh_length = htobe32(hdr->gh_length);
+ hdr->gh_seq = htobe64(hdr->gh_seq);
hdr->gh_error = htobe16(hdr->gh_error);
}
#endif /* _GGATE_H_ */
OpenPOWER on IntegriCloud