From patchwork Wed Jul 10 09:59:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 2825582 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BEFEDC0AB2 for ; Wed, 10 Jul 2013 10:00:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0595920163 for ; Wed, 10 Jul 2013 10:00:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 02BD42015A for ; Wed, 10 Jul 2013 10:00:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754209Ab3GJKAS (ORCPT ); Wed, 10 Jul 2013 06:00:18 -0400 Received: from mail-la0-f50.google.com ([209.85.215.50]:47704 "EHLO mail-la0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753201Ab3GJKAQ (ORCPT ); Wed, 10 Jul 2013 06:00:16 -0400 Received: by mail-la0-f50.google.com with SMTP id ep20so1173200lab.23 for ; Wed, 10 Jul 2013 03:00:15 -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=Qns+Ny9hOlBe7ZbiC3i+bz5VB0Vm6tniwn7Do7YLbM4=; b=mTEPVjGAjenkv84KvHGFa2D4k+Pba+GNjXPrr5rfGv0ZP8n6iVTpdN7A7+2w/AjhJr 6HoclskUuU4uoEBZw9q4fe77p86UEnTAmmaqXGKDie+PewWReSYKfXvYQjb7drgsjSyc Nb9EBMHus0RMOt8zui0yWewLSiZnGO9NXfLhPI0xY7SdErrFXZzq/oKMggHh2LzBkCQT JFPKAFhk1HMFPLAodI0VwL64paMNZBhGSFXcMXH2H3R0Vxnjj+LV431L0BPZQQuLF+EB LP+9Z7FtyPDoltdmC3DsxPCs2AP2xNfrfH5aGwihM+OMkv4X+zdcQnJef1lVzHQxX1eY vMvQ== X-Received: by 10.112.28.48 with SMTP id y16mr14919631lbg.37.1373450415132; Wed, 10 Jul 2013 03:00:15 -0700 (PDT) Received: from localhost.localdomain (PPPoE-78-29-83-145.san.ru. [78.29.83.145]) by mx.google.com with ESMTPSA id 6sm10421833lbu.13.2013.07.10.03.00.13 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 10 Jul 2013 03:00:14 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 3/8] CIFS: Simplify SMB2_open code path Date: Wed, 10 Jul 2013 13:59:55 +0400 Message-Id: <1373450401-4135-4-git-send-email-pshilovsky@samba.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1373450401-4135-1-git-send-email-pshilovsky@samba.org> References: <1373450401-4135-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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP by passing a filename to a separate iovec regardless of its length. Signed-off-by: Pavel Shilovsky --- fs/cifs/smb2pdu.c | 59 ++++++++++++++++++++++------------------------------- fs/cifs/smb2pdu.h | 2 +- 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 4c046a5..9a35dcd 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -894,7 +894,7 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, __le16 *copy_path = NULL; int copy_size; int rc = 0; - int num_iovecs = 2; + unsigned int num_iovecs = 2; __u32 file_attributes = 0; cifs_dbg(FYI, "create/open\n"); @@ -919,47 +919,36 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, req->CreateDisposition = cpu_to_le32(create_disposition); req->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2; - req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req) - - 8 /* pad */ - 4 /* do not count rfc1001 len field */); + /* do not count rfc1001 len field */ + req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req) - 4); iov[0].iov_base = (char *)req; /* 4 for rfc1002 length field */ iov[0].iov_len = get_rfc1002_length(req) + 4; /* MUST set path len (NameLength) to 0 opening root of share */ - if (uni_path_len >= 4) { - req->NameLength = cpu_to_le16(uni_path_len - 2); - /* -1 since last byte is buf[0] which is sent below (path) */ - iov[0].iov_len--; - if (uni_path_len % 8 != 0) { - copy_size = uni_path_len / 8 * 8; - if (copy_size < uni_path_len) - copy_size += 8; - - copy_path = kzalloc(copy_size, GFP_KERNEL); - if (!copy_path) - return -ENOMEM; - memcpy((char *)copy_path, (const char *)path, - uni_path_len); - uni_path_len = copy_size; - path = copy_path; - } - - iov[1].iov_len = uni_path_len; - iov[1].iov_base = path; - /* - * -1 since last byte is buf[0] which was counted in - * smb2_buf_len. - */ - inc_rfc1001_len(req, uni_path_len - 1); - } else { - iov[0].iov_len += 7; - req->hdr.smb2_buf_length = cpu_to_be32(be32_to_cpu( - req->hdr.smb2_buf_length) + 8 - 1); - num_iovecs = 1; - req->NameLength = 0; + req->NameLength = cpu_to_le16(uni_path_len - 2); + /* -1 since last byte is buf[0] which is sent below (path) */ + iov[0].iov_len--; + if (uni_path_len % 8 != 0) { + copy_size = uni_path_len / 8 * 8; + if (copy_size < uni_path_len) + copy_size += 8; + + copy_path = kzalloc(copy_size, GFP_KERNEL); + if (!copy_path) + return -ENOMEM; + memcpy((char *)copy_path, (const char *)path, + uni_path_len); + uni_path_len = copy_size; + path = copy_path; } + iov[1].iov_len = uni_path_len; + iov[1].iov_base = path; + /* -1 since last byte is buf[0] which was counted in smb2_buf_len */ + inc_rfc1001_len(req, uni_path_len - 1); + if (!server->oplocks) *oplock = SMB2_OPLOCK_LEVEL_NONE; @@ -976,7 +965,7 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, iov[num_iovecs].iov_len = sizeof(struct create_lease); req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE; req->CreateContextsOffset = cpu_to_le32( - sizeof(struct smb2_create_req) - 4 - 8 + + sizeof(struct smb2_create_req) - 4 + iov[num_iovecs-1].iov_len); req->CreateContextsLength = cpu_to_le32( sizeof(struct create_lease)); diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h index f31043b..8b1025f 100644 --- a/fs/cifs/smb2pdu.h +++ b/fs/cifs/smb2pdu.h @@ -428,7 +428,7 @@ struct smb2_create_req { __le16 NameLength; __le32 CreateContextsOffset; __le32 CreateContextsLength; - __u8 Buffer[8]; + __u8 Buffer[0]; } __packed; struct smb2_create_rsp {