* [PATCH 1/2] rsocket: Fix removing rsocket from service thread @ 2014-07-03 22:08 sean.hefty-ral2JQCrhuEAvxtiuMwx3w [not found] ` <1404425324-20201-1-git-send-email-sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: sean.hefty-ral2JQCrhuEAvxtiuMwx3w @ 2014-07-03 22:08 UTC (permalink / raw) To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Sean Hefty From: Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> When removing an rsocket from a service thread, we replace the removed service with the one at the end of the service list. This keeps the array tightly packed. However, rs_svc_rm_rs decrements the rsocket count before doing the swap. The result is that the entry at the end of the list gets dropped off. Defer decrementing the count until the swap has been made. In this case, the cnt value is a valid index into the array, because we start at index 1. Index 0 is used internally by the service thread. Signed-off-by: Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> --- src/rsocket.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/rsocket.c b/src/rsocket.c index f81fb1b..e9d12c7 100644 --- a/src/rsocket.c +++ b/src/rsocket.c @@ -3947,11 +3947,11 @@ static int rs_svc_rm_rs(struct rs_svc *svc, struct rsocket *rs) for (i = 1; i <= svc->cnt; i++) { if (svc->rss[i] == rs) { - svc->cnt--; svc->rss[i] = svc->rss[svc->cnt]; memcpy(svc->contexts + i * svc->context_size, svc->contexts + svc->cnt * svc->context_size, svc->context_size); + svc->cnt--; return 0; } } -- 1.7.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 4+ messages in thread
[parent not found: <1404425324-20201-1-git-send-email-sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>]
* [PATCH 2/2] rsocket: Update correct rsocket keepalive time [not found] ` <1404425324-20201-1-git-send-email-sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> @ 2014-07-03 22:08 ` sean.hefty-ral2JQCrhuEAvxtiuMwx3w [not found] ` <1404425324-20201-2-git-send-email-sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> 2014-07-07 10:08 ` [PATCH 1/2] rsocket: Fix removing rsocket from service thread Hal Rosenstock 1 sibling, 1 reply; 4+ messages in thread From: sean.hefty-ral2JQCrhuEAvxtiuMwx3w @ 2014-07-03 22:08 UTC (permalink / raw) To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Sean Hefty From: Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> When the keepalive time of an rsocket is updated, the updated information is forwarded to the keepalive service thread. However, the thread updates the time for the wrong service as shown: tcp_svc_timeouts[svc->cnt] = rs_get_time() + msg.rs->keepalive_time; The index into tcp_svc_timeouts should correspond to the rsocket being updated, not the last one in the list. Signed-off-by: Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> --- src/rsocket.c | 37 ++++++++++++++++++++++++++----------- 1 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/rsocket.c b/src/rsocket.c index e9d12c7..b869d88 100644 --- a/src/rsocket.c +++ b/src/rsocket.c @@ -3941,19 +3941,28 @@ static int rs_svc_add_rs(struct rs_svc *svc, struct rsocket *rs) return 0; } -static int rs_svc_rm_rs(struct rs_svc *svc, struct rsocket *rs) +static int rs_svc_index(struct rs_svc *svc, struct rsocket *rs) { int i; for (i = 1; i <= svc->cnt; i++) { - if (svc->rss[i] == rs) { - svc->rss[i] = svc->rss[svc->cnt]; - memcpy(svc->contexts + i * svc->context_size, - svc->contexts + svc->cnt * svc->context_size, - svc->context_size); - svc->cnt--; - return 0; - } + if (svc->rss[i] == rs) + return i; + } + return -1; +} + +static int rs_svc_rm_rs(struct rs_svc *svc, struct rsocket *rs) +{ + int i; + + if ((i = rs_svc_index(svc, rs)) >= 0) { + svc->rss[i] = svc->rss[svc->cnt]; + memcpy(svc->contexts + i * svc->context_size, + svc->contexts + svc->cnt * svc->context_size, + svc->context_size); + svc->cnt--; + return 0; } return EBADF; } @@ -4197,6 +4206,7 @@ static uint32_t rs_get_time(void) static void tcp_svc_process_sock(struct rs_svc *svc) { struct rs_svc_msg msg; + int i; read(svc->sock[1], &msg, sizeof msg); switch (msg.cmd) { @@ -4215,8 +4225,13 @@ static void tcp_svc_process_sock(struct rs_svc *svc) msg.rs->opts &= ~RS_OPT_SVC_ACTIVE; break; case RS_SVC_MOD_KEEPALIVE: - tcp_svc_timeouts[svc->cnt] = rs_get_time() + msg.rs->keepalive_time; - msg.status = 0; + i = rs_svc_index(svc, msg.rs); + if (i >= 0) { + tcp_svc_timeouts[i] = rs_get_time() + msg.rs->keepalive_time; + msg.status = 0; + } else { + msg.status = EBADF; + } break; case RS_SVC_NOOP: msg.status = 0; -- 1.7.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 4+ messages in thread
[parent not found: <1404425324-20201-2-git-send-email-sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>]
* Re: [PATCH 2/2] rsocket: Update correct rsocket keepalive time [not found] ` <1404425324-20201-2-git-send-email-sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> @ 2014-07-07 10:08 ` Hal Rosenstock 0 siblings, 0 replies; 4+ messages in thread From: Hal Rosenstock @ 2014-07-07 10:08 UTC (permalink / raw) To: sean.hefty-ral2JQCrhuEAvxtiuMwx3w; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA On 7/3/2014 6:08 PM, sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org wrote: > From: Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> > > When the keepalive time of an rsocket is updated, the > updated information is forwarded to the keepalive service > thread. However, the thread updates the time for the > wrong service as shown: > > tcp_svc_timeouts[svc->cnt] = rs_get_time() + msg.rs->keepalive_time; > > The index into tcp_svc_timeouts should correspond to the > rsocket being updated, not the last one in the list. > > Signed-off-by: Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> Tested-by: Hal Rosenstock <hal-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] rsocket: Fix removing rsocket from service thread [not found] ` <1404425324-20201-1-git-send-email-sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> 2014-07-03 22:08 ` [PATCH 2/2] rsocket: Update correct rsocket keepalive time sean.hefty-ral2JQCrhuEAvxtiuMwx3w @ 2014-07-07 10:08 ` Hal Rosenstock 1 sibling, 0 replies; 4+ messages in thread From: Hal Rosenstock @ 2014-07-07 10:08 UTC (permalink / raw) To: sean.hefty-ral2JQCrhuEAvxtiuMwx3w; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA On 7/3/2014 6:08 PM, sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org wrote: > From: Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> > > When removing an rsocket from a service thread, we replace > the removed service with the one at the end of the service list. > This keeps the array tightly packed. However, rs_svc_rm_rs > decrements the rsocket count before doing the swap. The result > is that the entry at the end of the list gets dropped off. > Defer decrementing the count until the swap has been made. > > In this case, the cnt value is a valid index into the array, > because we start at index 1. Index 0 is used internally by > the service thread. > > Signed-off-by: Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> Tested-by: Hal Rosenstock <hal-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-07 10:08 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-07-03 22:08 [PATCH 1/2] rsocket: Fix removing rsocket from service thread sean.hefty-ral2JQCrhuEAvxtiuMwx3w [not found] ` <1404425324-20201-1-git-send-email-sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> 2014-07-03 22:08 ` [PATCH 2/2] rsocket: Update correct rsocket keepalive time sean.hefty-ral2JQCrhuEAvxtiuMwx3w [not found] ` <1404425324-20201-2-git-send-email-sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> 2014-07-07 10:08 ` Hal Rosenstock 2014-07-07 10:08 ` [PATCH 1/2] rsocket: Fix removing rsocket from service thread Hal Rosenstock
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.