Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753492AbdHBUOd (ORCPT ); Wed, 2 Aug 2017 16:14:33 -0400 Received: from a2nlsmtp01-05.prod.iad2.secureserver.net ([198.71.225.49]:47934 "EHLO a2nlsmtp01-05.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753020AbdHBUM0 (ORCPT ); Wed, 2 Aug 2017 16:12:26 -0400 x-originating-ip: 107.180.71.197 From: Long Li To: Steve French , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org Cc: Long Li Subject: [[PATCH v1] 24/37] [CIFS] SMBD: Support for SMBD keep alive protocol Date: Wed, 2 Aug 2017 13:10:35 -0700 Message-Id: <1501704648-20159-25-git-send-email-longli@exchange.microsoft.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1501704648-20159-1-git-send-email-longli@exchange.microsoft.com> References: <1501704648-20159-1-git-send-email-longli@exchange.microsoft.com> X-CMAE-Envelope: MS4wfJ1BTbgQAM+SNCJGSpQdbBP2ERSdXH1cP7h9WNH7aQN9Q+hox4yCFvRlORUnzQTRph1tnndlSVeUVZCQebOjXVuoRhof+Gx3g+L5AYbDLyuqL7zPoRr5 v1mqVO5Mxv96OI2TpZurVU1esfztdWrTZabLGXJR9Vzy0SKewdnDaQeJAtbcIFh2jwGj92BblPmItcb0qO7cYOaP8/4Rd71Li+5PWxjWCAoNYUvaaathLNqb QegeqBcqe/FgFbipx+dJHNAPn8PvSQEaSUUM4zh0tdYEUUoOZaiZQCO0HPtr1efsuaWFAqXyZ9VXaWsvRJntQ+olQX4aJPgkWoSkGTU45po= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3549 Lines: 106 From: Long Li SMBD uses a keep alive protocol to help peers detect if the remote is dead. When peer request keep alive, the transport needs to respond accordingly. Signed-off-by: Long Li --- fs/cifs/cifsrdma.c | 30 ++++++++++++++++++++++++++++++ fs/cifs/cifsrdma.h | 7 +++++++ 2 files changed, 37 insertions(+) diff --git a/fs/cifs/cifsrdma.c b/fs/cifs/cifsrdma.c index 4681cda..e275834 100644 --- a/fs/cifs/cifsrdma.c +++ b/fs/cifs/cifsrdma.c @@ -372,6 +372,12 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc) if (atomic_read(&info->send_credits)) wake_up(&info->wait_send_queue); + // send an emtpy response right away if requested + if (le16_to_cpu(data_transfer->flags) | + le16_to_cpu(SMB_DIRECT_RESPONSE_REQUESTED)) { + info->keep_alive_requested = KEEP_ALIVE_PENDING; + } + // process receive queue if (le32_to_cpu(data_transfer->data_length)) { if (info->full_packet_received) { @@ -627,6 +633,24 @@ static int manage_credits_prior_sending(struct cifs_rdma_info *info) } /* + * Check if we need to send a KEEP_ALIVE message + * The idle connection timer triggers a KEEP_ALIVE message when expires + * In this case, we need to set SMB_DIRECT_RESPONSE_REQUESTED in the message + * flag to have peer send back a KEEP_ALIVE + * return value: + * 1 if SMB_DIRECT_RESPONSE_REQUESTED needs to be set + * 0: otherwise + */ +static int manage_keep_alive_before_sending(struct cifs_rdma_info *info) +{ + if (info->keep_alive_requested == KEEP_ALIVE_PENDING) { + info->keep_alive_requested = KEEP_ALIVE_SENT; + return 1; + } + return 0; +} + +/* * Send a page * page: the page to send * offset: offset in the page to send @@ -662,6 +686,8 @@ static int cifs_rdma_post_send_page(struct cifs_rdma_info *info, struct page *pa packet->credits_granted = cpu_to_le16(manage_credits_prior_sending(info)); packet->flags = cpu_to_le16(0); + if (manage_keep_alive_before_sending(info)) + packet->flags |= cpu_to_le16(SMB_DIRECT_RESPONSE_REQUESTED); packet->reserved = cpu_to_le16(0); packet->data_offset = cpu_to_le32(24); @@ -773,6 +799,8 @@ static int cifs_rdma_post_send_empty(struct cifs_rdma_info *info) packet = (struct smbd_data_transfer_no_data *) request->packet; credits_granted = manage_credits_prior_sending(info); + if (manage_keep_alive_before_sending(info)) + flags = SMB_DIRECT_RESPONSE_REQUESTED; /* nothing to do? */ if (credits_granted==0 && flags==0) { @@ -885,6 +913,8 @@ static int cifs_rdma_post_send_data( packet->credits_requested = cpu_to_le16(info->send_credit_target); packet->credits_granted = cpu_to_le16(manage_credits_prior_sending(info)); packet->flags = cpu_to_le16(0); + if (manage_keep_alive_before_sending(info)) + packet->flags |= cpu_to_le16(SMB_DIRECT_RESPONSE_REQUESTED); packet->reserved = cpu_to_le16(0); packet->data_offset = cpu_to_le32(24); diff --git a/fs/cifs/cifsrdma.h b/fs/cifs/cifsrdma.h index c27db6f..62d0bb8 100644 --- a/fs/cifs/cifsrdma.h +++ b/fs/cifs/cifsrdma.h @@ -25,6 +25,12 @@ #include #include +enum keep_alive_status { + KEEP_ALIVE_NONE, + KEEP_ALIVE_PENDING, + KEEP_ALIVE_SENT, +}; + enum cifs_rdma_transport_status { CIFS_RDMA_CREATED, CIFS_RDMA_CONNECTING, @@ -68,6 +74,7 @@ struct cifs_rdma_info { int max_fragmented_send_size; int max_receive_size; int max_readwrite_size; + enum keep_alive_status keep_alive_requested; int protocol; atomic_t send_credits; atomic_t receive_credits; -- 2.7.4