From patchwork Wed Jul 10 09:59:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 2825585 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 092EB9F756 for ; Wed, 10 Jul 2013 10:00:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3594A20163 for ; Wed, 10 Jul 2013 10:00:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED1AA2011B for ; Wed, 10 Jul 2013 10:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754213Ab3GJKAX (ORCPT ); Wed, 10 Jul 2013 06:00:23 -0400 Received: from mail-la0-f50.google.com ([209.85.215.50]:33339 "EHLO mail-la0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754017Ab3GJKAU (ORCPT ); Wed, 10 Jul 2013 06:00:20 -0400 Received: by mail-la0-f50.google.com with SMTP id ep20so1173247lab.23 for ; Wed, 10 Jul 2013 03:00:18 -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=pEWDsBiWP9bvPvE+8ujlymPxOofaZlagI0PEvpQ0rNo=; b=rDPS/8dc34X3H+zEt8BqH2eTAU6GfhsiK+lOsXBVfFH5jBsDCBvk4yG4D+NfZH4Fmo /eErTyQCg8vSIE7gErQzmTAO+CQlf5WfPhKcsir3MWldPqwuCel1JpFsACrUHy0maOst JNNHjBNpsB+Pb7Pxwo/cgbj4799gCCd08kEPfOpGYpZk1aK/iO8t2qT1u0MvP4h74G83 UpJzF/4be3C5rIq8xnX18ei1l8PlFoxlNrqsL9akBiAAYo8TeKCaMLBLujgO+8zIRxr0 YVZT95h3avp7P5hsNRiDLivhW3vKg83pcPu/P8VyVR5a3rdEd9yWRZmNCTTjFNaislxv 16YA== X-Received: by 10.112.218.68 with SMTP id pe4mr14514614lbc.40.1373450418391; Wed, 10 Jul 2013 03:00:18 -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.16 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 10 Jul 2013 03:00:17 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 5/8] CIFS: Request durable open for SMB2 opens Date: Wed, 10 Jul 2013 13:59:57 +0400 Message-Id: <1373450401-4135-6-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 durable context together with a handle caching lease or batch oplock. Signed-off-by: Pavel Shilovsky --- fs/cifs/smb2file.c | 2 +- fs/cifs/smb2pdu.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++- fs/cifs/smb2pdu.h | 6 +++++ 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c index 46a4299..150a9b1 100644 --- a/fs/cifs/smb2file.c +++ b/fs/cifs/smb2file.c @@ -81,7 +81,7 @@ smb2_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path, } desired_access |= FILE_READ_ATTRIBUTES; - *smb2_oplock = SMB2_OPLOCK_LEVEL_EXCLUSIVE; + *smb2_oplock = SMB2_OPLOCK_LEVEL_BATCH; if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) memcpy(smb2_oplock + 1, fid->lease_key, SMB2_LEASE_KEY_SIZE); diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index e65ccdb..140a613 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -847,6 +847,28 @@ create_lease_buf(u8 *lease_key, u8 oplock) return buf; } +static struct create_durable * +create_durable_buf(void) +{ + struct create_durable *buf; + + buf = kzalloc(sizeof(struct create_durable), GFP_KERNEL); + if (!buf) + return NULL; + + buf->ccontext.DataOffset = cpu_to_le16(offsetof + (struct create_durable, Reserved)); + buf->ccontext.DataLength = cpu_to_le32(16); + buf->ccontext.NameOffset = cpu_to_le16(offsetof + (struct create_durable, Name)); + buf->ccontext.NameLength = cpu_to_le16(4); + buf->Name[0] = 'D'; + buf->Name[1] = 'H'; + buf->Name[2] = 'n'; + buf->Name[3] = 'Q'; + return buf; +} + static __u8 parse_lease_state(struct smb2_create_rsp *rsp) { @@ -901,6 +923,28 @@ add_lease_context(struct kvec *iov, unsigned int *num_iovec, __u8 *oplock) return 0; } +static int +add_durable_context(struct kvec *iov, unsigned int *num_iovec) +{ + struct smb2_create_req *req = iov[0].iov_base; + unsigned int num = *num_iovec; + + iov[num].iov_base = create_durable_buf(); + if (iov[num].iov_base == NULL) + return -ENOMEM; + iov[num].iov_len = sizeof(struct create_durable); + if (!req->CreateContextsOffset) + req->CreateContextsOffset = + cpu_to_le32(sizeof(struct smb2_create_req) - 4 + + iov[1].iov_len); + req->CreateContextsLength = + cpu_to_le32(le32_to_cpu(req->CreateContextsLength) + + sizeof(struct create_durable)); + inc_rfc1001_len(&req->hdr, sizeof(struct create_durable)); + *num_iovec = num + 1; + return 0; +} + int SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, u64 *persistent_fid, u64 *volatile_fid, __u32 desired_access, @@ -911,7 +955,7 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, struct smb2_create_rsp *rsp; struct TCP_Server_Info *server; struct cifs_ses *ses = tcon->ses; - struct kvec iov[3]; + struct kvec iov[4]; int resp_buftype; int uni_path_len; __le16 *copy_path = NULL; @@ -987,6 +1031,22 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, } } + if (*oplock == SMB2_OPLOCK_LEVEL_BATCH) { + /* need to set Next field of lease context if we request it */ + if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) { + struct create_context *ccontext = + (struct create_context *)iov[num_iovecs-1].iov_base; + ccontext->Next = sizeof(struct create_lease); + } + rc = add_durable_context(iov, &num_iovecs); + if (rc) { + cifs_small_buf_release(req); + kfree(copy_path); + kfree(iov[num_iovecs-1].iov_base); + return rc; + } + } + rc = SendReceive2(xid, ses, iov, num_iovecs, &resp_buftype, 0); rsp = (struct smb2_create_rsp *)iov[0].iov_base; diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h index 8b1025f..3e30f0a 100644 --- a/fs/cifs/smb2pdu.h +++ b/fs/cifs/smb2pdu.h @@ -485,6 +485,12 @@ struct create_lease { struct lease_context lcontext; } __packed; +struct create_durable { + struct create_context ccontext; + __u8 Name[8]; + __u8 Reserved[16]; +} __packed; + /* this goes in the ioctl buffer when doing a copychunk request */ struct copychunk_ioctl { char SourceKey[24];