#include <netinet/tcp.h>
#include <unistd.h>
#include <semaphore.h>
+#include <stdio.h>
+#include <sys/syscall.h>
#include <rdma/rdma_cma.h>
#include <rdma/rdma_verbs.h>
static int sq_inline;
static int fork_support;
+static FILE *fout;
+
enum fd_type {
fd_normal,
fd_rsocket,
rs.getsockopt = dlsym(RTLD_DEFAULT, "rgetsockopt");
rs.fcntl = dlsym(RTLD_DEFAULT, "rfcntl");
+ fout = fopen("rs-out.txt", "w+");
getenv_options();
init = 1;
out:
static __thread int recursive;
int index, ret;
+ fprintf(fout, "%d socket\n", (int)syscall(SYS_gettid));
if (recursive)
goto real;
if (index < 0)
return index;
+ fprintf(fout, "%d socket %d\n", (int)syscall(SYS_gettid), index);
+ fflush(fout);
recursive = 1;
ret = rsocket(domain, type, protocol);
recursive = 0;
fd_store(index, ret, fd_rsocket);
set_rsocket_options(ret);
}
+ fprintf(fout, "%d socket %d real fd %d type %d\n",
+ (int)syscall(SYS_gettid), index, ret, fd_gett(index));
+ fflush(fout);
return index;
}
fd_close(index, &ret);
int bind(int socket, const struct sockaddr *addr, socklen_t addrlen)
{
int fd;
+ fprintf(fout, "%d bind %d\n", (int)syscall(SYS_gettid), socket);
+ fflush(fout);
return (fd_get(socket, &fd) == fd_rsocket) ?
rbind(fd, addr, addrlen) : real.bind(fd, addr, addrlen);
}
int listen(int socket, int backlog)
{
int fd;
+ fprintf(fout, "%d listen %d\n", (int)syscall(SYS_gettid), socket);
+ fflush(fout);
return (fd_get(socket, &fd) == fd_rsocket) ?
rlisten(fd, backlog) : real.listen(fd, backlog);
}
enum fd_type type;
type = fd_get(socket, &fd);
+ fprintf(fout, "%d accept %d\n", (int)syscall(SYS_gettid), socket);
+ fflush(fout);
if (type == fd_rsocket || type == fd_fork) {
index = fd_open();
if (index < 0)
return ret;
}
+ fprintf(fout, "%d accept %d new fd %d new real fd %d\n",
+ (int)syscall(SYS_gettid), socket, index, ret);
+ fflush(fout);
fd_store(index, ret, type);
return index;
} else {
long flags;
fd = fd_getd(socket);
+ fprintf(fout, "%d fork_active - %d fd %d\n", (int)syscall(SYS_gettid), socket, fd);
+ fflush(fout);
flags = real.fcntl(fd, F_GETFL);
real.fcntl(fd, F_SETFL, 0);
ret = real.connect(fd, addr, addrlen);
uint32_t msg;
fd_get(socket, &sfd);
+ fprintf(fout, "%d fork_passive %d real fd %d\n", (int)syscall(SYS_gettid), socket, sfd);
+ fflush(fout);
len = sizeof sin6;
ret = real.getsockname(sfd, (struct sockaddr *) &sin6, &len);
ret = rlisten(lfd, 1);
if (ret)
goto lclose;
+ fprintf(fout, "%d fork_passive %d, listening for fork\n", (int)syscall(SYS_gettid), socket);
+ fflush(fout);
msg = 0;
len = real.write(sfd, &msg, sizeof msg);
if (len != sizeof msg)
+ {
+ fprintf(fout, "%d fork_passive - %d write failed\n", (int)syscall(SYS_gettid), socket);
+ fflush(fout);
goto lclose;
+ }
dfd = raccept(lfd, NULL, NULL);
if (dfd < 0) {
real.shutdown(sfd, SHUT_RDWR);
real.close(sfd);
fd_store(socket, dfd, fd_rsocket);
+ fprintf(fout, "%d fork_passive success %d new fd %d old fd %d\n",
+ (int)syscall(SYS_gettid), socket, dfd, sfd);
+ fflush(fout);
lclose:
rclose(lfd);
{
int fd, ret;
+ fprintf(fout, "%d connect %d\n", (int)syscall(SYS_gettid), socket);
+ fflush(fout);
switch (fd_get(socket, &fd)) {
case fd_fork:
return fork_active(socket, addr, addrlen);
int ret;
init_preload();
+ fprintf(fout, "%d close %d real fd %d type %d\n",
+ (int)syscall(SYS_gettid), socket, fd_getd(socket), fd_gett(socket));
+ fflush(fout);
fdi = idm_lookup(&idm, socket);
if (!fdi)
return real.close(socket);
if (fdi->dupfd != -1) {
+ fprintf(fout, "%d closing dupfd %d\n",
+ (int)syscall(SYS_gettid), fdi->dupfd);
+ fflush(fout);
ret = close(fdi->dupfd);
if (ret)
return ret;
}
if (atomic_dec(&fdi->refcnt))
+ {
+ fprintf(fout, "%d close - still have ref %d\n",
+ (int)syscall(SYS_gettid), atomic_get(&fdi->refcnt));
+ fflush(fout);
return 0;
+ }
idm_clear(&idm, socket);
real.close(socket);
int ret;
init_preload();
+ fprintf(fout, "%d dup2 %d -> %d\n", (int)syscall(SYS_gettid), oldfd, newfd);
+ fflush(fout);
oldfdi = idm_lookup(&idm, oldfd);
if (oldfdi && oldfdi->type == fd_fork)
fork_passive(oldfd);
atomic_init(&newfdi->refcnt);
atomic_set(&newfdi->refcnt, 1);
atomic_inc(&oldfdi->refcnt);
+ fprintf(fout, "%d dup2 %d -> %d, real fd %d type %d\n",
+ (int)syscall(SYS_gettid), oldfd, newfd, newfdi->fd, newfdi->type);
+ fflush(fout);
return newfd;
}
{
int fd, ret;
+ init_preload();
+ fprintf(fout, "%d fxstat64 socket %d - fd %d type %d\n",
+ (int)syscall(SYS_gettid), socket, fd_getd(socket), fd_gett(socket));
+ fflush(fout);
if (fd_get(socket, &fd) == fd_rsocket) {
ret = real.fxstat64(ver, socket, buf);
+ fprintf(fout, "%d fxstat64 - rsocket %d\n", (int)syscall(SYS_gettid), ret);
if (!ret)
buf->st_mode = (buf->st_mode & ~S_IFMT) | __S_IFSOCK;
} else {
ret = real.fxstat64(ver, fd, buf);
+ fprintf(fout, "%d fxstat64 - normal %d\n", (int)syscall(SYS_gettid), ret);
}
+ fflush(fout);
return ret;
}