From patchwork Fri Apr 15 06:58:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 710211 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3F6xYmY011864 for ; Fri, 15 Apr 2011 06:59:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755445Ab1DOG7a (ORCPT ); Fri, 15 Apr 2011 02:59:30 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:38205 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755427Ab1DOG72 (ORCPT ); Fri, 15 Apr 2011 02:59:28 -0400 Received: by bwz15 with SMTP id 15so1963895bwz.19 for ; Thu, 14 Apr 2011 23:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:subject:date:message-id:x-mailer; bh=7lsr22tE1hCaU3m7l71GAp0XKnrDyVGhRRpQtPJ/M3A=; b=thHU7zdrEE75Un4dRwOGFc5bKrCb0ECm7/HN5GLWkRYbre1PONqyy3JBBlUZF5SRMO 4jv6euTg61z3ZvXuxqFR6C6gLB6mhh6OJbpz4Hm2fk5c7K0ToOtF+J8XVTuT3O7QoF6P XvKJiGzroZoETUVV+inYVThP1gYCqBIW+7KoY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer; b=JTh6raHVq4q0z5R4T6QrImgCRPxIo6YstJJIC9JjyY+1ufPW6vOvitYjkgs0B6kj4x Rn3n9fIQYFDuvbQnKF/wLPRAkkbnuUWwP1YkTL7VnqwzW4TmGSETBkRjVJWgs4JdP+H7 B60jOaQ45ikCxWghoDq+t+O24xVQX1s/IhKu8= Received: by 10.204.128.85 with SMTP id j21mr1345281bks.89.1302850767467; Thu, 14 Apr 2011 23:59:27 -0700 (PDT) Received: from localhost.localdomain (PPPoE-78-29-118-4.san.ru [78.29.118.4]) by mx.google.com with ESMTPS id t1sm1354715bkx.7.2011.04.14.23.59.25 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 14 Apr 2011 23:59:26 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 1/4] CIFS: Simplify connection structure search calls Date: Fri, 15 Apr 2011 10:58:45 +0400 Message-Id: <1302850725-13867-1-git-send-email-piastry@etersoft.ru> X-Mailer: git-send-email 1.7.1 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 (demeter1.kernel.org [140.211.167.41]); Fri, 15 Apr 2011 06:59:34 +0000 (UTC) Use separate functions for comparison between existing structure and what we are requesting for to make server, session and tcon search code easier to use on next superblock match call. Signed-off-by: Pavel Shilovsky Reviewed-by: Jeff Layton --- fs/cifs/connect.c | 104 ++++++++++++++++++++++++++++++++--------------------- 1 files changed, 63 insertions(+), 41 deletions(-) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index dd9d3e9..990c3e0 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1640,32 +1640,41 @@ match_security(struct TCP_Server_Info *server, struct smb_vol *vol) return true; } -static struct TCP_Server_Info * -cifs_find_tcp_session(struct sockaddr *addr, struct smb_vol *vol) +static int match_server(struct TCP_Server_Info *server, struct sockaddr *addr, + struct smb_vol *vol) { - struct TCP_Server_Info *server; - - spin_lock(&cifs_tcp_ses_lock); - list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) { - if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns)) - continue; + if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns)) + return 0; - if (!match_address(server, addr, - (struct sockaddr *)&vol->srcaddr)) - continue; + if (!match_address(server, addr, + (struct sockaddr *)&vol->srcaddr)) + return 0; #ifdef CONFIG_CIFS_SMB2 - if ((server->is_smb2 == true) && (vol->use_smb2 == false)) - continue; + if ((server->is_smb2 == true) && (vol->use_smb2 == false)) + return 0; - if ((server->is_smb2 == false) && (vol->use_smb2 == true)) - continue; + if ((server->is_smb2 == false) && (vol->use_smb2 == true)) + return 0; #endif /* CONFIG_CIFS_SMB2 */ - if (!match_port(server, addr)) - continue; + if (!match_port(server, addr)) + return 0; + + if (!match_security(server, vol)) + return 0; + + return 1; +} + +static struct TCP_Server_Info * +cifs_find_tcp_session(struct sockaddr *addr, struct smb_vol *vol) +{ + struct TCP_Server_Info *server; - if (!match_security(server, vol)) + spin_lock(&cifs_tcp_ses_lock); + list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) { + if (!match_server(server, addr, vol)) continue; ++server->srv_count; @@ -1865,6 +1874,30 @@ out_err: return ERR_PTR(rc); } +static int match_session(struct cifs_ses *ses, struct smb_vol *vol) +{ + switch (ses->server->secType) { + case Kerberos: + if (vol->cred_uid != ses->cred_uid) + return 0; + break; + default: + /* anything else takes username/password */ + if (ses->user_name == NULL) + return 0; + if (strncmp(ses->user_name, vol->username, + MAX_USERNAME_SIZE)) + return 0; + if (strlen(vol->username) != 0 && + ses->password != NULL && + strncmp(ses->password, + vol->password ? vol->password : "", + MAX_PASSWORD_SIZE)) + return 0; + } + return 1; +} + static struct cifs_ses * cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol) { @@ -1872,25 +1905,8 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol) spin_lock(&cifs_tcp_ses_lock); list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { - switch (server->secType) { - case Kerberos: - if (vol->cred_uid != ses->cred_uid) - continue; - break; - default: - /* anything else takes username/password */ - if (ses->user_name == NULL) - continue; - if (strncmp(ses->user_name, vol->username, - MAX_USERNAME_SIZE)) - continue; - if (strlen(vol->username) != 0 && - ses->password != NULL && - strncmp(ses->password, - vol->password ? vol->password : "", - MAX_PASSWORD_SIZE)) - continue; - } + if (!match_session(ses, vol)) + continue; ++ses->ses_count; spin_unlock(&cifs_tcp_ses_lock); return ses; @@ -2033,6 +2049,15 @@ get_ses_fail: return ERR_PTR(rc); } +static int match_tcon(struct cifs_tcon *tcon, const char *unc) +{ + if (tcon->tidStatus == CifsExiting) + return 0; + if (strncmp(tcon->treeName, unc, MAX_TREE_SIZE)) + return 0; + return 1; +} + static struct cifs_tcon * cifs_find_tcon(struct cifs_ses *ses, const char *unc) { @@ -2042,11 +2067,8 @@ cifs_find_tcon(struct cifs_ses *ses, const char *unc) spin_lock(&cifs_tcp_ses_lock); list_for_each(tmp, &ses->tcon_list) { tcon = list_entry(tmp, struct cifs_tcon, tcon_list); - if (tcon->tidStatus == CifsExiting) - continue; - if (strncmp(tcon->treeName, unc, MAX_TREE_SIZE)) + if (!match_tcon(tcon, unc)) continue; - ++tcon->tc_count; spin_unlock(&cifs_tcp_ses_lock); return tcon;