From patchwork Tue Oct 6 10:47:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 7336761 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EB206BEEA4 for ; Tue, 6 Oct 2015 16:08:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E9A49206FD for ; Tue, 6 Oct 2015 16:08:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BCF7B2064D for ; Tue, 6 Oct 2015 16:08:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752293AbbJFQID (ORCPT ); Tue, 6 Oct 2015 12:08:03 -0400 Received: from mail-ob0-f169.google.com ([209.85.214.169]:35767 "EHLO mail-ob0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751829AbbJFQIB (ORCPT ); Tue, 6 Oct 2015 12:08:01 -0400 Received: by obbzf10 with SMTP id zf10so157815140obb.2 for ; Tue, 06 Oct 2015 09:08:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=lfYaosJ6VzbU1U0cOg8ePSO4RrtoGgDfvlDig1xfA84=; b=GozSuoFE8+Tdf41wcJgnViAw1DYHA1tn/KCQcKWLlysnX/y6Ht1VaFcj7YsfTnF62Y GqfO109XvOdxkJjveriHxF6q7p/YsgQf2sECiNiRI/a7Mplo8sLI3sJjCeY/kX0wUkbi EW7wX4s+3HoLWm1J0N+JtixYM9hLJkUD48YySPug1v9PqbggdDbWT0ldzO99e3Cee62t pR6cNeWAXqdRf2JDb6blRGxv/cjDaWqQxGaqzqoVveCRyF2cxYxN1N26Le5XRNNaK5J4 6BDTxk054f09BZCDqpVisX5T7pgK3sQA2HywxKIFfgFiHH8P1Q0vF/y5njvX3PofLG85 9Bew== X-Received: by 10.60.160.37 with SMTP id xh5mr22749689oeb.61.1444147680811; Tue, 06 Oct 2015 09:08:00 -0700 (PDT) Received: from ubuntu.localdomain (cpe-68-203-16-26.austin.res.rr.com. [68.203.16.26]) by smtp.gmail.com with ESMTPSA id y10sm14645376oie.10.2015.10.06.09.07.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Oct 2015 09:08:00 -0700 (PDT) From: Steve French To: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org Cc: Steve French , Steve French Subject: [PATCH] [SMB3] Add resilienthandles mount parm Date: Tue, 6 Oct 2015 05:47:54 -0500 Message-Id: <1444128474-67439-1-git-send-email-smfrench@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DATE_IN_PAST_03_06, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 Version 2 of patch (adds resiliency ioctl). Since many servers (Windows clients, and non-clustered servers) do not support persistent handles but do support resilient handles, allow the user to specify a mount option "resilienthandles" in order to get more reliable connections and less chance of data loss (at least when SMB2.1 or later). Default resilient handle timeout (120 seconds to recent Windows server) is used. Reviewed-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/cifsfs.c | 2 ++ fs/cifs/cifsglob.h | 2 ++ fs/cifs/connect.c | 24 +++++++++++++++++++++++- fs/cifs/smb2file.c | 19 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 13302e9..f578ef9 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -456,6 +456,8 @@ cifs_show_options(struct seq_file *s, struct dentry *root) seq_puts(s, ",hard"); if (tcon->use_persistent) seq_puts(s, ",persistenthandles"); + else if (tcon->use_resilient) + seq_puts(s, ",resilienthandles"); if (tcon->unix_ext) seq_puts(s, ",unix"); else diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index ec31a03..472daeb 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -496,6 +496,7 @@ struct smb_vol { bool nosharesock:1; bool persistent:1; bool nopersistent:1; + bool resilient:1; /* noresilient not required since not fored for CA */ unsigned int rsize; unsigned int wsize; bool sockopt_tcp_nodelay:1; @@ -901,6 +902,7 @@ struct cifs_tcon { bool broken_posix_open; /* e.g. Samba server versions < 3.3.2, 3.2.9 */ bool broken_sparse_sup; /* if server or share does not support sparse */ bool need_reconnect:1; /* connection reset, tid now invalid */ + bool use_resilient:1; /* use resilient instead of durable handles */ bool use_persistent:1; /* use persistent instead of durable handles */ #ifdef CONFIG_CIFS_SMB2 bool print:1; /* set if connection to printer share */ diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 9e44532..1e7840a 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -88,6 +88,7 @@ enum { Opt_fsc, Opt_mfsymlinks, Opt_multiuser, Opt_sloppy, Opt_nosharesock, Opt_persistent, Opt_nopersistent, + Opt_resilient, Opt_noresilient, /* Mount options which take numeric value */ Opt_backupuid, Opt_backupgid, Opt_uid, @@ -172,6 +173,8 @@ static const match_table_t cifs_mount_option_tokens = { { Opt_nosharesock, "nosharesock" }, { Opt_persistent, "persistenthandles"}, { Opt_nopersistent, "nopersistenthandles"}, + { Opt_resilient, "resilienthandles"}, + { Opt_noresilient, "noresilienthandles"}, { Opt_backupuid, "backupuid=%s" }, { Opt_backupgid, "backupgid=%s" }, @@ -1510,12 +1513,23 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, break; case Opt_persistent: vol->persistent = true; - if (vol->nopersistent) { + if ((vol->nopersistent) || (vol->resilient)) { cifs_dbg(VFS, "persistenthandles mount options conflict\n"); goto cifs_parse_mount_err; } break; + case Opt_resilient: + vol->resilient = true; + if (vol->persistent) { + cifs_dbg(VFS, + "persistenthandles mount options conflict\n"); + goto cifs_parse_mount_err; + } + break; + case Opt_noresilient: + vol->resilient = false; /* this is already the default */ + break; /* Numeric Values */ case Opt_backupuid: @@ -2695,6 +2709,14 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) && (volume_info->nopersistent == false)) { cifs_dbg(FYI, "enabling persistent handles\n"); tcon->use_persistent = true; + } else if (volume_info->resilient) { + if (ses->server->vals->protocol_id == 0) { + cifs_dbg(VFS, + "SMB2.1 or later required for resilient handles\n"); + rc = -EOPNOTSUPP; + goto out_fail; + } + tcon->use_resilient = true; } /* diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c index 2ab297d..f9e766f 100644 --- a/fs/cifs/smb2file.c +++ b/fs/cifs/smb2file.c @@ -43,6 +43,7 @@ smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, struct smb2_file_all_info *smb2_data = NULL; __u8 smb2_oplock[17]; struct cifs_fid *fid = oparms->fid; + struct network_resiliency_req nr_ioctl_req; smb2_path = cifs_convert_path_to_utf16(oparms->path, oparms->cifs_sb); if (smb2_path == NULL) { @@ -67,6 +68,24 @@ smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, if (rc) goto out; + + if (oparms->tcon->use_resilient) { + nr_ioctl_req.Timeout = 0; /* use server default (120 seconds) */ + nr_ioctl_req.Reserved = 0; + rc = SMB2_ioctl(xid, oparms->tcon, fid->persistent_fid, + fid->volatile_fid, FSCTL_LMR_REQUEST_RESILIENCY, true, + (char *)&nr_ioctl_req, sizeof(nr_ioctl_req), + NULL, NULL /* no return info */); + if (rc == -EOPNOTSUPP) { + cifs_dbg(VFS, + "resiliency not supported by server, disabling\n"); + oparms->tcon->use_resilient = false; + } else if (rc) + cifs_dbg(FYI, "error %d setting resiliency\n", rc); + + rc = 0; + } + if (buf) { /* open response does not have IndexNumber field - get it */ rc = SMB2_get_srv_num(xid, oparms->tcon, fid->persistent_fid,