All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Shilovsky <piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 4/5] CIFS: Move mid search to a separate function
Date: Fri, 24 Jun 2011 10:51:56 +0400	[thread overview]
Message-ID: <1308898317-7667-5-git-send-email-piastryyy@gmail.com> (raw)
In-Reply-To: <1308898317-7667-1-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Signed-off-by: Pavel Shilovsky <piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 fs/cifs/connect.c |  136 ++++++++++++++++++++++++++++-------------------------
 1 files changed, 72 insertions(+), 64 deletions(-)

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 26498d3..aa2925b 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -466,6 +466,76 @@ check_rfc1002_header(struct TCP_Server_Info *server, char *buf)
 	return true;
 }
 
+static struct mid_q_entry *
+find_cifs_mid(struct TCP_Server_Info *server, struct smb_hdr *buf,
+	      int *length, bool isLargeBuf, bool *isMultiRsp, char **pbigbuf)
+{
+	struct list_head *tmp, *tmp2;
+	struct mid_q_entry *mid_entry = NULL;
+
+	spin_lock(&GlobalMid_Lock);
+	list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
+		mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
+
+		if (mid_entry->mid != buf->Mid ||
+		    mid_entry->midState != MID_REQUEST_SUBMITTED ||
+		    mid_entry->command != buf->Command) {
+			mid_entry = NULL;
+			continue;
+		}
+
+		if (*length == 0 && check2ndT2(buf, server->maxBuf) > 0) {
+			/* We have a multipart transact2 resp */
+			*isMultiRsp = true;
+			if (mid_entry->resp_buf) {
+				/* merge response - fix up 1st*/
+				*length = coalesce_t2(buf, mid_entry->resp_buf);
+				if (*length > 0) {
+					*length = 0;
+					mid_entry->multiRsp = true;
+					break;
+				} else {
+					/* all parts received or
+					 * packet is malformed
+					 */
+					mid_entry->multiEnd = true;
+					goto multi_t2_fnd;
+				}
+			} else {
+				if (!isLargeBuf) {
+					/*
+					 * FIXME: switch to already
+					 *        allocated largebuf?
+					 */
+					cERROR(1, "1st trans2 resp "
+						  "needs bigbuf");
+				} else {
+					/* Have first buffer */
+					mid_entry->resp_buf = buf;
+					mid_entry->largeBuf = true;
+					*pbigbuf = NULL;
+				}
+			}
+			break;
+		}
+		mid_entry->resp_buf = buf;
+		mid_entry->largeBuf = isLargeBuf;
+multi_t2_fnd:
+		if (*length == 0)
+			mid_entry->midState = MID_RESPONSE_RECEIVED;
+		else
+			mid_entry->midState = MID_RESPONSE_MALFORMED;
+#ifdef CONFIG_CIFS_STATS2
+		mid_entry->when_received = jiffies;
+#endif
+		list_del_init(&mid_entry->qhead);
+		break;
+	}
+	spin_unlock(&GlobalMid_Lock);
+
+	return mid_entry;
+}
+
 static int
 cifs_demultiplex_thread(struct TCP_Server_Info *server)
 {
@@ -577,72 +647,10 @@ incomplete_rcv:
 			cifs_dump_mem("Bad SMB: ", smb_buffer,
 					min_t(unsigned int, total_read, 48));
 
-		mid_entry = NULL;
 		server->lstrp = jiffies;
 
-		spin_lock(&GlobalMid_Lock);
-		list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
-			mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
-
-			if (mid_entry->mid != smb_buffer->Mid ||
-			    mid_entry->midState != MID_REQUEST_SUBMITTED ||
-			    mid_entry->command != smb_buffer->Command) {
-				mid_entry = NULL;
-				continue;
-			}
-
-			if (length == 0 &&
-			    check2ndT2(smb_buffer, server->maxBuf) > 0) {
-				/* We have a multipart transact2 resp */
-				isMultiRsp = true;
-				if (mid_entry->resp_buf) {
-					/* merge response - fix up 1st*/
-					length = coalesce_t2(smb_buffer,
-							mid_entry->resp_buf);
-					if (length > 0) {
-						length = 0;
-						mid_entry->multiRsp = true;
-						break;
-					} else {
-						/* all parts received or
-						 * packet is malformed
-						 */
-						mid_entry->multiEnd = true;
-						goto multi_t2_fnd;
-					}
-				} else {
-					if (!isLargeBuf) {
-						/*
-						 * FIXME: switch to already
-						 *        allocated largebuf?
-						 */
-						cERROR(1, "1st trans2 resp "
-							  "needs bigbuf");
-					} else {
-						/* Have first buffer */
-						mid_entry->resp_buf =
-							 smb_buffer;
-						mid_entry->largeBuf = true;
-						bigbuf = NULL;
-					}
-				}
-				break;
-			}
-			mid_entry->resp_buf = smb_buffer;
-			mid_entry->largeBuf = isLargeBuf;
-multi_t2_fnd:
-			if (length == 0)
-				mid_entry->midState = MID_RESPONSE_RECEIVED;
-			else
-				mid_entry->midState = MID_RESPONSE_MALFORMED;
-#ifdef CONFIG_CIFS_STATS2
-			mid_entry->when_received = jiffies;
-#endif
-			list_del_init(&mid_entry->qhead);
-			break;
-		}
-		spin_unlock(&GlobalMid_Lock);
-
+		mid_entry = find_cifs_mid(server, smb_buffer, &length,
+					  isLargeBuf, &isMultiRsp, &bigbuf);
 		if (mid_entry != NULL) {
 			mid_entry->callback(mid_entry);
 			/* Was previous buf put in mpx struct for multi-rsp? */
-- 
1.7.1

  parent reply	other threads:[~2011-06-24  6:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-24  6:51 [PATCH 0/5] Simplify demultiplex thread Pavel Shilovsky
     [not found] ` <1308898317-7667-1-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-24  6:51   ` [PATCH 1/5] CIFS: Move buffer allocation to a separate function Pavel Shilovsky
     [not found]     ` <1308898317-7667-2-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-24  7:11       ` Christoph Hellwig
     [not found]         ` <20110624071159.GA11901-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2011-06-24  7:36           ` Pavel Shilovsky
2011-06-24  6:51   ` [PATCH 2/5] CIFS: Simplify socket reading in demultiplex thread Pavel Shilovsky
2011-06-24  6:51   ` [PATCH 3/5] CIFS: Move RFC1002 check to a separate function Pavel Shilovsky
2011-06-24  6:51   ` Pavel Shilovsky [this message]
     [not found]     ` <1308898317-7667-5-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-24  7:14       ` [PATCH 4/5] CIFS: Move mid search " Christoph Hellwig
2011-06-24  6:51   ` [PATCH 5/5] CIFS: Cleanup demupltiplex thread exiting code Pavel Shilovsky

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=1308898317-7667-5-git-send-email-piastryyy@gmail.com \
    --to=piastryyy-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.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 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.