NFS: Only initialize the ACL client in the v3 case

v2 and v4 don't use it, so I create two new nfs_rpc_ops functions to
initialize the ACL client only when we are using v3.

Signed-off-by: Bryan Schumaker <bjschuma@netapp.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
Bryan Schumaker 2012-07-30 16:05:19 -04:00 committed by Trond Myklebust
parent ff9099f266
commit 1179acc6a3
11 changed files with 99 additions and 69 deletions

View File

@ -10,7 +10,7 @@ nfs-y := client.o dir.o file.o getroot.o inode.o super.o \
dns_resolve.o cache_lib.o dns_resolve.o cache_lib.o
nfs-$(CONFIG_ROOT_NFS) += nfsroot.o nfs-$(CONFIG_ROOT_NFS) += nfsroot.o
nfs-$(CONFIG_NFS_V2) += nfs2super.o proc.o nfs2xdr.o nfs-$(CONFIG_NFS_V2) += nfs2super.o proc.o nfs2xdr.o
nfs-$(CONFIG_NFS_V3) += nfs3super.o nfs3proc.o nfs3xdr.o nfs-$(CONFIG_NFS_V3) += nfs3super.o nfs3client.o nfs3proc.o nfs3xdr.o
nfs-$(CONFIG_NFS_V3_ACL) += nfs3acl.o nfs-$(CONFIG_NFS_V3_ACL) += nfs3acl.o
nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \ nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \
nfs4super.o nfs4file.o delegation.o idmap.o \ nfs4super.o nfs4file.o delegation.o idmap.o \

View File

@ -83,22 +83,6 @@ struct rpc_stat nfs_rpcstat = {
.program = &nfs_program .program = &nfs_program
}; };
#ifdef CONFIG_NFS_V3_ACL
static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
static const struct rpc_version *nfsacl_version[] = {
[3] = &nfsacl_version3,
};
const struct rpc_program nfsacl_program = {
.name = "nfsacl",
.number = NFS_ACL_PROGRAM,
.nrvers = ARRAY_SIZE(nfsacl_version),
.version = nfsacl_version,
.stats = &nfsacl_rpcstat,
};
#endif /* CONFIG_NFS_V3_ACL */
static struct nfs_subversion *find_nfs_version(unsigned int version) static struct nfs_subversion *find_nfs_version(unsigned int version)
{ {
struct nfs_subversion *nfs; struct nfs_subversion *nfs;
@ -695,36 +679,6 @@ static int nfs_start_lockd(struct nfs_server *server)
return 0; return 0;
} }
/*
* Initialise an NFSv3 ACL client connection
*/
#ifdef CONFIG_NFS_V3_ACL
static void nfs_init_server_aclclient(struct nfs_server *server)
{
if (server->nfs_client->rpc_ops->version != 3)
goto out_noacl;
if (server->flags & NFS_MOUNT_NOACL)
goto out_noacl;
server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
if (IS_ERR(server->client_acl))
goto out_noacl;
/* No errors! Assume that Sun nfsacls are supported */
server->caps |= NFS_CAP_ACLS;
return;
out_noacl:
server->caps &= ~NFS_CAP_ACLS;
}
#else
static inline void nfs_init_server_aclclient(struct nfs_server *server)
{
server->flags &= ~NFS_MOUNT_NOACL;
server->caps &= ~NFS_CAP_ACLS;
}
#endif
/* /*
* Create a general RPC client * Create a general RPC client
*/ */
@ -874,8 +828,6 @@ static int nfs_init_server(struct nfs_server *server,
server->mountd_protocol = data->mount_server.protocol; server->mountd_protocol = data->mount_server.protocol;
server->namelen = data->namlen; server->namelen = data->namlen;
/* Create a client RPC handle for the NFSv3 ACL management interface */
nfs_init_server_aclclient(server);
dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp); dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp);
return 0; return 0;
@ -1108,8 +1060,7 @@ void nfs_free_server(struct nfs_server *server)
* Create a version 2 or 3 volume record * Create a version 2 or 3 volume record
* - keyed on server and FSID * - keyed on server and FSID
*/ */
struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data, struct nfs_server *nfs_create_server(struct nfs_mount_info *mount_info,
struct nfs_fh *mntfh,
struct nfs_subversion *nfs_mod) struct nfs_subversion *nfs_mod)
{ {
struct nfs_server *server; struct nfs_server *server;
@ -1126,7 +1077,7 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
goto error; goto error;
/* Get a client representation */ /* Get a client representation */
error = nfs_init_server(server, data, nfs_mod); error = nfs_init_server(server, mount_info->parsed, nfs_mod);
if (error < 0) if (error < 0)
goto error; goto error;
@ -1135,13 +1086,13 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
/* Probe the root fh to retrieve its FSID */ /* Probe the root fh to retrieve its FSID */
error = nfs_probe_fsinfo(server, mntfh, fattr); error = nfs_probe_fsinfo(server, mount_info->mntfh, fattr);
if (error < 0) if (error < 0)
goto error; goto error;
if (server->nfs_client->rpc_ops->version == 3) { if (server->nfs_client->rpc_ops->version == 3) {
if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN) if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
server->namelen = NFS3_MAXNAMLEN; server->namelen = NFS3_MAXNAMLEN;
if (!(data->flags & NFS_MOUNT_NORDIRPLUS)) if (!(mount_info->parsed->flags & NFS_MOUNT_NORDIRPLUS))
server->caps |= NFS_CAP_READDIRPLUS; server->caps |= NFS_CAP_READDIRPLUS;
} else { } else {
if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN) if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
@ -1149,7 +1100,7 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
} }
if (!(fattr->valid & NFS_ATTR_FATTR)) { if (!(fattr->valid & NFS_ATTR_FATTR)) {
error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr); error = nfs_mod->rpc_ops->getattr(server, mount_info->mntfh, fattr);
if (error < 0) { if (error < 0) {
dprintk("nfs_create_server: getattr error = %d\n", -error); dprintk("nfs_create_server: getattr error = %d\n", -error);
goto error; goto error;
@ -1210,8 +1161,6 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
flavor); flavor);
if (error < 0) if (error < 0)
goto out_free_server; goto out_free_server;
if (!IS_ERR(source->client_acl))
nfs_init_server_aclclient(server);
/* probe the filesystem info for this server filesystem */ /* probe the filesystem info for this server filesystem */
error = nfs_probe_fsinfo(server, fh, fattr_fsinfo); error = nfs_probe_fsinfo(server, fh, fattr_fsinfo);

View File

@ -187,13 +187,11 @@ extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
extern struct nfs_client * extern struct nfs_client *
nfs4_find_client_sessionid(struct net *, const struct sockaddr *, nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
struct nfs4_sessionid *); struct nfs4_sessionid *);
extern struct nfs_server *nfs_create_server( extern struct nfs_server *nfs_create_server(struct nfs_mount_info *,
const struct nfs_parsed_mount_data *,
struct nfs_fh *,
struct nfs_subversion *); struct nfs_subversion *);
extern struct nfs_server *nfs4_create_server( extern struct nfs_server *nfs4_create_server(
const struct nfs_parsed_mount_data *, struct nfs_mount_info *,
struct nfs_fh *); struct nfs_subversion *);
extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *, extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
struct nfs_fh *); struct nfs_fh *);
extern void nfs_free_server(struct nfs_server *server); extern void nfs_free_server(struct nfs_server *server);
@ -225,6 +223,13 @@ static inline void nfs_fs_proc_exit(void)
int nfs_sockaddr_match_ipaddr(const struct sockaddr *, const struct sockaddr *); int nfs_sockaddr_match_ipaddr(const struct sockaddr *, const struct sockaddr *);
#endif #endif
/* nfs3client.c */
#ifdef CONFIG_NFS_V3
struct nfs_server *nfs3_create_server(struct nfs_mount_info *, struct nfs_subversion *);
struct nfs_server *nfs3_clone_server(struct nfs_server *, struct nfs_fh *,
struct nfs_fattr *, rpc_authflavor_t);
#endif
/* callback_xdr.c */ /* callback_xdr.c */
extern struct svc_version nfs4_callback_version1; extern struct svc_version nfs4_callback_version1;
extern struct svc_version nfs4_callback_version4; extern struct svc_version nfs4_callback_version4;

65
fs/nfs/nfs3client.c Normal file
View File

@ -0,0 +1,65 @@
#include <linux/nfs_fs.h>
#include <linux/nfs_mount.h>
#include "internal.h"
#ifdef CONFIG_NFS_V3_ACL
static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
static const struct rpc_version *nfsacl_version[] = {
[3] = &nfsacl_version3,
};
const struct rpc_program nfsacl_program = {
.name = "nfsacl",
.number = NFS_ACL_PROGRAM,
.nrvers = ARRAY_SIZE(nfsacl_version),
.version = nfsacl_version,
.stats = &nfsacl_rpcstat,
};
/*
* Initialise an NFSv3 ACL client connection
*/
static void nfs_init_server_aclclient(struct nfs_server *server)
{
if (server->flags & NFS_MOUNT_NOACL)
goto out_noacl;
server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
if (IS_ERR(server->client_acl))
goto out_noacl;
/* No errors! Assume that Sun nfsacls are supported */
server->caps |= NFS_CAP_ACLS;
return;
out_noacl:
server->caps &= ~NFS_CAP_ACLS;
}
#else
static inline void nfs_init_server_aclclient(struct nfs_server *server)
{
server->flags &= ~NFS_MOUNT_NOACL;
server->caps &= ~NFS_CAP_ACLS;
}
#endif
struct nfs_server *nfs3_create_server(struct nfs_mount_info *mount_info,
struct nfs_subversion *nfs_mod)
{
struct nfs_server *server = nfs_create_server(mount_info, nfs_mod);
/* Create a client RPC handle for the NFS v3 ACL management interface */
if (!IS_ERR(server))
nfs_init_server_aclclient(server);
return server;
}
struct nfs_server *nfs3_clone_server(struct nfs_server *source,
struct nfs_fh *fh,
struct nfs_fattr *fattr,
rpc_authflavor_t flavor)
{
struct nfs_server *server = nfs_clone_server(source, fh, fattr, flavor);
if (!IS_ERR(server) && !IS_ERR(source->client_acl))
nfs_init_server_aclclient(server);
return server;
}

View File

@ -969,4 +969,6 @@ const struct nfs_rpc_ops nfs_v3_clientops = {
.alloc_client = nfs_alloc_client, .alloc_client = nfs_alloc_client,
.init_client = nfs_init_client, .init_client = nfs_init_client,
.free_client = nfs_free_client, .free_client = nfs_free_client,
.create_server = nfs3_create_server,
.clone_server = nfs3_clone_server,
}; };

View File

@ -574,8 +574,10 @@ error:
* Create a version 4 volume record * Create a version 4 volume record
* - keyed on server and FSID * - keyed on server and FSID
*/ */
struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data, /*struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
struct nfs_fh *mntfh) struct nfs_fh *mntfh)*/
struct nfs_server *nfs4_create_server(struct nfs_mount_info *mount_info,
struct nfs_subversion *nfs_mod)
{ {
struct nfs_server *server; struct nfs_server *server;
int error; int error;
@ -587,11 +589,11 @@ struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
/* set up the general RPC client */ /* set up the general RPC client */
error = nfs4_init_server(server, data); error = nfs4_init_server(server, mount_info->parsed);
if (error < 0) if (error < 0)
goto error; goto error;
error = nfs4_server_common_setup(server, mntfh); error = nfs4_server_common_setup(server, mount_info->mntfh);
if (error < 0) if (error < 0)
goto error; goto error;

View File

@ -6916,6 +6916,8 @@ const struct nfs_rpc_ops nfs_v4_clientops = {
.alloc_client = nfs4_alloc_client, .alloc_client = nfs4_alloc_client,
.init_client = nfs4_init_client, .init_client = nfs4_init_client,
.free_client = nfs4_free_client, .free_client = nfs4_free_client,
.create_server = nfs4_create_server,
.clone_server = nfs_clone_server,
}; };
static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {

View File

@ -105,7 +105,7 @@ nfs4_remote_mount(struct file_system_type *fs_type, int flags,
mount_info->set_security = nfs_set_sb_security; mount_info->set_security = nfs_set_sb_security;
/* Get a volume representation */ /* Get a volume representation */
server = nfs4_create_server(mount_info->parsed, mount_info->mntfh); server = nfs4_create_server(mount_info, &nfs_v4);
if (IS_ERR(server)) { if (IS_ERR(server)) {
mntroot = ERR_CAST(server); mntroot = ERR_CAST(server);
goto out; goto out;

View File

@ -817,4 +817,6 @@ const struct nfs_rpc_ops nfs_v2_clientops = {
.alloc_client = nfs_alloc_client, .alloc_client = nfs_alloc_client,
.init_client = nfs_init_client, .init_client = nfs_init_client,
.free_client = nfs_free_client, .free_client = nfs_free_client,
.create_server = nfs_create_server,
.clone_server = nfs_clone_server,
}; };

View File

@ -1664,7 +1664,7 @@ struct dentry *nfs_try_mount(int flags, const char *dev_name,
} }
/* Get a volume representation */ /* Get a volume representation */
server = nfs_create_server(mount_info->parsed, mount_info->mntfh, nfs_mod); server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
if (IS_ERR(server)) if (IS_ERR(server))
return ERR_CAST(server); return ERR_CAST(server);
@ -2458,7 +2458,7 @@ nfs_xdev_mount(struct file_system_type *fs_type, int flags,
mount_info.mntfh = mount_info.cloned->fh; mount_info.mntfh = mount_info.cloned->fh;
/* create a new volume representation */ /* create a new volume representation */
server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor); server = nfs_mod->rpc_ops->clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
if (IS_ERR(server)) { if (IS_ERR(server)) {
error = PTR_ERR(server); error = PTR_ERR(server);
goto out_err; goto out_err;

View File

@ -1439,6 +1439,9 @@ struct nfs_rpc_ops {
(*init_client) (struct nfs_client *, const struct rpc_timeout *, (*init_client) (struct nfs_client *, const struct rpc_timeout *,
const char *, rpc_authflavor_t); const char *, rpc_authflavor_t);
void (*free_client) (struct nfs_client *); void (*free_client) (struct nfs_client *);
struct nfs_server *(*create_server)(struct nfs_mount_info *, struct nfs_subversion *);
struct nfs_server *(*clone_server)(struct nfs_server *, struct nfs_fh *,
struct nfs_fattr *, rpc_authflavor_t);
}; };
/* /*