From patchwork Fri Jun 24 09:48:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 915572 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 p5O9movB028341 for ; Fri, 24 Jun 2011 09:48:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754518Ab1FXJs5 (ORCPT ); Fri, 24 Jun 2011 05:48:57 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:52175 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754242Ab1FXJs4 (ORCPT ); Fri, 24 Jun 2011 05:48:56 -0400 Received: by mail-bw0-f46.google.com with SMTP id 15so2083208bwz.19 for ; Fri, 24 Jun 2011 02:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:subject:date:message-id:x-mailer :in-reply-to:references; bh=VZDZAY6jxxeeGNpYimij5G/DIQvmvP54cxIeef3G8qE=; b=MtD3z1bdlapaxN8+YoDR10zmQQ9bs9Uj7IMZQ3hEZQyYOA4tptBt5d4zqictWlo3zp Nd8FjVAql4ejzP0Aun5YKPc7XRf6aKhtlipQHL/K4iru+0Q51pECTzqC6vqcSnlc0Vq/ 55uBGQS/K6a5FDaLKdLuJKQwtjLxKl2RLZVJg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; b=wzU4Q7dYTnFUjg52hW3VgWE9mKOTnuGbwqOlrKDKXIjafqZXNOu/mKY1UYVQVpHTE4 Fk+/trTEqS/rcyUH3vK7zkK7CNO0Gl8F6NnEVZ4GA7HhKO7htcBmWKcyYyqyVOtORX6L 35DE4+mqoN5xc7F1/zdNbV/CoG1hTM2WfmET4= Received: by 10.204.66.143 with SMTP id n15mr810198bki.182.1308908935774; Fri, 24 Jun 2011 02:48:55 -0700 (PDT) Received: from localhost.localdomain (PPPoE-78-29-92-47.san.ru [78.29.92.47]) by mx.google.com with ESMTPS id v6sm1499425bkf.23.2011.06.24.02.48.54 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 24 Jun 2011 02:48:55 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [v2 4/5] CIFS: Move mid search to a separate function Date: Fri, 24 Jun 2011 13:48:00 +0400 Message-Id: <1308908881-22760-5-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308908881-22760-1-git-send-email-piastryyy@gmail.com> References: <1308908881-22760-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]); Fri, 24 Jun 2011 09:48:57 +0000 (UTC) Signed-off-by: Pavel Shilovsky --- fs/cifs/connect.c | 125 ++++++++++++++++++++++++++--------------------------- 1 files changed, 61 insertions(+), 64 deletions(-) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 5389f04..b3659be 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -471,6 +471,65 @@ 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; + + 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) { + mid = NULL; + 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); + break; + } + spin_unlock(&GlobalMid_Lock); + + return mid; +} + static int cifs_demultiplex_thread(struct TCP_Server_Info *server) { @@ -586,72 +645,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? */