diff mbox series

[v2] NFSv4: use unique client identifiers in network namespaces

Message ID 7761eea51000e542e4304c32430e332b6ecac5a5.1644415460.git.bcodding@redhat.com (mailing list archive)
State New, archived
Headers show
Series [v2] NFSv4: use unique client identifiers in network namespaces | expand

Commit Message

Benjamin Coddington Feb. 9, 2022, 2:07 p.m. UTC
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 mbox series

Patch

diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
index 8cb70755e3c9..be05522a2c8b 100644
--- a/fs/nfs/sysfs.c
+++ b/fs/nfs/sysfs.c
@@ -150,6 +150,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)
 {
@@ -157,6 +169,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,