summaryrefslogtreecommitdiff
path: root/include/linux/nfslocalio.h
blob: 9aa8a43843d7179c9f71857599d7fb27a36727aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2024 Mike Snitzer <snitzer@hammerspace.com>
 * Copyright (C) 2024 NeilBrown <neilb@suse.de>
 */
#ifndef __LINUX_NFSLOCALIO_H
#define __LINUX_NFSLOCALIO_H

#if IS_ENABLED(CONFIG_NFS_LOCALIO)

#include <linux/module.h>
#include <linux/list.h>
#include <linux/uuid.h>
#include <linux/sunrpc/clnt.h>
#include <linux/sunrpc/svcauth.h>
#include <linux/nfs.h>
#include <net/net_namespace.h>

struct nfs_client;
struct nfs_file_localio;

/*
 * Useful to allow a client to negotiate if localio
 * possible with its server.
 *
 * See Documentation/filesystems/nfs/localio.rst for more detail.
 */
typedef struct {
	uuid_t uuid;
	unsigned nfs3_localio_probe_count;
	/* this struct is over a cacheline, avoid bouncing */
	spinlock_t ____cacheline_aligned lock;
	struct list_head list;
	spinlock_t *list_lock; /* nn->local_clients_lock */
	struct net __rcu *net; /* nfsd's network namespace */
	struct auth_domain *dom; /* auth_domain for localio */
	/* Local files to close when net is shut down or exports change */
	struct list_head files;
} nfs_uuid_t;

void nfs_uuid_init(nfs_uuid_t *);
bool nfs_uuid_begin(nfs_uuid_t *);
void nfs_uuid_end(nfs_uuid_t *);
void nfs_uuid_is_local(const uuid_t *, struct list_head *, spinlock_t *,
		       struct net *, struct auth_domain *, struct module *);

void nfs_localio_enable_client(struct nfs_client *clp);
void nfs_localio_disable_client(struct nfs_client *clp);
void nfs_localio_invalidate_clients(struct list_head *nn_local_clients,
				    spinlock_t *nn_local_clients_lock);

/* localio needs to map filehandle -> struct nfsd_file */
extern struct nfsd_file *
nfsd_open_local_fh(struct net *, struct auth_domain *, struct rpc_clnt *,
		   const struct cred *, const struct nfs_fh *,
		   const fmode_t) __must_hold(rcu);
void nfs_close_local_fh(struct nfs_file_localio *);

struct nfsd_localio_operations {
	bool (*nfsd_net_try_get)(struct net *);
	void (*nfsd_net_put)(struct net *);
	struct nfsd_file *(*nfsd_open_local_fh)(struct net *,
						struct auth_domain *,
						struct rpc_clnt *,
						const struct cred *,
						const struct nfs_fh *,
						const fmode_t);
	struct net *(*nfsd_file_put_local)(struct nfsd_file *);
	struct nfsd_file *(*nfsd_file_get)(struct nfsd_file *);
	void (*nfsd_file_put)(struct nfsd_file *);
	struct file *(*nfsd_file_file)(struct nfsd_file *);
} ____cacheline_aligned;

extern void nfsd_localio_ops_init(void);
extern const struct nfsd_localio_operations *nfs_to;

struct nfsd_file *nfs_open_local_fh(nfs_uuid_t *,
		   struct rpc_clnt *, const struct cred *,
		   const struct nfs_fh *, struct nfs_file_localio *,
		   const fmode_t);

static inline void nfs_to_nfsd_net_put(struct net *net)
{
	/*
	 * Once reference to net (and associated nfsd_serv) is dropped, NFSD
	 * could be unloaded, so ensure safe return from nfsd_net_put() by
	 * always taking RCU.
	 */
	rcu_read_lock();
	nfs_to->nfsd_net_put(net);
	rcu_read_unlock();
}

static inline void nfs_to_nfsd_file_put_local(struct nfsd_file *localio)
{
	/*
	 * Must not hold RCU otherwise nfsd_file_put() can easily trigger:
	 * "Voluntary context switch within RCU read-side critical section!"
	 * by scheduling deep in underlying filesystem (e.g. XFS).
	 */
	struct net *net = nfs_to->nfsd_file_put_local(localio);

	nfs_to_nfsd_net_put(net);
}

#else   /* CONFIG_NFS_LOCALIO */

struct nfs_file_localio;
static inline void nfs_close_local_fh(struct nfs_file_localio *nfl)
{
}
static inline void nfsd_localio_ops_init(void)
{
}
struct nfs_client;
static inline void nfs_localio_disable_client(struct nfs_client *clp)
{
}

#endif  /* CONFIG_NFS_LOCALIO */

#endif  /* __LINUX_NFSLOCALIO_H */