From: "J. Bruce Fields" <bfields@fieldses.org>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: aime.le-rouzic@bull.net, linux-nfs@vger.kernel.org
Subject: Re: [PATCH 05/22] NFSD: Add helper functions for __write_ports()
Date: Wed, 24 Dec 2008 23:15:23 -0500 [thread overview]
Message-ID: <20081225041523.GA17998@fieldses.org> (raw)
In-Reply-To: <20081212215742.24332.36578.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
On Fri, Dec 12, 2008 at 04:57:42PM -0500, Chuck Lever wrote:
> 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.
As stated in http://marc.info/?l=linux-nfs&m=122894134032274&w=2, I'd
prefer that new code be introduced with its callers where reasonable, so
in this case I'd rather this patch be combined with the following.
One question:
> +/*
> + * 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--;
Behavior on the error path seems slightly different here than in the
original code, which did the sv_nrthreads-- even when svc_addsock
failed. Could you check which is right? If the existing code is wrong,
could you break out the fix into a separate patch?
> +
> + 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;
I understand it's inherited from the original code, but the
error-handling logic seems a bit silly; e.g., the "err" variable isn't
really used. Why not:
if (port == 0 || nfsd_serv == NULL)
return -EINVAL;
xprt = svc_find_xprt(...)
if (!xprt)
return -ENOTCONN;
svc_close_xprt(xprt);
svc_xprt_put(xprt);
return 0;
?
This patch and the following look good otherwise.
--b.
> +}
> +
> static ssize_t __write_ports(struct file *file, char *buf, size_t size)
> {
> if (size == 0) {
>
next prev parent reply other threads:[~2008-12-25 4:15 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-12 21:57 [PATCH 00/22] IPv6 support NFSD Chuck Lever
[not found] ` <20081212215340.24332.88416.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-12 21:57 ` [PATCH 01/22] NFSD: clean up failover sysctl function naming Chuck Lever
2008-12-12 21:57 ` [PATCH 02/22] NFSD: Fix a handful of coding style issues in write_filehandle() Chuck Lever
2008-12-12 21:57 ` [PATCH 03/22] NFSD: Replace open-coded integer with macro Chuck Lever
2008-12-12 21:57 ` [PATCH 04/22] NFSD: Add documenting comments for nfsctl interface Chuck Lever
2008-12-12 21:57 ` [PATCH 05/22] NFSD: Add helper functions for __write_ports() Chuck Lever
[not found] ` <20081212215742.24332.36578.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-25 4:15 ` J. Bruce Fields [this message]
2008-12-29 17:04 ` Chuck Lever
2008-12-29 18:42 ` J. Bruce Fields
2008-12-12 21:57 ` [PATCH 06/22] NFSD: Refactor __write_ports() Chuck Lever
2008-12-12 21:57 ` [PATCH 07/22] NFSD: Prevent a buffer overflow in svc_xprt_names() Chuck Lever
[not found] ` <20081212215757.24332.77904.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-25 4:32 ` J. Bruce Fields
2008-12-12 21:58 ` [PATCH 08/22] SUNRPC: pass buffer size to svc_addsock() and svc_sock_names() Chuck Lever
[not found] ` <20081212215804.24332.24605.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-14 17:33 ` Tom Tucker
2008-12-15 16:40 ` Chuck Lever
2008-12-15 21:05 ` Tom Tucker
2008-12-15 21:17 ` J. Bruce Fields
2008-12-25 4:43 ` J. Bruce Fields
2008-12-29 19:24 ` Chuck Lever
2008-12-30 19:38 ` J. Bruce Fields
2008-12-12 21:58 ` [PATCH 09/22] SUNRPC: Switch one_sock_name() to use snprintf() Chuck Lever
2008-12-12 21:58 ` [PATCH 10/22] SUNRPC: Support AF_INET6 in one_sock_name() Chuck Lever
2008-12-12 21:58 ` [PATCH 11/22] SUNRPC: Clean up one_sock_name() Chuck Lever
2008-12-12 21:58 ` [PATCH 12/22] NFSD: Support AF_INET6 in svc_addsock() function Chuck Lever
2008-12-12 21:58 ` [PATCH 13/22] NFS: Move NFS client's IP address parser to nfs_common/ Chuck Lever
[not found] ` <20081212215842.24332.47093.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-25 4:47 ` J. Bruce Fields
2008-12-12 21:58 ` [PATCH 14/22] NFSD: Support IPv6 addresses in write_failover_ip() Chuck Lever
2008-12-12 21:58 ` [PATCH 15/22] NFSD: Enable NFS server use of AF_INET6 Chuck Lever
2008-12-12 21:59 ` [PATCH 16/22] NFSD: Prevent buffer overflow in write_threads() Chuck Lever
2008-12-12 21:59 ` [PATCH 17/22] NFSD: Prevent buffer overflow in write_versions() Chuck Lever
2008-12-12 21:59 ` [PATCH 18/22] NFSD: Prevent buffer overflow in write_maxblksize() Chuck Lever
2008-12-12 21:59 ` [PATCH 19/22] NFSD: Prevent buffer overflow in write_leasetime() Chuck Lever
2008-12-12 21:59 ` [PATCH 20/22] NFSD: Prevent buffer overflow in write_recoverydir() Chuck Lever
2008-12-12 21:59 ` [PATCH 21/22] NLM: Refactor make_socks() function Chuck Lever
2008-12-12 21:59 ` [PATCH 22/22] NLM: Clean up flow of control in " Chuck Lever
2008-12-16 16:53 ` [PATCH 00/22] IPv6 support NFSD J. Bruce Fields
2008-12-25 5:01 ` J. Bruce Fields
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081225041523.GA17998@fieldses.org \
--to=bfields@fieldses.org \
--cc=aime.le-rouzic@bull.net \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox