BROKEN; was commit 08445023786d => 190d8dd34c20cfc89ce8d3e2eb356ef761cac6e6 tcp ack...
authorStefan Metzmacher <metze@samba.org>
Mon, 22 Sep 2014 01:19:20 +0000 (03:19 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 10 Feb 2020 14:18:45 +0000 (15:18 +0100)
lib/async_req/async_sock.c
lib/async_req/wscript_build
source3/smbd/smb2_server.c

index 0a8a333f4f34152dedb6f3d423be3f4c3135144b..3ac9120f3be3e0f3fa910b0e5b7e7f01a88335b5 100644 (file)
 /* Note: lib/util/ is currently GPL */
 #include "lib/util/tevent_unix.h"
 #include "lib/util/samba_util.h"
+#include "lib/util/debug.h"
+#include <linux/sockios.h>
+
+struct io_stats {
+       int fd;
+       size_t w;
+       size_t r;
+};
+
+static struct io_stats g;
+
+static void incr_write(int fd, size_t v)
+{
+       struct io_stats *s = &g;
+
+       s->w += v;
+}
+static void incr_read(int fd, size_t v)
+{
+       struct io_stats *s = &g;
+
+       s->r += v;
+}
+static void _debug_info(int fd, const char *location, const char *func)
+
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct io_stats *s = &g;
+       struct tcp_info info;
+       socklen_t ilen = sizeof(info);
+       int ret;
+       int val0;
+       int val1;
+       int val2;
+if (0) return;
+       ret = getsockopt(fd, IPPROTO_TCP,
+                        TCP_INFO, (void *)&info, &ilen);
+       if (ret != 0) {
+               DEBUG(0,("%s:%s: errno[%d/%s]\n",
+                     location, func,
+                     errno, strerror(errno)));
+               ZERO_STRUCT(info);
+       }
+
+       ret = ioctl(fd, SIOCINQ, &val0);
+       if (ret != 0) {
+               DEBUG(0,("%s:%s: errno[%d/%s]\n",
+                     location, func,
+                     errno, strerror(errno)));
+               val0 = -1;
+       }
+       ret = ioctl(fd, SIOCOUTQ, &val1);
+       if (ret != 0) {
+               DEBUG(0,("%s:%s: errno[%d/%s]\n",
+                     location, func,
+                     errno, strerror(errno)));
+               val1 = -1;
+       }
+       ret = ioctl(fd, SIOCOUTQNSD, &val2);
+       if (ret != 0) {
+               DEBUG(0,("%s:%s: errno[%d/%s]\n",
+                     location, func,
+                     errno, strerror(errno)));
+               val1 = -1;
+       }
+       DEBUG(0,("%s:%s: %s: r[%u] w[%u] unacked[%u] sacked[%u] SIOCINQ[%u] SIOCOUTQ[%u] SIOCOUTQNSD[%u]\n",
+             location, func, current_timestring(talloc_tos(), true),
+             (unsigned)s->r, (unsigned)s->w,
+             (unsigned)info.tcpi_unacked,
+             (unsigned)info.tcpi_sacked,
+             (unsigned)val0,
+             (unsigned)val1,
+             (unsigned)val2));
+       TALLOC_FREE(frame);
+}
+
+#define debug_info(fd) _debug_info(fd, __location__, __func__)
 
 struct async_connect_state {
        int fd;
@@ -387,6 +464,8 @@ static void writev_handler(struct tevent_context *ev, struct tevent_fd *fde,
                }
        }
 
+       debug_info(state->fd);
+
        written = writev(state->fd, state->iov, state->count);
        if ((written == -1) && (errno == EINTR)) {
                /* retry */
@@ -408,6 +487,12 @@ static void writev_handler(struct tevent_context *ev, struct tevent_fd *fde,
                return;
        }
 
+       incr_write(state->fd, written);
+       debug_info(state->fd);
+                       DEBUG(0,("%s:%s: written[%u] total[%u]\n",
+                             __location__, __func__,
+                             (unsigned)written,
+                             (unsigned)state->total_size));
        if (state->count == 0) {
                tevent_req_done(req);
                return;
@@ -501,6 +586,7 @@ static void read_packet_handler(struct tevent_context *ev,
        ssize_t nread, more;
        uint8_t *tmp;
 
+       debug_info(state->fd);
        nread = recv(state->fd, state->buf+state->nread, total-state->nread,
                     0);
        if ((nread == -1) && (errno == ENOTSOCK)) {
@@ -520,6 +606,11 @@ static void read_packet_handler(struct tevent_context *ev,
                return;
        }
 
+       incr_read(state->fd, nread);
+       debug_info(state->fd);
+                       DEBUG(0,("%s:%s: total[%u] nread[%u]\n",
+                             __location__, __func__,
+                             (unsigned)total,(unsigned)nread));
        state->nread += nread;
        if (state->nread < total) {
                /* Come back later */
index 4486a5b2f06e1d238a2c0505f87609102d0b4878..907422a95d442519f301a863388f075a948380d2 100644 (file)
@@ -4,7 +4,7 @@
 bld.SAMBA_SUBSYSTEM('LIBASYNC_REQ',
        source='async_sock.c',
        public_deps='talloc tevent iov_buf',
-       deps='tevent-util socket-blocking'
+       deps='tevent-util socket-blocking samba-util'
        )
 
 bld.SAMBA_BINARY('async_connect_send_test',
index bdd074f427921824b983180b0207f8ee5442980d..d5f135151678e2049f7b3ec0d1b883684d04dbca 100644 (file)
 #include "auth.h"
 #include "libcli/smb/smbXcli_base.h"
 #include "lib/tevent_wait.h"
+<<<<<<< HEAD
 #include <sys/ioctl.h>
+=======
+>>>>>>> 190d8dd... tcp ack... doesn't work for unix...
 #include <linux/sockios.h>
 
 #include "lib/crypto/gnutls_helpers.h"
@@ -3804,8 +3807,84 @@ static int socket_error_from_errno(int ret,
        return sys_errno;
 }
 
+struct io_stats {
+       int fd;
+       size_t w;
+       size_t r;
+};
+
+static struct io_stats g;
+
+static void incr_write(int fd, size_t v)
+{
+       struct io_stats *s = &g;
+
+       s->w += v;
+}
+static void incr_read(int fd, size_t v)
+{
+       struct io_stats *s = &g;
+
+       s->r += v;
+}
+static void _debug_info(int fd, const char *location, const char *func)
+
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct io_stats *s = &g;
+       struct tcp_info info;
+       //socklen_t ilen = sizeof(info);
+       int ret;
+       int val0 = 0;
+       int val1 = 0;
+       int val2 = 0;
+
+               ZERO_STRUCT(info);
+       //ret = getsockopt(fd, IPPROTO_TCP,
+       //               TCP_INFO, (void *)&info, &ilen);
+       //if (ret != 0) {
+       //      DEBUG(0,("%s:%s: errno[%d/%s]\n",
+       //            location, func,
+       //            errno, strerror(errno)));
+       //      ZERO_STRUCT(info);
+       //}
+
+       ret = ioctl(fd, SIOCINQ, &val0);
+       if (ret != 0) {
+               DEBUG(0,("%s:%s: errno[%d/%s]\n",
+                     location, func,
+                     errno, strerror(errno)));
+               val0 = -1;
+       }
+       ret = ioctl(fd, SIOCOUTQ, &val1);
+       if (ret != 0) {
+               DEBUG(0,("%s:%s: errno[%d/%s]\n",
+                     location, func,
+                     errno, strerror(errno)));
+               val1 = -1;
+       }
+       //ret = ioctl(fd, SIOCOUTQNSD, &val2);
+       //if (ret != 0) {
+       //      DEBUG(0,("%s:%s: errno[%d/%s]\n",
+       //            location, func,
+       //            errno, strerror(errno)));
+       //      val1 = -1;
+       //}
+       DEBUG(0,("%s:%s: %s: r[%u] w[%u] unacked[%u] sacked[%u] SIOCINQ[%u] SIOCOUTQ[%u] SIOCOUTQNSD[%u]\n",
+             location, func, current_timestring(talloc_tos(), true),
+             (unsigned)s->r, (unsigned)s->w,
+             (unsigned)info.tcpi_unacked,
+             (unsigned)info.tcpi_sacked,
+             (unsigned)val0,
+             (unsigned)val1,
+             (unsigned)val2));
+       TALLOC_FREE(frame);
+}
+
+#define debug_info(fd) _debug_info(fd, __location__, __func__)
 static NTSTATUS smbd_smb2_check_ack_queue(struct smbXsrv_connection *xconn)
 {
+<<<<<<< HEAD
        struct smbd_smb2_send_queue *cur = NULL;
        struct smbd_smb2_send_queue *next = NULL;
        int value;
@@ -3834,6 +3913,12 @@ static NTSTATUS smbd_smb2_check_ack_queue(struct smbXsrv_connection *xconn)
                         */
                        break;
                }
+=======
+       while (xconn->smb2.ack_queue != NULL) {
+               struct smbd_smb2_send_queue *e = xconn->smb2.ack_queue;
+
+               debug_info(xconn->transport.sock);
+>>>>>>> 190d8dd... tcp ack... doesn't work for unix...
 
                DLIST_REMOVE(xconn->smb2.ack_queue, cur);       
                tevent_wait_done(cur->ack.req);
@@ -3918,24 +4003,10 @@ static NTSTATUS smbd_smb2_flush_send_queue(struct smbXsrv_connection *xconn)
 
 #if 0
                if (e->ack.req != NULL && !e->ack.started) {
-                       struct tcp_info info;
-                       socklen_t ilen = sizeof(info);
-
-                       ret = getsockopt(xconn->transport.sock, IPPROTO_TCP,
-                                        TCP_INFO, (void *)&info, &ilen);
-                       if (ret != 0) {
-                               DEBUG(0,("%s:%s: errno[%d/%s]\n",
-                                     __location__, __func__,
-                                     errno, strerror(errno)));
-                               ZERO_STRUCT(info);
-                       } else {
-                               DEBUG(0,("%s:%s: unacked[%u] sacked[%u]\n",
-                                     __location__, __func__,
-                                     (unsigned)info.tcpi_unacked,
-                                     (unsigned)info.tcpi_sacked));
-                       }
+                       //debug_info(xconn->transport.sock);
 
                        e->ack.started = true;
+<<<<<<< HEAD
                        e->ack.seqnum = info.tcpi_sacked + iov_buflen(e->vector, e->count);
 
                        ret = ioctl(xconn->transport.sock, SIOCOUTQ, &value1);
@@ -3944,15 +4015,23 @@ static NTSTATUS smbd_smb2_flush_send_queue(struct smbXsrv_connection *xconn)
                                        __location__, __func__,
                                        value1));
                        }
+=======
+                       e->ack.seqnum = 0;//info.tcpi_sacked + iov_buflen(e->vector, e->count);
+>>>>>>> 190d8dd... tcp ack... doesn't work for unix...
                }
 #endif
 
+<<<<<<< HEAD
                msg = (struct msghdr) {
                        .msg_iov = e->vector,
                        .msg_iovlen = e->count,
                };
 
                ret = sendmsg(xconn->transport.sock, &msg, 0);
+=======
+                       debug_info(xconn->transport.sock);
+               ret = writev(xconn->transport.sock, e->vector, e->count);
+>>>>>>> 08445023786d... BROKEN; was commit 190d8dd34c20cfc89ce8d3e2eb356ef761cac6e6 tcp ack... doesn't work for unix...
                if (ret == 0) {
                        /* propagate end of file */
                        return NT_STATUS_INTERNAL_ERROR;
@@ -3969,7 +4048,11 @@ static NTSTATUS smbd_smb2_flush_send_queue(struct smbXsrv_connection *xconn)
                        return map_nt_error_from_unix_common(err);
                }
 
+<<<<<<< HEAD
                xconn->smb2.sent_bytes += ret;
+=======
+               incr_write(xconn->transport.sock, ret);
+>>>>>>> 190d8dd... tcp ack... doesn't work for unix...
 
                ok = iov_advance(&e->vector, &e->count, ret);
                if (!ok) {
@@ -3983,9 +4066,10 @@ static NTSTATUS smbd_smb2_flush_send_queue(struct smbXsrv_connection *xconn)
                }
 
                if (e->ack.req != NULL && e->ack.started) {
-                       tevent_wait_done(e->ack.req);
+                       //tevent_wait_done(e->ack.req);
                }
 
+                       debug_info(xconn->transport.sock);
                xconn->smb2.send_queue_len--;
                DLIST_REMOVE(xconn->smb2.send_queue, e);
 
@@ -4063,12 +4147,17 @@ again:
                state->vector.iov_len = NBT_HDR_SIZE;
        }
 
+<<<<<<< HEAD
        msg = (struct msghdr) {
                .msg_iov = &state->vector,
                .msg_iovlen = 1,
        };
 
        ret = recvmsg(xconn->transport.sock, &msg, 0);
+=======
+                       debug_info(xconn->transport.sock);
+       ret = readv(xconn->transport.sock, &state->vector, 1);
+>>>>>>> 08445023786d... BROKEN; was commit 190d8dd34c20cfc89ce8d3e2eb356ef761cac6e6 tcp ack... doesn't work for unix...
        if (ret == 0) {
                /* propagate end of file */
                return NT_STATUS_END_OF_FILE;
@@ -4083,11 +4172,16 @@ again:
                return map_nt_error_from_unix_common(err);
        }
 
+<<<<<<< HEAD
        status = smbd_smb2_check_ack_queue(xconn);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
+=======
+       incr_read(xconn->transport.sock, ret);
+                       debug_info(xconn->transport.sock);
+>>>>>>> 190d8dd... tcp ack... doesn't work for unix...
        if (ret < state->vector.iov_len) {
                uint8_t *base;
                base = (uint8_t *)state->vector.iov_base;