1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

merge from peter

(This used to be ctdb commit e340d8d2af90d9a2819b0029f048cf4727617e7a)
This commit is contained in:
Andrew Tridgell 2007-04-26 17:13:58 +02:00
commit 4a01ec9035
5 changed files with 55 additions and 9 deletions

View File

@ -29,6 +29,21 @@
#include "ibwrapper.h"
#include "ibw_ctdb.h"
int ctdb_ibw_get_address(struct ctdb_context *ctdb,
const char *address, struct in_addr *addr)
{
if (inet_pton(AF_INET, address, addr) <= 0) {
struct hostent *he = gethostbyname(address);
if (he == NULL || he->h_length > sizeof(*addr)) {
ctdb_set_error(ctdb, "invalid nework address '%s'\n",
address);
return -1;
}
memcpy(addr, he->h_addr, he->h_length);
}
return 0;
}
int ctdb_ibw_node_connect(struct ctdb_node *node)
{
struct ctdb_ibw_node *cn = talloc_get_type(node->private_data, struct ctdb_ibw_node);
@ -39,9 +54,12 @@ int ctdb_ibw_node_connect(struct ctdb_node *node)
struct sockaddr_in sock_out;
memset(&sock_out, 0, sizeof(struct sockaddr_in));
inet_pton(AF_INET, node->address.address, &sock_out.sin_addr);
sock_out.sin_port = htons(node->address.port);
sock_out.sin_family = PF_INET;
if (ctdb_ibw_get_address(node->ctdb, node->address.address, &sock_out.sin_addr)) {
DEBUG(0, ("ctdb_ibw_node_connect failed\n"));
return -1;
}
rc = ibw_connect(cn->conn, &sock_out, node);
if (rc) {

View File

@ -36,6 +36,9 @@ struct ctdb_ibw_node {
int qcnt;
};
int ctdb_ibw_get_address(struct ctdb_context *ctdb,
const char *address, struct in_addr *addr);
int ctdb_ibw_connstate_handler(struct ibw_ctx *ctx, struct ibw_conn *conn);
int ctdb_ibw_receive_handler(struct ibw_conn *conn, void *buf, int n);
@ -44,3 +47,5 @@ void ctdb_ibw_node_connect_event(struct event_context *ev, struct timed_event *t
struct timeval t, void *private_data);
int ctdb_flush_cn_queue(struct ctdb_ibw_node *cn);
int ctdb_ibw_init(struct ctdb_context *ctdb);

View File

@ -38,7 +38,8 @@ static int ctdb_ibw_listen(struct ctdb_context *ctdb, int backlog)
memset(&my_addr, 0, sizeof(struct sockaddr_in));
my_addr.sin_port = htons(ctdb->address.port);
my_addr.sin_family = PF_INET;
inet_pton(AF_INET, ctdb->address.address, &my_addr.sin_addr);
if (ctdb_ibw_get_address(ctdb, ctdb->address.address, &my_addr.sin_addr))
return -1;
if (ibw_bind(ictx, &my_addr)) {
DEBUG(0, ("ctdb_ibw_listen: ibw_bind failed\n"));

View File

@ -495,7 +495,7 @@ static void ibw_event_handler_cm(struct event_context *ev,
case RDMA_CM_EVENT_ESTABLISHED:
/* expected after ibw_accept and ibw_connect[not directly] */
DEBUG(0, ("ESTABLISHED (conn: %p)\n", cma_id->context));
DEBUG(1, ("ESTABLISHED (conn: %p)\n", cma_id->context));
conn = talloc_get_type(cma_id->context, struct ibw_conn);
assert(conn!=NULL); /* important assumption */
@ -516,10 +516,13 @@ static void ibw_event_handler_cm(struct event_context *ev,
sprintf(ibw_lasterr, "RDMA_CM_EVENT_CONNECT_ERROR, error %d\n", event->status);
case RDMA_CM_EVENT_UNREACHABLE:
sprintf(ibw_lasterr, "RDMA_CM_EVENT_UNREACHABLE, error %d\n", event->status);
goto error;
case RDMA_CM_EVENT_REJECTED:
sprintf(ibw_lasterr, "RDMA_CM_EVENT_REJECTED, error %d\n", event->status);
DEBUG(1, ("cm event handler: %s", ibw_lasterr));
conn = talloc_get_type(cma_id->context, struct ibw_conn);
if (conn) {
/* must be done BEFORE connstate */
if ((rc=rdma_ack_cm_event(event)))
DEBUG(0, ("reject/rdma_ack_cm_event failed with %d\n", rc));
event = NULL; /* not to touch cma_id or conn */
@ -527,7 +530,7 @@ static void ibw_event_handler_cm(struct event_context *ev,
/* it should free the conn */
pctx->connstate_func(NULL, conn);
}
goto error;
break; /* this is not strictly an error */
case RDMA_CM_EVENT_DISCONNECTED:
DEBUG(11, ("RDMA_CM_EVENT_DISCONNECTED\n"));

View File

@ -290,7 +290,7 @@ int ibwtest_connstate_handler(struct ibw_ctx *ctx, struct ibw_conn *conn)
talloc_free(conn);
break;
case IBWC_ERROR:
DEBUG(10, ("test IBWC_ERROR\n"));
DEBUG(10, ("test IBWC_ERROR %s\n", ibw_getLastError()));
break;
default:
assert(0);
@ -466,6 +466,19 @@ int ibwtest_parse_attrs(struct ibwtest_ctx *tcx, char *optext,
return 0;
}
static int ibwtest_get_address(const char *address, struct in_addr *addr)
{
if (inet_pton(AF_INET, address, addr) <= 0) {
struct hostent *he = gethostbyname(address);
if (he == NULL || he->h_length > sizeof(*addr)) {
DEBUG(0, ("invalid nework address '%s'\n", address));
return -1;
}
memcpy(addr, he->h_addr, he->h_length);
}
return 0;
}
int ibwtest_getdests(struct ibwtest_ctx *tcx, char op)
{
int i;
@ -483,7 +496,8 @@ int ibwtest_getdests(struct ibwtest_ctx *tcx, char op)
for(i=0; i<tcx->naddrs; i++) {
p = tcx->addrs + i;
p->sin_family = AF_INET;
p->sin_addr.s_addr = inet_addr(attrs[i].name);
if (ibwtest_get_address(attrs[i].name, &p->sin_addr))
return -1;
p->sin_port = htons(atoi(attrs[i].value));
}
@ -517,13 +531,14 @@ void ibwtest_usage(struct ibwtest_ctx *tcx, char *name)
printf("\t%s -i <id> -o {name:value} -d {addr:port} -t nsec -s\n", name);
printf("\t-i <id> is a free text, acting as a server id, max 23 chars [mandatory]\n");
printf("\t-o name1:value1,name2:value2,... is a list of (name, value) pairs\n");
printf("\t-d addr1:port1,addr2:port2,... is a list of destination ip addresses\n");
printf("\t-a addr1:port1,addr2:port2,... is a list of destination ip addresses\n");
printf("\t-t nsec delta time between sends in nanosec [default %d]\n", tcx->nsec);
printf("\t\t send message periodically and endless when nsec is non-zero\n");
printf("\t-s server mode (you have to give exactly one -d address:port in this case)\n");
printf("\t-n number of messages to send [default %d]\n", tcx->nmsg);
printf("\t-l usec time to sleep in the main loop [default %d]\n", tcx->sleep_usec);
printf("\t-v max variable msg size in bytes [default %d], 0=don't send var. size\n", tcx->maxsize);
printf("\t-d LogLevel [default %d]\n", LogLevel);
printf("Press ctrl+C to stop the program.\n");
}
@ -539,13 +554,14 @@ int main(int argc, char *argv[])
memset(tcx, 0, sizeof(struct ibwtest_ctx));
tcx->nsec = 0;
tcx->nmsg = 1000;
LogLevel = 0;
/* here is the only case we can't avoid using global... */
testctx = tcx;
signal(SIGINT, ibwtest_sigint_handler);
srand((unsigned)time(NULL));
while ((op=getopt(argc, argv, "i:o:d:m:st:n:l:v:")) != -1) {
while ((op=getopt(argc, argv, "i:o:d:m:st:n:l:v:a:")) != -1) {
switch (op) {
case 'i':
tcx->id = talloc_strdup(tcx, optarg);
@ -556,7 +572,7 @@ int main(int argc, char *argv[])
&tcx->nattrs, op))
goto cleanup;
break;
case 'd':
case 'a':
if (ibwtest_getdests(tcx, op))
goto cleanup;
break;
@ -575,6 +591,9 @@ int main(int argc, char *argv[])
case 'v':
tcx->maxsize = (unsigned int)atoi(optarg);
break;
case 'd':
LogLevel = atoi(optarg);
break;
default:
fprintf(stderr, "ERROR: unknown option -%c\n", (char)op);
ibwtest_usage(tcx, argv[0]);