From patchwork Mon Jan 30 21:39:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovskiy X-Patchwork-Id: 9546117 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5805D604CC for ; Mon, 30 Jan 2017 21:42:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6315B283B3 for ; Mon, 30 Jan 2017 21:42:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 580C6283F1; Mon, 30 Jan 2017 21:42:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41659283B4 for ; Mon, 30 Jan 2017 21:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754380AbdA3VmM (ORCPT ); Mon, 30 Jan 2017 16:42:12 -0500 Received: from mail-by2nam03on0114.outbound.protection.outlook.com ([104.47.42.114]:27280 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754460AbdA3VmF (ORCPT ); Mon, 30 Jan 2017 16:42:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=bXBwqe0SsplEVPcA4iHsdYe+mgRh+6sx41JGRBD/rhM=; b=MxtC7v7UK+niTtKsKy/36PEKmReSoViYrHL2afzOM/e82RknwzKPpI1RNLSE/r64S5+tsr3R5fSXvvaVVRBqF0Zc+cwdDayWhmIUX5iwzo/tuHw47cSvsazf07fs2aD0oElfi0q1ZpsufkDu6W3GuF7yQp0QUDGrojsqGWbWres= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pshilov@microsoft.com; Received: from ubuntu-vm.corp.microsoft.com (2001:4898:80e8:b::63b) by BN6PR03MB2545.namprd03.prod.outlook.com (10.173.142.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.874.12; Mon, 30 Jan 2017 21:39:56 +0000 From: Pavel Shilovsky To: Subject: [PATCH v2 05/15] CIFS: Separate SMB2 sync header processing Date: Mon, 30 Jan 2017 13:39:34 -0800 Message-ID: <1485812384-28870-6-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485812384-28870-1-git-send-email-pshilov@microsoft.com> References: <1485812384-28870-1-git-send-email-pshilov@microsoft.com> MIME-Version: 1.0 X-Originating-IP: [2001:4898:80e8:b::63b] X-ClientProxiedBy: BN6PR1401CA0011.namprd14.prod.outlook.com (10.174.237.149) To BN6PR03MB2545.namprd03.prod.outlook.com (10.173.142.148) X-MS-Office365-Filtering-Correlation-Id: 29152f9e-7baf-414f-a41b-08d4495888e2 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BN6PR03MB2545; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2545; 3:W1G2OWQdHpf6jlL+uY4i7eoP6lcaHJIy5YBhWyLveF6xSPoMvkDsjgqGLkdHURR0ck3tjvlhCLpQBerGoSTbO8AoinG3gL3T1XEWcFHuVd7bL9IpjubBgZwEBW+x632JFjEf9nMVK93lyoenxJgsHy0hvYzLJEIJ7gfwLH3cCPjanxAMZWj7A3i48kFnF5LtuhEC5j1j6kqE+5/TMpkh96MSJ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m4PtY1eyn0dusxDajcyI/XWUlWaDCM9DiOVBzhX27cnJ35NpHqDvS8aoW/372Pbf3c6+Q5zdM308vu7i/FqNLCgqKP6mifdJnvlhhYZ3bH1ZG+7sjxo=; 20:x0Pq3JREPS8VgaqYmUpvUCmFSV3Ucdv0SQVD/JLCuwnwLACNn2D2F3OsZa4aVqsuYTcbGbtOJ9U5o6kBUTO2h1C5FlLmLazpSoARhBu4kvh+GaJPbUmjLhdbU3ztf6dLRijaY5mJ3S14TK+wzzbhy8N56Mt/DgWs5O1y4Wn/2p/C9Zl98T3C2NBo9EQoSKPVWtr1AMwjold1pi+yw8uS8+52oExqMBQ0+fLRX0w3owf8MCnbaKc79i2whRDdKREUuuNBPfdHnWFCfuZXxD3GGURMq3z2XjyXihzjAShNnKnQElYwb9MzUsaddHbSTph3RhMOfgwWL6nshVDaqXmDAbA8FFDp71zagNVCnKD6TArOKkqcap4MaO4QuvMdqQiANSUNI0DNcLg+kX9AR3cIxHZ77B0MoWg9buhngSN/oLYLh6/kiAw9KoTjBLgglylebaATqbN0l9G6b1RxJccdkO2tb8222wurWh5a/LCSH0EVaVYe7zHRXE37CrTnIXAq X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(158342451672863); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123555025)(20161123564025)(20161123562025)(20161123560025)(6072148)(6047074); SRVR:BN6PR03MB2545; BCL:0; PCL:0; RULEID:; SRVR:BN6PR03MB2545; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2545; 4:wocnVbEYnhxqX1knNbytUYTS4+4RZsHI+JXCehwy7pVvx8lm3O1jBUpMXg0+Ndz/tT8vFJ+deYksyDzya9gkHZii9nYJz+nznb+ul57I+exh3QO9uy+vZGVllAWCORYTWR7a/0CvxDNH+NmOoqmQ9mHDbO10/enmj6+BcfdYjbCdue3jlMX2ar08dglTLvSUBquOpYL0Z6mHu6AOoYKlpr5beGW2aDgC9QKKgT2Byl5ajDAHMhJYNlPyYIde7cV61w5qyytbG9+LNw9PphE0/D51MTPmdg8p3SLfOQBwemE6Kt76tPJJJDHK3KN+NC4w2bm6vcfZ79kPqtHvCOPgrfBqXMn8HO0jRfnkEG8M6z+mzl5Vp+sy1o/aOwSk0Tzv9dkXox3XiU1PlNrHHSYj5pDD2u7CD4F7jWm0IyNbi6VVMFFdw/yb5xKse1XnBl8Iwxt2imENEtDhWB+BqSxznD4yODzfgJdRNF8z2OpGBJA8OUdLXgxelRj6t7EPt3dXM3TywwtHBqj4Vf7EPGh0hz5KPAm6IftTjWefektbKE8prOyynM3q9R8XWV4Pa+ihF7PzSCFII7PcoL/EOJun2Dt0ToLTXUEzEJPoe15f/jwM9qNNw6rUxlS5Apn3/9LJxdqWxNZk5w1Hbg+pJh8oDa2XjRVoALs89UhFV+GKers= X-Forefront-PRVS: 0203C93D51 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(39450400003)(39410400002)(39840400002)(39860400002)(39850400002)(189002)(199003)(86612001)(38730400001)(25786008)(6916009)(6666003)(106356001)(2950100002)(189998001)(50986999)(76176999)(86362001)(50226002)(105586002)(68736007)(107886002)(97736004)(2906002)(450100001)(6486002)(53936002)(101416001)(42186005)(8676002)(5660300001)(81166006)(305945005)(50466002)(81156014)(48376002)(5003940100001)(6116002)(36756003)(2351001)(92566002)(10290500002)(110136003)(7736002)(10090500001)(33646002)(47776003)(5005710100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN6PR03MB2545; H:ubuntu-vm.corp.microsoft.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR03MB2545; 23:Xj0d2mVwikgnq8faZQxlOMvsXIn838JW5+twUx0oo?= =?us-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poFnhqzHIaBbuCW5llyVg9G8zcMqokmv9GSRMTuhUIU=; 24:PSJvEVNSZxORuUaVme0+Wxz+gontw4/OZnHRAoOj961kuIr4iMJ45NKOjkwJMP4z6o2wFrRCJYAgGRjpXdUXWtmS5pXp1wdygi38zCBDWRU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2545; 7:fh9CZn+PDpIwil4IqlGdbxdnTgIDKPXpNKk0i6tAD+WC6hzXssbcCAn/aC9KI+HBCFzwh35GkQ3EOMWmswL9pvt7fEgN2lobZ0UKpgvt4O+JT6Rz2a7FaIK/ukTuUPXtXrV3K7OK22AWVGDoz1fqbkSE2A8nspDF/ZWiYaPtTai6LeR9i9kAQUgig+XyE+rVd4r/KsUG0Q0PMK2quYuT7nq1S7MGeMX78aXoIq4lKxGaLw6CRKmgi9D0q7y4ktSKsv0Le2Cf0Ve3Lq/y0/0DCiAuNYnnHJTwkKS14enCdcWXn7FdQbV4MiXbVJnFsR5tvx7Hr01qTlNp61LjRUgYVih7aCmFO3lnfhhIrxWaybQQ7z4XgXRd4qWvH0yM0vFeWm1DmK/jITRib0vVe15gqXgdISpqaESBHFVxJ5+KfSK6EAeB2oX09iG+XTzqmw6WTQbDfl275rUzOCHx/ttEZQ== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2017 21:39:56.6304 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR03MB2545 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Do not process RFC1001 length in smb2_hdr_assemble() because it is not a part of SMB2 header. This allows to cleanup the code and adds a possibility combine several SMB2 packets into one for compounding. Signed-off-by: Pavel Shilovsky --- fs/cifs/smb2pdu.c | 50 ++++++++++++++++++++++++++++++-------------------- fs/cifs/smb2pdu.h | 5 +++++ 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 438c4b1..f6ba2c0 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -79,25 +79,9 @@ static const int smb2_req_struct_sizes[NUMBER_OF_SMB2_COMMANDS] = { static void -smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ , +smb2_hdr_assemble(struct smb2_sync_hdr *shdr, __le16 smb2_cmd, const struct cifs_tcon *tcon) { - struct smb2_pdu *pdu = (struct smb2_pdu *)hdr; - struct smb2_sync_hdr *shdr = get_sync_hdr(hdr); - char *temp = (char *)hdr; - /* lookup word count ie StructureSize from table */ - __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_cmd)]; - - /* - * smaller than SMALL_BUFFER_SIZE but bigger than fixed area of - * largest operations (Create) - */ - memset(temp, 0, 256); - - /* Note this is only network field converted to big endian */ - hdr->smb2_buf_length = - cpu_to_be32(parmsize + sizeof(struct smb2_sync_hdr)); - shdr->ProtocolId = SMB2_PROTO_NUMBER; shdr->StructureSize = cpu_to_le16(64); shdr->Command = smb2_cmd; @@ -149,7 +133,6 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ , if (tcon->ses && tcon->ses->server && tcon->ses->server->sign) shdr->Flags |= SMB2_FLAGS_SIGNED; out: - pdu->StructureSize2 = cpu_to_le16(parmsize); return; } @@ -290,6 +273,26 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon) return rc; } +static void +fill_small_buf(__le16 smb2_command, struct cifs_tcon *tcon, void *buf, + unsigned int *total_len) +{ + struct smb2_sync_pdu *spdu = (struct smb2_sync_pdu *)buf; + /* lookup word count ie StructureSize from table */ + __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_command)]; + + /* + * smaller than SMALL_BUFFER_SIZE but bigger than fixed area of + * largest operations (Create) + */ + memset(buf, 0, 256); + + smb2_hdr_assemble(&spdu->sync_hdr, smb2_command, tcon); + spdu->StructureSize2 = cpu_to_le16(parmsize); + + *total_len = parmsize + sizeof(struct smb2_sync_hdr); +} + /* * Allocate and return pointer to an SMB request hdr, and set basic * SMB information in the SMB header. If the return code is zero, this @@ -299,7 +302,9 @@ static int small_smb2_init(__le16 smb2_command, struct cifs_tcon *tcon, void **request_buf) { - int rc = 0; + int rc; + unsigned int total_len; + struct smb2_pdu *pdu; rc = smb2_reconnect(smb2_command, tcon); if (rc) @@ -312,7 +317,12 @@ small_smb2_init(__le16 smb2_command, struct cifs_tcon *tcon, return -ENOMEM; } - smb2_hdr_assemble((struct smb2_hdr *) *request_buf, smb2_command, tcon); + pdu = (struct smb2_pdu *)(*request_buf); + + fill_small_buf(smb2_command, tcon, get_sync_hdr(pdu), &total_len); + + /* Note this is only network field converted to big endian */ + pdu->hdr.smb2_buf_length = cpu_to_be32(total_len); if (tcon != NULL) { #ifdef CONFIG_CIFS_STATS2 diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h index 8dd24b7..052342d 100644 --- a/fs/cifs/smb2pdu.h +++ b/fs/cifs/smb2pdu.h @@ -117,6 +117,11 @@ struct smb2_sync_hdr { __u8 Signature[16]; } __packed; +struct smb2_sync_pdu { + struct smb2_sync_hdr sync_hdr; + __le16 StructureSize2; /* size of wct area (varies, request specific) */ +} __packed; + struct smb2_hdr { __be32 smb2_buf_length; /* big endian on wire */ /* length is only two or three bytes - with */