From patchwork Thu Mar 30 14:57:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1763298 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=Tq0oJGx8; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PnRNM3cgqz1yZ0 for ; Fri, 31 Mar 2023 01:57:22 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1phtiD-0001Yo-Pp; Thu, 30 Mar 2023 14:57:13 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1phtiB-0001YR-VI for kernel-team@lists.ubuntu.com; Thu, 30 Mar 2023 14:57:11 +0000 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 9F1FA3F204 for ; Thu, 30 Mar 2023 14:57:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1680188231; bh=AzoSWOCCq4d0OjEVD0IF0IbCNLEYTJn6gEWPVTFfqNA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Tq0oJGx8pyJ5RYLoetMuro96FVWJxyDOxODZ90miJkVkb+Pfk2uuAopPeBnvsdqNH xe9NLQ+4uzTn7bIASDad4Ci9KeuzPcR16cUcGpD5NCvf0mGRtdHOVoku+MW6OYnKaN AfvssW349phOHoFsxxTsNmYJFEAwRh60LylKuXMzjCq54wbHZ877Sk58Qc5IzLGqpX v8JFw4SHUTzX0ITvqOcirZ/oTu5ntUTsOjEhH4VrqJEDkL1fiHgUsNQgmX0R5yMaJG uyzatXS8zo8CEJtRYZUbc6vOTPmxsFzxet335ixA19tqhjQjCLuNjijF+rOvs6iIaZ Xys21zh5Ycq4w== Received: by mail-pl1-f200.google.com with SMTP id u18-20020a170902e5d200b001a1d70ea3b6so11225637plf.6 for ; Thu, 30 Mar 2023 07:57:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680188230; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AzoSWOCCq4d0OjEVD0IF0IbCNLEYTJn6gEWPVTFfqNA=; b=KmNZwbwmktSGX8CQ92LIr5iENrfmCzKbHX7eeodR2QlY3hT7LI9IF1CNXNEfkjpXuZ +vRh3tdRvmtVteZGTTpQ/sjIpjbj7Y5xd6c/b8h2avivijxCKyFshKbtUMvXdgG5h46I eQncWhHLt/8TKA9rgFbn0GbfYmFuq0Gw6vAqZKoF5/G7uYqh03LBvdQiHS4EqsAKyiOt 1Q1v3KyaehNvy4kuZ/LHbhT1Iai2RgUbvpz3DglKLCPuFZOfohzgL6DmsBhf8OzZZY/P C5uonaGmNRNqNKRIZ2lvNFSdfEmiqA3Kjy35TkdT8p5lqljMtN2+gbwpW+lGuR6jiAvl +vfg== X-Gm-Message-State: AAQBX9eX8jk7DJXoTFdNu6VD8zkZWgjqJ2gwg77+Eu0BlLHGGABx7ZFL goS+bYAyfPqYy6ujp5z7Aer/h54wIBhwQPC2qLAEk7cAYJlRjhXwBCaPmp/pMlH3zVRoLSCf84P 6pw7O9gcWKSFxfF/A4l4vK2SV+VjjNypMeh8VzQXJ+0Mk6QkjCg== X-Received: by 2002:a17:90b:4a46:b0:240:b3ae:d881 with SMTP id lb6-20020a17090b4a4600b00240b3aed881mr5851537pjb.5.1680188229744; Thu, 30 Mar 2023 07:57:09 -0700 (PDT) X-Google-Smtp-Source: AKy350afmUMWw10lNMXZZ9bP3fE/bfB2kJJIUyjfJKYc76WCanCrkB83ayvUbeVTtmOY2OR30PGCZg== X-Received: by 2002:a17:90b:4a46:b0:240:b3ae:d881 with SMTP id lb6-20020a17090b4a4600b00240b3aed881mr5851519pjb.5.1680188229473; Thu, 30 Mar 2023 07:57:09 -0700 (PDT) Received: from smtp.gmail.com ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id 13-20020a63134d000000b004fb171df68fsm23263866pgt.7.2023.03.30.07.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 07:57:09 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH] smb3: allow deferred close timeout to be configurable Date: Thu, 30 Mar 2023 08:57:05 -0600 Message-Id: <20230330145705.1098994-2-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230330145705.1098994-1-tim.gardner@canonical.com> References: <20230330145705.1098994-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Steve French BugLink: https://bugs.launchpad.net/bugs/2013349 Deferred close can be a very useful feature for allowing caching data for read, and for minimizing the number of reopens needed for a file that is repeatedly opened and close but there are workloads where its default (1 second, similar to actimeo/acregmax) is much too small. Allow the user to configure the amount of time we can defer sending the final smb3 close when we have a handle lease on the file (rather than forcing it to depend on value of actimeo which is often unrelated, and less safe). Adds new mount parameter "closetimeo=" which is the maximum number of seconds we can wait before sending an SMB3 close when we have a handle lease for it. Default value also is set to slightly larger at 5 seconds (although some other clients use larger default this should still help). Suggested-by: Bharath SM Reviewed-by: Bharath SM Reviewed-by: Shyam Prasad N Reviewed-by: Paulo Alcantara (SUSE) Signed-off-by: Steve French (cherry picked from commit 5efdd9122eff772eae2feae9f0fc0ec02d4846a3) Signed-off-by: Tim Gardner --- fs/cifs/cifsfs.c | 1 + fs/cifs/connect.c | 2 ++ fs/cifs/file.c | 4 ++-- fs/cifs/fs_context.c | 9 +++++++++ fs/cifs/fs_context.h | 8 ++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 5d188c548488..a258d901f5be 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -681,6 +681,7 @@ cifs_show_options(struct seq_file *s, struct dentry *root) seq_printf(s, ",acdirmax=%lu", cifs_sb->ctx->acdirmax / HZ); seq_printf(s, ",acregmax=%lu", cifs_sb->ctx->acregmax / HZ); } + seq_printf(s, ",closetimeo=%lu", cifs_sb->ctx->closetimeo / HZ); if (tcon->ses->chan_max > 1) seq_printf(s, ",multichannel,max_channels=%zu", diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 85c76fa61d5f..96b9f355b7a7 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -2615,6 +2615,8 @@ compare_mount_options(struct super_block *sb, struct cifs_mnt_data *mnt_data) return 0; if (old->ctx->acdirmax != new->ctx->acdirmax) return 0; + if (old->ctx->closetimeo != new->ctx->closetimeo) + return 0; return 1; } diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 4e72e687fe66..e37abfff626c 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -903,12 +903,12 @@ int cifs_close(struct inode *inode, struct file *file) * So, Increase the ref count to avoid use-after-free. */ if (!mod_delayed_work(deferredclose_wq, - &cfile->deferred, cifs_sb->ctx->acregmax)) + &cfile->deferred, cifs_sb->ctx->closetimeo)) cifsFileInfo_get(cfile); } else { /* Deferred close for files */ queue_delayed_work(deferredclose_wq, - &cfile->deferred, cifs_sb->ctx->acregmax); + &cfile->deferred, cifs_sb->ctx->closetimeo); cfile->deferred_close_scheduled = true; spin_unlock(&cinode->deferred_lock); return 0; diff --git a/fs/cifs/fs_context.c b/fs/cifs/fs_context.c index 8dc0d923ef6a..0e13dec86b25 100644 --- a/fs/cifs/fs_context.c +++ b/fs/cifs/fs_context.c @@ -147,6 +147,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = { fsparam_u32("actimeo", Opt_actimeo), fsparam_u32("acdirmax", Opt_acdirmax), fsparam_u32("acregmax", Opt_acregmax), + fsparam_u32("closetimeo", Opt_closetimeo), fsparam_u32("echo_interval", Opt_echo_interval), fsparam_u32("max_credits", Opt_max_credits), fsparam_u32("handletimeout", Opt_handletimeout), @@ -1074,6 +1075,13 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, } ctx->acdirmax = ctx->acregmax = HZ * result.uint_32; break; + case Opt_closetimeo: + ctx->closetimeo = HZ * result.uint_32; + if (ctx->closetimeo > SMB3_MAX_DCLOSETIMEO) { + cifs_errorf(fc, "closetimeo too large\n"); + goto cifs_parse_mount_err; + } + break; case Opt_echo_interval: ctx->echo_interval = result.uint_32; break; @@ -1521,6 +1529,7 @@ int smb3_init_fs_context(struct fs_context *fc) ctx->acregmax = CIFS_DEF_ACTIMEO; ctx->acdirmax = CIFS_DEF_ACTIMEO; + ctx->closetimeo = SMB3_DEF_DCLOSETIMEO; /* Most clients set timeout to 0, allows server to use its default */ ctx->handle_timeout = 0; /* See MS-SMB2 spec section 2.2.14.2.12 */ diff --git a/fs/cifs/fs_context.h b/fs/cifs/fs_context.h index 5f093cb7e9b9..bbaee4c2281f 100644 --- a/fs/cifs/fs_context.h +++ b/fs/cifs/fs_context.h @@ -125,6 +125,7 @@ enum cifs_param { Opt_actimeo, Opt_acdirmax, Opt_acregmax, + Opt_closetimeo, Opt_echo_interval, Opt_max_credits, Opt_snapshot, @@ -247,6 +248,8 @@ struct smb3_fs_context { /* attribute cache timemout for files and directories in jiffies */ unsigned long acregmax; unsigned long acdirmax; + /* timeout for deferred close of files in jiffies */ + unsigned long closetimeo; struct smb_version_operations *ops; struct smb_version_values *vals; char *prepath; @@ -279,4 +282,9 @@ static inline struct smb3_fs_context *smb3_fc2context(const struct fs_context *f extern int smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx); extern void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb); +/* + * max deferred close timeout (jiffies) - 2^30 + */ +#define SMB3_MAX_DCLOSETIMEO (1 << 30) +#define SMB3_DEF_DCLOSETIMEO (5 * HZ) /* Can increase later, other clients use larger */ #endif