Linux NFS development
 help / color / mirror / Atom feed
From: Trond Myklebust <trondmy@hammerspace.com>
To: "bcodding@redhat.com" <bcodding@redhat.com>,
	"anna.schumaker@netapp.com" <anna.schumaker@netapp.com>
Cc: "linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH] NFSv4: use unique client identifiers in network namespaces
Date: Tue, 8 Feb 2022 20:27:58 +0000	[thread overview]
Message-ID: <189aba691b341f64f653817c9cdf018ef34ac257.camel@hammerspace.com> (raw)
In-Reply-To: <6e05bf321ff50785360e6c339d111db368e7dfda.1644349990.git.bcodding@redhat.com>

On Tue, 2022-02-08 at 15:03 -0500, Benjamin Coddington wrote:
> In order to differentiate client state, assign a random uuid to the
> uniquifing portion of the client identifier when a network namespace
> is
> created.  Containers may still override this value if they wish to
> maintain
> stable client identifiers by writing to
> /sys/fs/nfs/net/client/identifier,
> either by udev rules or other means.
> 
> Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
> ---
>  fs/nfs/sysfs.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
> index 8cb70755e3c9..9b811323fd7f 100644
> --- a/fs/nfs/sysfs.c
> +++ b/fs/nfs/sysfs.c
> @@ -167,6 +167,18 @@ static struct nfs_netns_client
> *nfs_netns_client_alloc(struct kobject *parent,
>         return NULL;
>  }
>  
> +static void assign_unique_clientid(struct nfs_netns_client *clp)
> +{
> +       unsigned char client_uuid[16];
> +       char *uuid_str = kmalloc(UUID_STRING_LEN + 1, GFP_KERNEL);
> +
> +       if (uuid_str) {
> +               generate_random_uuid(client_uuid);
> +               sprintf(uuid_str, "%pU", client_uuid);
> +               rcu_assign_pointer(clp->identifier, uuid_str);
> +       }
> +}
> +
>  void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net)
>  {
>         struct nfs_netns_client *clp;
> @@ -174,6 +186,8 @@ void nfs_netns_sysfs_setup(struct nfs_net *netns,
> struct net *net)
>         clp = nfs_netns_client_alloc(nfs_client_kobj, net);
>         if (clp) {
>                 netns->nfs_client = clp;
> +               if (net != &init_net)
> +                       assign_unique_clientid(clp);

Why shouldn't this go in nfs_netns_client_alloc? At this point you've
already published the pointer in netns, so you're prone to races.

Also, why the exclusion of init_net?

>                 kobject_uevent(&clp->kobject, KOBJ_ADD);
>         }
>  }

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com



  reply	other threads:[~2022-02-08 22:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-08 20:03 [PATCH] NFSv4: use unique client identifiers in network namespaces Benjamin Coddington
2022-02-08 20:27 ` Trond Myklebust [this message]
2022-02-08 21:37   ` Benjamin Coddington
2022-02-08 21:47     ` Trond Myklebust
2022-02-09  0:58       ` Benjamin Coddington
2022-02-27 23:50     ` NeilBrown
2022-02-28 14:43       ` Benjamin Coddington
2022-02-28 15:16         ` Trond Myklebust
2022-02-28 15:33           ` Benjamin Coddington

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=189aba691b341f64f653817c9cdf018ef34ac257.camel@hammerspace.com \
    --to=trondmy@hammerspace.com \
    --cc=anna.schumaker@netapp.com \
    --cc=bcodding@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox