From patchwork Fri Jul 13 07:53:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 1194051 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 382F93FC4C for ; Fri, 13 Jul 2012 07:55:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754547Ab2GMHzD (ORCPT ); Fri, 13 Jul 2012 03:55:03 -0400 Received: from mail-lb0-f174.google.com ([209.85.217.174]:45138 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753739Ab2GMHzC (ORCPT ); Fri, 13 Jul 2012 03:55:02 -0400 Received: by mail-lb0-f174.google.com with SMTP id gm6so5433168lbb.19 for ; Fri, 13 Jul 2012 00:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=R1mCqaDyN0lVdnndEtxCRRFOVkgfrpOv/k3NBD9Svkk=; b=h5TMsbbs+0trBQn4pcSxABhFA3CdZmBnN/erinJv7ZvAlQW/WGnsgxkma5LWw17vzo B3mMSTFs87mu7s3D8SHxrM5LjSW7+2Rn849xOQS0Wag2hafBUYEy+QBaSQ21PYdPzNgV xSsaxLiYQMO07rZtCe17gAHEMPsoEmGVMBHAMhO/CCiAecuWXvYx5DJj9+a+HqN+zRJN WhXgMaGGoEywdvCul1SYkQipfxING01BXaj2sk6sPaGgTAkh/MXBHIm7DvowCWjBq8el fFq4shh6S5FZv+za50R7vsQTFQFl2OsrQJnewIuZJlEEOpQZCS4vrCVbjHSE0e0fnmrx 2SKg== Received: by 10.112.36.97 with SMTP id p1mr305867lbj.37.1342166101903; Fri, 13 Jul 2012 00:55:01 -0700 (PDT) Received: from localhost.localdomain ([178.45.132.158]) by mx.google.com with ESMTPS id er3sm1595545lbb.16.2012.07.13.00.55.00 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 13 Jul 2012 00:55:01 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH v3 03/32] CIFS: Move protocol specific negotiate code to ops struct Date: Fri, 13 Jul 2012 11:53:16 +0400 Message-Id: <1342166025-29377-4-git-send-email-pshilovsky@samba.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1342166025-29377-1-git-send-email-pshilovsky@samba.org> References: <1342166025-29377-1-git-send-email-pshilovsky@samba.org> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Reviewed-by: Jeff Layton Signed-off-by: Pavel Shilovsky --- fs/cifs/cifsglob.h | 8 ++++++-- fs/cifs/cifsproto.h | 6 +++--- fs/cifs/cifssmb.c | 4 ++-- fs/cifs/connect.c | 24 +++++++++++------------- fs/cifs/sess.c | 2 +- fs/cifs/smb1ops.c | 23 +++++++++++++++++++++++ 6 files changed, 46 insertions(+), 21 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 844b77c..8a41505 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -192,6 +192,10 @@ struct smb_version_operations { /* process transaction2 response */ bool (*check_trans2)(struct mid_q_entry *, struct TCP_Server_Info *, char *, int); + /* check if we need to negotiate */ + bool (*need_neg)(struct TCP_Server_Info *); + /* negotiate to the server */ + int (*negotiate)(const unsigned int, struct cifs_ses *); }; struct smb_version_values { @@ -324,7 +328,7 @@ struct TCP_Server_Info { struct mutex srv_mutex; struct task_struct *tsk; char server_GUID[16]; - char sec_mode; + __u16 sec_mode; bool session_estab; /* mark when very first sess is established */ u16 dialect; /* dialect index that server chose */ enum securityEnum secType; @@ -459,7 +463,7 @@ struct cifs_ses { char *serverOS; /* name of operating system underlying server */ char *serverNOS; /* name of network operating system of server */ char *serverDomain; /* security realm of server */ - int Suid; /* remote smb uid */ + __u64 Suid; /* remote smb uid */ uid_t linux_uid; /* overriding owner of files on the mount */ uid_t cred_uid; /* owner of credentials */ int capabilities; diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index f52074d..047b87e 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h @@ -178,11 +178,11 @@ extern void cifs_dfs_release_automount_timer(void); void cifs_proc_init(void); void cifs_proc_clean(void); -extern int cifs_negotiate_protocol(unsigned int xid, - struct cifs_ses *ses); +extern int cifs_negotiate_protocol(const unsigned int xid, + struct cifs_ses *ses); extern int cifs_setup_session(unsigned int xid, struct cifs_ses *ses, struct nls_table *nls_info); -extern int CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses); +extern int CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses); extern int CIFSTCon(unsigned int xid, struct cifs_ses *ses, const char *tree, struct cifs_tcon *tcon, diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 6cfbeec..22a6d6b 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -396,7 +396,7 @@ static inline void inc_rfc1001_len(void *pSMB, int count) } int -CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses) +CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses) { NEGOTIATE_REQ *pSMB; NEGOTIATE_RSP *pSMBr; @@ -480,7 +480,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses) rc = -EOPNOTSUPP; goto neg_err_exit; } - server->sec_mode = (__u8)le16_to_cpu(rsp->SecurityMode); + server->sec_mode = le16_to_cpu(rsp->SecurityMode); server->maxReq = min_t(unsigned int, le16_to_cpu(rsp->MaxMpxCount), cifs_max_pending); diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 7ada0ab..91b66b0 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -406,7 +406,7 @@ cifs_echo_request(struct work_struct *work) * done, which is indicated by maxBuf != 0. Also, no need to ping if * we got a response recently */ - if (server->maxBuf == 0 || + if (!server->ops->need_neg || server->ops->need_neg(server) || time_before(jiffies, server->lstrp + SMB_ECHO_INTERVAL - HZ)) goto requeue_echo; @@ -2405,7 +2405,8 @@ static bool warned_on_ntlm; /* globals init to false automatically */ static struct cifs_ses * cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info) { - int rc = -ENOMEM, xid; + int rc = -ENOMEM; + unsigned int xid; struct cifs_ses *ses; struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; @@ -3959,24 +3960,22 @@ cifs_umount(struct cifs_sb_info *cifs_sb) kfree(cifs_sb); } -int cifs_negotiate_protocol(unsigned int xid, struct cifs_ses *ses) +int +cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses) { int rc = 0; struct TCP_Server_Info *server = ses->server; + if (!server->ops->need_neg || !server->ops->negotiate) + return -ENOSYS; + /* only send once per connect */ - if (server->maxBuf != 0) + if (!server->ops->need_neg(server)) return 0; set_credits(server, 1); - rc = CIFSSMBNegotiate(xid, ses); - if (rc == -EAGAIN) { - /* retry only once on 1st time connection */ - set_credits(server, 1); - rc = CIFSSMBNegotiate(xid, ses); - if (rc == -EAGAIN) - rc = -EHOSTDOWN; - } + + rc = server->ops->negotiate(xid, ses); if (rc == 0) { spin_lock(&GlobalMid_Lock); if (server->tcpStatus == CifsNeedNegotiate) @@ -3984,7 +3983,6 @@ int cifs_negotiate_protocol(unsigned int xid, struct cifs_ses *ses) else rc = -EHOSTDOWN; spin_unlock(&GlobalMid_Lock); - } return rc; diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c index 551d0c2..f88fa4d 100644 --- a/fs/cifs/sess.c +++ b/fs/cifs/sess.c @@ -898,7 +898,7 @@ ssetup_ntlmssp_authenticate: if (action & GUEST_LOGIN) cFYI(1, "Guest login"); /* BB mark SesInfo struct? */ ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */ - cFYI(1, "UID = %d ", ses->Suid); + cFYI(1, "UID = %llu ", ses->Suid); /* response can have either 3 or 4 word count - Samba sends 3 */ /* and lanman response is 3 */ bytes_remaining = get_bcc(smb_buf); diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c index f4f8394..ea4fb8a 100644 --- a/fs/cifs/smb1ops.c +++ b/fs/cifs/smb1ops.c @@ -389,6 +389,27 @@ cifs_check_trans2(struct mid_q_entry *mid, struct TCP_Server_Info *server, return true; } +static bool +cifs_need_neg(struct TCP_Server_Info *server) +{ + return server->maxBuf == 0; +} + +static int +cifs_negotiate(const unsigned int xid, struct cifs_ses *ses) +{ + int rc; + rc = CIFSSMBNegotiate(xid, ses); + if (rc == -EAGAIN) { + /* retry only once on 1st time connection */ + set_credits(ses->server, 1); + rc = CIFSSMBNegotiate(xid, ses); + if (rc == -EAGAIN) + rc = -EHOSTDOWN; + } + return rc; +} + struct smb_version_operations smb1_operations = { .send_cancel = send_nt_cancel, .compare_fids = cifs_compare_fids, @@ -407,6 +428,8 @@ struct smb_version_operations smb1_operations = { .dump_detail = cifs_dump_detail, .is_oplock_break = is_valid_oplock_break, .check_trans2 = cifs_check_trans2, + .need_neg = cifs_need_neg, + .negotiate = cifs_negotiate, }; struct smb_version_values smb1_values = {