Skip to content

Commit 487fae0

Browse files
author
Trond Myklebust
committed
NFS: Add a mount option to make ENETUNREACH errors fatal
If the NFS client was initially created in a container, and that container is torn down, there is usually no possibity to go back and destroy any NFS clients that are hung because their virtual network devices have been unlinked. Add a flag that tells the NFS client that in these circumstances, it should treat ENETDOWN and ENETUNREACH errors as fatal to the NFS client. The option defaults to being on when the mount happens from inside a net namespace that is not "init_net". Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Tested-by: Jeff Layton <jlayton@kernel.org> Acked-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 4c2226b commit 487fae0

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

fs/nfs/fs_context.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ enum nfs_param {
5050
Opt_clientaddr,
5151
Opt_cto,
5252
Opt_alignwrite,
53+
Opt_fatal_neterrors,
5354
Opt_fg,
5455
Opt_fscache,
5556
Opt_fscache_flag,
@@ -97,6 +98,20 @@ enum nfs_param {
9798
Opt_xprtsec,
9899
};
99100

101+
enum {
102+
Opt_fatal_neterrors_default,
103+
Opt_fatal_neterrors_enetunreach,
104+
Opt_fatal_neterrors_none,
105+
};
106+
107+
static const struct constant_table nfs_param_enums_fatal_neterrors[] = {
108+
{ "default", Opt_fatal_neterrors_default },
109+
{ "ENETDOWN:ENETUNREACH", Opt_fatal_neterrors_enetunreach },
110+
{ "ENETUNREACH:ENETDOWN", Opt_fatal_neterrors_enetunreach },
111+
{ "none", Opt_fatal_neterrors_none },
112+
{}
113+
};
114+
100115
enum {
101116
Opt_local_lock_all,
102117
Opt_local_lock_flock,
@@ -153,6 +168,8 @@ static const struct fs_parameter_spec nfs_fs_parameters[] = {
153168
fsparam_string("clientaddr", Opt_clientaddr),
154169
fsparam_flag_no("cto", Opt_cto),
155170
fsparam_flag_no("alignwrite", Opt_alignwrite),
171+
fsparam_enum("fatal_neterrors", Opt_fatal_neterrors,
172+
nfs_param_enums_fatal_neterrors),
156173
fsparam_flag ("fg", Opt_fg),
157174
fsparam_flag_no("fsc", Opt_fscache_flag),
158175
fsparam_string("fsc", Opt_fscache),
@@ -896,6 +913,25 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
896913
goto out_of_bounds;
897914
ctx->nfs_server.max_connect = result.uint_32;
898915
break;
916+
case Opt_fatal_neterrors:
917+
trace_nfs_mount_assign(param->key, param->string);
918+
switch (result.uint_32) {
919+
case Opt_fatal_neterrors_default:
920+
if (fc->net_ns != &init_net)
921+
ctx->flags |= NFS_MOUNT_NETUNREACH_FATAL;
922+
else
923+
ctx->flags &= ~NFS_MOUNT_NETUNREACH_FATAL;
924+
break;
925+
case Opt_fatal_neterrors_enetunreach:
926+
ctx->flags |= NFS_MOUNT_NETUNREACH_FATAL;
927+
break;
928+
case Opt_fatal_neterrors_none:
929+
ctx->flags &= ~NFS_MOUNT_NETUNREACH_FATAL;
930+
break;
931+
default:
932+
goto out_invalid_value;
933+
}
934+
break;
899935
case Opt_lookupcache:
900936
trace_nfs_mount_assign(param->key, param->string);
901937
switch (result.uint_32) {
@@ -1675,6 +1711,9 @@ static int nfs_init_fs_context(struct fs_context *fc)
16751711
ctx->xprtsec.cert_serial = TLS_NO_CERT;
16761712
ctx->xprtsec.privkey_serial = TLS_NO_PRIVKEY;
16771713

1714+
if (fc->net_ns != &init_net)
1715+
ctx->flags |= NFS_MOUNT_NETUNREACH_FATAL;
1716+
16781717
fc->s_iflags |= SB_I_STABLE_WRITES;
16791718
}
16801719
fc->fs_private = ctx;

fs/nfs/super.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
457457
{ NFS_MOUNT_FORCE_RDIRPLUS, ",rdirplus=force", "" },
458458
{ NFS_MOUNT_UNSHARED, ",nosharecache", "" },
459459
{ NFS_MOUNT_NORESVPORT, ",noresvport", "" },
460+
{ NFS_MOUNT_NETUNREACH_FATAL,
461+
",fatal_neterrors=ENETDOWN:ENETUNREACH",
462+
",fatal_neterrors=none" },
460463
{ 0, NULL, NULL }
461464
};
462465
const struct proc_nfs_info *nfs_infop;

include/linux/nfs_fs_sb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ struct nfs_server {
168168
#define NFS_MOUNT_SHUTDOWN 0x08000000
169169
#define NFS_MOUNT_NO_ALIGNWRITE 0x10000000
170170
#define NFS_MOUNT_FORCE_RDIRPLUS 0x20000000
171+
#define NFS_MOUNT_NETUNREACH_FATAL 0x40000000
171172

172173
unsigned int fattr_valid; /* Valid attributes */
173174
unsigned int caps; /* server capabilities */

0 commit comments

Comments
 (0)