NFSv4: use unique client identifiers in network namespaces
authorBenjamin Coddington <bcodding@redhat.com>
Wed, 9 Feb 2022 14:07:01 +0000 (09:07 -0500)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Fri, 25 Feb 2022 23:50:12 +0000 (18:50 -0500)
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>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/sysfs.c

index a6f7403..886ed1e 100644 (file)
@@ -151,6 +151,18 @@ static struct kobj_type nfs_netns_client_type = {
        .namespace = nfs_netns_client_namespace,
 };
 
+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);
+       }
+}
+
 static struct nfs_netns_client *nfs_netns_client_alloc(struct kobject *parent,
                struct net *net)
 {
@@ -158,6 +170,8 @@ static struct nfs_netns_client *nfs_netns_client_alloc(struct kobject *parent,
 
        p = kzalloc(sizeof(*p), GFP_KERNEL);
        if (p) {
+               if (net != &init_net)
+                       assign_unique_clientid(p);
                p->net = net;
                p->kobject.kset = nfs_client_kset;
                if (kobject_init_and_add(&p->kobject, &nfs_netns_client_type,