Skip to content

Commit 51d8fa6

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
NFS: Add timeout to submounts
Make automounted partitions expire using the mark_mounts_for_expiry() function. The timeout is controlled via a sysctl. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 55a9759 commit 51d8fa6

4 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎fs/nfs/inode.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
167167
struct nfs_server *server;
168168
struct rpc_clnt *rpc;
169169

170+
shrink_submounts(vfsmnt, &nfs_automount_list);
170171
if (!(flags & MNT_FORCE))
171172
return;
172173
/* -EIO all pending I/O */
@@ -1943,6 +1944,7 @@ static void nfs_kill_super(struct super_block *s)
19431944
nfs_free_iostats(server->io_stats);
19441945
kfree(server->hostname);
19451946
kfree(server);
1947+
nfs_release_automount_timer();
19461948
}
19471949

19481950
static struct file_system_type nfs_fs_type = {
@@ -2288,6 +2290,7 @@ static void nfs4_kill_super(struct super_block *sb)
22882290
nfs_free_iostats(server->io_stats);
22892291
kfree(server->hostname);
22902292
kfree(server);
2293+
nfs_release_automount_timer();
22912294
}
22922295

22932296
static struct file_system_type nfs4_fs_type = {

‎fs/nfs/namespace.c‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
#define NFSDBG_FACILITY NFSDBG_VFS
2020

21+
LIST_HEAD(nfs_automount_list);
22+
static void nfs_expire_automounts(void *list);
23+
static DECLARE_WORK(nfs_automount_task, nfs_expire_automounts, &nfs_automount_list);
24+
int nfs_mountpoint_expiry_timeout = 500 * HZ;
25+
2126
/*
2227
* nfs_follow_mountpoint - handle crossing a mountpoint on the server
2328
* @dentry - dentry of mountpoint
@@ -59,7 +64,7 @@ static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
5964
goto out_err;
6065

6166
mntget(mnt);
62-
err = do_add_mount(mnt, nd, nd->mnt->mnt_flags, NULL);
67+
err = do_add_mount(mnt, nd, nd->mnt->mnt_flags|MNT_SHRINKABLE, &nfs_automount_list);
6368
if (err < 0) {
6469
mntput(mnt);
6570
if (err == -EBUSY)
@@ -70,6 +75,7 @@ static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
7075
dput(nd->dentry);
7176
nd->mnt = mnt;
7277
nd->dentry = dget(mnt->mnt_root);
78+
schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
7379
out:
7480
dprintk("%s: done, returned %d\n", __FUNCTION__, err);
7581
return ERR_PTR(err);
@@ -87,3 +93,20 @@ struct inode_operations nfs_mountpoint_inode_operations = {
8793
.follow_link = nfs_follow_mountpoint,
8894
.getattr = nfs_getattr,
8995
};
96+
97+
static void nfs_expire_automounts(void *data)
98+
{
99+
struct list_head *list = (struct list_head *)data;
100+
101+
mark_mounts_for_expiry(list);
102+
if (!list_empty(list))
103+
schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
104+
}
105+
106+
void nfs_release_automount_timer(void)
107+
{
108+
if (list_empty(&nfs_automount_list)) {
109+
cancel_delayed_work(&nfs_automount_task);
110+
flush_scheduled_work();
111+
}
112+
}

‎fs/nfs/sysctl.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/module.h>
1313
#include <linux/nfs4.h>
1414
#include <linux/nfs_idmap.h>
15+
#include <linux/nfs_fs.h>
1516

1617
#include "callback.h"
1718

@@ -46,6 +47,15 @@ static ctl_table nfs_cb_sysctls[] = {
4647
.strategy = &sysctl_jiffies,
4748
},
4849
#endif
50+
{
51+
.ctl_name = CTL_UNNUMBERED,
52+
.procname = "nfs_mountpoint_timeout",
53+
.data = &nfs_mountpoint_expiry_timeout,
54+
.maxlen = sizeof(nfs_mountpoint_expiry_timeout),
55+
.mode = 0644,
56+
.proc_handler = &proc_dointvec_jiffies,
57+
.strategy = &sysctl_jiffies,
58+
},
4959
{ .ctl_name = 0 }
5060
};
5161

‎include/linux/nfs_fs.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,10 @@ extern void nfs_unregister_sysctl(void);
405405
/*
406406
* linux/fs/nfs/namespace.c
407407
*/
408+
extern struct list_head nfs_automount_list;
408409
extern struct inode_operations nfs_mountpoint_inode_operations;
410+
extern int nfs_mountpoint_expiry_timeout;
411+
extern void nfs_release_automount_timer(void);
409412

410413
/*
411414
* linux/fs/nfs/unlink.c

0 commit comments

Comments
 (0)