Give containers a unique client id
Subsystems (2)
[email protected]
maintainerv2 cover Give containers a unique client id
From: Trond Myklebust <[email protected]>
This series adds the missing patches to allow a container to set a unique client id using /sys/fs/nfs/net/nfs_client/identifier, and have NFS use that for any new NFS mounts that are initiated by that container.
--
v2: Fix a variable initialisation in nfs4_get_uniquifier
Switch to using preferred strscpy()
Trond Myklebust (2):
NFSv4: Clean up initialisation of uniquified client id strings
NFSv4: Use the net namespace uniquifier if it is set
fs/nfs/nfs4proc.c | 88 +++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 41 deletions(-)
Signature · 1 line
2.26.2
[email protected]
maintainerPATCH v2 1/2 NFSv4: Clean up initialisation of uniquified client id strings
From: Trond Myklebust <[email protected]>
When the user sets a uniquifier, then ensure we copy the string so that calls to strlen() etc are atomic with calls to snprintf().
--- fs/nfs/nfs4proc.c | 75 +++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 41 deletions(-)
fs/nfs/nfs4proc.c +34 -41
@@ -6006,9 +6006,22 @@ static void nfs4_init_boot_verifier(const struct nfs_client *clp,memcpy (bootverf->data, verf,sizeof (bootverf->data)); } +static size_t +nfs4_get_uniquifier (char *buf,size_t buflen) +{ + buf[0 ] ='\0' ; + +if (nfs4_client_id_uniquifier[0 ] !='\0' ) +strscpy (buf, nfs4_client_id_uniquifier, buflen); + +return strlen (buf); +} +static int nfs4_init_nonuniform_client_string (struct nfs_client *clp) { +char buf[NFS4_CLIENT_ID_UNIQ_LEN ]; +size_t buflen;size_t len;char *str;
@@ -6022,8 +6035,11 @@ nfs4_init_nonuniform_client_string(struct nfs_client *clp)strlen (rpc_peeraddr2str (clp->cl_rpcclient,RPC_DISPLAY_ADDR )) +1 ;rcu_read_unlock (); -if (nfs4_client_id_uniquifier[0 ] !='\0' ) - len +=strlen (nfs4_client_id_uniquifier) +1 ; + + buflen =nfs4_get_uniquifier (buf,sizeof (buf)); +if (buflen) + len += buflen +1 ; +if (len >NFS4_OPAQUE_LIMIT +1 )return -EINVAL ;
@@ -6037,10 +6053,9 @@ nfs4_init_nonuniform_client_string(struct nfs_client *clp)return -ENOMEM ;rcu_read_lock (); -if (nfs4_client_id_uniquifier[0 ] !='\0' ) +if (buflen)scnprintf (str, len,"Linux NFSv4.0 %s/%s/%s" , - clp->cl_rpcclient->cl_nodename, - nfs4_client_id_uniquifier, + clp->cl_rpcclient->cl_nodename, buf,rpc_peeraddr2str (clp->cl_rpcclient,RPC_DISPLAY_ADDR ));else
@@ -6054,51 +6069,24 @@ nfs4_init_nonuniform_client_string(struct nfs_client *clp)return 0 ; } -static int -nfs4_init_uniquifier_client_string (struct nfs_client *clp) -{ -size_t len; -char *str; - - len =10 +10 +1 +10 +1 + -strlen (nfs4_client_id_uniquifier) +1 + -strlen (clp->cl_rpcclient->cl_nodename) +1 ; - -if (len >NFS4_OPAQUE_LIMIT +1 ) -return -EINVAL ; - -/* -* Since this string is allocated at mount time, and held until the -* nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying -* about a memory-reclaim deadlock. -*/ - str =kmalloc (len,GFP_KERNEL ); -if (!str) -return -ENOMEM ; - -scnprintf (str, len,"Linux NFSv%u.%u %s/%s" , - clp->rpc_ops->version, clp->cl_minorversion, - nfs4_client_id_uniquifier, - clp->cl_rpcclient->cl_nodename); - clp->cl_owner_id = str; -return 0 ; -} -static int nfs4_init_uniform_client_string (struct nfs_client *clp) { +char buf[NFS4_CLIENT_ID_UNIQ_LEN ]; +size_t buflen;size_t len;char *str;if (clp->cl_owner_id !=NULL )return 0 ; -if (nfs4_client_id_uniquifier[0 ] !='\0' ) -return nfs4_init_uniquifier_client_string (clp); - len =10 +10 +1 +10 +1 +strlen (clp->cl_rpcclient->cl_nodename) +1 ; + buflen =nfs4_get_uniquifier (buf,sizeof (buf)); +if (buflen) + len += buflen +1 ; +if (len >NFS4_OPAQUE_LIMIT +1 )return -EINVAL ;
@@ -6111,9 +6099,14 @@ nfs4_init_uniform_client_string(struct nfs_client *clp)if (!str)return -ENOMEM ; -scnprintf (str, len,"Linux NFSv%u.%u %s" , - clp->rpc_ops->version, clp->cl_minorversion, - clp->cl_rpcclient->cl_nodename); +if (buflen) +scnprintf (str, len,"Linux NFSv%u.%u %s/%s" , + clp->rpc_ops->version, clp->cl_minorversion, + buf, clp->cl_rpcclient->cl_nodename); +else +scnprintf (str, len,"Linux NFSv%u.%u %s" , + clp->rpc_ops->version, clp->cl_minorversion, + clp->cl_rpcclient->cl_nodename); clp->cl_owner_id = str;return 0 ; }
Signature · 1 line
2.26.2
[email protected]
maintainerPATCH v2 2/2 NFSv4: Use the net namespace uniquifier if it is set
From: Trond Myklebust <[email protected]>
If a container sets a net namespace specific uniquifier, then use that in the setclientid/exchangeid process.
--- fs/nfs/nfs4proc.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
fs/nfs/nfs4proc.c +17 -4
@@ -63,6 +63,7 @@#include "callback.h" #include "pnfs.h" #include "netns.h" +#include "sysfs.h" #include "nfs4idmap.h" #include "nfs4session.h" #include "fscache.h"
@@ -6007,11 +6008,23 @@ static void nfs4_init_boot_verifier(const struct nfs_client *clp, }static size_t -nfs4_get_uniquifier (char *buf,size_t buflen) +nfs4_get_uniquifier (struct nfs_client *clp,char *buf,size_t buflen) { +struct nfs_net *nn =net_generic (clp->cl_net, nfs_net_id); +struct nfs_netns_client *nn_clp = nn->nfs_client; +const char *id; + buf[0 ] ='\0' ; -if (nfs4_client_id_uniquifier[0 ] !='\0' ) +if (nn_clp) { +rcu_read_lock (); + id =rcu_dereference (nn_clp->identifier); +if (id) +strscpy (buf, id, buflen); +rcu_read_unlock (); + } + +if (nfs4_client_id_uniquifier[0 ] !='\0' && buf[0 ] =='\0' )strscpy (buf, nfs4_client_id_uniquifier, buflen);return strlen (buf);
@@ -6036,7 +6049,7 @@ nfs4_init_nonuniform_client_string(struct nfs_client *clp)1 ;rcu_read_unlock (); - buflen =nfs4_get_uniquifier (buf,sizeof (buf)); + buflen =nfs4_get_uniquifier (clp, buf,sizeof (buf));if (buflen) len += buflen +1 ;
@@ -6083,7 +6096,7 @@ nfs4_init_uniform_client_string(struct nfs_client *clp) len =10 +10 +1 +10 +1 +strlen (clp->cl_rpcclient->cl_nodename) +1 ; - buflen =nfs4_get_uniquifier (buf,sizeof (buf)); + buflen =nfs4_get_uniquifier (clp, buf,sizeof (buf));if (buflen) len += buflen +1 ;
Signature · 1 line
2.26.2