NFS: Introduce nlm client setup function
Subsystems (2)
PATCH 1/4 NFS: Introduce nlm client setup function
Add a function that will handle mount-time NLM set up for the NFS client.
Note this patch also prevents NLM activation on a mount point when the server address is an IPv6 address, until such a time that the NLM supports IPv6.
Signed-off-by Chuck Lever <[email protected]>
---
fs/lockd/clntlock.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/lockd/bind.h | 6 ++++++ 2 files changed, 51 insertions(+), 0 deletions(-)
fs/lockd/clntlock.c +45 -0
@@ -41,6 +41,51 @@ struct nlm_wait {static LIST_HEAD (nlm_blocked); +/** +* nlmclnt_init - Set up per-NFS mount point lockd data structures +* @server_address: server's network address +* @server_addrlen: length of server's address +* @server_name: server's hostname +* @nfs_version: NFS protocol version for this mount point +* @protocol: transport protocol lockd should use +* +* Returns pointer to an appropriate nlm_host struct, +* or an error value. +*/ +struct nlm_host *nlmclnt_init (struct sockaddr *server_address, +size_t server_addrlen, +char *server_name,u32 nfs_version, +unsigned short protocol) +{ +struct nlm_host *host; +u32 nlm_version; +int status; + +/* NLM doesn't support non-AF_INET addresses yet. */ +if (server_address->sa_family !=AF_INET ) +return ERR_PTR (-EAFNOSUPPORT ); + +/* Assert client is not trying to use NLM for NFSv4 */ +if (nfs_version >3 ) +return ERR_PTR (-EPROTONOSUPPORT ); + + status =lockd_up (protocol); +if (status <0 ) +return ERR_PTR (status); + + nlm_version = (nfs_version ==3 ) ?4 :1 ; + host =nlmclnt_lookup_host ((struct sockaddr_in *)server_address, + protocol, nlm_version, + server_name,strlen (server_name)); +if (host ==NULL ) { +lockd_down (); +return ERR_PTR (-ENOLCK ); + } + +return host; +} +EXPORT_SYMBOL (nlmclnt_init); +/* * Queue up a lock for blocking so that the GRANTED request can see it */
include/linux/lockd/bind.h +6 -0
@@ -35,6 +35,12 @@ extern struct nlmsvc_binding * nlmsvc_ops;/* * Functions exported by the lockd module */ +extern struct nlm_host *nlmclnt_init (struct sockaddr *server_address, +size_t server_addrlen, +char *server_name, +u32 nfs_version, +unsigned short protocol); +extern int nlmclnt_proc (struct inode *,int ,struct file_lock *);extern int lockd_up (int proto);extern void lockd_down (void );
Quoted 34 lines · Chuck Lever
Add a function that will handle mount-time NLM set up for the NFS client.
Note this patch also prevents NLM activation on a mount point when the server address is an IPv6 address, until such a time that the NLM supports IPv6.
Signed-off-by Chuck Lever <[email protected]>---
fs/lockd/clntlock.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/lockd/bind.h | 6 ++++++ 2 files changed, 51 insertions(+), 0 deletions(-)fs/lockd/clntlock.c +13
-0@@ -41,6 +41,51 @@ struct nlm_wait {static LIST_HEAD (nlm_blocked); +/** +* nlmclnt_init - Set up per-NFS mount point lockd data structures +* @server_address: server's network address +* @server_addrlen: length of server's address +* @server_name: server's hostname +* @nfs_version: NFS protocol version for this mount point +* @protocol: transport protocol lockd should use +* +* Returns pointer to an appropriate nlm_host struct, +* or an error value. +*/ +struct nlm_host *nlmclnt_init(struct sockaddr *server_address, + size_t server_addrlen,
fs/lockd/clntlock.c struct nlm_wait { · line 66
Quoted 10 lines
fs/lockd/clntlock.c +10
-0+ char *server_name, u32 nfs_version, + unsigned short protocol) +{ + struct nlm_host *host; +u32 nlm_version; +int status; + +/* NLM doesn't support non-AF_INET addresses yet. */ +if (server_address->sa_family !=AF_INET ) +return ERR_PTR (-EAFNOSUPPORT );
^^^^^^^^^^^^ Please could you make this a BUG_ON?
The address family needs to be checked in the mount parsing code, and _only_ there.
fs/lockd/clntlock.c struct nlm_wait { · line 70
Quoted 3 lines
fs/lockd/clntlock.c +3
-0+/* Assert client is not trying to use NLM for NFSv4 */ +if (nfs_version >3 ) +return ERR_PTR (-EPROTONOSUPPORT );
^^^^^^^^^^^^ Please could you make this a BUG_ON?
This isn't something that is _ever_ supposed to occur at runtime.
Quoted 38 lines
fs/lockd/clntlock.c +17
-0+ status =lockd_up (protocol); +if (status <0 ) +return ERR_PTR (status); + + nlm_version = (nfs_version ==3 ) ?4 :1 ; + host =nlmclnt_lookup_host ((struct sockaddr_in *)server_address, + protocol, nlm_version, + server_name,strlen (server_name)); +if (host ==NULL ) { +lockd_down (); +return ERR_PTR (-ENOLCK ); + } + +return host; +} +EXPORT_SYMBOL (nlmclnt_init); +/* * Queue up a lock for blocking so that the GRANTED request can see it */ include/linux/lockd/bind.h +6
-0@@ -35,6 +35,12 @@ extern struct nlmsvc_binding * nlmsvc_ops;/* * Functions exported by the lockd module */ +extern struct nlm_host *nlmclnt_init (struct sockaddr *server_address, +size_t server_addrlen, +char *server_name, +u32 nfs_version, +unsigned short protocol); +extern int nlmclnt_proc (struct inode *,int ,struct file_lock *);extern int lockd_up (int proto);extern void lockd_down (void );