diff options
author | Benjamin Coddington | 2022-02-09 09:07:01 -0500 |
---|---|---|
committer | Trond Myklebust | 2022-02-25 18:50:12 -0500 |
commit | 50c790a0b69bdc420f00f30bdf348d6c90194c78 (patch) | |
tree | fa38907328107d0ab08e8f9472e3d07db8f67dc8 | |
parent | 43245eca6e670ebf65908b549641c1460a9cc944 (diff) |
NFSv4: use unique client identifiers in network namespaces
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>
-rw-r--r-- | fs/nfs/sysfs.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c index a6f740366963..886ed1eec2e5 100644 --- a/fs/nfs/sysfs.c +++ b/fs/nfs/sysfs.c @@ -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, |