mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Long Li <longli@exchange.microsoft.com>
To: Steve French <sfrench@samba.org>,
	linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
	linux-kernel@vger.kernel.org
Cc: Long Li <longli@microsoft.com>
Subject: [[PATCH v1] 07/37] [CIFS] SMBD: Implement receive buffer for handling SMBD response
Date: Wed,  2 Aug 2017 13:10:18 -0700	[thread overview]
Message-ID: <1501704648-20159-8-git-send-email-longli@exchange.microsoft.com> (raw)
In-Reply-To: <1501704648-20159-1-git-send-email-longli@exchange.microsoft.com>

From: Long Li <longli@microsoft.com>

Create recevie buffers to handling SMBD response messages. Each SMBD response message is assocated with a receive buffer, where the message payload is received. The number of receive buffer is determine after negotiating SMBD transport with the server.

Signed-off-by: Long Li <longli@microsoft.com>
---
 fs/cifs/cifsrdma.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/cifs/cifsrdma.h |  3 ++
 2 files changed, 92 insertions(+)

diff --git a/fs/cifs/cifsrdma.c b/fs/cifs/cifsrdma.c
index 1636304..b3e43b1 100644
--- a/fs/cifs/cifsrdma.c
+++ b/fs/cifs/cifsrdma.c
@@ -54,6 +54,14 @@
 
 #include "cifsrdma.h"
 
+static struct cifs_rdma_response* get_receive_buffer(
+		struct cifs_rdma_info *info);
+static void put_receive_buffer(
+		struct cifs_rdma_info *info,
+		struct cifs_rdma_response *response);
+static int allocate_receive_buffers(struct cifs_rdma_info *info, int num_buf);
+static void destroy_receive_buffers(struct cifs_rdma_info *info);
+
 /*
  * Per RDMA transport connection parameters
  * as defined in [MS-SMBD] 3.1.1.1
@@ -280,6 +288,85 @@ static int cifs_rdma_ia_open(
 	return rc;
 }
 
+/*
+ * Receive buffer operations.
+ * For each remote send, we need to post a receive. The receive buffers are
+ * pre-allocated in advance.
+ */
+static struct cifs_rdma_response* get_receive_buffer(struct cifs_rdma_info *info)
+{
+	struct cifs_rdma_response *ret = NULL;
+	unsigned long flags;
+
+	spin_lock_irqsave(&info->receive_queue_lock, flags);
+	if (!list_empty(&info->receive_queue)) {
+		ret = list_first_entry(
+			&info->receive_queue,
+			struct cifs_rdma_response, list);
+		list_del(&ret->list);
+		info->count_receive_buffer--;
+		info->count_get_receive_buffer++;
+	}
+	spin_unlock_irqrestore(&info->receive_queue_lock, flags);
+
+	return ret;
+}
+
+static void put_receive_buffer(
+	struct cifs_rdma_info *info, struct cifs_rdma_response *response)
+{
+	unsigned long flags;
+
+	ib_dma_unmap_single(info->id->device, response->sge.addr,
+		response->sge.length, DMA_FROM_DEVICE);
+
+	spin_lock_irqsave(&info->receive_queue_lock, flags);
+	list_add_tail(&response->list, &info->receive_queue);
+	info->count_receive_buffer++;
+	info->count_put_receive_buffer++;
+	spin_unlock_irqrestore(&info->receive_queue_lock, flags);
+}
+
+static int allocate_receive_buffers(struct cifs_rdma_info *info, int num_buf)
+{
+	int i;
+	struct cifs_rdma_response *response;
+
+	INIT_LIST_HEAD(&info->receive_queue);
+	spin_lock_init(&info->receive_queue_lock);
+
+	for (i=0; i<num_buf; i++) {
+		response = mempool_alloc(info->response_mempool, GFP_KERNEL);
+		if (!response)
+			goto allocate_failed;
+
+		response->info = info;
+		list_add_tail(&response->list, &info->receive_queue);
+		info->count_receive_buffer++;
+	}
+
+	return 0;
+
+allocate_failed:
+	while (!list_empty(&info->receive_queue)) {
+		response = list_first_entry(
+				&info->receive_queue,
+				struct cifs_rdma_response, list);
+		list_del(&response->list);
+		info->count_receive_buffer--;
+
+		mempool_free(response, info->response_mempool);
+	}
+	return -ENOMEM;
+}
+
+static void destroy_receive_buffers(struct cifs_rdma_info *info)
+{
+	struct cifs_rdma_response *response;
+	while ((response = get_receive_buffer(info)))
+		mempool_free(response, info->response_mempool);
+}
+
 struct cifs_rdma_info* cifs_create_rdma_session(
 	struct TCP_Server_Info *server, struct sockaddr *dstaddr)
 {
@@ -383,6 +470,8 @@ struct cifs_rdma_info* cifs_create_rdma_session(
 	info->response_mempool =
 		mempool_create(info->receive_credit_max, mempool_alloc_slab,
 		       mempool_free_slab, info->response_cache);
+
+	allocate_receive_buffers(info, info->receive_credit_max);
 out2:
 	rdma_destroy_id(info->id);
 
diff --git a/fs/cifs/cifsrdma.h b/fs/cifs/cifsrdma.h
index 41ae61a..78ce2bf 100644
--- a/fs/cifs/cifsrdma.h
+++ b/fs/cifs/cifsrdma.h
@@ -59,6 +59,9 @@ struct cifs_rdma_info {
 	atomic_t receive_credits;
 	atomic_t receive_credit_target;
 
+	struct list_head receive_queue;
+	spinlock_t receive_queue_lock;
+
 	// response pool for RDMA receive
 	struct kmem_cache *response_cache;
 	mempool_t *response_mempool;
-- 
2.7.4

  parent reply	other threads:[~2017-08-02 20:12 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-02 20:10 [[PATCH v1] 00/37] Implement SMBD protocol: Series 1 Long Li
2017-08-02 20:10 ` [[PATCH v1] 01/37] [CIFS] SMBD: Add parsing for new rdma mount option Long Li
2017-08-14 19:10   ` Tom Talpey
2017-08-14 22:53     ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 02/37] [CIFS] SMBD: Add structure for SMBD transport Long Li
2017-08-08  6:58   ` Stefan Metzmacher
2017-08-12  8:32     ` Long Li
2017-08-12 18:49       ` Christoph Hellwig
2017-08-14 13:41       ` Stefan Metzmacher
2017-08-14 18:10         ` Long Li
2017-08-13 10:10   ` Christoph Hellwig
2017-08-02 20:10 ` [[PATCH v1] 03/37] [CIFS] SMBD: Add logging functions for debug Long Li
2017-08-02 20:10 ` [[PATCH v1] 04/37] [CIFS] SMBD: Define per-channel SMBD transport parameters and default values Long Li
2017-08-13 10:11   ` Christoph Hellwig
2017-08-14 19:28     ` Tom Talpey
2017-08-14 22:57       ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 05/37] [CIFS] SMBD: Implement API for upper layer to create SMBD transport and establish RDMA connection Long Li
2017-08-14 19:54   ` Tom Talpey
2017-08-30  2:35     ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 06/37] [CIFS] SMBD: Add definition and cache for SMBD response Long Li
2017-08-02 20:10 ` Long Li [this message]
2017-08-14 20:09   ` [[PATCH v1] 07/37] [CIFS] SMBD: Implement receive buffer for handling " Tom Talpey
2017-08-19 23:41     ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 08/37] [CIFS] SMBD: Define packet format for SMBD data transfer message Long Li
2017-08-13 10:15   ` Christoph Hellwig
2017-08-14 10:24     ` Jeff Layton
2017-08-02 20:10 ` [[PATCH v1] 09/37] [CIFS] SMBD: Add SMBD request and cache Long Li
2017-08-02 20:10 ` [[PATCH v1] 10/37] [CIFS] SMBD: Introduce wait queue when sending SMBD request Long Li
2017-08-02 20:10 ` [[PATCH v1] 11/37] [CIFS] SMBD: Post a receive request Long Li
2017-08-13 10:18   ` Christoph Hellwig
2017-08-02 20:10 ` [[PATCH v1] 12/37] [CIFS] SMBD: Handle send completion from CQ Long Li
2017-08-13 10:19   ` Christoph Hellwig
2017-08-14 18:16     ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 13/37] [CIFS] SMBD: Implement SMBD protocol negotiation Long Li
2017-08-13 10:22   ` Christoph Hellwig
2017-08-02 20:10 ` [[PATCH v1] 14/37] [CIFS] SMBD: Post a SMBD data transfer message with page payload Long Li
2017-08-14 20:23   ` Tom Talpey
2017-08-14 22:58     ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 15/37] [CIFS] SMBD: Post a SMBD data transfer message with data payload Long Li
2017-08-13 10:23   ` Christoph Hellwig
2017-08-30  2:17     ` Long Li
2017-08-30  8:51       ` Christoph Hellwig
2017-08-30 18:17         ` Long Li
2017-08-14 20:26   ` Tom Talpey
2017-08-02 20:10 ` [[PATCH v1] 16/37] [CIFS] SMBD: Post a SMBD message with no payload Long Li
2017-08-13 10:24   ` Christoph Hellwig
2017-08-14 18:20     ` Long Li
2017-08-14 19:00       ` Tom Talpey
2017-08-14 22:51         ` Long Li
2017-08-14 23:12           ` Tom Talpey
2017-08-02 20:10 ` [[PATCH v1] 17/37] [CIFS] SMBD: Track status for transport Long Li
2017-08-02 20:10 ` [[PATCH v1] 18/37] [CIFS] SMBD: Implement API for upper layer to send data Long Li
2017-08-14 20:44   ` Tom Talpey
2017-08-19 23:41     ` Long Li
2017-08-30  2:30     ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 19/37] [CIFS] SMBD: Manage credits on SMBD client and server Long Li
2017-08-14 20:47   ` Tom Talpey
2017-08-14 23:03     ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 20/37] [CIFS] SMBD: Implement reassembly queue for receiving data Long Li
2017-08-02 20:10 ` [[PATCH v1] 21/37] [CIFS] SMBD: Implement API for upper layer to receive data Long Li
2017-08-14 20:57   ` Tom Talpey
2017-08-14 23:24     ` Long Li
2017-08-14 23:35       ` Tom Talpey
2017-08-02 20:10 ` [[PATCH v1] 22/37] [CIFS] SMBD: Implement API for upper layer to receive data to page Long Li
2017-08-14 20:59   ` Tom Talpey
2017-08-02 20:10 ` [[PATCH v1] 23/37] [CIFS] SMBD: Implement API for upper layer to reconnect transport Long Li
2017-08-14 21:02   ` Tom Talpey
2017-08-14 23:37     ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 24/37] [CIFS] SMBD: Support for SMBD keep alive protocol Long Li
2017-08-14 21:06   ` Tom Talpey
2017-08-14 23:27     ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 25/37] [CIFS] SMBD: Support SMBD idle connection timer Long Li
2017-08-14 21:12   ` Tom Talpey
2017-08-14 23:29     ` Long Li
2017-08-14 23:42       ` Tom Talpey
2017-08-15  0:10         ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 26/37] [CIFS] SMBD: Send an immediate packet when it's needed Long Li
2017-08-14 21:15   ` Tom Talpey
2017-08-02 20:10 ` [[PATCH v1] 27/37] [CIFS] SMBD: Destroy transport when RDMA channel is disconnected Long Li
2017-08-02 20:10 ` [[PATCH v1] 28/37] [CIFS] SMBD: Implement API for upper layer to destroy the transport Long Li
2017-08-02 20:10 ` [[PATCH v1] 29/37] [CIFS] SMBD: Disconnect RDMA connection on QP errors Long Li
2017-08-02 20:10 ` [[PATCH v1] 30/37] [CIFS] SMBD: Add SMBDirect transport to Makefile Long Li
2017-08-14 21:20   ` Tom Talpey
2017-08-14 23:30     ` Long Li
2017-08-02 20:10 ` [[PATCH v1] 31/37] [CIFS] Add SMBD transport to SMB session context Long Li
2017-08-02 20:10 ` [[PATCH v1] 32/37] [CIFS] Add SMBD debug couters to CIFS debug exports Long Li
2017-08-02 20:10 ` [[PATCH v1] 33/37] [CIFS] Connect to SMBD transport when specified in mount option Long Li
2017-08-02 20:10 ` [[PATCH v1] 34/37] [CIFS] Reconnect to SMBD transport when it's used Long Li
2017-08-02 20:10 ` [[PATCH v1] 35/37] [CIFS] Destroy SMBD transport on exit Long Li
2017-08-02 20:10 ` [[PATCH v1] 36/37] [CIFS] Read from SMBD transport when it's used Long Li
2017-08-02 20:10 ` [[PATCH v1] 37/37] [CIFS] Write to " Long Li
2017-08-13 10:27 ` [[PATCH v1] 00/37] Implement SMBD protocol: Series 1 Christoph Hellwig
2017-08-13 10:31   ` Christoph Hellwig
2017-08-14 17:04   ` Long Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1501704648-20159-8-git-send-email-longli@exchange.microsoft.com \
    --to=longli@exchange.microsoft.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longli@microsoft.com \
    --cc=samba-technical@lists.samba.org \
    --cc=sfrench@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®