mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: NeilBrown <neilb@suse.de>
Cc: nfs@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 009 of 9] knfsd: Allow sockets to be passed to nfsd via 'portlist'
Date: Tue, 25 Jul 2006 23:53:09 -0700	[thread overview]
Message-ID: <20060725235309.8f30b28f.akpm@osdl.org> (raw)
In-Reply-To: <1060725015508.22007@suse.de>

On Tue, 25 Jul 2006 11:55:08 +1000
NeilBrown <neilb@suse.de> wrote:

> 
> Userspace should create and bind a socket (but not connectted)
> and write the 'fd' to portlist.  This will cause the nfs server
> to listen on that socket.
> 
> To close a socket, the name of the socket - as read from 'portlist'
> can be written to 'portlist' with a preceding '-'.
> 

ick.  Is that the best API we can come up with?

It's a privileged operation, but heck.  Do we perform validation on the fd
to make sure that it's refers to a socket and not to /dev/fb0?

>  static ssize_t write_ports(struct file *file, char *buf, size_t size)
>  {
> -	/* for now, ignore what was written and just
> -	 * return known ports
> -	 * AF proto address port
> +	if (size == 0) {
> +		int len = 0;
> +		lock_kernel();
> +		if (nfsd_serv)
> +			len = svc_sock_names(buf, nfsd_serv, NULL);
> +		unlock_kernel();
> +		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.
>  	 */
> -	int len = 0;
> -	lock_kernel();
> -	if (nfsd_serv)
> -		len = svc_sock_names(buf, nfsd_serv);
> -	unlock_kernel();
> -	return len;
> +	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) {
> +			int proto = 0;
> +			err = svc_addsock(nfsd_serv, fd, buf, &proto);
> +			/* Decrease the count, but don't shutdown the
> +			 * the service
> +			 */
> +			if (err >= 0)
> +				lockd_up(proto);
> +			nfsd_serv->sv_nrthreads--;
> +		}
> +		return err;
> +	}
> +	if (buf[0] == '-') {
> +		char *toclose = kstrdup(buf+1, GFP_KERNEL);
> +		int len = 0;
> +		if (!toclose)
> +			return -ENOMEM;
> +		lock_kernel();
> +		if (nfsd_serv)
> +			len = svc_sock_names(buf, nfsd_serv, toclose);
> +		unlock_kernel();
> +		kfree(toclose);
> +		return len;
> +	}
> +	return -EINVAL;
>  }

<checks>

OK, simple_transaction_get() guarantees that *buf is null-terminated.  It
might be worth a comment to stop code-reviewers from freaking out ;)


  reply	other threads:[~2006-07-26  6:53 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-25  1:54 [PATCH 000 of 9] knfsd: Introduction NeilBrown
2006-07-25  1:54 ` [PATCH 001 of 9] knfsd: knfsd: Add some missing newlines in printks NeilBrown
2006-07-25  1:54 ` [PATCH 002 of 9] knfsd: knfsd: Remove an unused variable from e_show() NeilBrown
2006-07-25  4:10   ` Josef Sipek
2006-07-25  4:20     ` Neil Brown
2006-07-25  4:24       ` [NFS] " Greg Banks
2006-07-25  4:32       ` Greg Banks
2006-07-25  4:36         ` Neil Brown
2006-07-25  5:53         ` Greg Banks
2006-07-25  1:54 ` [PATCH 003 of 9] knfsd: knfsd: Remove an unused variable from auth_unix_lookup() NeilBrown
2006-07-25  1:54 ` [PATCH 004 of 9] knfsd: Add a callback for when last rpc thread finishes NeilBrown
2006-07-25  1:54 ` [PATCH 005 of 9] knfsd: Be more selective in which sockets lockd listens on NeilBrown
2006-07-26 19:17   ` [NFS] " J. Bruce Fields
2006-07-28  2:32     ` Neil Brown
2006-07-25  1:54 ` [PATCH 006 of 9] knfsd: Remove nfsd_versbits as intermediate storage for desired versions NeilBrown
2006-07-26 19:34   ` [NFS] " J. Bruce Fields
2006-07-25  1:54 ` [PATCH 007 of 9] knfsd: Separate out some parts of nfsd_svc, which start nfs servers NeilBrown
2006-07-26  6:42   ` Andrew Morton
2006-07-25  1:55 ` [PATCH 008 of 9] knfsd: Define new nfsdfs file: portlist - contains list of ports NeilBrown
2006-07-25  1:55 ` [PATCH 009 of 9] knfsd: Allow sockets to be passed to nfsd via 'portlist' NeilBrown
2006-07-26  6:53   ` Andrew Morton [this message]
2006-07-26 20:41   ` [NFS] " 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=20060725235309.8f30b28f.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=nfs@lists.sourceforge.net \
    /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

all inboxes | Powered by JetHome®