* [PATCH 01/13] lockd: Enable NLM use of AF_INET6
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
@ 2008-11-05 17:28 ` Chuck Lever
2008-11-05 17:28 ` [PATCH 02/13] NFSD: Add documenting comments for nfsctl interface Chuck Lever
` (12 subsequent siblings)
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:28 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
If the kernel is configured to support IPv6 and the RPC server can register
services via rpcbindv4, we are all set to enable IPv6 support for lockd.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Cc: Aime Le Rouzic <aime.le-rouzic@bull.net>
---
fs/lockd/svc.c | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
index 50de426..582372d 100644
--- a/fs/lockd/svc.c
+++ b/fs/lockd/svc.c
@@ -53,6 +53,17 @@ static struct svc_rqst *nlmsvc_rqst;
unsigned long nlmsvc_timeout;
/*
+ * If the kernel has IPv6 support available, always listen for
+ * both AF_INET and AF_INET6 requests.
+ */
+#if (defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)) && \
+ defined(CONFIG_SUNRPC_REGISTER_V4)
+static const sa_family_t nlmsvc_family = AF_INET6;
+#else /* (CONFIG_IPV6 || CONFIG_IPV6_MODULE) && CONFIG_SUNRPC_REGISTER_V4 */
+static const sa_family_t nlmsvc_family = AF_INET;
+#endif /* (CONFIG_IPV6 || CONFIG_IPV6_MODULE) && CONFIG_SUNRPC_REGISTER_V4 */
+
+/*
* These can be set at insmod time (useful for NFS as root filesystem),
* and also changed through the sysctl interface. -- Jamie Lokier, Aug 2003
*/
@@ -250,7 +261,7 @@ int lockd_up(void)
"lockd_up: no pid, %d users??\n", nlmsvc_users);
error = -ENOMEM;
- serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, AF_INET, NULL);
+ serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, nlmsvc_family, NULL);
if (!serv) {
printk(KERN_WARNING "lockd_up: create service failed\n");
goto out;
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 02/13] NFSD: Add documenting comments for nfsctl interface
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-11-05 17:28 ` [PATCH 01/13] lockd: Enable NLM use of AF_INET6 Chuck Lever
@ 2008-11-05 17:28 ` Chuck Lever
2008-11-05 17:28 ` [PATCH 03/13] NFSD: Add helper functions for __write_ports() Chuck Lever
` (11 subsequent siblings)
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:28 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
Document the NFSD interface between user space and the kernel laid out in
fs/nfsd/nfsctl.c.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/nfsctl.c | 479 +++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 451 insertions(+), 28 deletions(-)
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index e3f9783..5c75f8a 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -84,6 +84,8 @@ static ssize_t write_unexport(struct file *file, char *buf, size_t size);
static ssize_t write_getfd(struct file *file, char *buf, size_t size);
static ssize_t write_getfs(struct file *file, char *buf, size_t size);
static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
+static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
+static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
static ssize_t write_threads(struct file *file, char *buf, size_t size);
static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
static ssize_t write_versions(struct file *file, char *buf, size_t size);
@@ -94,9 +96,6 @@ static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
#endif
-static ssize_t failover_unlock_ip(struct file *file, char *buf, size_t size);
-static ssize_t failover_unlock_fs(struct file *file, char *buf, size_t size);
-
static ssize_t (*write_op[])(struct file *, char *, size_t) = {
[NFSD_Svc] = write_svc,
[NFSD_Add] = write_add,
@@ -106,8 +105,8 @@ static ssize_t (*write_op[])(struct file *, char *, size_t) = {
[NFSD_Getfd] = write_getfd,
[NFSD_Getfs] = write_getfs,
[NFSD_Fh] = write_filehandle,
- [NFSD_FO_UnlockIP] = failover_unlock_ip,
- [NFSD_FO_UnlockFS] = failover_unlock_fs,
+ [NFSD_FO_UnlockIP] = write_unlock_ip,
+ [NFSD_FO_UnlockFS] = write_unlock_fs,
[NFSD_Threads] = write_threads,
[NFSD_Pool_Threads] = write_pool_threads,
[NFSD_Versions] = write_versions,
@@ -176,10 +175,24 @@ static const struct file_operations exports_operations = {
/*----------------------------------------------------------------------------*/
/*
* payload - write methods
- * If the method has a response, the response should be put in buf,
- * and the length returned. Otherwise return 0 or and -error.
*/
+/**
+ * write_svc - Start kernel's NFSD server
+ *
+ * Deprecated. /proc/fs/nfsd/threads is preferred.
+ * Function remains to support old versions of nfs-utils.
+ *
+ * Input:
+ * buf: struct nfsctl_svc
+ * svc_port: port number of this
+ * server's listener
+ * svc_nthreads: number of threads to start
+ * size: size in bytes of passed in nfsctl_svc
+ * Output:
+ * On success: returns zero
+ * On error: return code is negative errno value
+ */
static ssize_t write_svc(struct file *file, char *buf, size_t size)
{
struct nfsctl_svc *data;
@@ -189,6 +202,30 @@ static ssize_t write_svc(struct file *file, char *buf, size_t size)
return nfsd_svc(data->svc_port, data->svc_nthreads);
}
+/**
+ * write_add - Add or modify client entry in auth unix cache
+ *
+ * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
+ * Function remains to support old versions of nfs-utils.
+ *
+ * Input:
+ * buf: struct nfsctl_client
+ * cl_ident: '\0'-terminated C string
+ * containing domain name
+ * of client
+ * cl_naddr: no. of items in cl_addrlist
+ * cl_addrlist: array of client addresses
+ * cl_fhkeytype: ignored
+ * cl_fhkeylen: ignored
+ * cl_fhkey: ignored
+ * size: size in bytes of passed in nfsctl_client
+ * Output:
+ * On success: returns zero
+ * On error: return code is negative errno value
+ *
+ * Note: Only AF_INET client addresses are passed in, since
+ * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
+ */
static ssize_t write_add(struct file *file, char *buf, size_t size)
{
struct nfsctl_client *data;
@@ -198,6 +235,30 @@ static ssize_t write_add(struct file *file, char *buf, size_t size)
return exp_addclient(data);
}
+/**
+ * write_del - Remove client from auth unix cache
+ *
+ * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
+ * Function remains to support old versions of nfs-utils.
+ *
+ * Input:
+ * buf: struct nfsctl_client
+ * cl_ident: '\0'-terminated C string
+ * containing domain name
+ * of client
+ * cl_naddr: ignored
+ * cl_addrlist: ignored
+ * cl_fhkeytype: ignored
+ * cl_fhkeylen: ignored
+ * cl_fhkey: ignored
+ * size: size in bytes of passed in nfsctl_client
+ * Output:
+ * On success: returns zero
+ * On error: return code is negative errno value
+ *
+ * Note: Only AF_INET client addresses are passed in, since
+ * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
+ */
static ssize_t write_del(struct file *file, char *buf, size_t size)
{
struct nfsctl_client *data;
@@ -207,6 +268,33 @@ static ssize_t write_del(struct file *file, char *buf, size_t size)
return exp_delclient(data);
}
+/**
+ * write_export - Export part or all of a local file system
+ *
+ * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
+ * Function remains to support old versions of nfs-utils.
+ *
+ * Input:
+ * buf: struct nfsctl_export
+ * ex_client: '\0'-terminated C string
+ * containing domain name
+ * of client allowed to access
+ * this export
+ * ex_path: '\0'-terminated C string
+ * containing pathname of
+ * directory in local file system
+ * ex_dev: fsid to use for this export
+ * ex_ino: ignored
+ * ex_flags: export flags for this export
+ * ex_anon_uid: UID to use for anonymous
+ * requests
+ * ex_anon_gid: GID to use for anonymous
+ * requests
+ * size: size in bytes of passed in nfsctl_export
+ * Output:
+ * On success: returns zero
+ * On error: return code is negative errno value
+ */
static ssize_t write_export(struct file *file, char *buf, size_t size)
{
struct nfsctl_export *data;
@@ -216,6 +304,31 @@ static ssize_t write_export(struct file *file, char *buf, size_t size)
return exp_export(data);
}
+/**
+ * write_unexport - Unexport a previously exported file system
+ *
+ * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
+ * Function remains to support old versions of nfs-utils.
+ *
+ * Input:
+ * buf: struct nfsctl_export
+ * ex_client: '\0'-terminated C string
+ * containing domain name
+ * of client no longer allowed
+ * to access this export
+ * ex_path: '\0'-terminated C string
+ * containing pathname of
+ * directory in local file system
+ * ex_dev: ignored
+ * ex_ino: ignored
+ * ex_flags: ignored
+ * ex_anon_uid: ignored
+ * ex_anon_gid: ignored
+ * size: size in bytes of passed in nfsctl_export
+ * Output:
+ * On success: returns zero
+ * On error: return code is negative errno value
+ */
static ssize_t write_unexport(struct file *file, char *buf, size_t size)
{
struct nfsctl_export *data;
@@ -226,6 +339,30 @@ static ssize_t write_unexport(struct file *file, char *buf, size_t size)
return exp_unexport(data);
}
+/**
+ * write_getfs - Get a variable-length NFS file handle by path
+ *
+ * Deprecated. /proc/fs/nfsd/filehandle is preferred.
+ * Function remains to support old versions of nfs-utils.
+ *
+ * Input:
+ * buf: struct nfsctl_fsparm
+ * gd_addr: socket address of client
+ * gd_path: '\0'-terminated C string
+ * containing pathname of
+ * directory in local file system
+ * gd_maxlen: maximum size of returned file
+ * handle
+ * size: size in bytes of passed in nfsctl_fsparm
+ * Output:
+ * On success: passed-in buffer filled with a knfsd_fh structure
+ * (a variable-length raw NFS file handle);
+ * return code is the size in bytes of the file handle
+ * On error: return code is negative errno value
+ *
+ * Note: Only AF_INET client addresses are passed in, since gd_addr
+ * is the same size as a struct sockaddr_in.
+ */
static ssize_t write_getfs(struct file *file, char *buf, size_t size)
{
struct nfsctl_fsparm *data;
@@ -265,6 +402,29 @@ static ssize_t write_getfs(struct file *file, char *buf, size_t size)
return err;
}
+/**
+ * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
+ *
+ * Deprecated. /proc/fs/nfsd/filehandle is preferred.
+ * Function remains to support old versions of nfs-utils.
+ *
+ * Input:
+ * buf: struct nfsctl_fdparm
+ * gd_addr: socket address of client
+ * gd_path: '\0'-terminated C string
+ * containing pathname of
+ * directory in local file system
+ * gd_version: fdparm structure version
+ * size: size in bytes of passed in nfsctl_fdparm
+ * Output:
+ * On success: passed-in buffer filled with nfsctl_res
+ * (a fixed-length raw NFS file handle);
+ * return code is the size in bytes of the file handle
+ * On error: return code is negative errno value
+ *
+ * Note: Only AF_INET client addresses are passed in, since gd_addr
+ * is the same size as a struct sockaddr_in.
+ */
static ssize_t write_getfd(struct file *file, char *buf, size_t size)
{
struct nfsctl_fdparm *data;
@@ -309,7 +469,23 @@ static ssize_t write_getfd(struct file *file, char *buf, size_t size)
return err;
}
-static ssize_t failover_unlock_ip(struct file *file, char *buf, size_t size)
+/**
+ * write_unlock_ip - Release all locks used by a client
+ *
+ * Experimental.
+ *
+ * Input:
+ * buf: '\n'-terminated C string containing a
+ * presentation format IPv4 address
+ * size: length of C string in @buf
+ * Output:
+ * On success: returns zero if all specified locks were released;
+ * returns one if one or more locks were not released
+ * On error: return code is negative errno value
+ *
+ * Note: Only AF_INET client addresses are passed in
+ */
+static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
{
struct sockaddr_in sin = {
.sin_family = AF_INET,
@@ -339,7 +515,21 @@ static ssize_t failover_unlock_ip(struct file *file, char *buf, size_t size)
return nlmsvc_unlock_all_by_ip((struct sockaddr *)&sin);
}
-static ssize_t failover_unlock_fs(struct file *file, char *buf, size_t size)
+/**
+ * write_unlock_fs - Release all locks on a local file system
+ *
+ * Experimental.
+ *
+ * Input:
+ * buf: '\n'-terminated C string containing the
+ * absolute pathname of a local file system
+ * size: length of C string in @buf
+ * Output:
+ * On success: returns zero if all specified locks were released;
+ * returns one if one or more locks were not released
+ * On error: return code is negative errno value
+ */
+static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
{
struct path path;
char *fo_path;
@@ -360,21 +550,44 @@ static ssize_t failover_unlock_fs(struct file *file, char *buf, size_t size)
if (error)
return error;
+ /*
+ * XXX: Needs better sanity checking. Otherwise we could end up
+ * releasing locks on the wrong file system.
+ *
+ * For example:
+ * 1. Does the path refer to a directory?
+ * 2. Is that directory a mount point, or
+ * 3. Is that directory the root of an exported file system?
+ */
error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
path_put(&path);
return error;
}
+/**
+ * write_filehandle - Get a variable-length NFS file handle by path
+ *
+ * On input, the buffer contains a '\n'-terminated C string comprised of
+ * three alphanumeric words separated by whitespace. The string may
+ * contain escape sequences.
+ *
+ * Input:
+ * buf:
+ * domain: client domain name
+ * path: export pathname
+ * maxsize: numeric maximum size of
+ * @buf
+ * size: length of C string in @buf
+ * Output:
+ * On success: passed-in buffer filled with '\n'-terminated C
+ * string containing a ASCII hex text version
+ * of the NFS file handle;
+ * return code is the size in bytes of the string
+ * On error: return code is negative errno value
+ */
static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
{
- /* request is:
- * domain path maxsize
- * response is
- * filehandle
- *
- * qword quoting is used, so filehandle will be \x....
- */
char *dname, *path;
int uninitialized_var(maxsize);
char *mesg = buf;
@@ -391,11 +604,13 @@ static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
dname = mesg;
len = qword_get(&mesg, dname, size);
- if (len <= 0) return -EINVAL;
+ if (len <= 0)
+ return -EINVAL;
path = dname+len+1;
len = qword_get(&mesg, path, size);
- if (len <= 0) return -EINVAL;
+ if (len <= 0)
+ return -EINVAL;
len = get_int(&mesg, &maxsize);
if (len)
@@ -419,17 +634,43 @@ static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
if (len)
return len;
- mesg = buf; len = SIMPLE_TRANSACTION_LIMIT;
+ mesg = buf;
+ len = SIMPLE_TRANSACTION_LIMIT;
qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
mesg[-1] = '\n';
return mesg - buf;
}
+/**
+ * write_threads - Start NFSD, or report the current number of running threads
+ *
+ * Input:
+ * buf: ignored
+ * size: zero
+ * Output:
+ * On success: passed-in buffer filled with '\n'-terminated C
+ * string numeric value representing the number of
+ * running NFSD threads;
+ * return code is the size in bytes of the string
+ * On error: return code is zero
+ *
+ * OR
+ *
+ * Input:
+ * buf: C string containing an unsigned
+ * integer value representing the
+ * number of NFSD threads to start
+ * size: non-zero length of C string in @buf
+ * Output:
+ * On success: NFS service is started;
+ * passed-in buffer filled with '\n'-terminated C
+ * string numeric value representing the number of
+ * running NFSD threads;
+ * return code is the size in bytes of the string
+ * On error: return code is zero or a negative errno value
+ */
static ssize_t write_threads(struct file *file, char *buf, size_t size)
{
- /* if size > 0, look for a number of threads and call nfsd_svc
- * then write out number of threads as reply
- */
char *mesg = buf;
int rv;
if (size > 0) {
@@ -437,9 +678,9 @@ static ssize_t write_threads(struct file *file, char *buf, size_t size)
rv = get_int(&mesg, &newthreads);
if (rv)
return rv;
- if (newthreads <0)
+ if (newthreads < 0)
return -EINVAL;
- rv = nfsd_svc(2049, newthreads);
+ rv = nfsd_svc(NFS_PORT, newthreads);
if (rv)
return rv;
}
@@ -447,6 +688,28 @@ static ssize_t write_threads(struct file *file, char *buf, size_t size)
return strlen(buf);
}
+/**
+ * write_pool_threads - Set or report the current number of threads per pool
+ *
+ * Input:
+ * buf: ignored
+ * size: zero
+ *
+ * OR
+ *
+ * Input:
+ * buf: C string containing whitespace-
+ * separated unsigned integer values
+ * representing the number of NFSD
+ * threads to start in each pool
+ * size: non-zero length of C string in @buf
+ * Output:
+ * On success: passed-in buffer filled with '\n'-terminated C
+ * string containing integer values representing the
+ * number of NFSD threads in each pool;
+ * return code is the size in bytes of the string
+ * On error: return code is zero or a negative errno value
+ */
static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
{
/* if size > 0, look for an array of number of threads per node
@@ -517,10 +780,6 @@ out_free:
static ssize_t __write_versions(struct file *file, char *buf, size_t size)
{
- /*
- * Format:
- * [-/+]vers [-/+]vers ...
- */
char *mesg = buf;
char *vers, sign;
int len, num;
@@ -578,6 +837,38 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size)
return len;
}
+/**
+ * write_versions - Set or report the available NFS protocol versions
+ *
+ * Input:
+ * buf: ignored
+ * size: zero
+ * Output:
+ * On success: passed-in buffer filled with '\n'-terminated C
+ * string containing positive or negative integer
+ * values representing the current status of each
+ * protocol version;
+ * return code is the size in bytes of the string
+ * On error: return code is zero or a negative errno value
+ *
+ * OR
+ *
+ * Input:
+ * buf: C string containing whitespace-
+ * separated positive or negative
+ * integer values representing NFS
+ * protocol versions to enable ("+n")
+ * or disable ("-n")
+ * size: non-zero length of C string in @buf
+ * Output:
+ * On success: status of zero or more protocol versions has
+ * been updated; passed-in buffer filled with
+ * '\n'-terminated C string containing positive
+ * or negative integer values representing the
+ * current status of each protocol version;
+ * return code is the size in bytes of the string
+ * On error: return code is zero or a negative errno value
+ */
static ssize_t write_versions(struct file *file, char *buf, size_t size)
{
ssize_t rv;
@@ -687,6 +978,75 @@ static ssize_t __write_ports(struct file *file, char *buf, size_t size)
return -EINVAL;
}
+/**
+ * write_ports - Pass a socket file descriptor or transport name to listen on
+ *
+ * Input:
+ * buf: ignored
+ * size: zero
+ * Output:
+ * On success: passed-in buffer filled with a '\n'-terminated C
+ * string containing a whitespace-separated list of
+ * named NFSD listeners;
+ * return code is the size in bytes of the string
+ * On error: return code is zero or a negative errno value
+ *
+ * OR
+ *
+ * Input:
+ * buf: C string containing an unsigned
+ * integer value representing a bound
+ * but unconnected socket that is to be
+ * used as an NFSD listener
+ * size: non-zero length of C string in @buf
+ * Output:
+ * On success: NFS service is started;
+ * passed-in buffer filled with a '\n'-terminated C
+ * string containing a unique alphanumeric name of
+ * the listener;
+ * return code is the size in bytes of the string
+ * On error: return code is a negative errno value
+ *
+ * OR
+ *
+ * Input:
+ * buf: C string containing a "-" followed
+ * by an integer value representing a
+ * previously passed in socket file
+ * descriptor
+ * size: non-zero length of C string in @buf
+ * Output:
+ * On success: NFS service no longer listens on that socket;
+ * passed-in buffer filled with a '\n'-terminated C
+ * string containing a unique name of the listener;
+ * return code is the size in bytes of the string
+ * On error: return code is a negative errno value
+ *
+ * OR
+ *
+ * Input:
+ * buf: C string containing a transport
+ * name and an unsigned integer value
+ * representing the port to listen on,
+ * separated by whitespace
+ * size: non-zero length of C string in @buf
+ * Output:
+ * On success: returns zero; NFS service is started
+ * On error: return code is a negative errno value
+ *
+ * OR
+ *
+ * Input:
+ * buf: C string containing a "-" followed
+ * by a transport name and an unsigned
+ * integer value representing the port
+ * to listen on, separated by whitespace
+ * size: non-zero length of C string in @buf
+ * Output:
+ * On success: returns zero; NFS service no longer listens
+ * on that transport
+ * On error: return code is a negative errno value
+ */
static ssize_t write_ports(struct file *file, char *buf, size_t size)
{
ssize_t rv;
@@ -700,6 +1060,27 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size)
int nfsd_max_blksize;
+/**
+ * write_maxblksize - Set or report the current NFS blksize
+ *
+ * Input:
+ * buf: ignored
+ * size: zero
+ *
+ * OR
+ *
+ * Input:
+ * buf: C string containing an unsigned
+ * integer value representing the new
+ * NFS blksize
+ * size: non-zero length of C string in @buf
+ * Output:
+ * On success: passed-in buffer filled with '\n'-terminated C string
+ * containing numeric value of the current NFS blksize
+ * setting;
+ * return code is the size in bytes of the string
+ * On error: return code is zero or a negative errno value
+ */
static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
{
char *mesg = buf;
@@ -752,6 +1133,27 @@ static ssize_t __write_leasetime(struct file *file, char *buf, size_t size)
return strlen(buf);
}
+/**
+ * write_leasetime - Set or report the current NFSv4 lease time
+ *
+ * Input:
+ * buf: ignored
+ * size: zero
+ *
+ * OR
+ *
+ * Input:
+ * buf: C string containing an unsigned
+ * integer value representing the new
+ * NFSv4 lease expiry time
+ * size: non-zero length of C string in @buf
+ * Output:
+ * On success: passed-in buffer filled with '\n'-terminated C
+ * string containing unsigned integer value of the
+ * current lease expiry time;
+ * return code is the size in bytes of the string
+ * On error: return code is zero or a negative errno value
+ */
static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
{
ssize_t rv;
@@ -788,6 +1190,27 @@ static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
return strlen(buf);
}
+/**
+ * write_recoverydir - Set or report the pathname of the recovery directory
+ *
+ * Input:
+ * buf: ignored
+ * size: zero
+ *
+ * OR
+ *
+ * Input:
+ * buf: C string containing the pathname
+ * of the directory on a local file
+ * system containing permanent NFSv4
+ * recovery data
+ * size: non-zero length of C string in @buf
+ * Output:
+ * On success: passed-in buffer filled with '\n'-terminated C string
+ * containing the current recovery pathname setting;
+ * return code is the size in bytes of the string
+ * On error: return code is zero or a negative errno value
+ */
static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
{
ssize_t rv;
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 03/13] NFSD: Add helper functions for __write_ports()
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-11-05 17:28 ` [PATCH 01/13] lockd: Enable NLM use of AF_INET6 Chuck Lever
2008-11-05 17:28 ` [PATCH 02/13] NFSD: Add documenting comments for nfsctl interface Chuck Lever
@ 2008-11-05 17:28 ` Chuck Lever
2008-11-05 17:28 ` [PATCH 04/13] NFSD: Refactor __write_ports() Chuck Lever
` (10 subsequent siblings)
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:28 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
Clean up: I'd like to refactor __write_ports() to make it easier to
understand and maintain. Introduce a set of helper functions to
handle the details of the __write_ports() function.
New helpers are not used yet.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/nfsctl.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 110 insertions(+), 0 deletions(-)
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 5c75f8a..0e64d92 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -879,6 +879,116 @@ static ssize_t write_versions(struct file *file, char *buf, size_t size)
return rv;
}
+/*
+ * Zero-length write. Return a list of NFSD's current listener
+ * transports.
+ */
+static ssize_t __write_ports_names(char *buf, size_t size)
+{
+ if (!nfsd_serv)
+ return 0;
+ return svc_xprt_names(nfsd_serv, buf, 0);
+}
+
+/*
+ * A single 'fd' number was written, in which case it must be for
+ * a socket of a supported family/protocol, and we use it as an
+ * nfsd listener.
+ */
+static ssize_t __write_ports_addfd(char *buf, size_t size)
+{
+ char *mesg = buf;
+ int fd, err;
+
+ err = get_int(&mesg, &fd);
+ if (err || fd < 0)
+ return -EINVAL;
+
+ err = nfsd_create_serv();
+ if (err)
+ return err;
+
+ err = svc_addsock(nfsd_serv, fd, buf);
+ if (err < 0)
+ return err;
+
+ err = lockd_up();
+ if (err < 0)
+ svc_sock_names(buf + strlen(buf) + 1, nfsd_serv, buf);
+
+ /* Decrease the count, but don't shut down the the service */
+ nfsd_serv->sv_nrthreads--;
+
+ return err < 0 ? err : 0;
+}
+
+/*
+ * A '-' followed by the 'name' of a socket means we close the socket.
+ */
+static ssize_t __write_ports_delfd(char *buf, size_t size)
+{
+ char *toclose;
+ int len = 0;
+
+ toclose = kstrdup(buf + 1, GFP_KERNEL);
+ if (!toclose)
+ return -ENOMEM;
+
+ if (nfsd_serv)
+ len = svc_sock_names(buf, nfsd_serv, toclose);
+ if (len >= 0)
+ lockd_down();
+
+ kfree(toclose);
+ return len;
+}
+
+/*
+ * A transport listener is added by writing it's transport name and
+ * a port number
+ */
+static ssize_t __write_ports_addxprt(char *buf, size_t size,
+ char *transport, unsigned short port)
+{
+ int err;
+
+ err = nfsd_create_serv();
+ if (err)
+ return err;
+
+ err = svc_create_xprt(nfsd_serv, transport, port, SVC_SOCK_ANONYMOUS);
+ if (err == -ENOENT)
+ /* Give a reasonable perror msg for
+ * bad transport string */
+ err = -EPROTONOSUPPORT;
+
+ return err < 0 ? err : 0;
+}
+
+/*
+ * A transport listener is removed by writing a "-", it's transport
+ * name, and it's port number
+ */
+static ssize_t __write_ports_delxprt(char *buf, size_t size,
+ char *transport, int port)
+{
+ struct svc_xprt *xprt;
+ int err = -EINVAL;
+
+ if (port == 0 || nfsd_serv == NULL)
+ return err;
+
+ xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port);
+ if (xprt) {
+ svc_close_xprt(xprt);
+ svc_xprt_put(xprt);
+ err = 0;
+ } else
+ err = -ENOTCONN;
+
+ return err < 0 ? err : 0;
+}
+
static ssize_t __write_ports(struct file *file, char *buf, size_t size)
{
if (size == 0) {
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 04/13] NFSD: Refactor __write_ports()
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
` (2 preceding siblings ...)
2008-11-05 17:28 ` [PATCH 03/13] NFSD: Add helper functions for __write_ports() Chuck Lever
@ 2008-11-05 17:28 ` Chuck Lever
2008-11-05 17:28 ` [PATCH 05/13] NFSD: Prevent a buffer overflow in svc_xprt_names() Chuck Lever
` (9 subsequent siblings)
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:28 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
Clean up: The __write_ports() function is a twisty little maze of
"if" statements, all alike.
The /proc/fs/nfsd/portlist file interface has grown in complexity
since it was first introduced. Use recently introduced helpers to
refactor the portlist file's parser function into something easier to
read and expand.
I don't intend to expand it, but in subsequent patches I will fix a
few bugs, and introduce IPv6 support.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/nfsctl.c | 114 ++++++++++--------------------------------------------
1 files changed, 21 insertions(+), 93 deletions(-)
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 0e64d92..fa6441b 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -991,100 +991,28 @@ static ssize_t __write_ports_delxprt(char *buf, size_t size,
static ssize_t __write_ports(struct file *file, char *buf, size_t size)
{
- if (size == 0) {
- int len = 0;
+ char transport[16];
+ int port;
+
+ if (size == 0)
+ return __write_ports_names(buf, size);
+
+ if (isdigit(buf[0]))
+ return __write_ports_addfd(buf, size);
+
+ if (buf[0] == '-' && isdigit(buf[1]))
+ return __write_ports_delfd(buf, size);
+
+ if (isalpha(buf[0]))
+ if (sscanf(buf, "%15s %4u", transport, &port) == 2)
+ return __write_ports_addxprt(buf, size,
+ transport, port);
+
+ if (buf[0] == '-' && isalpha(buf[1]))
+ if (sscanf(&buf[1], "%15s %4u", transport, &port) == 2)
+ return __write_ports_delxprt(buf, size,
+ transport, port);
- if (nfsd_serv)
- len = svc_xprt_names(nfsd_serv, buf, 0);
- return len;
- }
- /* Either a single 'fd' number is written, in which
- * case it must be for a socket of a supported family/protocol,
- * and we use it as an nfsd socket, or
- * A '-' followed by the 'name' of a socket in which case
- * we close the socket.
- */
- if (isdigit(buf[0])) {
- char *mesg = buf;
- int fd;
- int err;
- err = get_int(&mesg, &fd);
- if (err)
- return -EINVAL;
- if (fd < 0)
- return -EINVAL;
- err = nfsd_create_serv();
- if (!err) {
- err = svc_addsock(nfsd_serv, fd, buf);
- if (err >= 0) {
- err = lockd_up();
- if (err < 0)
- svc_sock_names(buf+strlen(buf)+1, nfsd_serv, buf);
- }
- /* Decrease the count, but don't shutdown the
- * the service
- */
- nfsd_serv->sv_nrthreads--;
- }
- return err < 0 ? err : 0;
- }
- if (buf[0] == '-' && isdigit(buf[1])) {
- char *toclose = kstrdup(buf+1, GFP_KERNEL);
- int len = 0;
- if (!toclose)
- return -ENOMEM;
- if (nfsd_serv)
- len = svc_sock_names(buf, nfsd_serv, toclose);
- if (len >= 0)
- lockd_down();
- kfree(toclose);
- return len;
- }
- /*
- * Add a transport listener by writing it's transport name
- */
- if (isalpha(buf[0])) {
- int err;
- char transport[16];
- int port;
- if (sscanf(buf, "%15s %4d", transport, &port) == 2) {
- err = nfsd_create_serv();
- if (!err) {
- err = svc_create_xprt(nfsd_serv,
- transport, port,
- SVC_SOCK_ANONYMOUS);
- if (err == -ENOENT)
- /* Give a reasonable perror msg for
- * bad transport string */
- err = -EPROTONOSUPPORT;
- }
- return err < 0 ? err : 0;
- }
- }
- /*
- * Remove a transport by writing it's transport name and port number
- */
- if (buf[0] == '-' && isalpha(buf[1])) {
- struct svc_xprt *xprt;
- int err = -EINVAL;
- char transport[16];
- int port;
- if (sscanf(&buf[1], "%15s %4d", transport, &port) == 2) {
- if (port == 0)
- return -EINVAL;
- if (nfsd_serv) {
- xprt = svc_find_xprt(nfsd_serv, transport,
- AF_UNSPEC, port);
- if (xprt) {
- svc_close_xprt(xprt);
- svc_xprt_put(xprt);
- err = 0;
- } else
- err = -ENOTCONN;
- }
- return err < 0 ? err : 0;
- }
- }
return -EINVAL;
}
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 05/13] NFSD: Prevent a buffer overflow in svc_xprt_names()
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
` (3 preceding siblings ...)
2008-11-05 17:28 ` [PATCH 04/13] NFSD: Refactor __write_ports() Chuck Lever
@ 2008-11-05 17:28 ` Chuck Lever
2008-11-05 17:29 ` [PATCH 06/13] SUNRPC: pass buffer size to svc_addsock() and svc_sock_names() Chuck Lever
` (8 subsequent siblings)
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:28 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
The svc_xprt_names() function can overflow its buffer if it's so near
the end of the passed in buffer that the "name too long" string still
doesn't fit. Of course, it could never tell if it was near the end
of the passed in buffer, since its only caller passes in zero as the
buffer length.
Let's make this API a little safer.
Change svc_xprt_names() so it *always* checks for a buffer overflow,
and change its only caller to pass in the correct buffer length.
If svc_xprt_names() does overflow its buffer, just fail with a
reasonable errno code, instead of trying to write a message at the end
of the buffer. I don't like this much, but I can't figure out a safe
way to return some of the names, *and* an indication that the buffer
was not long enough.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/nfsctl.c | 2 +-
net/sunrpc/svc_xprt.c | 53 ++++++++++++++++++++++++++++++++++---------------
2 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index fa6441b..22fc8e5 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -887,7 +887,7 @@ static ssize_t __write_ports_names(char *buf, size_t size)
{
if (!nfsd_serv)
return 0;
- return svc_xprt_names(nfsd_serv, buf, 0);
+ return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
}
/*
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index bf5b5cd..eb546ce 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -1045,36 +1045,57 @@ struct svc_xprt *svc_find_xprt(struct svc_serv *serv, char *xcl_name,
}
EXPORT_SYMBOL_GPL(svc_find_xprt);
-/*
- * Format a buffer with a list of the active transports. A zero for
- * the buflen parameter disables target buffer overflow checking.
+static int svc_one_xprt_name(struct svc_xprt *xprt, char *pos, int remaining)
+{
+ int len;
+
+ len = snprintf(pos, remaining, "%s %u\n",
+ xprt->xpt_class->xcl_name,
+ svc_xprt_local_port(xprt));
+ if (len >= remaining)
+ return -ENAMETOOLONG;
+ return len;
+}
+
+/**
+ * svc_xprt_names - format a buffer with a list of transport names
+ * @serv: pointer to an RPC service
+ * @buf: pointer to a buffer to be filled in
+ * @buflen: length of buffer to be filled in
+ *
+ * Fills in @buf with a string containing a list of transport names,
+ * each name terminated with '\n'.
+ *
+ * Returns positive length of the filled-in string on success; otherwise
+ * a negative errno value is returned if an error occurs.
*/
int svc_xprt_names(struct svc_serv *serv, char *buf, int buflen)
{
struct svc_xprt *xprt;
- char xprt_str[64];
- int totlen = 0;
- int len;
+ int len, totlen;
+ char *pos;
/* Sanity check args */
if (!serv)
return 0;
spin_lock_bh(&serv->sv_lock);
+
+ pos = buf;
+ totlen = 0;
list_for_each_entry(xprt, &serv->sv_permsocks, xpt_list) {
- len = snprintf(xprt_str, sizeof(xprt_str),
- "%s %d\n", xprt->xpt_class->xcl_name,
- svc_xprt_local_port(xprt));
- /* If the string was truncated, replace with error string */
- if (len >= sizeof(xprt_str))
- strcpy(xprt_str, "name-too-long\n");
- /* Don't overflow buffer */
- len = strlen(xprt_str);
- if (buflen && (len + totlen >= buflen))
+ len = svc_one_xprt_name(xprt, pos, buflen - totlen);
+ if (len < 0) {
+ *buf = '\0';
+ totlen = len;
+ }
+ if (len <= 0)
break;
- strcpy(buf+totlen, xprt_str);
+
+ pos += len;
totlen += len;
}
+
spin_unlock_bh(&serv->sv_lock);
return totlen;
}
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 06/13] SUNRPC: pass buffer size to svc_addsock() and svc_sock_names()
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
` (4 preceding siblings ...)
2008-11-05 17:28 ` [PATCH 05/13] NFSD: Prevent a buffer overflow in svc_xprt_names() Chuck Lever
@ 2008-11-05 17:29 ` Chuck Lever
2008-11-05 17:29 ` [PATCH 07/13] SUNRPC: Switch one_sock_name() to use snprintf() Chuck Lever
` (7 subsequent siblings)
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:29 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
Pass the size of the output buffer to the RPC functions that construct
the list of socket names in that buffer. Add documenting comments to
these functions.
This is a cosmetic change for now. A subsequent patch will make sure
the buffer length is passed to one_sock_name(), where the length will
actually be useful.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/nfsctl.c | 12 ++++++++----
include/linux/sunrpc/svcsock.h | 6 ++++--
net/sunrpc/svcsock.c | 34 +++++++++++++++++++++++++++++-----
3 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 22fc8e5..19db9f4 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -898,7 +898,7 @@ static ssize_t __write_ports_names(char *buf, size_t size)
static ssize_t __write_ports_addfd(char *buf, size_t size)
{
char *mesg = buf;
- int fd, err;
+ int fd, err, len;
err = get_int(&mesg, &fd);
if (err || fd < 0)
@@ -908,13 +908,16 @@ static ssize_t __write_ports_addfd(char *buf, size_t size)
if (err)
return err;
- err = svc_addsock(nfsd_serv, fd, buf);
+ len = SIMPLE_TRANSACTION_LIMIT;
+ err = svc_addsock(nfsd_serv, fd, buf, len);
if (err < 0)
return err;
+ len -= err;
err = lockd_up();
if (err < 0)
- svc_sock_names(buf + strlen(buf) + 1, nfsd_serv, buf);
+ svc_sock_names(nfsd_serv, buf + strlen(buf) + 1,
+ len - strlen(buf) - 1, buf);
/* Decrease the count, but don't shut down the the service */
nfsd_serv->sv_nrthreads--;
@@ -935,7 +938,8 @@ static ssize_t __write_ports_delfd(char *buf, size_t size)
return -ENOMEM;
if (nfsd_serv)
- len = svc_sock_names(buf, nfsd_serv, toclose);
+ len = svc_sock_names(nfsd_serv, buf,
+ SIMPLE_TRANSACTION_LIMIT, toclose);
if (len >= 0)
lockd_down();
diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h
index 483e103..f57ce85 100644
--- a/include/linux/sunrpc/svcsock.h
+++ b/include/linux/sunrpc/svcsock.h
@@ -38,8 +38,10 @@ int svc_recv(struct svc_rqst *, long);
int svc_send(struct svc_rqst *);
void svc_drop(struct svc_rqst *);
void svc_sock_update_bufs(struct svc_serv *serv);
-int svc_sock_names(char *buf, struct svc_serv *serv, char *toclose);
-int svc_addsock(struct svc_serv *serv, int fd, char *name_return);
+int svc_sock_names(struct svc_serv *serv, char *buf, size_t buflen,
+ char *toclose);
+int svc_addsock(struct svc_serv *serv, int fd, char *name_return,
+ size_t len);
void svc_init_xprt_sock(void);
void svc_cleanup_xprt_sock(void);
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 95293f5..ee42edd 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -263,8 +263,23 @@ static int one_sock_name(char *buf, struct svc_sock *svsk)
return len;
}
-int
-svc_sock_names(char *buf, struct svc_serv *serv, char *toclose)
+/**
+ * svc_sock_names - construct a list of listener names in a string
+ * @serv: pointer to RPC service
+ * @buf: pointer to a buffer to fill in with socket names
+ * @buflen: size of the buffer to be filled
+ * @toclose: pointer to '\0'-terminated C string containing the name
+ * of a listener to be closed
+ *
+ * Fills in @buf with a '\n'-separated list of names of listener
+ * sockets. If @toclose is not NULL, the socket named by @toclose
+ * is closed, and is not included in the output list.
+ *
+ * Returns positive length of the socket name string, or a negative
+ * errno value on error.
+ */
+int svc_sock_names(struct svc_serv *serv, char *buf, size_t buflen,
+ char *toclose)
{
struct svc_sock *svsk, *closesk = NULL;
int len = 0;
@@ -1165,9 +1180,18 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
return svsk;
}
-int svc_addsock(struct svc_serv *serv,
- int fd,
- char *name_return)
+/**
+ * svc_addsock - add a listener socket to an RPC service
+ * @serv: pointer to RPC service to which to add a new listener
+ * @fd: file descriptor of the new listener
+ * @name_return: pointer to buffer to pass back name of listener
+ * @len: size of the buffer
+ *
+ * Fills in socket name and returns positive length of name if successful.
+ * Name is terminated with '\n'. On error, returns a negative errno
+ * value.
+ */
+int svc_addsock(struct svc_serv *serv, int fd, char *name_return, size_t len)
{
int err = 0;
struct socket *so = sockfd_lookup(fd, &err);
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 07/13] SUNRPC: Switch one_sock_name() to use snprintf()
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
` (5 preceding siblings ...)
2008-11-05 17:29 ` [PATCH 06/13] SUNRPC: pass buffer size to svc_addsock() and svc_sock_names() Chuck Lever
@ 2008-11-05 17:29 ` Chuck Lever
2008-11-05 17:29 ` [PATCH 08/13] SUNRPC: Support AF_INET6 in one_sock_name() Chuck Lever
` (6 subsequent siblings)
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:29 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
Use snprintf() in one_sock_name() to help prevent buffer overflows.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
net/sunrpc/svcsock.c | 23 +++++++++++++++++------
1 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index ee42edd..db5eb7d 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -244,22 +244,27 @@ out:
/*
* Report socket names for nfsdfs
*/
-static int one_sock_name(char *buf, struct svc_sock *svsk)
+static int svc_one_sock_name(struct svc_sock *svsk, char *buf, int remaining)
{
int len;
switch(svsk->sk_sk->sk_family) {
case AF_INET:
- len = sprintf(buf, "ipv4 %s %u.%u.%u.%u %d\n",
+ len = snprintf(buf, remaining, "ipv4 %s %u.%u.%u.%u %d\n",
svsk->sk_sk->sk_protocol==IPPROTO_UDP?
"udp" : "tcp",
NIPQUAD(inet_sk(svsk->sk_sk)->rcv_saddr),
inet_sk(svsk->sk_sk)->num);
break;
default:
- len = sprintf(buf, "*unknown-%d*\n",
+ len = snprintf(buf, remaining, "*unknown-%d*\n",
svsk->sk_sk->sk_family);
}
+
+ if (len >= remaining) {
+ *buf = '\0';
+ return -ENAMETOOLONG;
+ }
return len;
}
@@ -286,15 +291,21 @@ int svc_sock_names(struct svc_serv *serv, char *buf, size_t buflen,
if (!serv)
return 0;
+
spin_lock_bh(&serv->sv_lock);
list_for_each_entry(svsk, &serv->sv_permsocks, sk_xprt.xpt_list) {
- int onelen = one_sock_name(buf+len, svsk);
- if (toclose && strcmp(toclose, buf+len) == 0)
+ int onelen = svc_one_sock_name(svsk, buf + len, buflen - len);
+ if (onelen < 0) {
+ len = onelen;
+ break;
+ }
+ if (toclose && strcmp(toclose, buf + len) == 0)
closesk = svsk;
else
len += onelen;
}
spin_unlock_bh(&serv->sv_lock);
+
if (closesk)
/* Should unregister with portmap, but you cannot
* unregister just one protocol...
@@ -1226,7 +1237,7 @@ int svc_addsock(struct svc_serv *serv, int fd, char *name_return, size_t len)
sockfd_put(so);
return err;
}
- return one_sock_name(name_return, svsk);
+ return svc_one_sock_name(svsk, name_return, len);
}
EXPORT_SYMBOL_GPL(svc_addsock);
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 08/13] SUNRPC: Support AF_INET6 in one_sock_name()
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
` (6 preceding siblings ...)
2008-11-05 17:29 ` [PATCH 07/13] SUNRPC: Switch one_sock_name() to use snprintf() Chuck Lever
@ 2008-11-05 17:29 ` Chuck Lever
2008-11-05 17:29 ` [PATCH 09/13] SUNRPC: Clean up one_sock_name() Chuck Lever
` (5 subsequent siblings)
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:29 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
Add an arm to the switch statement in svc_one_sock_name() so it can
construct the name of PF_INET6 sockets properly.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
net/sunrpc/svcsock.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index db5eb7d..98cee11 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -256,6 +256,13 @@ static int svc_one_sock_name(struct svc_sock *svsk, char *buf, int remaining)
NIPQUAD(inet_sk(svsk->sk_sk)->rcv_saddr),
inet_sk(svsk->sk_sk)->num);
break;
+ case AF_INET6:
+ len = snprintf(buf, remaining, "ipv6 %s " NIP6_FMT " %d\n",
+ svsk->sk_sk->sk_protocol == IPPROTO_UDP ?
+ "udp" : "tcp",
+ NIP6(inet6_sk(svsk->sk_sk)->rcv_saddr),
+ inet_sk(svsk->sk_sk)->num);
+ break;
default:
len = snprintf(buf, remaining, "*unknown-%d*\n",
svsk->sk_sk->sk_family);
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 09/13] SUNRPC: Clean up one_sock_name()
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
` (7 preceding siblings ...)
2008-11-05 17:29 ` [PATCH 08/13] SUNRPC: Support AF_INET6 in one_sock_name() Chuck Lever
@ 2008-11-05 17:29 ` Chuck Lever
2008-11-05 17:29 ` [PATCH 10/13] NFSD: Support AF_INET6 in svc_addsock() function Chuck Lever
` (4 subsequent siblings)
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:29 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
Clean up svc_one_sock_name() by setting up automatic variables for
frequently used expressions.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
net/sunrpc/svcsock.c | 26 +++++++++++++++-----------
1 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 98cee11..62d65bb 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -246,26 +246,30 @@ out:
*/
static int svc_one_sock_name(struct svc_sock *svsk, char *buf, int remaining)
{
+ struct sock *sk = svsk->sk_sk;
+ char *proto_name;
int len;
- switch(svsk->sk_sk->sk_family) {
+ proto_name = "tcp";
+ if (sk->sk_protocol == IPPROTO_UDP)
+ proto_name = "udp";
+
+ switch (sk->sk_family) {
case AF_INET:
- len = snprintf(buf, remaining, "ipv4 %s %u.%u.%u.%u %d\n",
- svsk->sk_sk->sk_protocol==IPPROTO_UDP?
- "udp" : "tcp",
- NIPQUAD(inet_sk(svsk->sk_sk)->rcv_saddr),
- inet_sk(svsk->sk_sk)->num);
+ len = snprintf(buf, remaining, "ipv4 %s " NIPQUAD_FMT " %d\n",
+ proto_name,
+ NIPQUAD(inet_sk(sk)->rcv_saddr),
+ inet_sk(sk)->num);
break;
case AF_INET6:
len = snprintf(buf, remaining, "ipv6 %s " NIP6_FMT " %d\n",
- svsk->sk_sk->sk_protocol == IPPROTO_UDP ?
- "udp" : "tcp",
- NIP6(inet6_sk(svsk->sk_sk)->rcv_saddr),
- inet_sk(svsk->sk_sk)->num);
+ proto_name,
+ NIP6(inet6_sk(sk)->rcv_saddr),
+ inet_sk(sk)->num);
break;
default:
len = snprintf(buf, remaining, "*unknown-%d*\n",
- svsk->sk_sk->sk_family);
+ sk->sk_family);
}
if (len >= remaining) {
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 10/13] NFSD: Support AF_INET6 in svc_addsock() function
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
` (8 preceding siblings ...)
2008-11-05 17:29 ` [PATCH 09/13] SUNRPC: Clean up one_sock_name() Chuck Lever
@ 2008-11-05 17:29 ` Chuck Lever
2008-11-05 17:29 ` [PATCH 11/13] NFS: Move NFS client's IP address parser to nfs_common/ Chuck Lever
` (3 subsequent siblings)
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:29 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
From: Aime Le Rouzic <aime.le-rouzic@bull.net>
Relax the address family check at the top of svc_addsock() to allow AF_INET6
listener sockets to be specified via /proc/fs/nfsd/portlist.
Signed-off-by: Aime Le Rouzic <aime.le-rouzic@bull.net>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
net/sunrpc/svcsock.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 62d65bb..a307834 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -1221,7 +1221,7 @@ int svc_addsock(struct svc_serv *serv, int fd, char *name_return, size_t len)
if (!so)
return err;
- if (so->sk->sk_family != AF_INET)
+ if ((so->sk->sk_family != AF_INET) && (so->sk->sk_family != AF_INET6))
err = -EAFNOSUPPORT;
else if (so->sk->sk_protocol != IPPROTO_TCP &&
so->sk->sk_protocol != IPPROTO_UDP)
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 11/13] NFS: Move NFS client's IP address parser to nfs_common/
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
` (9 preceding siblings ...)
2008-11-05 17:29 ` [PATCH 10/13] NFSD: Support AF_INET6 in svc_addsock() function Chuck Lever
@ 2008-11-05 17:29 ` Chuck Lever
2008-11-05 17:29 ` [PATCH 12/13] NFSD: Support IPv6 addresses in write_failover_ip() Chuck Lever
` (2 subsequent siblings)
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:29 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
The kernel's NFS server also needs to parse presentation format IP
addresses. Since both the client and the server can reside in their own
modules, move the parser logic to nfs_common, which can be used by either.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfs/internal.h | 3 -
fs/nfs/nfs4namespace.c | 2 +
fs/nfs/super.c | 121 -------------------------------
fs/nfs_common/Makefile | 1
fs/nfs_common/nfs_addr_parse.c | 155 ++++++++++++++++++++++++++++++++++++++++
include/linux/nfs_addr_parse.h | 32 ++++++++
6 files changed, 191 insertions(+), 123 deletions(-)
create mode 100644 fs/nfs_common/nfs_addr_parse.c
create mode 100644 include/linux/nfs_addr_parse.h
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index e256520..4f484fe 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -153,7 +153,6 @@ extern void nfs4_clear_inode(struct inode *);
void nfs_zap_acl_cache(struct inode *inode);
/* super.c */
-void nfs_parse_ip_address(char *, size_t, struct sockaddr *, size_t *);
extern struct file_system_type nfs_xdev_fs_type;
#ifdef CONFIG_NFS_V4
extern struct file_system_type nfs4_xdev_fs_type;
@@ -277,8 +276,6 @@ unsigned int nfs_page_array_len(unsigned int base, size_t len)
PAGE_SIZE - 1) >> PAGE_SHIFT;
}
-#define IPV6_SCOPE_DELIMITER '%'
-
/*
* Set the port number in an address. Be agnostic about the address
* family.
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index 30befc3..660fc36 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -15,6 +15,8 @@
#include <linux/sunrpc/clnt.h>
#include <linux/vfs.h>
#include <linux/inet.h>
+#include <linux/nfs_addr_parse.h>
+
#include "internal.h"
#include "nfs4_fs.h"
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index f48db67..6900734 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -51,6 +51,7 @@
#include <linux/nfs_xdr.h>
#include <linux/magic.h>
#include <linux/parser.h>
+#include <linux/nfs_addr_parse.h>
#include <asm/system.h>
#include <asm/uaccess.h>
@@ -696,126 +697,6 @@ static int nfs_verify_server_address(struct sockaddr *addr)
return 0;
}
-static void nfs_parse_ipv4_address(char *string, size_t str_len,
- struct sockaddr *sap, size_t *addr_len)
-{
- struct sockaddr_in *sin = (struct sockaddr_in *)sap;
- u8 *addr = (u8 *)&sin->sin_addr.s_addr;
-
- if (str_len <= INET_ADDRSTRLEN) {
- dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
- (int)str_len, string);
-
- sin->sin_family = AF_INET;
- *addr_len = sizeof(*sin);
- if (in4_pton(string, str_len, addr, '\0', NULL))
- return;
- }
-
- sap->sa_family = AF_UNSPEC;
- *addr_len = 0;
-}
-
-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
-static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
- const char *delim,
- struct sockaddr_in6 *sin6)
-{
- char *p;
- size_t len;
-
- if ((string + str_len) == delim)
- return 1;
-
- if (*delim != IPV6_SCOPE_DELIMITER)
- return 0;
-
- if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
- return 0;
-
- len = (string + str_len) - delim - 1;
- p = kstrndup(delim + 1, len, GFP_KERNEL);
- if (p) {
- unsigned long scope_id = 0;
- struct net_device *dev;
-
- dev = dev_get_by_name(&init_net, p);
- if (dev != NULL) {
- scope_id = dev->ifindex;
- dev_put(dev);
- } else {
- if (strict_strtoul(p, 10, &scope_id) == 0) {
- kfree(p);
- return 0;
- }
- }
-
- kfree(p);
-
- sin6->sin6_scope_id = scope_id;
- dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
- return 1;
- }
-
- return 0;
-}
-
-static void nfs_parse_ipv6_address(char *string, size_t str_len,
- struct sockaddr *sap, size_t *addr_len)
-{
- struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
- u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
- const char *delim;
-
- if (str_len <= INET6_ADDRSTRLEN) {
- dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
- (int)str_len, string);
-
- sin6->sin6_family = AF_INET6;
- *addr_len = sizeof(*sin6);
- if (in6_pton(string, str_len, addr,
- IPV6_SCOPE_DELIMITER, &delim) != 0) {
- if (nfs_parse_ipv6_scope_id(string, str_len,
- delim, sin6) != 0)
- return;
- }
- }
-
- sap->sa_family = AF_UNSPEC;
- *addr_len = 0;
-}
-#else
-static void nfs_parse_ipv6_address(char *string, size_t str_len,
- struct sockaddr *sap, size_t *addr_len)
-{
- sap->sa_family = AF_UNSPEC;
- *addr_len = 0;
-}
-#endif
-
-/*
- * Construct a sockaddr based on the contents of a string that contains
- * an IP address in presentation format.
- *
- * If there is a problem constructing the new sockaddr, set the address
- * family to AF_UNSPEC.
- */
-void nfs_parse_ip_address(char *string, size_t str_len,
- struct sockaddr *sap, size_t *addr_len)
-{
- unsigned int i, colons;
-
- colons = 0;
- for (i = 0; i < str_len; i++)
- if (string[i] == ':')
- colons++;
-
- if (colons >= 2)
- nfs_parse_ipv6_address(string, str_len, sap, addr_len);
- else
- nfs_parse_ipv4_address(string, str_len, sap, addr_len);
-}
-
/*
* Sanity check the NFS transport protocol.
*
diff --git a/fs/nfs_common/Makefile b/fs/nfs_common/Makefile
index f689ed8..032b4c5 100644
--- a/fs/nfs_common/Makefile
+++ b/fs/nfs_common/Makefile
@@ -2,6 +2,7 @@
# Makefile for Linux filesystem routines that are shared by client and server.
#
+obj-$(CONFIG_NFS_COMMON) += nfs_addr_parse.o
obj-$(CONFIG_NFS_ACL_SUPPORT) += nfs_acl.o
nfs_acl-objs := nfsacl.o
diff --git a/fs/nfs_common/nfs_addr_parse.c b/fs/nfs_common/nfs_addr_parse.c
new file mode 100644
index 0000000..afb64dd
--- /dev/null
+++ b/fs/nfs_common/nfs_addr_parse.c
@@ -0,0 +1,155 @@
+/*
+ * Convert presentation format IP address string to socket
+ * address.
+ *
+ * Copyright (C) 2008 Oracle Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/unistd.h>
+
+#include <linux/inet.h>
+#include <linux/in6.h>
+#include <net/ipv6.h>
+#include <linux/netdevice.h>
+
+#include <linux/nfs_addr_parse.h>
+
+static void nfs_parse_ipv4_address(char *buf, size_t buflen,
+ struct sockaddr *sap, size_t *salenp)
+{
+ struct sockaddr_in *sin = (struct sockaddr_in *)sap;
+ u8 *addr = (u8 *)&sin->sin_addr.s_addr;
+
+ if (buflen <= INET_ADDRSTRLEN) {
+ sin->sin_family = AF_INET;
+ *salenp = sizeof(*sin);
+ if (in4_pton(buf, buflen, addr, '\0', NULL))
+ return;
+ }
+
+ sap->sa_family = AF_UNSPEC;
+ *salenp = 0;
+}
+
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+static int nfs_parse_ipv6_scope_id(const char *buf, const size_t buflen,
+ const char *delim,
+ struct sockaddr_in6 *sin6)
+{
+ char *p;
+ size_t len;
+
+ if ((buf + buflen) == delim)
+ return 1;
+
+ if (*delim != IPV6_SCOPE_DELIMITER)
+ return 0;
+
+ if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
+ return 0;
+
+ len = (buf + buflen) - delim - 1;
+ p = kstrndup(delim + 1, len, GFP_KERNEL);
+ if (p) {
+ unsigned long scope_id = 0;
+ struct net_device *dev;
+
+ dev = dev_get_by_name(&init_net, p);
+ if (dev != NULL) {
+ scope_id = dev->ifindex;
+ dev_put(dev);
+ } else {
+ if (strict_strtoul(p, 10, &scope_id) == 0) {
+ kfree(p);
+ return 0;
+ }
+ }
+
+ kfree(p);
+
+ sin6->sin6_scope_id = scope_id;
+ return 1;
+ }
+
+ return 0;
+}
+
+static void nfs_parse_ipv6_address(char *buf, size_t buflen,
+ struct sockaddr *sap, size_t *salenp)
+{
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
+ u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
+ const char *delim;
+
+ if (buflen <= INET6_ADDRSTRLEN) {
+ sin6->sin6_family = AF_INET6;
+ *salenp = sizeof(*sin6);
+ if (in6_pton(buf, buflen, addr,
+ IPV6_SCOPE_DELIMITER, &delim) != 0) {
+ if (nfs_parse_ipv6_scope_id(buf, buflen,
+ delim, sin6) != 0)
+ return;
+ }
+ }
+
+ sap->sa_family = AF_UNSPEC;
+ *salenp = 0;
+}
+#else
+static void nfs_parse_ipv6_address(char *buf, size_t buflen,
+ struct sockaddr *sap, size_t *salenp)
+{
+ sap->sa_family = AF_UNSPEC;
+ *salenp = 0;
+}
+#endif
+
+/**
+ * nfs_parse_ip_address - convert IP address string to sockaddr
+ * @buf: pointer to C string containing presentation format IP address
+ * @buflen: length of @buf in bytes
+ * @sap: pointer to buffer in which to construct sockaddr
+ * @salenp: IN: length of buffer in bytes
+ * OUT: size of address in bytes
+ *
+ * Construct a sockaddr based on the contents of a string that contains
+ * an IP address in presentation format.
+ *
+ * If there is a problem constructing the new sockaddr, set the address
+ * family to AF_UNSPEC.
+ */
+void nfs_parse_ip_address(char *buf, size_t buflen,
+ struct sockaddr *sap, size_t *salenp)
+{
+ unsigned int i, colons;
+
+ colons = 0;
+ for (i = 0; i < buflen; i++)
+ if (buf[i] == ':')
+ colons++;
+
+ if (colons >= 2)
+ nfs_parse_ipv6_address(buf, buflen, sap, salenp);
+ else
+ nfs_parse_ipv4_address(buf, buflen, sap, salenp);
+}
+EXPORT_SYMBOL_GPL(nfs_parse_ip_address);
diff --git a/include/linux/nfs_addr_parse.h b/include/linux/nfs_addr_parse.h
new file mode 100644
index 0000000..484f511
--- /dev/null
+++ b/include/linux/nfs_addr_parse.h
@@ -0,0 +1,32 @@
+/*
+ * include/linux/nfs_addr_parse.h
+ *
+ * Copyright (C) 2008 Oracle Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+#ifndef __LINUX_NFS_ADDR_PARSE_H
+#define __LINUX_NFS_ADDR_PARSE_H
+
+#define IPV6_SCOPE_DELIMITER '%'
+
+void nfs_parse_ip_address(char *buf, size_t buflen,
+ struct sockaddr *sap,
+ size_t *salenp);
+
+#endif /* __LINUX_NFS_ADDR_PARSE_H */
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 12/13] NFSD: Support IPv6 addresses in write_failover_ip()
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
` (10 preceding siblings ...)
2008-11-05 17:29 ` [PATCH 11/13] NFS: Move NFS client's IP address parser to nfs_common/ Chuck Lever
@ 2008-11-05 17:29 ` Chuck Lever
2008-11-05 17:29 ` [PATCH 13/13] NFSD: Enable NFS server use of AF_INET6 Chuck Lever
2008-11-05 20:06 ` [PATCH 01/12] lockd: fix inconsistent use of nsm_use_hostnames J. Bruce Fields
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:29 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
In write_failover_ip(), replace the sscanf() with a call to the common
NFS presentation address parser.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/nfsctl.c | 22 ++++++++--------------
1 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 19db9f4..a8e3f6b 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -38,6 +38,7 @@
#include <linux/nfsd/xdr.h>
#include <linux/nfsd/syscall.h>
#include <linux/lockd/lockd.h>
+#include <linux/nfs_addr_parse.h>
#include <asm/uaccess.h>
#include <net/ipv6.h>
@@ -476,22 +477,18 @@ static ssize_t write_getfd(struct file *file, char *buf, size_t size)
*
* Input:
* buf: '\n'-terminated C string containing a
- * presentation format IPv4 address
+ * presentation format IP address
* size: length of C string in @buf
* Output:
* On success: returns zero if all specified locks were released;
* returns one if one or more locks were not released
* On error: return code is negative errno value
- *
- * Note: Only AF_INET client addresses are passed in
*/
static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
{
- struct sockaddr_in sin = {
- .sin_family = AF_INET,
- };
- int b1, b2, b3, b4;
- char c;
+ struct sockaddr_storage address;
+ struct sockaddr *sap = (struct sockaddr *)&address;
+ size_t salen = sizeof(address);
char *fo_path;
/* sanity check */
@@ -505,14 +502,11 @@ static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
if (qword_get(&buf, fo_path, size) < 0)
return -EINVAL;
- /* get ipv4 address */
- if (sscanf(fo_path, NIPQUAD_FMT "%c", &b1, &b2, &b3, &b4, &c) != 4)
- return -EINVAL;
- if (b1 > 255 || b2 > 255 || b3 > 255 || b4 > 255)
+ nfs_parse_ip_address(fo_path, size, sap, &salen);
+ if (sap->sa_family == AF_UNSPEC)
return -EINVAL;
- sin.sin_addr.s_addr = htonl((b1 << 24) | (b2 << 16) | (b3 << 8) | b4);
- return nlmsvc_unlock_all_by_ip((struct sockaddr *)&sin);
+ return nlmsvc_unlock_all_by_ip(sap);
}
/**
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 13/13] NFSD: Enable NFS server use of AF_INET6
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
` (11 preceding siblings ...)
2008-11-05 17:29 ` [PATCH 12/13] NFSD: Support IPv6 addresses in write_failover_ip() Chuck Lever
@ 2008-11-05 17:29 ` Chuck Lever
2008-11-05 20:06 ` [PATCH 01/12] lockd: fix inconsistent use of nsm_use_hostnames J. Bruce Fields
13 siblings, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 17:29 UTC (permalink / raw)
To: bfields; +Cc: linux-nfs
If the kernel is configured to support IPv6 and the RPC server can register
services via rpcbindv4, we are all set to enable IPv6 support for NFSD.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Cc: Aime Le Rouzic <aime.le-rouzic@bull.net>
---
fs/nfsd/nfssvc.c | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index 07e4f5d..47e21d0 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -45,6 +45,17 @@ static unsigned long nfsd_last_call;
static DEFINE_SPINLOCK(nfsd_call_lock);
/*
+ * If the kernel has IPv6 support available, always listen for
+ * both AF_INET and AF_INET6 requests.
+ */
+#if (defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)) && \
+ defined(CONFIG_SUNRPC_REGISTER_V4)
+static const sa_family_t nfsd_family = AF_INET6;
+#else /* (CONFIG_IPV6 || CONFIG_IPV6_MODULE) && CONFIG_SUNRPC_REGISTER_V4 */
+static const sa_family_t nfsd_family = AF_INET;
+#endif /* (CONFIG_IPV6 || CONFIG_IPV6_MODULE) && CONFIG_SUNRPC_REGISTER_V4 */
+
+/*
* nfsd_mutex protects nfsd_serv -- both the pointer itself and the members
* of the svc_serv struct. In particular, ->sv_nrthreads but also to some
* extent ->sv_temp_socks and ->sv_permsocks. It also protects nfsdstats.th_cnt
@@ -229,7 +240,7 @@ int nfsd_create_serv(void)
atomic_set(&nfsd_busy, 0);
nfsd_serv = svc_create_pooled(&nfsd_program, nfsd_max_blksize,
- AF_INET,
+ nfsd_family,
nfsd_last_thread, nfsd, THIS_MODULE);
if (nfsd_serv == NULL)
err = -ENOMEM;
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 01/12] lockd: fix inconsistent use of nsm_use_hostnames
[not found] ` <20081105172351.7330.50739.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
` (12 preceding siblings ...)
2008-11-05 17:29 ` [PATCH 13/13] NFSD: Enable NFS server use of AF_INET6 Chuck Lever
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-05 20:06 ` [PATCH 02/12] lockd: kill redundant host->h_server check J. Bruce Fields
2008-11-05 22:10 ` [PATCH 01/12] lockd: fix inconsistent use of nsm_use_hostnames Chuck Lever
13 siblings, 2 replies; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
In nlm_lookup_host() there's an optimization that looks for matching nsm
handles at the same time as looking for hosts, so that if a host
isn't found but a matching nsm handle is, we save a second lookup for
the nsm handle.
The optimization (unlike nsm_find()) ignores nsm_use_hostnames, so may
give incorrect results when that parameter is set. We could probably
find some way to fix this and keep the optimization, but it seems
unlikely to be very significant, so just skip it entirely.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/host.c | 23 +++++++----------------
1 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 9fd8889..e9069c2 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -138,7 +138,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
struct hlist_head *chain;
struct hlist_node *pos;
struct nlm_host *host;
- struct nsm_handle *nsm = NULL;
+ struct nsm_handle *nsm;
mutex_lock(&nlm_host_mutex);
@@ -157,10 +157,6 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
if (!nlm_cmp_addr(nlm_addr(host), ni->sap))
continue;
- /* See if we have an NSM handle for this client */
- if (!nsm)
- nsm = host->h_nsmhandle;
-
if (host->h_proto != ni->protocol)
continue;
if (host->h_version != ni->version)
@@ -184,17 +180,12 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
* The host wasn't in our hash table. If we don't
* have an NSM handle for it yet, create one.
*/
- if (nsm)
- atomic_inc(&nsm->sm_count);
- else {
- host = NULL;
- nsm = nsm_find(ni->sap, ni->salen,
- ni->hostname, ni->hostname_len, 1);
- if (!nsm) {
- dprintk("lockd: nlm_lookup_host failed; "
- "no nsm handle\n");
- goto out;
- }
+ host = NULL;
+ nsm = nsm_find(ni->sap, ni->salen, ni->hostname, ni->hostname_len, 1);
+ if (!nsm) {
+ dprintk("lockd: nlm_lookup_host failed; "
+ "no nsm handle\n");
+ goto out;
}
host = kzalloc(sizeof(*host), GFP_KERNEL);
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 02/12] lockd: kill redundant host->h_server check
2008-11-05 20:06 ` [PATCH 01/12] lockd: fix inconsistent use of nsm_use_hostnames J. Bruce Fields
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-05 20:06 ` [PATCH 03/12] lockd: fix nsm_unmonitor return value J. Bruce Fields
2008-11-05 22:10 ` [PATCH 01/12] lockd: fix inconsistent use of nsm_use_hostnames Chuck Lever
1 sibling, 1 reply; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
Note that the first argument to nlmsvc_is_client always has h_server
set, since it is the host associated with a lock, block, or share held
by the server.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/svcsubs.c | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c
index 34c2766..9c186f0 100644
--- a/fs/lockd/svcsubs.c
+++ b/fs/lockd/svcsubs.c
@@ -335,16 +335,15 @@ nlmsvc_is_client(void *data, struct nlm_host *dummy)
{
struct nlm_host *host = data;
- if (host->h_server) {
- /* we are destroying locks even though the client
- * hasn't asked us too, so don't unmonitor the
- * client
- */
- if (host->h_nsmhandle)
- host->h_nsmhandle->sm_sticky = 1;
- return 1;
- } else
- return 0;
+ BUG_ON(!host->h_server);
+ /* we are destroying locks even though the client
+ * hasn't asked us too, so don't unmonitor the
+ * client
+ */
+ if (host->h_nsmhandle)
+ host->h_nsmhandle->sm_sticky = 1;
+ return 1;
+
}
/*
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 03/12] lockd: fix nsm_unmonitor return value
2008-11-05 20:06 ` [PATCH 02/12] lockd: kill redundant host->h_server check J. Bruce Fields
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-05 20:06 ` [PATCH 04/12] lockd: unmonitor only when last host goes away J. Bruce Fields
2008-11-05 22:14 ` [PATCH 03/12] lockd: fix nsm_unmonitor return value Chuck Lever
0 siblings, 2 replies; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
Note that the only caller of nsm_unmonitor has no use for its return
value.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/mon.c | 8 +++-----
include/linux/lockd/sm_inter.h | 2 +-
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c
index 4e7e958..480f197 100644
--- a/fs/lockd/mon.c
+++ b/fs/lockd/mon.c
@@ -97,15 +97,14 @@ nsm_monitor(struct nlm_host *host)
/*
* Cease to monitor remote host
*/
-int
-nsm_unmonitor(struct nlm_host *host)
+void nsm_unmonitor(struct nlm_host *host)
{
struct nsm_handle *nsm = host->h_nsmhandle;
struct nsm_res res;
- int status = 0;
+ int status;
if (nsm == NULL)
- return 0;
+ return;
host->h_nsmhandle = NULL;
if (atomic_read(&nsm->sm_count) == 1
@@ -120,7 +119,6 @@ nsm_unmonitor(struct nlm_host *host)
nsm->sm_monitored = 0;
}
nsm_release(nsm);
- return status;
}
/*
diff --git a/include/linux/lockd/sm_inter.h b/include/linux/lockd/sm_inter.h
index 5a5448b..b069598 100644
--- a/include/linux/lockd/sm_inter.h
+++ b/include/linux/lockd/sm_inter.h
@@ -42,7 +42,7 @@ struct nsm_res {
};
int nsm_monitor(struct nlm_host *);
-int nsm_unmonitor(struct nlm_host *);
+void nsm_unmonitor(struct nlm_host *);
extern int nsm_local_state;
#endif /* LINUX_LOCKD_SM_INTER_H */
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 04/12] lockd: unmonitor only when last host goes away
2008-11-05 20:06 ` [PATCH 03/12] lockd: fix nsm_unmonitor return value J. Bruce Fields
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-05 20:06 ` [PATCH 05/12] lockd: encapsulate nlm_hosts table variables in one structure J. Bruce Fields
2008-11-05 22:22 ` [PATCH 04/12] lockd: unmonitor only when last host goes away Chuck Lever
2008-11-05 22:14 ` [PATCH 03/12] lockd: fix nsm_unmonitor return value Chuck Lever
1 sibling, 2 replies; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
The sm_sticky logic seems racy; instead just unmonitor before
destruction of handle.
XXX: how to test?
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/host.c | 24 ++++++++++++++++++++----
fs/lockd/mon.c | 15 +--------------
fs/lockd/svcsubs.c | 6 ------
include/linux/lockd/lockd.h | 3 +--
4 files changed, 22 insertions(+), 26 deletions(-)
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index e9069c2..1a1adb9 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -683,6 +683,10 @@ found:
return nsm;
}
+
+/* XXX: */
+int nsm_mon_unmon(struct nsm_handle *, u32, struct nsm_res *);
+
/*
* Release an NSM handle
*/
@@ -691,9 +695,21 @@ nsm_release(struct nsm_handle *nsm)
{
if (!nsm)
return;
- if (atomic_dec_and_lock(&nsm->sm_count, &nsm_lock)) {
- list_del(&nsm->sm_link);
- spin_unlock(&nsm_lock);
- kfree(nsm);
+ if (!atomic_dec_and_lock(&nsm->sm_count, &nsm_lock))
+ return;
+ list_del(&nsm->sm_link);
+ spin_unlock(&nsm_lock);
+ if (nsm->sm_monitored) {
+ struct nsm_res res;
+ int status;
+
+ dprintk("lockd: nsm_unmonitor(%s)\n", nsm->sm_name);
+ status = nsm_mon_unmon(nsm, SM_UNMON, &res);
+ if (status < 0)
+ printk(KERN_NOTICE "lockd: cannot unmonitor %s\n",
+ nsm->sm_name);
+ else
+ nsm->sm_monitored = 0;
}
+ kfree(nsm);
}
diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c
index 480f197..8cc0e97 100644
--- a/fs/lockd/mon.c
+++ b/fs/lockd/mon.c
@@ -32,7 +32,7 @@ int nsm_local_state;
/*
* Common procedure for SM_MON/SM_UNMON calls
*/
-static int
+int
nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res)
{
struct rpc_clnt *clnt;
@@ -100,24 +100,11 @@ nsm_monitor(struct nlm_host *host)
void nsm_unmonitor(struct nlm_host *host)
{
struct nsm_handle *nsm = host->h_nsmhandle;
- struct nsm_res res;
- int status;
if (nsm == NULL)
return;
host->h_nsmhandle = NULL;
- if (atomic_read(&nsm->sm_count) == 1
- && nsm->sm_monitored && !nsm->sm_sticky) {
- dprintk("lockd: nsm_unmonitor(%s)\n", host->h_name);
-
- status = nsm_mon_unmon(nsm, SM_UNMON, &res);
- if (status < 0)
- printk(KERN_NOTICE "lockd: cannot unmonitor %s\n",
- host->h_name);
- else
- nsm->sm_monitored = 0;
- }
nsm_release(nsm);
}
diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c
index 9c186f0..0296904 100644
--- a/fs/lockd/svcsubs.c
+++ b/fs/lockd/svcsubs.c
@@ -336,12 +336,6 @@ nlmsvc_is_client(void *data, struct nlm_host *dummy)
struct nlm_host *host = data;
BUG_ON(!host->h_server);
- /* we are destroying locks even though the client
- * hasn't asked us too, so don't unmonitor the
- * client
- */
- if (host->h_nsmhandle)
- host->h_nsmhandle->sm_sticky = 1;
return 1;
}
diff --git a/include/linux/lockd/lockd.h b/include/linux/lockd/lockd.h
index b56d5aa..e1c2690 100644
--- a/include/linux/lockd/lockd.h
+++ b/include/linux/lockd/lockd.h
@@ -75,8 +75,7 @@ struct nsm_handle {
char * sm_name;
struct sockaddr_storage sm_addr;
size_t sm_addrlen;
- unsigned int sm_monitored : 1,
- sm_sticky : 1; /* don't unmonitor */
+ unsigned int sm_monitored : 1;
char sm_addrbuf[48]; /* address eyecatcher */
};
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 05/12] lockd: encapsulate nlm_hosts table variables in one structure
2008-11-05 20:06 ` [PATCH 04/12] lockd: unmonitor only when last host goes away J. Bruce Fields
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-05 20:06 ` [PATCH 06/12] lockd: define host_for_each{_safe} macros J. Bruce Fields
2008-11-05 22:25 ` [PATCH 05/12] lockd: encapsulate nlm_hosts table variables in one structure Chuck Lever
2008-11-05 22:22 ` [PATCH 04/12] lockd: unmonitor only when last host goes away Chuck Lever
1 sibling, 2 replies; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
This will simplify splitting these variables into client and server
sides.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/host.c | 46 ++++++++++++++++++++++++++--------------------
1 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 1a1adb9..199ca8c 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -26,10 +26,16 @@
#define NLM_HOST_EXPIRE (300 * HZ)
#define NLM_HOST_COLLECT (120 * HZ)
-static struct hlist_head nlm_hosts[NLM_HOST_NRHASH];
+struct host_table {
+ struct hlist_head ht_chains[NLM_HOST_NRHASH];
+ int ht_num;
+ struct mutex ht_mutex;
+};
+
+static struct host_table nlm_hosts = {
+ .ht_mutex = __MUTEX_INITIALIZER(nlm_hosts.ht_mutex)
+};
static unsigned long next_gc;
-static int nrhosts;
-static DEFINE_MUTEX(nlm_host_mutex);
static void nlm_gc_hosts(void);
static struct nsm_handle *nsm_find(const struct sockaddr *sap,
@@ -140,7 +146,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
struct nlm_host *host;
struct nsm_handle *nsm;
- mutex_lock(&nlm_host_mutex);
+ mutex_lock(&nlm_hosts.ht_mutex);
if (time_after_eq(jiffies, next_gc))
nlm_gc_hosts();
@@ -152,7 +158,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
* different NLM rpc_clients into one single nlm_host object.
* This would allow us to have one nlm_host per address.
*/
- chain = &nlm_hosts[nlm_hash_address(ni->sap)];
+ chain = &nlm_hosts.ht_chains[nlm_hash_address(ni->sap)];
hlist_for_each_entry(host, pos, chain, h_hash) {
if (!nlm_cmp_addr(nlm_addr(host), ni->sap))
continue;
@@ -218,7 +224,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
INIT_LIST_HEAD(&host->h_granted);
INIT_LIST_HEAD(&host->h_reclaim);
- nrhosts++;
+ nlm_hosts.ht_num++;
nlm_display_address((struct sockaddr *)&host->h_addr,
host->h_addrbuf, sizeof(host->h_addrbuf));
@@ -229,7 +235,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
host->h_name);
out:
- mutex_unlock(&nlm_host_mutex);
+ mutex_unlock(&nlm_hosts.ht_mutex);
return host;
}
@@ -498,8 +504,8 @@ void nlm_host_rebooted(const struct sockaddr_in *sin,
* lock for this.
* To avoid processing a host several times, we match the nsmstate.
*/
-again: mutex_lock(&nlm_host_mutex);
- for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
+again: mutex_lock(&nlm_hosts.ht_mutex);
+ for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains + NLM_HOST_NRHASH; ++chain) {
hlist_for_each_entry(host, pos, chain, h_hash) {
if (host->h_nsmhandle == nsm
&& host->h_nsmstate != new_state) {
@@ -507,7 +513,7 @@ again: mutex_lock(&nlm_host_mutex);
host->h_state++;
nlm_get_host(host);
- mutex_unlock(&nlm_host_mutex);
+ mutex_unlock(&nlm_hosts.ht_mutex);
if (host->h_server) {
/* We're server for this guy, just ditch
@@ -524,7 +530,7 @@ again: mutex_lock(&nlm_host_mutex);
}
}
- mutex_unlock(&nlm_host_mutex);
+ mutex_unlock(&nlm_hosts.ht_mutex);
}
/*
@@ -539,11 +545,11 @@ nlm_shutdown_hosts(void)
struct nlm_host *host;
dprintk("lockd: shutting down host module\n");
- mutex_lock(&nlm_host_mutex);
+ mutex_lock(&nlm_hosts.ht_mutex);
/* First, make all hosts eligible for gc */
dprintk("lockd: nuking all hosts...\n");
- for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
+ for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains + NLM_HOST_NRHASH; ++chain) {
hlist_for_each_entry(host, pos, chain, h_hash) {
host->h_expires = jiffies - 1;
if (host->h_rpcclnt) {
@@ -555,13 +561,13 @@ nlm_shutdown_hosts(void)
/* Then, perform a garbage collection pass */
nlm_gc_hosts();
- mutex_unlock(&nlm_host_mutex);
+ mutex_unlock(&nlm_hosts.ht_mutex);
/* complain if any hosts are left */
- if (nrhosts) {
+ if (nlm_hosts.ht_num) {
printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
- dprintk("lockd: %d hosts left:\n", nrhosts);
- for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
+ dprintk("lockd: %d hosts left:\n", nlm_hosts.ht_num);
+ for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains + NLM_HOST_NRHASH; ++chain) {
hlist_for_each_entry(host, pos, chain, h_hash) {
dprintk(" %s (cnt %d use %d exp %ld)\n",
host->h_name, atomic_read(&host->h_count),
@@ -584,7 +590,7 @@ nlm_gc_hosts(void)
struct nlm_host *host;
dprintk("lockd: host garbage collection\n");
- for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
+ for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains + NLM_HOST_NRHASH; ++chain) {
hlist_for_each_entry(host, pos, chain, h_hash)
host->h_inuse = 0;
}
@@ -592,7 +598,7 @@ nlm_gc_hosts(void)
/* Mark all hosts that hold locks, blocks or shares */
nlmsvc_mark_resources();
- for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
+ for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains + NLM_HOST_NRHASH; ++chain) {
hlist_for_each_entry_safe(host, pos, next, chain, h_hash) {
if (atomic_read(&host->h_count) || host->h_inuse
|| time_before(jiffies, host->h_expires)) {
@@ -605,7 +611,7 @@ nlm_gc_hosts(void)
hlist_del_init(&host->h_hash);
nlm_destroy_host(host);
- nrhosts--;
+ nlm_hosts.ht_num--;
}
}
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 06/12] lockd: define host_for_each{_safe} macros
2008-11-05 20:06 ` [PATCH 05/12] lockd: encapsulate nlm_hosts table variables in one structure J. Bruce Fields
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-05 20:06 ` [PATCH 07/12] lockd: reorganize nlm_host_rebooted J. Bruce Fields
2008-11-05 22:25 ` [PATCH 05/12] lockd: encapsulate nlm_hosts table variables in one structure Chuck Lever
1 sibling, 1 reply; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
We've got a lot of loops like this, and I find them a little easier to
read with the macros.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/host.c | 108 ++++++++++++++++++++++++++++--------------------------
1 files changed, 56 insertions(+), 52 deletions(-)
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 199ca8c..1b90b49 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -32,6 +32,19 @@ struct host_table {
struct mutex ht_mutex;
};
+#define for_each_host(host, pos, chain, table) \
+ for ((chain) = (table)->ht_chains; \
+ (chain) < (table)->ht_chains + NLM_HOST_NRHASH; \
+ ++(chain)) \
+ hlist_for_each_entry((host), (pos), (chain), h_hash)
+
+#define for_each_host_safe(host, pos, next, chain, table) \
+ for ((chain) = (table)->ht_chains; \
+ (chain) < (table)->ht_chains + NLM_HOST_NRHASH; \
+ ++(chain)) \
+ hlist_for_each_entry_safe((host), (pos), (next), (chain), \
+ h_hash)
+
static struct host_table nlm_hosts = {
.ht_mutex = __MUTEX_INITIALIZER(nlm_hosts.ht_mutex)
};
@@ -505,28 +518,26 @@ void nlm_host_rebooted(const struct sockaddr_in *sin,
* To avoid processing a host several times, we match the nsmstate.
*/
again: mutex_lock(&nlm_hosts.ht_mutex);
- for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains + NLM_HOST_NRHASH; ++chain) {
- hlist_for_each_entry(host, pos, chain, h_hash) {
- if (host->h_nsmhandle == nsm
- && host->h_nsmstate != new_state) {
- host->h_nsmstate = new_state;
- host->h_state++;
-
- nlm_get_host(host);
- mutex_unlock(&nlm_hosts.ht_mutex);
-
- if (host->h_server) {
- /* We're server for this guy, just ditch
- * all the locks he held. */
- nlmsvc_free_host_resources(host);
- } else {
- /* He's the server, initiate lock recovery. */
- nlmclnt_recovery(host);
- }
-
- nlm_release_host(host);
- goto again;
+ for_each_host(host, pos, chain, &nlm_hosts) {
+ if (host->h_nsmhandle == nsm
+ && host->h_nsmstate != new_state) {
+ host->h_nsmstate = new_state;
+ host->h_state++;
+
+ nlm_get_host(host);
+ mutex_unlock(&nlm_hosts.ht_mutex);
+
+ if (host->h_server) {
+ /* We're server for this guy, just ditch
+ * all the locks he held. */
+ nlmsvc_free_host_resources(host);
+ } else {
+ /* He's the server, initiate lock recovery. */
+ nlmclnt_recovery(host);
}
+
+ nlm_release_host(host);
+ goto again;
}
}
@@ -549,13 +560,11 @@ nlm_shutdown_hosts(void)
/* First, make all hosts eligible for gc */
dprintk("lockd: nuking all hosts...\n");
- for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains + NLM_HOST_NRHASH; ++chain) {
- hlist_for_each_entry(host, pos, chain, h_hash) {
- host->h_expires = jiffies - 1;
- if (host->h_rpcclnt) {
- rpc_shutdown_client(host->h_rpcclnt);
- host->h_rpcclnt = NULL;
- }
+ for_each_host(host, pos, chain, &nlm_hosts) {
+ host->h_expires = jiffies - 1;
+ if (host->h_rpcclnt) {
+ rpc_shutdown_client(host->h_rpcclnt);
+ host->h_rpcclnt = NULL;
}
}
@@ -567,12 +576,10 @@ nlm_shutdown_hosts(void)
if (nlm_hosts.ht_num) {
printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
dprintk("lockd: %d hosts left:\n", nlm_hosts.ht_num);
- for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains + NLM_HOST_NRHASH; ++chain) {
- hlist_for_each_entry(host, pos, chain, h_hash) {
- dprintk(" %s (cnt %d use %d exp %ld)\n",
- host->h_name, atomic_read(&host->h_count),
- host->h_inuse, host->h_expires);
- }
+ for_each_host(host, pos, chain, &nlm_hosts) {
+ dprintk(" %s (cnt %d use %d exp %ld)\n",
+ host->h_name, atomic_read(&host->h_count),
+ host->h_inuse, host->h_expires);
}
}
}
@@ -590,29 +597,26 @@ nlm_gc_hosts(void)
struct nlm_host *host;
dprintk("lockd: host garbage collection\n");
- for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains + NLM_HOST_NRHASH; ++chain) {
- hlist_for_each_entry(host, pos, chain, h_hash)
- host->h_inuse = 0;
- }
+ for_each_host(host, pos, chain, &nlm_hosts)
+ host->h_inuse = 0;
/* Mark all hosts that hold locks, blocks or shares */
nlmsvc_mark_resources();
- for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains + NLM_HOST_NRHASH; ++chain) {
- hlist_for_each_entry_safe(host, pos, next, chain, h_hash) {
- if (atomic_read(&host->h_count) || host->h_inuse
- || time_before(jiffies, host->h_expires)) {
- dprintk("nlm_gc_hosts skipping %s (cnt %d use %d exp %ld)\n",
- host->h_name, atomic_read(&host->h_count),
- host->h_inuse, host->h_expires);
- continue;
- }
- dprintk("lockd: delete host %s\n", host->h_name);
- hlist_del_init(&host->h_hash);
-
- nlm_destroy_host(host);
- nlm_hosts.ht_num--;
+ for_each_host_safe(host, pos, next, chain, &nlm_hosts) {
+ if (atomic_read(&host->h_count) || host->h_inuse
+ || time_before(jiffies, host->h_expires)) {
+ dprintk("nlm_gc_hosts skipping %s"
+ " (cnt %d use %d exp %ld)\n",
+ host->h_name, atomic_read(&host->h_count),
+ host->h_inuse, host->h_expires);
+ continue;
}
+ dprintk("lockd: delete host %s\n", host->h_name);
+ hlist_del_init(&host->h_hash);
+
+ nlm_destroy_host(host);
+ nlm_hosts.ht_num--;
}
next_gc = jiffies + NLM_HOST_COLLECT;
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 07/12] lockd: reorganize nlm_host_rebooted
2008-11-05 20:06 ` [PATCH 06/12] lockd: define host_for_each{_safe} macros J. Bruce Fields
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-05 20:06 ` [PATCH 08/12] lockd: move debugging warning into a separate function J. Bruce Fields
2008-11-05 22:29 ` [PATCH 07/12] lockd: reorganize nlm_host_rebooted Chuck Lever
0 siblings, 2 replies; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
Minor reorganization; no change in behavior. This will save some
duplicated code after we split apart the client and server host lists.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/host.c | 59 +++++++++++++++++++++++++++++++-----------------------
1 files changed, 34 insertions(+), 25 deletions(-)
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 1b90b49..bb3bf36 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -482,6 +482,31 @@ void nlm_release_host(struct nlm_host *host)
}
}
+static struct nlm_host *next_host_state(struct host_table *table,
+ struct nsm_handle *nsm,
+ u32 new_state)
+{
+ struct hlist_head *chain;
+ struct hlist_node *pos;
+ struct nlm_host *host = NULL;
+
+ mutex_lock(&table->ht_mutex);
+ for_each_host(host, pos, chain, table) {
+ if (host->h_nsmhandle == nsm
+ && host->h_nsmstate != new_state) {
+ host->h_nsmstate = new_state;
+ host->h_state++;
+
+ nlm_get_host(host);
+ mutex_unlock(&table->ht_mutex);
+ goto out;
+ }
+ }
+out:
+ mutex_unlock(&table->ht_mutex);
+ return host;
+}
+
/*
* We were notified that the host indicated by address &sin
* has rebooted.
@@ -492,8 +517,6 @@ void nlm_host_rebooted(const struct sockaddr_in *sin,
unsigned int hostname_len,
u32 new_state)
{
- struct hlist_head *chain;
- struct hlist_node *pos;
struct nsm_handle *nsm;
struct nlm_host *host;
@@ -517,31 +540,17 @@ void nlm_host_rebooted(const struct sockaddr_in *sin,
* lock for this.
* To avoid processing a host several times, we match the nsmstate.
*/
-again: mutex_lock(&nlm_hosts.ht_mutex);
- for_each_host(host, pos, chain, &nlm_hosts) {
- if (host->h_nsmhandle == nsm
- && host->h_nsmstate != new_state) {
- host->h_nsmstate = new_state;
- host->h_state++;
-
- nlm_get_host(host);
- mutex_unlock(&nlm_hosts.ht_mutex);
-
- if (host->h_server) {
- /* We're server for this guy, just ditch
- * all the locks he held. */
- nlmsvc_free_host_resources(host);
- } else {
- /* He's the server, initiate lock recovery. */
- nlmclnt_recovery(host);
- }
-
- nlm_release_host(host);
- goto again;
+ while ((host = next_host_state(&nlm_hosts, nsm, new_state)) != NULL) {
+ if (host->h_server) {
+ /* We're server for this guy, just ditch
+ * all the locks he held. */
+ nlmsvc_free_host_resources(host);
+ } else {
+ /* He's the server, initiate lock recovery. */
+ nlmclnt_recovery(host);
}
+ nlm_release_host(host);
}
-
- mutex_unlock(&nlm_hosts.ht_mutex);
}
/*
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 08/12] lockd: move debugging warning into a separate function
2008-11-05 20:06 ` [PATCH 07/12] lockd: reorganize nlm_host_rebooted J. Bruce Fields
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-05 20:06 ` [PATCH 09/12] lockd: move garbage collection loop into " J. Bruce Fields
2008-11-05 22:29 ` [PATCH 07/12] lockd: reorganize nlm_host_rebooted Chuck Lever
1 sibling, 1 reply; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
This will also save some duplicated code after splitting apart client
and server.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/host.c | 26 +++++++++++++++++---------
1 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index bb3bf36..3fd7573 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -553,6 +553,21 @@ void nlm_host_rebooted(const struct sockaddr_in *sin,
}
}
+static void warn_host_leak(struct host_table *table)
+{
+ struct hlist_head *chain;
+ struct hlist_node *pos;
+ struct nlm_host *host;
+
+ printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
+ dprintk("lockd: %d hosts left:\n", table->ht_num);
+ for_each_host(host, pos, chain, table) {
+ dprintk(" %s (cnt %d use %d exp %ld)\n",
+ host->h_name, atomic_read(&host->h_count),
+ host->h_inuse, host->h_expires);
+ }
+}
+
/*
* Shut down the hosts module.
* Note that this routine is called only at server shutdown time.
@@ -582,15 +597,8 @@ nlm_shutdown_hosts(void)
mutex_unlock(&nlm_hosts.ht_mutex);
/* complain if any hosts are left */
- if (nlm_hosts.ht_num) {
- printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
- dprintk("lockd: %d hosts left:\n", nlm_hosts.ht_num);
- for_each_host(host, pos, chain, &nlm_hosts) {
- dprintk(" %s (cnt %d use %d exp %ld)\n",
- host->h_name, atomic_read(&host->h_count),
- host->h_inuse, host->h_expires);
- }
- }
+ if (nlm_hosts.ht_num)
+ warn_host_leak(&nlm_hosts);
}
/*
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 09/12] lockd: move garbage collection loop into separate function
2008-11-05 20:06 ` [PATCH 08/12] lockd: move debugging warning into a separate function J. Bruce Fields
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-05 20:06 ` [PATCH 10/12] lockd: move immediate host expiry " J. Bruce Fields
0 siblings, 1 reply; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
This code will later be shared.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/host.c | 46 +++++++++++++++++++++++++++-------------------
1 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 3fd7573..fa006af 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -553,6 +553,31 @@ void nlm_host_rebooted(const struct sockaddr_in *sin,
}
}
+static void nlm_gc_table(struct host_table *table)
+{
+ struct hlist_head *chain;
+ struct hlist_node *pos, *next;
+ struct nlm_host *host;
+
+ for_each_host_safe(host, pos, next, chain, table) {
+ if (atomic_read(&host->h_count) || host->h_inuse
+ || time_before(jiffies, host->h_expires)) {
+ dprintk("nlm_gc_hosts skipping %s"
+ " (cnt %d use %d exp %ld)\n",
+ host->h_name, atomic_read(&host->h_count),
+ host->h_inuse, host->h_expires);
+ continue;
+ }
+ dprintk("lockd: delete host %s\n", host->h_name);
+ hlist_del_init(&host->h_hash);
+
+ nlm_destroy_host(host);
+ table->ht_num--;
+ }
+
+ next_gc = jiffies + NLM_HOST_COLLECT;
+}
+
static void warn_host_leak(struct host_table *table)
{
struct hlist_head *chain;
@@ -610,7 +635,7 @@ static void
nlm_gc_hosts(void)
{
struct hlist_head *chain;
- struct hlist_node *pos, *next;
+ struct hlist_node *pos;
struct nlm_host *host;
dprintk("lockd: host garbage collection\n");
@@ -620,26 +645,9 @@ nlm_gc_hosts(void)
/* Mark all hosts that hold locks, blocks or shares */
nlmsvc_mark_resources();
- for_each_host_safe(host, pos, next, chain, &nlm_hosts) {
- if (atomic_read(&host->h_count) || host->h_inuse
- || time_before(jiffies, host->h_expires)) {
- dprintk("nlm_gc_hosts skipping %s"
- " (cnt %d use %d exp %ld)\n",
- host->h_name, atomic_read(&host->h_count),
- host->h_inuse, host->h_expires);
- continue;
- }
- dprintk("lockd: delete host %s\n", host->h_name);
- hlist_del_init(&host->h_hash);
-
- nlm_destroy_host(host);
- nlm_hosts.ht_num--;
- }
-
- next_gc = jiffies + NLM_HOST_COLLECT;
+ nlm_gc_table(&nlm_hosts);
}
-
/*
* Manage NSM handles
*/
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 10/12] lockd: move immediate host expiry into separate function
2008-11-05 20:06 ` [PATCH 09/12] lockd: move garbage collection loop into " J. Bruce Fields
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-05 20:06 ` [PATCH 11/12] lockd: split client and server host lists J. Bruce Fields
2008-11-05 22:33 ` [PATCH 10/12] lockd: move immediate host expiry into separate function Chuck Lever
0 siblings, 2 replies; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
This code will later be shared.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/host.c | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index fa006af..588017f 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -593,29 +593,34 @@ static void warn_host_leak(struct host_table *table)
}
}
-/*
- * Shut down the hosts module.
- * Note that this routine is called only at server shutdown time.
- */
-void
-nlm_shutdown_hosts(void)
+static void expire_hosts(struct host_table *table)
{
struct hlist_head *chain;
struct hlist_node *pos;
struct nlm_host *host;
- dprintk("lockd: shutting down host module\n");
- mutex_lock(&nlm_hosts.ht_mutex);
-
- /* First, make all hosts eligible for gc */
dprintk("lockd: nuking all hosts...\n");
- for_each_host(host, pos, chain, &nlm_hosts) {
+ for_each_host(host, pos, chain, table) {
host->h_expires = jiffies - 1;
if (host->h_rpcclnt) {
rpc_shutdown_client(host->h_rpcclnt);
host->h_rpcclnt = NULL;
}
}
+}
+
+/*
+ * Shut down the hosts module.
+ * Note that this routine is called only at server shutdown time.
+ */
+void
+nlm_shutdown_hosts(void)
+{
+ dprintk("lockd: shutting down host module\n");
+ mutex_lock(&nlm_hosts.ht_mutex);
+
+ /* First, make all hosts eligible for gc */
+ expire_hosts(&nlm_hosts);
/* Then, perform a garbage collection pass */
nlm_gc_hosts();
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 11/12] lockd: split client and server host lists
2008-11-05 20:06 ` [PATCH 10/12] lockd: move immediate host expiry " J. Bruce Fields
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-05 20:06 ` [PATCH 12/12] lockd: remove redundant rpc_shutdown_client() J. Bruce Fields
2008-11-05 22:33 ` [PATCH 10/12] lockd: move immediate host expiry into separate function Chuck Lever
1 sibling, 1 reply; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
Separate out client and server host lists. Most logic is just
duplicated, but note that the garbage-collection logic is slightly
different for the two, since the client doesn't need to do the mark and
sweep of all its hosts.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/host.c | 59 ++++++++++++++++++++++++++++++++----------------------
1 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 588017f..73c2be2 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -45,8 +45,11 @@ struct host_table {
hlist_for_each_entry_safe((host), (pos), (next), (chain), \
h_hash)
-static struct host_table nlm_hosts = {
- .ht_mutex = __MUTEX_INITIALIZER(nlm_hosts.ht_mutex)
+static struct host_table nlm_clients = {
+ .ht_mutex = __MUTEX_INITIALIZER(nlm_clients.ht_mutex)
+};
+static struct host_table nlm_servers = {
+ .ht_mutex = __MUTEX_INITIALIZER(nlm_servers.ht_mutex)
};
static unsigned long next_gc;
@@ -158,8 +161,9 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
struct hlist_node *pos;
struct nlm_host *host;
struct nsm_handle *nsm;
+ struct host_table *table = ni->server ? &nlm_servers : &nlm_clients;
- mutex_lock(&nlm_hosts.ht_mutex);
+ mutex_lock(&table->ht_mutex);
if (time_after_eq(jiffies, next_gc))
nlm_gc_hosts();
@@ -171,17 +175,16 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
* different NLM rpc_clients into one single nlm_host object.
* This would allow us to have one nlm_host per address.
*/
- chain = &nlm_hosts.ht_chains[nlm_hash_address(ni->sap)];
+ chain = &table->ht_chains[nlm_hash_address(ni->sap)];
hlist_for_each_entry(host, pos, chain, h_hash) {
if (!nlm_cmp_addr(nlm_addr(host), ni->sap))
continue;
+ BUG_ON(host->h_server != ni->server); /* XXX */
if (host->h_proto != ni->protocol)
continue;
if (host->h_version != ni->version)
continue;
- if (host->h_server != ni->server)
- continue;
if (!nlm_cmp_addr(nlm_srcaddr(host), ni->src_sap))
continue;
@@ -237,7 +240,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
INIT_LIST_HEAD(&host->h_granted);
INIT_LIST_HEAD(&host->h_reclaim);
- nlm_hosts.ht_num++;
+ table->ht_num++;
nlm_display_address((struct sockaddr *)&host->h_addr,
host->h_addrbuf, sizeof(host->h_addrbuf));
@@ -248,7 +251,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
host->h_name);
out:
- mutex_unlock(&nlm_hosts.ht_mutex);
+ mutex_unlock(&table->ht_mutex);
return host;
}
@@ -540,15 +543,15 @@ void nlm_host_rebooted(const struct sockaddr_in *sin,
* lock for this.
* To avoid processing a host several times, we match the nsmstate.
*/
- while ((host = next_host_state(&nlm_hosts, nsm, new_state)) != NULL) {
- if (host->h_server) {
- /* We're server for this guy, just ditch
- * all the locks he held. */
- nlmsvc_free_host_resources(host);
- } else {
- /* He's the server, initiate lock recovery. */
- nlmclnt_recovery(host);
- }
+ while ((host = next_host_state(&nlm_servers, nsm, new_state)) != NULL) {
+ /* We're server for this guy, just ditch
+ * all the locks he held. */
+ nlmsvc_free_host_resources(host);
+ nlm_release_host(host);
+ }
+ while ((host = next_host_state(&nlm_clients, nsm, new_state)) != NULL) {
+ /* He's the server, initiate lock recovery. */
+ nlmclnt_recovery(host);
nlm_release_host(host);
}
}
@@ -617,18 +620,23 @@ void
nlm_shutdown_hosts(void)
{
dprintk("lockd: shutting down host module\n");
- mutex_lock(&nlm_hosts.ht_mutex);
+ mutex_lock(&nlm_servers.ht_mutex);
+ mutex_lock(&nlm_clients.ht_mutex);
/* First, make all hosts eligible for gc */
- expire_hosts(&nlm_hosts);
+ expire_hosts(&nlm_clients);
+ expire_hosts(&nlm_servers);
/* Then, perform a garbage collection pass */
nlm_gc_hosts();
- mutex_unlock(&nlm_hosts.ht_mutex);
+ mutex_unlock(&nlm_clients.ht_mutex);
+ mutex_unlock(&nlm_servers.ht_mutex);
/* complain if any hosts are left */
- if (nlm_hosts.ht_num)
- warn_host_leak(&nlm_hosts);
+ if (nlm_clients.ht_num)
+ warn_host_leak(&nlm_clients);
+ if (nlm_servers.ht_num)
+ warn_host_leak(&nlm_servers);
}
/*
@@ -644,13 +652,16 @@ nlm_gc_hosts(void)
struct nlm_host *host;
dprintk("lockd: host garbage collection\n");
- for_each_host(host, pos, chain, &nlm_hosts)
+ for_each_host(host, pos, chain, &nlm_servers)
host->h_inuse = 0;
/* Mark all hosts that hold locks, blocks or shares */
nlmsvc_mark_resources();
- nlm_gc_table(&nlm_hosts);
+ nlm_gc_table(&nlm_servers);
+
+ /* Note client doesn't need mark/sweep logic: */
+ nlm_gc_table(&nlm_clients);
}
/*
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* [PATCH 12/12] lockd: remove redundant rpc_shutdown_client()
2008-11-05 20:06 ` [PATCH 11/12] lockd: split client and server host lists J. Bruce Fields
@ 2008-11-05 20:06 ` J. Bruce Fields
2008-11-06 12:17 ` Jeff Layton
[not found] ` <20081106071733.6d4983ce@barsoom .rdu.redhat.com>
0 siblings, 2 replies; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 20:06 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs, J. Bruce Fields
These clients will all be shut down by nlm_destroy_host() when we do
garbage collection a little later, so this is redundant.
XXX: Ask Jeff Layton why he added this again?
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/host.c | 8 +-------
1 files changed, 1 insertions(+), 7 deletions(-)
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 73c2be2..0387c6b 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -602,14 +602,8 @@ static void expire_hosts(struct host_table *table)
struct hlist_node *pos;
struct nlm_host *host;
- dprintk("lockd: nuking all hosts...\n");
- for_each_host(host, pos, chain, table) {
+ for_each_host(host, pos, chain, table)
host->h_expires = jiffies - 1;
- if (host->h_rpcclnt) {
- rpc_shutdown_client(host->h_rpcclnt);
- host->h_rpcclnt = NULL;
- }
- }
}
/*
--
1.5.5.rc1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH 12/12] lockd: remove redundant rpc_shutdown_client()
2008-11-05 20:06 ` [PATCH 12/12] lockd: remove redundant rpc_shutdown_client() J. Bruce Fields
@ 2008-11-06 12:17 ` Jeff Layton
[not found] ` <20081106071733.6d4983ce@barsoom .rdu.redhat.com>
1 sibling, 0 replies; 42+ messages in thread
From: Jeff Layton @ 2008-11-06 12:17 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: Chuck Lever, linux-nfs, J. Bruce Fields
On Wed, 5 Nov 2008 15:06:51 -0500
"J. Bruce Fields" <bfields@citi.umich.edu> wrote:
> These clients will all be shut down by nlm_destroy_host() when we do
> garbage collection a little later, so this is redundant.
>
> XXX: Ask Jeff Layton why he added this again?
>
> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
> ---
> fs/lockd/host.c | 8 +-------
> 1 files changed, 1 insertions(+), 7 deletions(-)
>
> diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> index 73c2be2..0387c6b 100644
> --- a/fs/lockd/host.c
> +++ b/fs/lockd/host.c
> @@ -602,14 +602,8 @@ static void expire_hosts(struct host_table *table)
> struct hlist_node *pos;
> struct nlm_host *host;
>
> - dprintk("lockd: nuking all hosts...\n");
> - for_each_host(host, pos, chain, table) {
> + for_each_host(host, pos, chain, table)
> host->h_expires = jiffies - 1;
> - if (host->h_rpcclnt) {
> - rpc_shutdown_client(host->h_rpcclnt);
> - host->h_rpcclnt = NULL;
> - }
> - }
> }
>
> /*
Thank goodness for my OC commenting in the BZ I was using to track this!
https://bugzilla.redhat.com/show_bug.cgi?id=254195#c4
IIRC, there is a chicken and egg problem with refcounting -- at
least in the code at the time that I did this. If there is still
an active grant callback in queue at the time that nlm_shutdown_hosts
is called, the h_count will stay high and nlm_destroy_host won't be
called. This can happen if we try to bring down lockd while trying to
do a grant callback to an unresponsive client.
--
Jeff Layton <jlayton@redhat.com>
^ permalink raw reply [flat|nested] 42+ messages in thread[parent not found: <20081106071733.6d4983ce@barsoom .rdu.redhat.com>]
* Re: [PATCH 10/12] lockd: move immediate host expiry into separate function
2008-11-05 20:06 ` [PATCH 10/12] lockd: move immediate host expiry " J. Bruce Fields
2008-11-05 20:06 ` [PATCH 11/12] lockd: split client and server host lists J. Bruce Fields
@ 2008-11-05 22:33 ` Chuck Lever
1 sibling, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 22:33 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: linux-nfs
Not that this is a performance-critical path...
But it might be cleaner to create a helper that garbage collects a
single host, and then call that routine from a loop in both
nlm_shutdown_hosts() and nlm_gc_hosts(), instead of using a two pass
shutdown.
On Nov 5, 2008, at 3:06 PM, J. Bruce Fields wrote:
> This code will later be shared.
>
> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
> ---
> fs/lockd/host.c | 27 ++++++++++++++++-----------
> 1 files changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> index fa006af..588017f 100644
> --- a/fs/lockd/host.c
> +++ b/fs/lockd/host.c
> @@ -593,29 +593,34 @@ static void warn_host_leak(struct host_table
> *table)
> }
> }
>
> -/*
> - * Shut down the hosts module.
> - * Note that this routine is called only at server shutdown time.
> - */
> -void
> -nlm_shutdown_hosts(void)
> +static void expire_hosts(struct host_table *table)
> {
> struct hlist_head *chain;
> struct hlist_node *pos;
> struct nlm_host *host;
>
> - dprintk("lockd: shutting down host module\n");
> - mutex_lock(&nlm_hosts.ht_mutex);
> -
> - /* First, make all hosts eligible for gc */
> dprintk("lockd: nuking all hosts...\n");
> - for_each_host(host, pos, chain, &nlm_hosts) {
> + for_each_host(host, pos, chain, table) {
> host->h_expires = jiffies - 1;
> if (host->h_rpcclnt) {
> rpc_shutdown_client(host->h_rpcclnt);
> host->h_rpcclnt = NULL;
> }
> }
> +}
> +
> +/*
> + * Shut down the hosts module.
> + * Note that this routine is called only at server shutdown time.
> + */
> +void
> +nlm_shutdown_hosts(void)
> +{
> + dprintk("lockd: shutting down host module\n");
> + mutex_lock(&nlm_hosts.ht_mutex);
> +
> + /* First, make all hosts eligible for gc */
> + expire_hosts(&nlm_hosts);
>
> /* Then, perform a garbage collection pass */
> nlm_gc_hosts();
> --
> 1.5.5.rc1
>
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH 07/12] lockd: reorganize nlm_host_rebooted
2008-11-05 20:06 ` [PATCH 07/12] lockd: reorganize nlm_host_rebooted J. Bruce Fields
2008-11-05 20:06 ` [PATCH 08/12] lockd: move debugging warning into a separate function J. Bruce Fields
@ 2008-11-05 22:29 ` Chuck Lever
1 sibling, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 22:29 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: linux-nfs
On Nov 5, 2008, at 3:06 PM, J. Bruce Fields wrote:
> Minor reorganization; no change in behavior. This will save some
> duplicated code after we split apart the client and server host lists.
>
> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
> ---
> fs/lockd/host.c | 59 ++++++++++++++++++++++++++++++
> +-----------------------
> 1 files changed, 34 insertions(+), 25 deletions(-)
>
> diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> index 1b90b49..bb3bf36 100644
> --- a/fs/lockd/host.c
> +++ b/fs/lockd/host.c
> @@ -482,6 +482,31 @@ void nlm_release_host(struct nlm_host *host)
> }
> }
>
> +static struct nlm_host *next_host_state(struct host_table *table,
> + struct nsm_handle *nsm,
> + u32 new_state)
> +{
> + struct hlist_head *chain;
> + struct hlist_node *pos;
> + struct nlm_host *host = NULL;
> +
> + mutex_lock(&table->ht_mutex);
> + for_each_host(host, pos, chain, table) {
> + if (host->h_nsmhandle == nsm
> + && host->h_nsmstate != new_state) {
> + host->h_nsmstate = new_state;
> + host->h_state++;
> +
> + nlm_get_host(host);
> + mutex_unlock(&table->ht_mutex);
> + goto out;
If you exit here, you end up calling mutex_unlock() twice. Instead of
"goto out;", you could just "return host;"
>
> + }
> + }
> +out:
> + mutex_unlock(&table->ht_mutex);
> + return host;
> +}
>
> +
> /*
> * We were notified that the host indicated by address &sin
> * has rebooted.
> @@ -492,8 +517,6 @@ void nlm_host_rebooted(const struct sockaddr_in
> *sin,
> unsigned int hostname_len,
> u32 new_state)
> {
> - struct hlist_head *chain;
> - struct hlist_node *pos;
> struct nsm_handle *nsm;
> struct nlm_host *host;
>
> @@ -517,31 +540,17 @@ void nlm_host_rebooted(const struct
> sockaddr_in *sin,
> * lock for this.
> * To avoid processing a host several times, we match the nsmstate.
> */
> -again: mutex_lock(&nlm_hosts.ht_mutex);
> - for_each_host(host, pos, chain, &nlm_hosts) {
> - if (host->h_nsmhandle == nsm
> - && host->h_nsmstate != new_state) {
> - host->h_nsmstate = new_state;
> - host->h_state++;
> -
> - nlm_get_host(host);
> - mutex_unlock(&nlm_hosts.ht_mutex);
> -
> - if (host->h_server) {
> - /* We're server for this guy, just ditch
> - * all the locks he held. */
> - nlmsvc_free_host_resources(host);
> - } else {
> - /* He's the server, initiate lock recovery. */
> - nlmclnt_recovery(host);
> - }
> -
> - nlm_release_host(host);
> - goto again;
> + while ((host = next_host_state(&nlm_hosts, nsm, new_state)) !=
> NULL) {
> + if (host->h_server) {
> + /* We're server for this guy, just ditch
> + * all the locks he held. */
> + nlmsvc_free_host_resources(host);
> + } else {
> + /* He's the server, initiate lock recovery. */
> + nlmclnt_recovery(host);
> }
> + nlm_release_host(host);
> }
> -
> - mutex_unlock(&nlm_hosts.ht_mutex);
> }
>
> /*
> --
> 1.5.5.rc1
>
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH 05/12] lockd: encapsulate nlm_hosts table variables in one structure
2008-11-05 20:06 ` [PATCH 05/12] lockd: encapsulate nlm_hosts table variables in one structure J. Bruce Fields
2008-11-05 20:06 ` [PATCH 06/12] lockd: define host_for_each{_safe} macros J. Bruce Fields
@ 2008-11-05 22:25 ` Chuck Lever
2008-11-05 22:41 ` J. Bruce Fields
1 sibling, 1 reply; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 22:25 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: linux-nfs
On Nov 5, 2008, at 3:06 PM, J. Bruce Fields wrote:
> This will simplify splitting these variables into client and server
> sides.
>
> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
> ---
> fs/lockd/host.c | 46 ++++++++++++++++++++++++++--------------------
> 1 files changed, 26 insertions(+), 20 deletions(-)
>
> diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> index 1a1adb9..199ca8c 100644
> --- a/fs/lockd/host.c
> +++ b/fs/lockd/host.c
> @@ -26,10 +26,16 @@
> #define NLM_HOST_EXPIRE (300 * HZ)
> #define NLM_HOST_COLLECT (120 * HZ)
>
> -static struct hlist_head nlm_hosts[NLM_HOST_NRHASH];
> +struct host_table {
> + struct hlist_head ht_chains[NLM_HOST_NRHASH];
> + int ht_num;
> + struct mutex ht_mutex;
> +};
> +
> +static struct host_table nlm_hosts = {
> + .ht_mutex = __MUTEX_INITIALIZER(nlm_hosts.ht_mutex)
> +};
> static unsigned long next_gc;
I also moved next_gc into the host_table struct in my version of these
patches. Do we want to garbage collect the client and server host
caches separately? I'm not sure.
>
> -static int nrhosts;
> -static DEFINE_MUTEX(nlm_host_mutex);
>
> static void nlm_gc_hosts(void);
> static struct nsm_handle *nsm_find(const struct sockaddr *sap,
> @@ -140,7 +146,7 @@ static struct nlm_host *nlm_lookup_host(struct
> nlm_lookup_host_info *ni)
> struct nlm_host *host;
> struct nsm_handle *nsm;
>
> - mutex_lock(&nlm_host_mutex);
> + mutex_lock(&nlm_hosts.ht_mutex);
>
> if (time_after_eq(jiffies, next_gc))
> nlm_gc_hosts();
> @@ -152,7 +158,7 @@ static struct nlm_host *nlm_lookup_host(struct
> nlm_lookup_host_info *ni)
> * different NLM rpc_clients into one single nlm_host object.
> * This would allow us to have one nlm_host per address.
> */
> - chain = &nlm_hosts[nlm_hash_address(ni->sap)];
> + chain = &nlm_hosts.ht_chains[nlm_hash_address(ni->sap)];
> hlist_for_each_entry(host, pos, chain, h_hash) {
> if (!nlm_cmp_addr(nlm_addr(host), ni->sap))
> continue;
> @@ -218,7 +224,7 @@ static struct nlm_host *nlm_lookup_host(struct
> nlm_lookup_host_info *ni)
> INIT_LIST_HEAD(&host->h_granted);
> INIT_LIST_HEAD(&host->h_reclaim);
>
> - nrhosts++;
> + nlm_hosts.ht_num++;
>
> nlm_display_address((struct sockaddr *)&host->h_addr,
> host->h_addrbuf, sizeof(host->h_addrbuf));
> @@ -229,7 +235,7 @@ static struct nlm_host *nlm_lookup_host(struct
> nlm_lookup_host_info *ni)
> host->h_name);
>
> out:
> - mutex_unlock(&nlm_host_mutex);
> + mutex_unlock(&nlm_hosts.ht_mutex);
> return host;
> }
>
> @@ -498,8 +504,8 @@ void nlm_host_rebooted(const struct sockaddr_in
> *sin,
> * lock for this.
> * To avoid processing a host several times, we match the nsmstate.
> */
> -again: mutex_lock(&nlm_host_mutex);
> - for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; +
> +chain) {
> +again: mutex_lock(&nlm_hosts.ht_mutex);
> + for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains +
> NLM_HOST_NRHASH; ++chain) {
> hlist_for_each_entry(host, pos, chain, h_hash) {
> if (host->h_nsmhandle == nsm
> && host->h_nsmstate != new_state) {
> @@ -507,7 +513,7 @@ again: mutex_lock(&nlm_host_mutex);
> host->h_state++;
>
> nlm_get_host(host);
> - mutex_unlock(&nlm_host_mutex);
> + mutex_unlock(&nlm_hosts.ht_mutex);
>
> if (host->h_server) {
> /* We're server for this guy, just ditch
> @@ -524,7 +530,7 @@ again: mutex_lock(&nlm_host_mutex);
> }
> }
>
> - mutex_unlock(&nlm_host_mutex);
> + mutex_unlock(&nlm_hosts.ht_mutex);
> }
>
> /*
> @@ -539,11 +545,11 @@ nlm_shutdown_hosts(void)
> struct nlm_host *host;
>
> dprintk("lockd: shutting down host module\n");
> - mutex_lock(&nlm_host_mutex);
> + mutex_lock(&nlm_hosts.ht_mutex);
>
> /* First, make all hosts eligible for gc */
> dprintk("lockd: nuking all hosts...\n");
> - for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; +
> +chain) {
> + for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains +
> NLM_HOST_NRHASH; ++chain) {
> hlist_for_each_entry(host, pos, chain, h_hash) {
> host->h_expires = jiffies - 1;
> if (host->h_rpcclnt) {
> @@ -555,13 +561,13 @@ nlm_shutdown_hosts(void)
>
> /* Then, perform a garbage collection pass */
> nlm_gc_hosts();
> - mutex_unlock(&nlm_host_mutex);
> + mutex_unlock(&nlm_hosts.ht_mutex);
>
> /* complain if any hosts are left */
> - if (nrhosts) {
> + if (nlm_hosts.ht_num) {
> printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
> - dprintk("lockd: %d hosts left:\n", nrhosts);
> - for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; +
> +chain) {
> + dprintk("lockd: %d hosts left:\n", nlm_hosts.ht_num);
> + for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains +
> NLM_HOST_NRHASH; ++chain) {
> hlist_for_each_entry(host, pos, chain, h_hash) {
> dprintk(" %s (cnt %d use %d exp %ld)\n",
> host->h_name, atomic_read(&host->h_count),
> @@ -584,7 +590,7 @@ nlm_gc_hosts(void)
> struct nlm_host *host;
>
> dprintk("lockd: host garbage collection\n");
> - for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; +
> +chain) {
> + for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains +
> NLM_HOST_NRHASH; ++chain) {
> hlist_for_each_entry(host, pos, chain, h_hash)
> host->h_inuse = 0;
> }
> @@ -592,7 +598,7 @@ nlm_gc_hosts(void)
> /* Mark all hosts that hold locks, blocks or shares */
> nlmsvc_mark_resources();
>
> - for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; +
> +chain) {
> + for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains +
> NLM_HOST_NRHASH; ++chain) {
> hlist_for_each_entry_safe(host, pos, next, chain, h_hash) {
> if (atomic_read(&host->h_count) || host->h_inuse
> || time_before(jiffies, host->h_expires)) {
> @@ -605,7 +611,7 @@ nlm_gc_hosts(void)
> hlist_del_init(&host->h_hash);
>
> nlm_destroy_host(host);
> - nrhosts--;
> + nlm_hosts.ht_num--;
> }
> }
>
> --
> 1.5.5.rc1
>
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
^ permalink raw reply [flat|nested] 42+ messages in thread* Re: [PATCH 05/12] lockd: encapsulate nlm_hosts table variables in one structure
2008-11-05 22:25 ` [PATCH 05/12] lockd: encapsulate nlm_hosts table variables in one structure Chuck Lever
@ 2008-11-05 22:41 ` J. Bruce Fields
2008-11-05 23:11 ` Trond Myklebust
0 siblings, 1 reply; 42+ messages in thread
From: J. Bruce Fields @ 2008-11-05 22:41 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs
On Wed, Nov 05, 2008 at 05:25:40PM -0500, Chuck Lever wrote:
> On Nov 5, 2008, at 3:06 PM, J. Bruce Fields wrote:
>> This will simplify splitting these variables into client and server
>> sides.
>>
>> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
>> ---
>> fs/lockd/host.c | 46 ++++++++++++++++++++++++++--------------------
>> 1 files changed, 26 insertions(+), 20 deletions(-)
>>
>> diff --git a/fs/lockd/host.c b/fs/lockd/host.c
>> index 1a1adb9..199ca8c 100644
>> --- a/fs/lockd/host.c
>> +++ b/fs/lockd/host.c
>> @@ -26,10 +26,16 @@
>> #define NLM_HOST_EXPIRE (300 * HZ)
>> #define NLM_HOST_COLLECT (120 * HZ)
>>
>> -static struct hlist_head nlm_hosts[NLM_HOST_NRHASH];
>> +struct host_table {
>> + struct hlist_head ht_chains[NLM_HOST_NRHASH];
>> + int ht_num;
>> + struct mutex ht_mutex;
>> +};
>> +
>> +static struct host_table nlm_hosts = {
>> + .ht_mutex = __MUTEX_INITIALIZER(nlm_hosts.ht_mutex)
>> +};
>> static unsigned long next_gc;
>
> I also moved next_gc into the host_table struct in my version of these
> patches. Do we want to garbage collect the client and server host
> caches separately? I'm not sure.
I always figured we should get rid of the garbage collection entirely.
--b.
>
>>
>> -static int nrhosts;
>> -static DEFINE_MUTEX(nlm_host_mutex);
>>
>> static void nlm_gc_hosts(void);
>> static struct nsm_handle *nsm_find(const struct sockaddr *sap,
>> @@ -140,7 +146,7 @@ static struct nlm_host *nlm_lookup_host(struct
>> nlm_lookup_host_info *ni)
>> struct nlm_host *host;
>> struct nsm_handle *nsm;
>>
>> - mutex_lock(&nlm_host_mutex);
>> + mutex_lock(&nlm_hosts.ht_mutex);
>>
>> if (time_after_eq(jiffies, next_gc))
>> nlm_gc_hosts();
>> @@ -152,7 +158,7 @@ static struct nlm_host *nlm_lookup_host(struct
>> nlm_lookup_host_info *ni)
>> * different NLM rpc_clients into one single nlm_host object.
>> * This would allow us to have one nlm_host per address.
>> */
>> - chain = &nlm_hosts[nlm_hash_address(ni->sap)];
>> + chain = &nlm_hosts.ht_chains[nlm_hash_address(ni->sap)];
>> hlist_for_each_entry(host, pos, chain, h_hash) {
>> if (!nlm_cmp_addr(nlm_addr(host), ni->sap))
>> continue;
>> @@ -218,7 +224,7 @@ static struct nlm_host *nlm_lookup_host(struct
>> nlm_lookup_host_info *ni)
>> INIT_LIST_HEAD(&host->h_granted);
>> INIT_LIST_HEAD(&host->h_reclaim);
>>
>> - nrhosts++;
>> + nlm_hosts.ht_num++;
>>
>> nlm_display_address((struct sockaddr *)&host->h_addr,
>> host->h_addrbuf, sizeof(host->h_addrbuf));
>> @@ -229,7 +235,7 @@ static struct nlm_host *nlm_lookup_host(struct
>> nlm_lookup_host_info *ni)
>> host->h_name);
>>
>> out:
>> - mutex_unlock(&nlm_host_mutex);
>> + mutex_unlock(&nlm_hosts.ht_mutex);
>> return host;
>> }
>>
>> @@ -498,8 +504,8 @@ void nlm_host_rebooted(const struct sockaddr_in
>> *sin,
>> * lock for this.
>> * To avoid processing a host several times, we match the nsmstate.
>> */
>> -again: mutex_lock(&nlm_host_mutex);
>> - for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; +
>> +chain) {
>> +again: mutex_lock(&nlm_hosts.ht_mutex);
>> + for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains +
>> NLM_HOST_NRHASH; ++chain) {
>> hlist_for_each_entry(host, pos, chain, h_hash) {
>> if (host->h_nsmhandle == nsm
>> && host->h_nsmstate != new_state) {
>> @@ -507,7 +513,7 @@ again: mutex_lock(&nlm_host_mutex);
>> host->h_state++;
>>
>> nlm_get_host(host);
>> - mutex_unlock(&nlm_host_mutex);
>> + mutex_unlock(&nlm_hosts.ht_mutex);
>>
>> if (host->h_server) {
>> /* We're server for this guy, just ditch
>> @@ -524,7 +530,7 @@ again: mutex_lock(&nlm_host_mutex);
>> }
>> }
>>
>> - mutex_unlock(&nlm_host_mutex);
>> + mutex_unlock(&nlm_hosts.ht_mutex);
>> }
>>
>> /*
>> @@ -539,11 +545,11 @@ nlm_shutdown_hosts(void)
>> struct nlm_host *host;
>>
>> dprintk("lockd: shutting down host module\n");
>> - mutex_lock(&nlm_host_mutex);
>> + mutex_lock(&nlm_hosts.ht_mutex);
>>
>> /* First, make all hosts eligible for gc */
>> dprintk("lockd: nuking all hosts...\n");
>> - for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; +
>> +chain) {
>> + for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains +
>> NLM_HOST_NRHASH; ++chain) {
>> hlist_for_each_entry(host, pos, chain, h_hash) {
>> host->h_expires = jiffies - 1;
>> if (host->h_rpcclnt) {
>> @@ -555,13 +561,13 @@ nlm_shutdown_hosts(void)
>>
>> /* Then, perform a garbage collection pass */
>> nlm_gc_hosts();
>> - mutex_unlock(&nlm_host_mutex);
>> + mutex_unlock(&nlm_hosts.ht_mutex);
>>
>> /* complain if any hosts are left */
>> - if (nrhosts) {
>> + if (nlm_hosts.ht_num) {
>> printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
>> - dprintk("lockd: %d hosts left:\n", nrhosts);
>> - for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; +
>> +chain) {
>> + dprintk("lockd: %d hosts left:\n", nlm_hosts.ht_num);
>> + for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains +
>> NLM_HOST_NRHASH; ++chain) {
>> hlist_for_each_entry(host, pos, chain, h_hash) {
>> dprintk(" %s (cnt %d use %d exp %ld)\n",
>> host->h_name, atomic_read(&host->h_count),
>> @@ -584,7 +590,7 @@ nlm_gc_hosts(void)
>> struct nlm_host *host;
>>
>> dprintk("lockd: host garbage collection\n");
>> - for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; +
>> +chain) {
>> + for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains +
>> NLM_HOST_NRHASH; ++chain) {
>> hlist_for_each_entry(host, pos, chain, h_hash)
>> host->h_inuse = 0;
>> }
>> @@ -592,7 +598,7 @@ nlm_gc_hosts(void)
>> /* Mark all hosts that hold locks, blocks or shares */
>> nlmsvc_mark_resources();
>>
>> - for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; +
>> +chain) {
>> + for (chain = nlm_hosts.ht_chains; chain < nlm_hosts.ht_chains +
>> NLM_HOST_NRHASH; ++chain) {
>> hlist_for_each_entry_safe(host, pos, next, chain, h_hash) {
>> if (atomic_read(&host->h_count) || host->h_inuse
>> || time_before(jiffies, host->h_expires)) {
>> @@ -605,7 +611,7 @@ nlm_gc_hosts(void)
>> hlist_del_init(&host->h_hash);
>>
>> nlm_destroy_host(host);
>> - nrhosts--;
>> + nlm_hosts.ht_num--;
>> }
>> }
>>
>> --
>> 1.5.5.rc1
>>
>
> --
> Chuck Lever
> chuck[dot]lever[at]oracle[dot]com
>
>
>
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH 04/12] lockd: unmonitor only when last host goes away
2008-11-05 20:06 ` [PATCH 04/12] lockd: unmonitor only when last host goes away J. Bruce Fields
2008-11-05 20:06 ` [PATCH 05/12] lockd: encapsulate nlm_hosts table variables in one structure J. Bruce Fields
@ 2008-11-05 22:22 ` Chuck Lever
1 sibling, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 22:22 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: linux-nfs
On Nov 5, 2008, at 3:06 PM, J. Bruce Fields wrote:
> The sm_sticky logic seems racy;
Can you describe what races you suspect?
> instead just unmonitor before destruction of handle.
>
> XXX: how to test?
Would this allow the nsm_handle cache to grow large on long-running
hosts?
Instead of sm_sticky, maybe we should put a "don't unmonitor" flag in
the nlm_host structure instead.
> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
> ---
> fs/lockd/host.c | 24 ++++++++++++++++++++----
> fs/lockd/mon.c | 15 +--------------
> fs/lockd/svcsubs.c | 6 ------
> include/linux/lockd/lockd.h | 3 +--
> 4 files changed, 22 insertions(+), 26 deletions(-)
>
> diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> index e9069c2..1a1adb9 100644
> --- a/fs/lockd/host.c
> +++ b/fs/lockd/host.c
> @@ -683,6 +683,10 @@ found:
> return nsm;
> }
>
> +
> +/* XXX: */
> +int nsm_mon_unmon(struct nsm_handle *, u32, struct nsm_res *);
> +
> /*
> * Release an NSM handle
> */
> @@ -691,9 +695,21 @@ nsm_release(struct nsm_handle *nsm)
> {
> if (!nsm)
> return;
> - if (atomic_dec_and_lock(&nsm->sm_count, &nsm_lock)) {
> - list_del(&nsm->sm_link);
> - spin_unlock(&nsm_lock);
> - kfree(nsm);
> + if (!atomic_dec_and_lock(&nsm->sm_count, &nsm_lock))
> + return;
> + list_del(&nsm->sm_link);
> + spin_unlock(&nsm_lock);
> + if (nsm->sm_monitored) {
> + struct nsm_res res;
> + int status;
> +
> + dprintk("lockd: nsm_unmonitor(%s)\n", nsm->sm_name);
> + status = nsm_mon_unmon(nsm, SM_UNMON, &res);
> + if (status < 0)
> + printk(KERN_NOTICE "lockd: cannot unmonitor %s\n",
> + nsm->sm_name);
> + else
> + nsm->sm_monitored = 0;
> }
> + kfree(nsm);
> }
> diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c
> index 480f197..8cc0e97 100644
> --- a/fs/lockd/mon.c
> +++ b/fs/lockd/mon.c
> @@ -32,7 +32,7 @@ int nsm_local_state;
> /*
> * Common procedure for SM_MON/SM_UNMON calls
> */
> -static int
> +int
> nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res)
> {
> struct rpc_clnt *clnt;
>
> @@ -100,24 +100,11 @@ nsm_monitor(struct nlm_host *host)
> void nsm_unmonitor(struct nlm_host *host)
> {
> struct nsm_handle *nsm = host->h_nsmhandle;
> - struct nsm_res res;
> - int status;
>
> if (nsm == NULL)
> return;
> host->h_nsmhandle = NULL;
>
> - if (atomic_read(&nsm->sm_count) == 1
> - && nsm->sm_monitored && !nsm->sm_sticky) {
> - dprintk("lockd: nsm_unmonitor(%s)\n", host->h_name);
> -
> - status = nsm_mon_unmon(nsm, SM_UNMON, &res);
> - if (status < 0)
> - printk(KERN_NOTICE "lockd: cannot unmonitor %s\n",
> - host->h_name);
> - else
> - nsm->sm_monitored = 0;
> - }
> nsm_release(nsm);
> }
>
> diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c
> index 9c186f0..0296904 100644
> --- a/fs/lockd/svcsubs.c
> +++ b/fs/lockd/svcsubs.c
> @@ -336,12 +336,6 @@ nlmsvc_is_client(void *data, struct nlm_host
> *dummy)
> struct nlm_host *host = data;
>
> BUG_ON(!host->h_server);
> - /* we are destroying locks even though the client
> - * hasn't asked us too, so don't unmonitor the
> - * client
> - */
> - if (host->h_nsmhandle)
> - host->h_nsmhandle->sm_sticky = 1;
> return 1;
>
> }
> diff --git a/include/linux/lockd/lockd.h b/include/linux/lockd/lockd.h
> index b56d5aa..e1c2690 100644
> --- a/include/linux/lockd/lockd.h
> +++ b/include/linux/lockd/lockd.h
> @@ -75,8 +75,7 @@ struct nsm_handle {
> char * sm_name;
> struct sockaddr_storage sm_addr;
> size_t sm_addrlen;
> - unsigned int sm_monitored : 1,
> - sm_sticky : 1; /* don't unmonitor */
> + unsigned int sm_monitored : 1;
> char sm_addrbuf[48]; /* address eyecatcher */
> };
>
> --
> 1.5.5.rc1
>
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH 03/12] lockd: fix nsm_unmonitor return value
2008-11-05 20:06 ` [PATCH 03/12] lockd: fix nsm_unmonitor return value J. Bruce Fields
2008-11-05 20:06 ` [PATCH 04/12] lockd: unmonitor only when last host goes away J. Bruce Fields
@ 2008-11-05 22:14 ` Chuck Lever
1 sibling, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 22:14 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: linux-nfs
On Nov 5, 2008, at 3:06 PM, J. Bruce Fields wrote:
> Note that the only caller of nsm_unmonitor has no use for its return
> value.
I noticed this too.
It might be cleaner if we passed the nsm_handle by itself as the
argument to nsm_{un}monitor. h_name actually points to the name in
the nsm_handle.
>
>
> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
> ---
> fs/lockd/mon.c | 8 +++-----
> include/linux/lockd/sm_inter.h | 2 +-
> 2 files changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c
> index 4e7e958..480f197 100644
> --- a/fs/lockd/mon.c
> +++ b/fs/lockd/mon.c
> @@ -97,15 +97,14 @@ nsm_monitor(struct nlm_host *host)
> /*
> * Cease to monitor remote host
> */
> -int
> -nsm_unmonitor(struct nlm_host *host)
> +void nsm_unmonitor(struct nlm_host *host)
> {
> struct nsm_handle *nsm = host->h_nsmhandle;
> struct nsm_res res;
> - int status = 0;
> + int status;
>
> if (nsm == NULL)
> - return 0;
> + return;
> host->h_nsmhandle = NULL;
>
> if (atomic_read(&nsm->sm_count) == 1
> @@ -120,7 +119,6 @@ nsm_unmonitor(struct nlm_host *host)
> nsm->sm_monitored = 0;
> }
> nsm_release(nsm);
> - return status;
> }
>
> /*
> diff --git a/include/linux/lockd/sm_inter.h b/include/linux/lockd/
> sm_inter.h
> index 5a5448b..b069598 100644
> --- a/include/linux/lockd/sm_inter.h
> +++ b/include/linux/lockd/sm_inter.h
> @@ -42,7 +42,7 @@ struct nsm_res {
> };
>
> int nsm_monitor(struct nlm_host *);
> -int nsm_unmonitor(struct nlm_host *);
> +void nsm_unmonitor(struct nlm_host *);
> extern int nsm_local_state;
>
> #endif /* LINUX_LOCKD_SM_INTER_H */
> --
> 1.5.5.rc1
>
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH 01/12] lockd: fix inconsistent use of nsm_use_hostnames
2008-11-05 20:06 ` [PATCH 01/12] lockd: fix inconsistent use of nsm_use_hostnames J. Bruce Fields
2008-11-05 20:06 ` [PATCH 02/12] lockd: kill redundant host->h_server check J. Bruce Fields
@ 2008-11-05 22:10 ` Chuck Lever
1 sibling, 0 replies; 42+ messages in thread
From: Chuck Lever @ 2008-11-05 22:10 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: linux-nfs
On Nov 5, 2008, at 3:06 PM, J. Bruce Fields wrote:
> In nlm_lookup_host() there's an optimization that looks for matching
> nsm
> handles at the same time as looking for hosts, so that if a host
> isn't found but a matching nsm handle is, we save a second lookup for
> the nsm handle.
>
> The optimization (unlike nsm_find()) ignores nsm_use_hostnames, so may
> give incorrect results when that parameter is set.
I don't think that's a problem here. There's only one nsm_handle per
peer address. "nsm_use_hostnames" determines how to communicate with
the local statd, so it shouldn't make any difference how we pick an
nsm_handle that matches this nlm_host.
> We could probably
> find some way to fix this and keep the optimization, but it seems
> unlikely to be very significant, so just skip it entirely.
>
> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
> ---
> fs/lockd/host.c | 23 +++++++----------------
> 1 files changed, 7 insertions(+), 16 deletions(-)
>
> diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> index 9fd8889..e9069c2 100644
> --- a/fs/lockd/host.c
> +++ b/fs/lockd/host.c
> @@ -138,7 +138,7 @@ static struct nlm_host *nlm_lookup_host(struct
> nlm_lookup_host_info *ni)
> struct hlist_head *chain;
> struct hlist_node *pos;
> struct nlm_host *host;
> - struct nsm_handle *nsm = NULL;
> + struct nsm_handle *nsm;
>
> mutex_lock(&nlm_host_mutex);
>
> @@ -157,10 +157,6 @@ static struct nlm_host *nlm_lookup_host(struct
> nlm_lookup_host_info *ni)
> if (!nlm_cmp_addr(nlm_addr(host), ni->sap))
> continue;
>
> - /* See if we have an NSM handle for this client */
> - if (!nsm)
> - nsm = host->h_nsmhandle;
> -
> if (host->h_proto != ni->protocol)
> continue;
> if (host->h_version != ni->version)
> @@ -184,17 +180,12 @@ static struct nlm_host *nlm_lookup_host(struct
> nlm_lookup_host_info *ni)
> * The host wasn't in our hash table. If we don't
> * have an NSM handle for it yet, create one.
> */
> - if (nsm)
> - atomic_inc(&nsm->sm_count);
I've always found this slightly confusing. If we grab the nsm handle
above in the loop, shouldn't we bump the refcount there?
Anyway, I like the idea of having only one way to acquire the
nsm_handle for this host, exactly because it keeps our refcount
management more straightforward.
>
> - else {
> - host = NULL;
> - nsm = nsm_find(ni->sap, ni->salen,
> - ni->hostname, ni->hostname_len, 1);
> - if (!nsm) {
> - dprintk("lockd: nlm_lookup_host failed; "
> - "no nsm handle\n");
> - goto out;
> - }
> + host = NULL;
> + nsm = nsm_find(ni->sap, ni->salen, ni->hostname, ni->hostname_len,
> 1);
> + if (!nsm) {
I've tried to stick with (nsm == NULL) instead, since nsm isn't a
boolean, it's a pointer.
>
> + dprintk("lockd: nlm_lookup_host failed; "
> + "no nsm handle\n");
> + goto out;
> }
>
> host = kzalloc(sizeof(*host), GFP_KERNEL);
>
> --
> 1.5.5.rc1
>
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
^ permalink raw reply [flat|nested] 42+ messages in thread