[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CANT5p=qrSg7FH4SSG5EyFDwt8LsQ1ztKzJJYQOfPG18ROPTcqQ@mail.gmail.com>
Date: Fri, 30 Jan 2026 16:03:17 +0530
From: Shyam Prasad N <nspmangalore@...il.com>
To: Piyush Sachdeva <s.piyush1024@...il.com>
Cc: sfrench@...ba.org, linux-cifs@...r.kernel.org,
linux-kernel@...r.kernel.org, sprasad@...rosoft.com, bharathsm@...rosoft.com,
msetiya@...rosoft.com, rajasimandal@...rosoft.com, psachdeva@...rosoft.com
Subject: Re: [PATCH] smb: client: close all files marked for deferred close immediately
On Tue, Dec 23, 2025 at 6:21 PM Piyush Sachdeva <s.piyush1024@...il.com> wrote:
>
> From: Piyush Sachdeva <psachdeva@...rosoft.com>
>
> SMB client has a feature to delay the close of a file on the server,
> expecting if an open call comes for the same file, the file doesn't
> need to be re-opened. The time duration of the deferred close is set
> by the mount option `closetimeo`.
> This patch lets a user list all handles marked for deferred close, by
> cat /proc/fs/cifs/close_deferred_closes.
> It also allow for force close of all files marked for deferred close,
> across all session by writing a non-zero value to the same procfs file.
>
> Signed-off-by: Piyush Sachdeva <psachdeva@...rosoft.com>
> Signed-off-by: Piyush Sachdeva <s.piyush1024@...il.com>
> ---
> fs/smb/client/cifs_debug.c | 137 +++++++++++++++++++++++++++++++++++++
> fs/smb/client/cifsglob.h | 5 ++
> 2 files changed, 142 insertions(+)
>
> diff --git a/fs/smb/client/cifs_debug.c b/fs/smb/client/cifs_debug.c
> index 7fdcaf9feb16..e149a403b16e 100644
> --- a/fs/smb/client/cifs_debug.c
> +++ b/fs/smb/client/cifs_debug.c
> @@ -952,6 +952,7 @@ static const struct proc_ops traceSMB_proc_ops;
> static const struct proc_ops cifs_security_flags_proc_ops;
> static const struct proc_ops cifs_linux_ext_proc_ops;
> static const struct proc_ops cifs_mount_params_proc_ops;
> +static const struct proc_ops close_all_deferred_close_ops;
>
> void
> cifs_proc_init(void)
> @@ -981,6 +982,8 @@ cifs_proc_init(void)
>
> proc_create("mount_params", 0444, proc_fs_cifs, &cifs_mount_params_proc_ops);
>
> + proc_create("close_deferred_closes", 0644, proc_fs_cifs, &close_all_deferred_close_ops);
> +
> #ifdef CONFIG_CIFS_DFS_UPCALL
> proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_ops);
> #endif
> @@ -1021,6 +1024,7 @@ cifs_proc_clean(void)
> remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
> remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
> remove_proc_entry("mount_params", proc_fs_cifs);
> + remove_proc_entry("close_deferred_closes", proc_fs_cifs);
>
> #ifdef CONFIG_CIFS_DFS_UPCALL
> remove_proc_entry("dfscache", proc_fs_cifs);
> @@ -1317,6 +1321,139 @@ static const struct proc_ops cifs_mount_params_proc_ops = {
> /* .proc_write = cifs_mount_params_proc_write, */
> };
>
> +static struct list_head *get_all_tcons(void)
> +{
> + struct TCP_Server_Info *server;
> + struct cifs_ses *ses;
> + struct cifs_tcon *tcon;
> + struct global_tcon_list *tree_con_list, *tmp_tree_con_list;
> + struct list_head *tcon_head;
> +
> + tcon_head = kmalloc(sizeof(struct list_head), GFP_KERNEL);
> + if (tcon_head == NULL)
> + return NULL;
> +
> + INIT_LIST_HEAD(tcon_head);
> + spin_lock(&cifs_tcp_ses_lock);
> + list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
> + list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
> + if (cifs_ses_exiting(ses))
> + continue;
> + list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
> + tree_con_list =
> + kmalloc(sizeof(struct global_tcon_list),
> + GFP_ATOMIC);
> + if (tree_con_list == NULL)
> + goto tcon_alloc_fail;
> + tree_con_list->tcon = tcon;
> + list_add_tail(&tree_con_list->list, tcon_head);
> + }
> + }
> + }
> + spin_unlock(&cifs_tcp_ses_lock);
> + return tcon_head;
> +
> +tcon_alloc_fail:
> + spin_unlock(&cifs_tcp_ses_lock);
> + list_for_each_entry_safe(tree_con_list, tmp_tree_con_list, tcon_head,
> + list) {
> + list_del(&tree_con_list->list);
> + kfree(tree_con_list);
> + }
> + kfree(tcon_head);
> + return NULL;
> +}
> +
> +static ssize_t close_all_deferred_close_files(struct file *file,
> + const char __user *buffer,
> + size_t count, loff_t *ppos)
> +{
> + char c;
> + int rc;
> + struct global_tcon_list *tmp_list, *tmp_next_list;
> + struct list_head *tcon_head;
> +
> + rc = get_user(c, buffer);
> + if (rc)
> + return rc;
> + if (c == '0')
> + return -EINVAL;
> +
> + tcon_head = get_all_tcons();
> + if (tcon_head == NULL)
> + return count;
> +
> + list_for_each_entry_safe(tmp_list, tmp_next_list, tcon_head, list) {
> + cifs_close_all_deferred_files(tmp_list->tcon);
> + list_del(&tmp_list->list);
> + kfree(tmp_list);
> + }
> +
> + kfree(tcon_head);
> + return count;
> +}
> +
> +static int show_all_deferred_close_files(struct seq_file *m, void *v)
> +{
> + struct global_tcon_list *tmp_list, *tmp_next_list;
> + struct list_head *tcon_head;
> + struct cifs_tcon *tcon;
> + struct cifsFileInfo *cfile;
> +
> + seq_puts(m, "# Version:1\n");
> + seq_puts(m, "# Format:\n");
> + seq_puts(m, "# <tree id> <ses id> <persistent fid> <flags> <count> <pid> <uid>");
> +#ifdef CONFIG_CIFS_DEBUG2
> + seq_puts(m, " <filename> <mid>\n");
> +#else
> + seq_puts(m, " <filename>\n");
> +#endif /* CIFS_DEBUG2 */
> +
> + tcon_head = get_all_tcons();
> + if (tcon_head == NULL)
> + return 0;
> +
> + list_for_each_entry_safe(tmp_list, tmp_next_list, tcon_head, list) {
> + tcon = tmp_list->tcon;
> + spin_lock(&tcon->open_file_lock);
> + list_for_each_entry(cfile, &tcon->openFileList, tlist) {
> + if (delayed_work_pending(&cfile->deferred)) {
> + seq_printf(
> + m,
> + "0x%x 0x%llx 0x%llx 0x%x %d %d %d %pd",
> + tcon->tid, tcon->ses->Suid,
> + cfile->fid.persistent_fid,
> + cfile->f_flags, cfile->count,
> + cfile->pid,
> + from_kuid(&init_user_ns, cfile->uid),
> + cfile->dentry);
> + }
> + }
> + spin_unlock(&tcon->open_file_lock);
> + list_del(&tmp_list->list);
> + kfree(tmp_list);
> + }
> +
> + kfree(tcon_head);
> + seq_putc(m, '\n');
> +
> + return 0;
> +}
> +
> +static int show_all_deferred_close_proc_open(struct inode *inode,
> + struct file *file)
> +{
> + return single_open(file, show_all_deferred_close_files, NULL);
> +}
> +
> +static const struct proc_ops close_all_deferred_close_ops = {
> + .proc_open = show_all_deferred_close_proc_open,
> + .proc_read = seq_read,
> + .proc_lseek = seq_lseek,
> + .proc_release = single_release,
> + .proc_write = close_all_deferred_close_files,
> +};
> +
> #else
> inline void cifs_proc_init(void)
> {
> diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h
> index 203e2aaa3c25..56c987258c4b 100644
> --- a/fs/smb/client/cifsglob.h
> +++ b/fs/smb/client/cifsglob.h
> @@ -1806,6 +1806,11 @@ struct dfs_info3_param {
> int ttl;
> };
>
> +struct global_tcon_list {
> + struct list_head list;
> + struct cifs_tcon *tcon;
> +};
> +
> struct file_list {
> struct list_head list;
> struct cifsFileInfo *cfile;
> --
> 2.52.0
>
>
Did an offline review of this patch with Piyush.
He noted that the lock ordering rules in cifsglob.h stopped him from
using code similar to open_files listing. (Thanks Piyush for bringing
it up)
I think this is an error in the lock ordering comment. I'll submit a
patch to fix that.
I've asked Piyush to submit a v2 patch based on that.
--
Regards,
Shyam
Powered by blists - more mailing lists