7be67fe3d1
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)
197 lines
5.5 KiB
C
197 lines
5.5 KiB
C
/*-
|
|
* Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*
|
|
* $FreeBSD$
|
|
*/
|
|
|
|
#ifndef _GGATE_H_
|
|
#define _GGATE_H_
|
|
|
|
#include <sys/endian.h>
|
|
#include <stdarg.h>
|
|
|
|
#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 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];
|
|
uint64_t gc_flags;
|
|
uint16_t gc_nconn;
|
|
uint32_t gc_token;
|
|
} __packed;
|
|
|
|
/* Server's initial packet. */
|
|
struct g_gate_sinit {
|
|
uint8_t gs_flags;
|
|
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 */
|
|
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, ...);
|
|
void g_gate_xvlog(const char *message, va_list ap);
|
|
void g_gate_xlog(const char *message, ...);
|
|
off_t g_gate_mediasize(int fd);
|
|
size_t g_gate_sectorsize(int fd);
|
|
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);
|
|
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
|
|
in_addr_t g_gate_str2ip(const char *str);
|
|
|
|
/*
|
|
* g_gate_swap2h_* - functions swap bytes to host byte order (from big endian).
|
|
* g_gate_swap2n_* - functions swap bytes to network byte order (actually
|
|
* to big endian byte order).
|
|
*/
|
|
|
|
static __inline void
|
|
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)
|
|
{
|
|
|
|
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)
|
|
{
|
|
|
|
cinit->gc_flags = htobe64(cinit->gc_flags);
|
|
cinit->gc_nconn = htobe16(cinit->gc_nconn);
|
|
cinit->gc_token = htobe32(cinit->gc_token);
|
|
}
|
|
|
|
static __inline void
|
|
g_gate_swap2h_sinit(struct g_gate_sinit *sinit)
|
|
{
|
|
|
|
/* Swap only used fields. */
|
|
sinit->gs_mediasize = be64toh(sinit->gs_mediasize);
|
|
sinit->gs_sectorsize = be32toh(sinit->gs_sectorsize);
|
|
sinit->gs_error = be16toh(sinit->gs_error);
|
|
}
|
|
|
|
static __inline void
|
|
g_gate_swap2n_sinit(struct g_gate_sinit *sinit)
|
|
{
|
|
|
|
/* Swap only used fields. */
|
|
sinit->gs_mediasize = htobe64(sinit->gs_mediasize);
|
|
sinit->gs_sectorsize = htobe32(sinit->gs_sectorsize);
|
|
sinit->gs_error = htobe16(sinit->gs_error);
|
|
}
|
|
|
|
static __inline void
|
|
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);
|
|
}
|
|
|
|
static __inline void
|
|
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_ */
|