Skip to content

Commit 779a395

Browse files
Mike SnitzerAnna Schumaker
authored andcommitted
nfs/localio: remove redundant code and simplify LOCALIO enablement
Remove nfs_local_enable and nfs_local_disable, instead use nfs_localio_enable_client and nfs_localio_disable_client. Discontinue use of the NFS_CS_LOCAL_IO bit in the nfs_client struct's cl_flags to reflect that LOCALIO is enabled; instead just test if the net member of the nfs_uuid_t struct is set. Also remove NFS_CS_LOCAL_IO. Lastly, remove trace_nfs_local_enable and trace_nfs_local_disable because comparable traces are available from nfs_localio.ko. Suggested-by: NeilBrown <[email protected]> Signed-off-by: Mike Snitzer <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 0dc7314 commit 779a395

File tree

7 files changed

+22
-83
lines changed

7 files changed

+22
-83
lines changed

fs/nfs/client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <linux/sunrpc/bc_xprt.h>
3939
#include <linux/nsproxy.h>
4040
#include <linux/pid_namespace.h>
41-
41+
#include <linux/nfslocalio.h>
4242

4343
#include "nfs4_fs.h"
4444
#include "callback.h"
@@ -243,7 +243,7 @@ static void pnfs_init_server(struct nfs_server *server)
243243
*/
244244
void nfs_free_client(struct nfs_client *clp)
245245
{
246-
nfs_local_disable(clp);
246+
nfs_localio_disable_client(clp);
247247

248248
/* -EIO all pending I/O */
249249
if (!IS_ERR(clp->cl_rpcclient))

fs/nfs/internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
455455

456456
#if IS_ENABLED(CONFIG_NFS_LOCALIO)
457457
/* localio.c */
458-
extern void nfs_local_disable(struct nfs_client *);
459458
extern void nfs_local_probe(struct nfs_client *);
460459
extern struct nfsd_file *nfs_local_open_fh(struct nfs_client *,
461460
const struct cred *,
@@ -472,7 +471,6 @@ extern int nfs_local_commit(struct nfsd_file *,
472471
extern bool nfs_server_is_local(const struct nfs_client *clp);
473472

474473
#else /* CONFIG_NFS_LOCALIO */
475-
static inline void nfs_local_disable(struct nfs_client *clp) {}
476474
static inline void nfs_local_probe(struct nfs_client *clp) {}
477475
static inline struct nfsd_file *
478476
nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,

fs/nfs/localio.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ MODULE_PARM_DESC(localio_O_DIRECT_semantics,
5656

5757
static inline bool nfs_client_is_local(const struct nfs_client *clp)
5858
{
59-
return !!test_bit(NFS_CS_LOCAL_IO, &clp->cl_flags);
59+
return !!rcu_access_pointer(clp->cl_uuid.net);
6060
}
6161

6262
bool nfs_server_is_local(const struct nfs_client *clp)
@@ -121,24 +121,6 @@ const struct rpc_program nfslocalio_program = {
121121
.stats = &nfslocalio_rpcstat,
122122
};
123123

124-
/*
125-
* nfs_local_enable - enable local i/o for an nfs_client
126-
*/
127-
static void nfs_local_enable(struct nfs_client *clp)
128-
{
129-
trace_nfs_local_enable(clp);
130-
nfs_localio_enable_client(clp);
131-
}
132-
133-
/*
134-
* nfs_local_disable - disable local i/o for an nfs_client
135-
*/
136-
void nfs_local_disable(struct nfs_client *clp)
137-
{
138-
trace_nfs_local_disable(clp);
139-
nfs_localio_disable_client(clp);
140-
}
141-
142124
/*
143125
* nfs_init_localioclient - Initialise an NFS localio client connection
144126
*/
@@ -194,19 +176,19 @@ void nfs_local_probe(struct nfs_client *clp)
194176
/* Disallow localio if disabled via sysfs or AUTH_SYS isn't used */
195177
if (!localio_enabled ||
196178
clp->cl_rpcclient->cl_auth->au_flavor != RPC_AUTH_UNIX) {
197-
nfs_local_disable(clp);
179+
nfs_localio_disable_client(clp);
198180
return;
199181
}
200182

201183
if (nfs_client_is_local(clp)) {
202184
/* If already enabled, disable and re-enable */
203-
nfs_local_disable(clp);
185+
nfs_localio_disable_client(clp);
204186
}
205187

206188
if (!nfs_uuid_begin(&clp->cl_uuid))
207189
return;
208190
if (nfs_server_uuid_is_local(clp))
209-
nfs_local_enable(clp);
191+
nfs_localio_enable_client(clp);
210192
nfs_uuid_end(&clp->cl_uuid);
211193
}
212194
EXPORT_SYMBOL_GPL(nfs_local_probe);
@@ -748,7 +730,7 @@ int nfs_local_doio(struct nfs_client *clp, struct nfsd_file *localio,
748730

749731
if (status != 0) {
750732
if (status == -EAGAIN)
751-
nfs_local_disable(clp);
733+
nfs_localio_disable_client(clp);
752734
nfs_local_file_put(localio);
753735
hdr->task.tk_status = status;
754736
nfs_local_hdr_release(hdr, call_ops);

fs/nfs/nfstrace.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,38 +1714,6 @@ TRACE_EVENT(nfs_local_open_fh,
17141714
)
17151715
);
17161716

1717-
DECLARE_EVENT_CLASS(nfs_local_client_event,
1718-
TP_PROTO(
1719-
const struct nfs_client *clp
1720-
),
1721-
1722-
TP_ARGS(clp),
1723-
1724-
TP_STRUCT__entry(
1725-
__field(unsigned int, protocol)
1726-
__string(server, clp->cl_hostname)
1727-
),
1728-
1729-
TP_fast_assign(
1730-
__entry->protocol = clp->rpc_ops->version;
1731-
__assign_str(server);
1732-
),
1733-
1734-
TP_printk(
1735-
"server=%s NFSv%u", __get_str(server), __entry->protocol
1736-
)
1737-
);
1738-
1739-
#define DEFINE_NFS_LOCAL_CLIENT_EVENT(name) \
1740-
DEFINE_EVENT(nfs_local_client_event, name, \
1741-
TP_PROTO( \
1742-
const struct nfs_client *clp \
1743-
), \
1744-
TP_ARGS(clp))
1745-
1746-
DEFINE_NFS_LOCAL_CLIENT_EVENT(nfs_local_enable);
1747-
DEFINE_NFS_LOCAL_CLIENT_EVENT(nfs_local_disable);
1748-
17491717
DECLARE_EVENT_CLASS(nfs_xdr_event,
17501718
TP_PROTO(
17511719
const struct xdr_stream *xdr,

fs/nfs_common/nfslocalio.c

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static LIST_HEAD(nfs_uuids);
3737

3838
void nfs_uuid_init(nfs_uuid_t *nfs_uuid)
3939
{
40-
nfs_uuid->net = NULL;
40+
RCU_INIT_POINTER(nfs_uuid->net, NULL);
4141
nfs_uuid->dom = NULL;
4242
nfs_uuid->list_lock = NULL;
4343
INIT_LIST_HEAD(&nfs_uuid->list);
@@ -49,7 +49,7 @@ EXPORT_SYMBOL_GPL(nfs_uuid_init);
4949
bool nfs_uuid_begin(nfs_uuid_t *nfs_uuid)
5050
{
5151
spin_lock(&nfs_uuid->lock);
52-
if (nfs_uuid->net) {
52+
if (rcu_access_pointer(nfs_uuid->net)) {
5353
/* This nfs_uuid is already in use */
5454
spin_unlock(&nfs_uuid->lock);
5555
return false;
@@ -74,9 +74,9 @@ EXPORT_SYMBOL_GPL(nfs_uuid_begin);
7474

7575
void nfs_uuid_end(nfs_uuid_t *nfs_uuid)
7676
{
77-
if (nfs_uuid->net == NULL) {
77+
if (!rcu_access_pointer(nfs_uuid->net)) {
7878
spin_lock(&nfs_uuid->lock);
79-
if (nfs_uuid->net == NULL) {
79+
if (!rcu_access_pointer(nfs_uuid->net)) {
8080
/* Not local, remove from nfs_uuids */
8181
spin_lock(&nfs_uuids_lock);
8282
list_del_init(&nfs_uuid->list);
@@ -139,28 +139,24 @@ EXPORT_SYMBOL_GPL(nfs_uuid_is_local);
139139

140140
void nfs_localio_enable_client(struct nfs_client *clp)
141141
{
142-
nfs_uuid_t *nfs_uuid = &clp->cl_uuid;
143-
144-
spin_lock(&nfs_uuid->lock);
145-
set_bit(NFS_CS_LOCAL_IO, &clp->cl_flags);
142+
/* nfs_uuid_is_local() does the actual enablement */
146143
trace_nfs_localio_enable_client(clp);
147-
spin_unlock(&nfs_uuid->lock);
148144
}
149145
EXPORT_SYMBOL_GPL(nfs_localio_enable_client);
150146

151147
/*
152148
* Cleanup the nfs_uuid_t embedded in an nfs_client.
153149
* This is the long-form of nfs_uuid_init().
154150
*/
155-
static void nfs_uuid_put(nfs_uuid_t *nfs_uuid)
151+
static bool nfs_uuid_put(nfs_uuid_t *nfs_uuid)
156152
{
157153
LIST_HEAD(local_files);
158154
struct nfs_file_localio *nfl, *tmp;
159155

160156
spin_lock(&nfs_uuid->lock);
161-
if (unlikely(!nfs_uuid->net)) {
157+
if (unlikely(!rcu_access_pointer(nfs_uuid->net))) {
162158
spin_unlock(&nfs_uuid->lock);
163-
return;
159+
return false;
164160
}
165161
RCU_INIT_POINTER(nfs_uuid->net, NULL);
166162

@@ -192,22 +188,14 @@ static void nfs_uuid_put(nfs_uuid_t *nfs_uuid)
192188

193189
module_put(nfsd_mod);
194190
spin_unlock(&nfs_uuid->lock);
191+
192+
return true;
195193
}
196194

197195
void nfs_localio_disable_client(struct nfs_client *clp)
198196
{
199-
nfs_uuid_t *nfs_uuid = NULL;
200-
201-
spin_lock(&clp->cl_uuid.lock); /* aka &nfs_uuid->lock */
202-
if (test_and_clear_bit(NFS_CS_LOCAL_IO, &clp->cl_flags)) {
203-
/* &clp->cl_uuid is always not NULL, using as bool here */
204-
nfs_uuid = &clp->cl_uuid;
197+
if (nfs_uuid_put(&clp->cl_uuid))
205198
trace_nfs_localio_disable_client(clp);
206-
}
207-
spin_unlock(&clp->cl_uuid.lock);
208-
209-
if (nfs_uuid)
210-
nfs_uuid_put(nfs_uuid);
211199
}
212200
EXPORT_SYMBOL_GPL(nfs_localio_disable_client);
213201

include/linux/nfs_fs_sb.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ struct nfs_client {
5050
#define NFS_CS_DS 7 /* - Server is a DS */
5151
#define NFS_CS_REUSEPORT 8 /* - reuse src port on reconnect */
5252
#define NFS_CS_PNFS 9 /* - Server used for pnfs */
53-
#define NFS_CS_LOCAL_IO 10 /* - client is local */
5453
struct sockaddr_storage cl_addr; /* server identifier */
5554
size_t cl_addrlen;
5655
char * cl_hostname; /* hostname of server */

include/linux/nfslocalio.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ static inline void nfs_close_local_fh(struct nfs_file_localio *nfl)
111111
static inline void nfsd_localio_ops_init(void)
112112
{
113113
}
114+
struct nfs_client;
115+
static inline void nfs_localio_disable_client(struct nfs_client *clp)
116+
{
117+
}
114118

115119
#endif /* CONFIG_NFS_LOCALIO */
116120

0 commit comments

Comments
 (0)