xref: /linux-6.15/include/linux/nfslocalio.h (revision b0ef514b)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2024 Mike Snitzer <[email protected]>
4  * Copyright (C) 2024 NeilBrown <[email protected]>
5  */
6 #ifndef __LINUX_NFSLOCALIO_H
7 #define __LINUX_NFSLOCALIO_H
8 
9 /* nfsd_file structure is purposely kept opaque to NFS client */
10 struct nfsd_file;
11 
12 #if IS_ENABLED(CONFIG_NFS_LOCALIO)
13 
14 #include <linux/module.h>
15 #include <linux/list.h>
16 #include <linux/uuid.h>
17 #include <linux/sunrpc/clnt.h>
18 #include <linux/sunrpc/svcauth.h>
19 #include <linux/nfs.h>
20 #include <net/net_namespace.h>
21 
22 /*
23  * Useful to allow a client to negotiate if localio
24  * possible with its server.
25  *
26  * See Documentation/filesystems/nfs/localio.rst for more detail.
27  */
28 typedef struct {
29 	uuid_t uuid;
30 	struct list_head list;
31 	struct net __rcu *net; /* nfsd's network namespace */
32 	struct auth_domain *dom; /* auth_domain for localio */
33 } nfs_uuid_t;
34 
35 void nfs_uuid_begin(nfs_uuid_t *);
36 void nfs_uuid_end(nfs_uuid_t *);
37 void nfs_uuid_is_local(const uuid_t *, struct list_head *,
38 		       struct net *, struct auth_domain *, struct module *);
39 void nfs_uuid_invalidate_clients(struct list_head *list);
40 void nfs_uuid_invalidate_one_client(nfs_uuid_t *nfs_uuid);
41 
42 /* localio needs to map filehandle -> struct nfsd_file */
43 extern struct nfsd_file *
44 nfsd_open_local_fh(struct net *, struct auth_domain *, struct rpc_clnt *,
45 		   const struct cred *, const struct nfs_fh *,
46 		   const fmode_t) __must_hold(rcu);
47 
48 struct nfsd_localio_operations {
49 	bool (*nfsd_serv_try_get)(struct net *);
50 	void (*nfsd_serv_put)(struct net *);
51 	struct nfsd_file *(*nfsd_open_local_fh)(struct net *,
52 						struct auth_domain *,
53 						struct rpc_clnt *,
54 						const struct cred *,
55 						const struct nfs_fh *,
56 						const fmode_t);
57 	void (*nfsd_file_put_local)(struct nfsd_file *);
58 	struct file *(*nfsd_file_file)(struct nfsd_file *);
59 } ____cacheline_aligned;
60 
61 extern void nfsd_localio_ops_init(void);
62 extern const struct nfsd_localio_operations *nfs_to;
63 
64 struct nfsd_file *nfs_open_local_fh(nfs_uuid_t *,
65 		   struct rpc_clnt *, const struct cred *,
66 		   const struct nfs_fh *, const fmode_t);
67 
68 static inline void nfs_to_nfsd_file_put_local(struct nfsd_file *localio)
69 {
70 	/*
71 	 * Once reference to nfsd_serv is dropped, NFSD could be
72 	 * unloaded, so ensure safe return from nfsd_file_put_local()
73 	 * by always taking RCU.
74 	 */
75 	rcu_read_lock();
76 	nfs_to->nfsd_file_put_local(localio);
77 	rcu_read_unlock();
78 }
79 
80 #else   /* CONFIG_NFS_LOCALIO */
81 static inline void nfsd_localio_ops_init(void)
82 {
83 }
84 static inline void nfs_to_nfsd_file_put_local(struct nfsd_file *localio)
85 {
86 }
87 #endif  /* CONFIG_NFS_LOCALIO */
88 
89 #endif  /* __LINUX_NFSLOCALIO_H */
90