c->state.receive_posted
authorStefan Metzmacher <metze@samba.org>
Wed, 5 Oct 2016 17:39:46 +0000 (19:39 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 1 Jun 2018 12:35:18 +0000 (14:35 +0200)
libcli/smb/smb_direct.c

index 3dbfe55a5dc99065395d8c72e77caf59e95c8217..c3ffd851586db80860c24c5b7446af7569e93fd3 100644 (file)
@@ -77,6 +77,7 @@ struct smb_direct_connection {
                uint16_t send_credit_target;
                uint16_t send_credits;
                uint16_t receive_credit_max;
+               uint16_t receive_posted;
                uint16_t receive_credit_target;
                uint16_t receive_credits;
                uint32_t keep_alive_internal;
@@ -402,10 +403,11 @@ static void smb_direct_connection_debug_credits(struct smb_direct_connection *c,
                                                const struct smb_direct_io *io,
                                                const char *location, const char *func)
 {
-       DEBUG(0,("%s:%s: IO[%p] CREDITS: RMAX[%u] RTARGET[%u] R[%u] RSIZE[%u] "
+       DEBUG(0,("%s:%s: IO[%p] CREDITS: RMAX[%u] RPOSTED[%u] RTARGET[%u] R[%u] RSIZE[%u] "
                 "STARGET[%u] S[%u] SSIZE[%u] MF[%u] MRW[%u]\n",
                location, reason, io, //"",//func,
                c->state.receive_credit_max,
+               c->state.receive_posted,
                c->state.receive_credit_target,
                c->state.receive_credits,
                c->state.max_receive_size,
@@ -499,13 +501,14 @@ smb_direct_connection_debug_credits(c, "post_recv", NULL, __location__, __func__
        }
 
        for (io = c->r2s.idle; io != NULL; io = io->next) {
+//DEBUG(0,("%s:%s: POST RECV[%p]\n", __location__, __func__, io));
+               c->state.receive_posted += 1;
 smb_direct_connection_debug_credits(c, "POST_RECV", io, __location__, __func__);
                if (io->next == NULL) {
                        io->recv_wr.next = NULL;
                        break;
                }
 
-DEBUG(0,("%s:%s: POST RECV[%p]\n", __location__, __func__, io));
                io->recv_wr.next = &io->next->recv_wr;
        }
 
@@ -572,7 +575,7 @@ smb_direct_connection_debug_credits(c, "WAIT_FOR_POST_SEND", io, __location__, _
                        flags |= SMB_DIRECT_RESPONSE_REQUESTED;
                }
 
-               granted = c->state.receive_credit_max;
+               granted = c->state.receive_posted;
                granted -= c->state.receive_credits;
                granted = MIN(granted, c->state.receive_credit_target);
                c->state.receive_credits += granted;
@@ -678,19 +681,36 @@ static int smb_direct_connection_post_keep(struct smb_direct_connection *c)
 
 DEBUG(0,("%s:%s: KEEP posted[%p] ready[%p] idle[%p]\n",
        __location__, __func__, c->s2r.posted, c->s2r.ready, c->s2r.idle));
+
+       errno = 0;
+       ret = smb_direct_connection_post_recv(c);
+       if (ret != 0) {
+               NTSTATUS status;
+               status = map_nt_error_from_unix_common(errno);
+               DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
+                       __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
+               return ret;
+       }
+
 smb_direct_connection_debug_credits(c, "post_keep", NULL, __location__, __func__);
+
        if (c->s2r.posted != NULL) {
 DEBUG(0,("%s:%s: KEEP skip...(posted)\n", __location__, __func__));
                return 0;
        }
 
+       if (c->state.receive_posted > 0) {
+DEBUG(0,("%s:%s: KEEP skip...(no RECV posted)\n", __location__, __func__));
+               return 0;
+       }
+
        if (c->s2r.ready != NULL) {
 DEBUG(0,("%s:%s: KEEP skip...(ready)\n", __location__, __func__));
                return 0;
        }
 
        if (c->s2r.idle == NULL) {
-//DEBUG(0,("%s:%s: here...\n", __location__, __func__));
+DEBUG(0,("%s:%s: KEEP skip...(no idle)\n", __location__, __func__));
                return 0;
        }
 
@@ -704,7 +724,7 @@ DEBUG(0,("%s:%s: KEEP skip...(ready)\n", __location__, __func__));
        DLIST_ADD_END(c->s2r.ready, io);
 
 smb_direct_connection_debug_credits(c, "POST_KEEP", io, __location__, __func__);
-       ret = smb_direct_connection_post_io(c);
+       ret = smb_direct_connection_post_send(c);
        if (ret != 0) {
                NTSTATUS status;
                status = map_nt_error_from_unix_common(errno);
@@ -1922,7 +1942,7 @@ DEBUG(0,("%s:%s: here...\n", __location__, __func__));
                SSVAL(neg_send->data, 0x04, 0x0100);
                SSVAL(neg_send->data, 0x06, 0x0000);
 
-               credits_granted = c->state.receive_credit_max;
+               credits_granted = c->state.receive_posted;
                credits_granted -= c->state.receive_credits;
                credits_granted = MIN(credits_granted, c->state.receive_credit_target);
                c->state.receive_credits += credits_granted;
@@ -2227,6 +2247,7 @@ try_again:
                data_offset = IVAL(io->smbd_hdr, 0x0C);
                io->data_length = IVAL(io->smbd_hdr, 0x10);
 
+               c->state.receive_posted -= 1;
                c->state.receive_credits -= 1;
                c->state.receive_credit_target = credits_requested;