summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@hammerspace.com>2019-01-24 16:10:46 -0500
committerTrond Myklebust <trond.myklebust@hammerspace.com>2019-07-06 14:54:49 -0400
commit996bc4f405d37ffd88c9b830202ee47fc7a6c449 (patch)
tree81a89b1e6f1a4ebd54b42bc700c667bb6003f089
parent44942b4e457beda00981f616402a1a791e8c616e (diff)
NFS: Create a root NFS directory in /sys/fs/nfs
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
-rw-r--r--fs/nfs/Makefile3
-rw-r--r--fs/nfs/inode.c8
-rw-r--r--fs/nfs/sysfs.c69
-rw-r--r--fs/nfs/sysfs.h15
4 files changed, 94 insertions, 1 deletions
diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile
index c587e3c4c6a6..34cdeaecccf6 100644
--- a/fs/nfs/Makefile
+++ b/fs/nfs/Makefile
@@ -8,7 +8,8 @@ obj-$(CONFIG_NFS_FS) += nfs.o
8CFLAGS_nfstrace.o += -I$(src) 8CFLAGS_nfstrace.o += -I$(src)
9nfs-y := client.o dir.o file.o getroot.o inode.o super.o \ 9nfs-y := client.o dir.o file.o getroot.o inode.o super.o \
10 io.o direct.o pagelist.o read.o symlink.o unlink.o \ 10 io.o direct.o pagelist.o read.o symlink.o unlink.o \
11 write.o namespace.o mount_clnt.o nfstrace.o export.o 11 write.o namespace.o mount_clnt.o nfstrace.o \
12 export.o sysfs.o
12nfs-$(CONFIG_ROOT_NFS) += nfsroot.o 13nfs-$(CONFIG_ROOT_NFS) += nfsroot.o
13nfs-$(CONFIG_SYSCTL) += sysctl.o 14nfs-$(CONFIG_SYSCTL) += sysctl.o
14nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o 15nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 53777813ca95..8dba56491de2 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -51,6 +51,7 @@
51#include "pnfs.h" 51#include "pnfs.h"
52#include "nfs.h" 52#include "nfs.h"
53#include "netns.h" 53#include "netns.h"
54#include "sysfs.h"
54 55
55#include "nfstrace.h" 56#include "nfstrace.h"
56 57
@@ -2182,6 +2183,10 @@ static int __init init_nfs_fs(void)
2182{ 2183{
2183 int err; 2184 int err;
2184 2185
2186 err = nfs_sysfs_init();
2187 if (err < 0)
2188 goto out10;
2189
2185 err = register_pernet_subsys(&nfs_net_ops); 2190 err = register_pernet_subsys(&nfs_net_ops);
2186 if (err < 0) 2191 if (err < 0)
2187 goto out9; 2192 goto out9;
@@ -2245,6 +2250,8 @@ out7:
2245out8: 2250out8:
2246 unregister_pernet_subsys(&nfs_net_ops); 2251 unregister_pernet_subsys(&nfs_net_ops);
2247out9: 2252out9:
2253 nfs_sysfs_exit();
2254out10:
2248 return err; 2255 return err;
2249} 2256}
2250 2257
@@ -2261,6 +2268,7 @@ static void __exit exit_nfs_fs(void)
2261 unregister_nfs_fs(); 2268 unregister_nfs_fs();
2262 nfs_fs_proc_exit(); 2269 nfs_fs_proc_exit();
2263 nfsiod_stop(); 2270 nfsiod_stop();
2271 nfs_sysfs_exit();
2264} 2272}
2265 2273
2266/* Not quite true; I just maintain it */ 2274/* Not quite true; I just maintain it */
diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
new file mode 100644
index 000000000000..7070711ff6c5
--- /dev/null
+++ b/fs/nfs/sysfs.c
@@ -0,0 +1,69 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2019 Hammerspace Inc
4 */
5
6#include <linux/module.h>
7#include <linux/kobject.h>
8#include <linux/sysfs.h>
9#include <linux/fs.h>
10#include <linux/slab.h>
11#include <linux/netdevice.h>
12
13#include "sysfs.h"
14
15struct kobject *nfs_client_kobj;
16static struct kset *nfs_client_kset;
17
18static void nfs_netns_object_release(struct kobject *kobj)
19{
20 kfree(kobj);
21}
22
23static const struct kobj_ns_type_operations *nfs_netns_object_child_ns_type(
24 struct kobject *kobj)
25{
26 return &net_ns_type_operations;
27}
28
29static struct kobj_type nfs_netns_object_type = {
30 .release = nfs_netns_object_release,
31 .sysfs_ops = &kobj_sysfs_ops,
32 .child_ns_type = nfs_netns_object_child_ns_type,
33};
34
35static struct kobject *nfs_netns_object_alloc(const char *name,
36 struct kset *kset, struct kobject *parent)
37{
38 struct kobject *kobj;
39
40 kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
41 if (kobj) {
42 kobj->kset = kset;
43 if (kobject_init_and_add(kobj, &nfs_netns_object_type,
44 parent, "%s", name) == 0)
45 return kobj;
46 kobject_put(kobj);
47 }
48 return NULL;
49}
50
51int nfs_sysfs_init(void)
52{
53 nfs_client_kset = kset_create_and_add("nfs", NULL, fs_kobj);
54 if (!nfs_client_kset)
55 return -ENOMEM;
56 nfs_client_kobj = nfs_netns_object_alloc("net", nfs_client_kset, NULL);
57 if (!nfs_client_kobj) {
58 kset_unregister(nfs_client_kset);
59 nfs_client_kset = NULL;
60 return -ENOMEM;
61 }
62 return 0;
63}
64
65void nfs_sysfs_exit(void)
66{
67 kobject_put(nfs_client_kobj);
68 kset_unregister(nfs_client_kset);
69}
diff --git a/fs/nfs/sysfs.h b/fs/nfs/sysfs.h
new file mode 100644
index 000000000000..666f8db2ba92
--- /dev/null
+++ b/fs/nfs/sysfs.h
@@ -0,0 +1,15 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2019 Hammerspace Inc
4 */
5
6#ifndef __NFS_SYSFS_H
7#define __NFS_SYSFS_H
8
9
10extern struct kobject *nfs_client_kobj;
11
12extern int nfs_sysfs_init(void);
13extern void nfs_sysfs_exit(void);
14
15#endif