Skip to content

Commit a902274

Browse files
metze-sambasmfrench
authored andcommitted
smb: server: simplify sibling_list handling in smb_direct_flush_send_list/send_done
We have a list handling that is much easier to understand: 1. Before smb_direct_flush_send_list() is called all struct smbdirect_send_io messages are part of send_ctx->msg_list 2. Before smb_direct_flush_send_list() calls smb_direct_post_send() we remove the last element in send_ctx->msg_list and move all others into last->sibling_list. As only last has IB_SEND_SIGNALED and gets a completion vis send_done(). 3. send_done() has an easy way to free all others in sendmsg->sibling_list (if there are any). And use list_for_each_entry_safe() instead of a complex custom logic. This will help us to share send_done() in common code soon, as it will work fine for the client too, where last->sibling_list is currently always an empty list. Cc: Namjae Jeon <[email protected]> Cc: Steve French <[email protected]> Cc: Tom Talpey <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Stefan Metzmacher <[email protected]> Acked-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 8059c64 commit a902274

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

fs/smb/server/transport_rdma.c

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ static void smb_direct_free_sendmsg(struct smbdirect_socket *sc,
523523
{
524524
int i;
525525

526+
/*
527+
* The list needs to be empty!
528+
* The caller should take care of it.
529+
*/
530+
WARN_ON_ONCE(!list_empty(&msg->sibling_list));
531+
526532
if (msg->num_sge > 0) {
527533
ib_dma_unmap_single(sc->ib.dev,
528534
msg->sge[0].addr, msg->sge[0].length,
@@ -908,9 +914,8 @@ static void smb_direct_post_recv_credits(struct work_struct *work)
908914

909915
static void send_done(struct ib_cq *cq, struct ib_wc *wc)
910916
{
911-
struct smbdirect_send_io *sendmsg, *sibling;
917+
struct smbdirect_send_io *sendmsg, *sibling, *next;
912918
struct smbdirect_socket *sc;
913-
struct list_head *pos, *prev, *end;
914919

915920
sendmsg = container_of(wc->wr_cqe, struct smbdirect_send_io, cqe);
916921
sc = sendmsg->socket;
@@ -919,27 +924,26 @@ static void send_done(struct ib_cq *cq, struct ib_wc *wc)
919924
ib_wc_status_msg(wc->status), wc->status,
920925
wc->opcode);
921926

927+
/*
928+
* Free possible siblings and then the main send_io
929+
*/
930+
list_for_each_entry_safe(sibling, next, &sendmsg->sibling_list, sibling_list) {
931+
list_del_init(&sibling->sibling_list);
932+
smb_direct_free_sendmsg(sc, sibling);
933+
}
934+
/* Note this frees wc->wr_cqe, but not wc */
935+
smb_direct_free_sendmsg(sc, sendmsg);
936+
922937
if (wc->status != IB_WC_SUCCESS || wc->opcode != IB_WC_SEND) {
923938
pr_err("Send error. status='%s (%d)', opcode=%d\n",
924939
ib_wc_status_msg(wc->status), wc->status,
925940
wc->opcode);
926941
smb_direct_disconnect_rdma_connection(sc);
942+
return;
927943
}
928944

929945
if (atomic_dec_and_test(&sc->send_io.pending.count))
930946
wake_up(&sc->send_io.pending.zero_wait_queue);
931-
932-
/* iterate and free the list of messages in reverse. the list's head
933-
* is invalid.
934-
*/
935-
for (pos = &sendmsg->sibling_list, prev = pos->prev, end = sendmsg->sibling_list.next;
936-
prev != end; pos = prev, prev = prev->prev) {
937-
sibling = container_of(pos, struct smbdirect_send_io, sibling_list);
938-
smb_direct_free_sendmsg(sc, sibling);
939-
}
940-
941-
sibling = container_of(pos, struct smbdirect_send_io, sibling_list);
942-
smb_direct_free_sendmsg(sc, sibling);
943947
}
944948

945949
static int manage_credits_prior_sending(struct smbdirect_socket *sc)
@@ -1029,17 +1033,29 @@ static int smb_direct_flush_send_list(struct smbdirect_socket *sc,
10291033
last->wr.send_flags = IB_SEND_SIGNALED;
10301034
last->wr.wr_cqe = &last->cqe;
10311035

1036+
/*
1037+
* Remove last from send_ctx->msg_list
1038+
* and splice the rest of send_ctx->msg_list
1039+
* to last->sibling_list.
1040+
*
1041+
* send_ctx->msg_list is a valid empty list
1042+
* at the end.
1043+
*/
1044+
list_del_init(&last->sibling_list);
1045+
list_splice_tail_init(&send_ctx->msg_list, &last->sibling_list);
1046+
send_ctx->wr_cnt = 0;
1047+
10321048
ret = smb_direct_post_send(sc, &first->wr);
1033-
if (!ret) {
1034-
smb_direct_send_ctx_init(send_ctx,
1035-
send_ctx->need_invalidate_rkey,
1036-
send_ctx->remote_key);
1037-
} else {
1038-
list_for_each_entry_safe(first, last, &send_ctx->msg_list,
1039-
sibling_list) {
1040-
smb_direct_free_sendmsg(sc, first);
1049+
if (ret) {
1050+
struct smbdirect_send_io *sibling, *next;
1051+
1052+
list_for_each_entry_safe(sibling, next, &last->sibling_list, sibling_list) {
1053+
list_del_init(&sibling->sibling_list);
1054+
smb_direct_free_sendmsg(sc, sibling);
10411055
}
1056+
smb_direct_free_sendmsg(sc, last);
10421057
}
1058+
10431059
return ret;
10441060
}
10451061

0 commit comments

Comments
 (0)