From patchwork Mon Aug 1 09:19:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 1025132 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p719KIpA031141 for ; Mon, 1 Aug 2011 09:20:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752829Ab1HAJUh (ORCPT ); Mon, 1 Aug 2011 05:20:37 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:35513 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751589Ab1HAJUg (ORCPT ); Mon, 1 Aug 2011 05:20:36 -0400 Received: by mail-fx0-f46.google.com with SMTP id 19so4371466fxh.19 for ; Mon, 01 Aug 2011 02:20:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; bh=/i/Rzw8fOPf1Uv9nkxv50SOR9kGwW7of0XaDIwSfpf8=; b=fH1fdVHHlYIeSN748SdptMJLBSfSYUhWfwtW8PAz6LMq8UIVuQ0g3jo2gt1AokWDxs +PW6fr/qdKd20R3+oH5R4jq5PMVQAJfPOcpH49vffZOXBdkaNg6O2WEbvexboKWH3v1p QUHJmF/Me9N0HcJkZlYC5rc8egpq8wm8igNBE= Received: by 10.204.14.147 with SMTP id g19mr1178591bka.101.1312190436128; Mon, 01 Aug 2011 02:20:36 -0700 (PDT) Received: from localhost.localdomain ([85.26.232.135]) by mx.google.com with ESMTPS id a22sm1249911bke.53.2011.08.01.02.20.31 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 01 Aug 2011 02:20:34 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [v5 PATCH 4/5] CIFS: Move mid search to a separate function Date: Mon, 1 Aug 2011 13:19:43 +0400 Message-Id: <1312190384-3376-5-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1312190384-3376-1-git-send-email-piastryyy@gmail.com> References: <1312190384-3376-1-git-send-email-piastryyy@gmail.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 01 Aug 2011 09:20:37 +0000 (UTC) Reviewed-and-Tested-by: Jeff Layton Signed-off-by: Pavel Shilovsky --- fs/cifs/connect.c | 126 +++++++++++++++++++++++++--------------------------- 1 files changed, 61 insertions(+), 65 deletions(-) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 2a53ade..12b2741 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -473,6 +473,64 @@ 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 is_large_buf, bool *is_multi_rsp, char **bigbuf) +{ + struct mid_q_entry *mid = NULL, *tmp_mid, *ret = NULL; + + spin_lock(&GlobalMid_Lock); + list_for_each_entry_safe(mid, tmp_mid, &server->pending_mid_q, qhead) { + if (mid->mid != buf->Mid || + mid->midState != MID_REQUEST_SUBMITTED || + mid->command != buf->Command) + continue; + + if (*length == 0 && check2ndT2(buf, server->maxBuf) > 0) { + /* We have a multipart transact2 resp */ + *is_multi_rsp = true; + if (mid->resp_buf) { + /* merge response - fix up 1st*/ + *length = coalesce_t2(buf, mid->resp_buf); + if (*length > 0) { + *length = 0; + mid->multiRsp = true; + break; + } + /* All parts received or packet is malformed. */ + mid->multiEnd = true; + goto multi_t2_fnd; + } + if (!is_large_buf) { + /*FIXME: switch to already allocated largebuf?*/ + cERROR(1, "1st trans2 resp needs bigbuf"); + } else { + /* Have first buffer */ + mid->resp_buf = buf; + mid->largeBuf = true; + *bigbuf = NULL; + } + break; + } + mid->resp_buf = buf; + mid->largeBuf = is_large_buf; +multi_t2_fnd: + if (*length == 0) + mid->midState = MID_RESPONSE_RECEIVED; + else + mid->midState = MID_RESPONSE_MALFORMED; +#ifdef CONFIG_CIFS_STATS2 + mid->when_received = jiffies; +#endif + list_del_init(&mid->qhead); + ret = mid; + break; + } + spin_unlock(&GlobalMid_Lock); + + return ret; +} + static int cifs_demultiplex_thread(void *p) { @@ -487,7 +545,7 @@ cifs_demultiplex_thread(void *p) struct task_struct *task_to_wake = NULL; struct mid_q_entry *mid_entry; bool isLargeBuf = false; - bool isMultiRsp; + bool isMultiRsp = false; int rc; current->flags |= PF_MEMALLOC; @@ -589,72 +647,10 @@ incomplete_rcv: cifs_dump_mem("Bad SMB: ", buf, 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? */