Commit 28ade856 authored by Trond Myklebust's avatar Trond Myklebust

Merge branch 'containers'

parents 02a2779f bf11fbdb
...@@ -8,7 +8,8 @@ obj-$(CONFIG_NFS_FS) += nfs.o ...@@ -8,7 +8,8 @@ obj-$(CONFIG_NFS_FS) += nfs.o
CFLAGS_nfstrace.o += -I$(src) CFLAGS_nfstrace.o += -I$(src)
nfs-y := client.o dir.o file.o getroot.o inode.o super.o \ nfs-y := client.o dir.o file.o getroot.o inode.o super.o \
io.o direct.o pagelist.o read.o symlink.o unlink.o \ io.o direct.o pagelist.o read.o symlink.o unlink.o \
write.o namespace.o mount_clnt.o nfstrace.o export.o write.o namespace.o mount_clnt.o nfstrace.o \
export.o sysfs.o
nfs-$(CONFIG_ROOT_NFS) += nfsroot.o nfs-$(CONFIG_ROOT_NFS) += nfsroot.o
nfs-$(CONFIG_SYSCTL) += sysctl.o nfs-$(CONFIG_SYSCTL) += sysctl.o
nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "pnfs.h" #include "pnfs.h"
#include "nfs.h" #include "nfs.h"
#include "netns.h" #include "netns.h"
#include "sysfs.h"
#define NFSDBG_FACILITY NFSDBG_CLIENT #define NFSDBG_FACILITY NFSDBG_CLIENT
...@@ -192,7 +193,7 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) ...@@ -192,7 +193,7 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
EXPORT_SYMBOL_GPL(nfs_alloc_client); EXPORT_SYMBOL_GPL(nfs_alloc_client);
#if IS_ENABLED(CONFIG_NFS_V4) #if IS_ENABLED(CONFIG_NFS_V4)
void nfs_cleanup_cb_ident_idr(struct net *net) static void nfs_cleanup_cb_ident_idr(struct net *net)
{ {
struct nfs_net *nn = net_generic(net, nfs_net_id); struct nfs_net *nn = net_generic(net, nfs_net_id);
...@@ -214,7 +215,7 @@ static void pnfs_init_server(struct nfs_server *server) ...@@ -214,7 +215,7 @@ static void pnfs_init_server(struct nfs_server *server)
} }
#else #else
void nfs_cleanup_cb_ident_idr(struct net *net) static void nfs_cleanup_cb_ident_idr(struct net *net)
{ {
} }
...@@ -1072,6 +1073,18 @@ void nfs_clients_init(struct net *net) ...@@ -1072,6 +1073,18 @@ void nfs_clients_init(struct net *net)
#endif #endif
spin_lock_init(&nn->nfs_client_lock); spin_lock_init(&nn->nfs_client_lock);
nn->boot_time = ktime_get_real(); nn->boot_time = ktime_get_real();
nfs_netns_sysfs_setup(nn, net);
}
void nfs_clients_exit(struct net *net)
{
struct nfs_net *nn = net_generic(net, nfs_net_id);
nfs_netns_sysfs_destroy(nn);
nfs_cleanup_cb_ident_idr(net);
WARN_ON_ONCE(!list_empty(&nn->nfs_client_list));
WARN_ON_ONCE(!list_empty(&nn->nfs_volume_list));
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "pnfs.h" #include "pnfs.h"
#include "nfs.h" #include "nfs.h"
#include "netns.h" #include "netns.h"
#include "sysfs.h"
#include "nfstrace.h" #include "nfstrace.h"
...@@ -2167,12 +2168,8 @@ static int nfs_net_init(struct net *net) ...@@ -2167,12 +2168,8 @@ static int nfs_net_init(struct net *net)
static void nfs_net_exit(struct net *net) static void nfs_net_exit(struct net *net)
{ {
struct nfs_net *nn = net_generic(net, nfs_net_id);
nfs_fs_proc_net_exit(net); nfs_fs_proc_net_exit(net);
nfs_cleanup_cb_ident_idr(net); nfs_clients_exit(net);
WARN_ON_ONCE(!list_empty(&nn->nfs_client_list));
WARN_ON_ONCE(!list_empty(&nn->nfs_volume_list));
} }
static struct pernet_operations nfs_net_ops = { static struct pernet_operations nfs_net_ops = {
...@@ -2189,6 +2186,10 @@ static int __init init_nfs_fs(void) ...@@ -2189,6 +2186,10 @@ static int __init init_nfs_fs(void)
{ {
int err; int err;
err = nfs_sysfs_init();
if (err < 0)
goto out10;
err = register_pernet_subsys(&nfs_net_ops); err = register_pernet_subsys(&nfs_net_ops);
if (err < 0) if (err < 0)
goto out9; goto out9;
...@@ -2252,6 +2253,8 @@ static int __init init_nfs_fs(void) ...@@ -2252,6 +2253,8 @@ static int __init init_nfs_fs(void)
out8: out8:
unregister_pernet_subsys(&nfs_net_ops); unregister_pernet_subsys(&nfs_net_ops);
out9: out9:
nfs_sysfs_exit();
out10:
return err; return err;
} }
...@@ -2268,6 +2271,7 @@ static void __exit exit_nfs_fs(void) ...@@ -2268,6 +2271,7 @@ static void __exit exit_nfs_fs(void)
unregister_nfs_fs(); unregister_nfs_fs();
nfs_fs_proc_exit(); nfs_fs_proc_exit();
nfsiod_stop(); nfsiod_stop();
nfs_sysfs_exit();
} }
/* Not quite true; I just maintain it */ /* Not quite true; I just maintain it */
......
...@@ -158,6 +158,7 @@ extern void nfs_umount(const struct nfs_mount_request *info); ...@@ -158,6 +158,7 @@ extern void nfs_umount(const struct nfs_mount_request *info);
/* client.c */ /* client.c */
extern const struct rpc_program nfs_program; extern const struct rpc_program nfs_program;
extern void nfs_clients_init(struct net *net); extern void nfs_clients_init(struct net *net);
extern void nfs_clients_exit(struct net *net);
extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *); extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t); int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
struct nfs_client *nfs_get_client(const struct nfs_client_initdata *); struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
...@@ -170,7 +171,6 @@ int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t, ...@@ -170,7 +171,6 @@ int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
struct nfs_server *nfs_alloc_server(void); struct nfs_server *nfs_alloc_server(void);
void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *); void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
extern void nfs_cleanup_cb_ident_idr(struct net *);
extern void nfs_put_client(struct nfs_client *); extern void nfs_put_client(struct nfs_client *);
extern void nfs_free_client(struct nfs_client *); extern void nfs_free_client(struct nfs_client *);
extern struct nfs_client *nfs4_find_client_ident(struct net *, int); extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
......
...@@ -15,6 +15,8 @@ struct bl_dev_msg { ...@@ -15,6 +15,8 @@ struct bl_dev_msg {
uint32_t major, minor; uint32_t major, minor;
}; };
struct nfs_netns_client;
struct nfs_net { struct nfs_net {
struct cache_detail *nfs_dns_resolve; struct cache_detail *nfs_dns_resolve;
struct rpc_pipe *bl_device_pipe; struct rpc_pipe *bl_device_pipe;
...@@ -29,6 +31,7 @@ struct nfs_net { ...@@ -29,6 +31,7 @@ struct nfs_net {
unsigned short nfs_callback_tcpport6; unsigned short nfs_callback_tcpport6;
int cb_users[NFS4_MAX_MINOR_VERSION + 1]; int cb_users[NFS4_MAX_MINOR_VERSION + 1];
#endif #endif
struct nfs_netns_client *nfs_client;
spinlock_t nfs_client_lock; spinlock_t nfs_client_lock;
ktime_t boot_time; ktime_t boot_time;
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
......
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 Hammerspace Inc
*/
#include <linux/module.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/netdevice.h>
#include <linux/string.h>
#include <linux/nfs_fs.h>
#include <linux/rcupdate.h>
#include "nfs4_fs.h"
#include "netns.h"
#include "sysfs.h"
struct kobject *nfs_client_kobj;
static struct kset *nfs_client_kset;
static void nfs_netns_object_release(struct kobject *kobj)
{
kfree(kobj);
}
static const struct kobj_ns_type_operations *nfs_netns_object_child_ns_type(
struct kobject *kobj)
{
return &net_ns_type_operations;
}
static struct kobj_type nfs_netns_object_type = {
.release = nfs_netns_object_release,
.sysfs_ops = &kobj_sysfs_ops,
.child_ns_type = nfs_netns_object_child_ns_type,
};
static struct kobject *nfs_netns_object_alloc(const char *name,
struct kset *kset, struct kobject *parent)
{
struct kobject *kobj;
kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
if (kobj) {
kobj->kset = kset;
if (kobject_init_and_add(kobj, &nfs_netns_object_type,
parent, "%s", name) == 0)
return kobj;
kobject_put(kobj);
}
return NULL;
}
int nfs_sysfs_init(void)
{
nfs_client_kset = kset_create_and_add("nfs", NULL, fs_kobj);
if (!nfs_client_kset)
return -ENOMEM;
nfs_client_kobj = nfs_netns_object_alloc("net", nfs_client_kset, NULL);
if (!nfs_client_kobj) {
kset_unregister(nfs_client_kset);
nfs_client_kset = NULL;
return -ENOMEM;
}
return 0;
}
void nfs_sysfs_exit(void)
{
kobject_put(nfs_client_kobj);
kset_unregister(nfs_client_kset);
}
static ssize_t nfs_netns_identifier_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
struct nfs_netns_client *c = container_of(kobj,
struct nfs_netns_client,
kobject);
return scnprintf(buf, PAGE_SIZE, "%s\n", c->identifier);
}
/* Strip trailing '\n' */
static size_t nfs_string_strip(const char *c, size_t len)
{
while (len > 0 && c[len-1] == '\n')
--len;
return len;
}
static ssize_t nfs_netns_identifier_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
struct nfs_netns_client *c = container_of(kobj,
struct nfs_netns_client,
kobject);
const char *old;
char *p;
size_t len;
len = nfs_string_strip(buf, min_t(size_t, count, CONTAINER_ID_MAXLEN));
if (!len)
return 0;
p = kmemdup_nul(buf, len, GFP_KERNEL);
if (!p)
return -ENOMEM;
old = xchg(&c->identifier, p);
if (old) {
synchronize_rcu();
kfree(old);
}
return count;
}
static void nfs_netns_client_release(struct kobject *kobj)
{
struct nfs_netns_client *c = container_of(kobj,
struct nfs_netns_client,
kobject);
if (c->identifier)
kfree(c->identifier);
kfree(c);
}
static const void *nfs_netns_client_namespace(struct kobject *kobj)
{
return container_of(kobj, struct nfs_netns_client, kobject)->net;
}
static struct kobj_attribute nfs_netns_client_id = __ATTR(identifier,
0644, nfs_netns_identifier_show, nfs_netns_identifier_store);
static struct attribute *nfs_netns_client_attrs[] = {
&nfs_netns_client_id.attr,
NULL,
};
static struct kobj_type nfs_netns_client_type = {
.release = nfs_netns_client_release,
.default_attrs = nfs_netns_client_attrs,
.sysfs_ops = &kobj_sysfs_ops,
.namespace = nfs_netns_client_namespace,
};
static struct nfs_netns_client *nfs_netns_client_alloc(struct kobject *parent,
struct net *net)
{
struct nfs_netns_client *p;
p = kzalloc(sizeof(*p), GFP_KERNEL);
if (p) {
p->net = net;
p->kobject.kset = nfs_client_kset;
if (kobject_init_and_add(&p->kobject, &nfs_netns_client_type,
parent, "nfs_client") == 0)
return p;
kobject_put(&p->kobject);
}
return NULL;
}
void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net)
{
struct nfs_netns_client *clp;
clp = nfs_netns_client_alloc(nfs_client_kobj, net);
if (clp) {
netns->nfs_client = clp;
kobject_uevent(&clp->kobject, KOBJ_ADD);
}
}
void nfs_netns_sysfs_destroy(struct nfs_net *netns)
{
struct nfs_netns_client *clp = netns->nfs_client;
if (clp) {
kobject_uevent(&clp->kobject, KOBJ_REMOVE);
kobject_del(&clp->kobject);
kobject_put(&clp->kobject);
netns->nfs_client = NULL;
}
}
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 Hammerspace Inc
*/
#ifndef __NFS_SYSFS_H
#define __NFS_SYSFS_H
#define CONTAINER_ID_MAXLEN (64)
struct nfs_netns_client {
struct kobject kobject;
struct net *net;
const char *identifier;
};
extern struct kobject *nfs_client_kobj;
extern int nfs_sysfs_init(void);
extern void nfs_sysfs_exit(void);
void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net);
void nfs_netns_sysfs_destroy(struct nfs_net *netns);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment