All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Matt Helsley <matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: Re: [PATCH 1/3] Checkpoint/restart epoll sets
Date: Tue, 20 Oct 2009 19:31:28 -0500	[thread overview]
Message-ID: <20091021003128.GA23721@us.ibm.com> (raw)
In-Reply-To: <ce2e15faf44e254b80578c6c62e71d8685516896.1255971848.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

Quoting Matt Helsley (matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org):
> @@ -1226,35 +1242,18 @@ SYSCALL_DEFINE1(epoll_create, int, size)
>   * the eventpoll file that enables the insertion/removal/change of
>   * file descriptors inside the interest set.
>   */
> -SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
> -		struct epoll_event __user *, event)
> +int do_epoll_ctl(int op, int fd,
> +		 struct file *file, struct file *tfile,
> +		 struct epoll_event *epds)
>  {
>  	int error;
> -	struct file *file, *tfile;
>  	struct eventpoll *ep;
>  	struct epitem *epi;
> -	struct epoll_event epds;
> -
> -	error = -EFAULT;
> -	if (ep_op_has_event(op) &&
> -	    copy_from_user(&epds, event, sizeof(struct epoll_event)))
> -		goto error_return;
> -
> -	/* Get the "struct file *" for the eventpoll file */
> -	error = -EBADF;
> -	file = fget(epfd);
> -	if (!file)
> -		goto error_return;
> -
> -	/* Get the "struct file *" for the target file */
> -	tfile = fget(fd);
> -	if (!tfile)
> -		goto error_fput;
> 
>  	/* The target file descriptor must support poll */
>  	error = -EPERM;
>  	if (!tfile->f_op || !tfile->f_op->poll)
> -		goto error_tgt_fput;
> +		return error;
> 
>  	/*
>  	 * We have to check that the file structure underneath the file descriptor
> @@ -1263,7 +1262,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
>  	 */
>  	error = -EINVAL;
>  	if (file == tfile || !is_file_epoll(file))
> -		goto error_tgt_fput;
> +		return error;
> 
>  	/*
>  	 * At this point it is safe to assume that the "private_data" contains
> @@ -1284,8 +1283,8 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
>  	switch (op) {
>  	case EPOLL_CTL_ADD:
>  		if (!epi) {
> -			epds.events |= POLLERR | POLLHUP;
> -			error = ep_insert(ep, &epds, tfile, fd);
> +			epds->events |= POLLERR | POLLHUP;
> +			error = ep_insert(ep, epds, tfile, fd);
>  		} else
>  			error = -EEXIST;
>  		break;
> @@ -1297,15 +1296,46 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
>  		break;
>  	case EPOLL_CTL_MOD:
>  		if (epi) {
> -			epds.events |= POLLERR | POLLHUP;
> -			error = ep_modify(ep, epi, &epds);
> +			epds->events |= POLLERR | POLLHUP;
> +			error = ep_modify(ep, epi, epds);
>  		} else
>  			error = -ENOENT;
>  		break;
>  	}
>  	mutex_unlock(&ep->mtx);
> 
> -error_tgt_fput:
> +	return error;
> +}
> +
> +/*
> + * The following function implements the controller interface for
> + * the eventpoll file that enables the insertion/removal/change of
> + * file descriptors inside the interest set.
> + */
> +SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
> +		struct epoll_event __user *, event)
> +{
> +	int error;
> +	struct file *file, *tfile;
> +	struct epoll_event epds;
> +
> +	error = -EFAULT;
> +	if (ep_op_has_event(op) &&
> +	    copy_from_user(&epds, event, sizeof(struct epoll_event)))
> +		goto error_return;
> +
> +	/* Get the "struct file *" for the eventpoll file */
> +	error = -EBADF;
> +	file = fget(epfd);
> +	if (!file)
> +		goto error_return;
> +
> +	/* Get the "struct file *" for the target file */
> +	tfile = fget(fd);
> +	if (!tfile)
> +		goto error_fput;
> +
> +	error = do_epoll_ctl(op, fd, file, tfile, &epds);
>  	fput(tfile);
>  error_fput:
>  	fput(file);

(Just figured I'd do a sanity check of this code)  looks ok to me

...

> +struct file* ep_file_restore(struct ckpt_ctx *ctx,
> +			     struct ckpt_hdr_file *h)
> +{
> +	struct file *epfile;
> +	int epfd, ret;
> +
> +	if (h->h.type != CKPT_HDR_FILE ||
> +	    h->h.len  != sizeof(*h) ||
> +	    h->f_type != CKPT_FILE_EPOLL)
> +		return ERR_PTR(-EINVAL);
> +
> +	epfd = sys_epoll_create1(h->f_flags & EPOLL_CLOEXEC);
> +	if (epfd < 0)
> +		return ERR_PTR(epfd);
> +	epfile = fget(epfd);
> +	sys_close(epfd); /* harmless even if an error occured */
> +	BUG_ON(!epfile);

Would perhaps return ERR_PTR(-ENOENT) be nicer?  (And maybe safer - I'm
not quite clear on under which arches BUG_ON does nothing).

> +
> +	/*
> +	 * Needed before we can properly restore the watches and enforce the
> +	 * limit on watch numbers.
> +	 */
> +	ret = restore_file_common(ctx, epfile, h);
> +	if (ret < 0)
> +		goto fput_out;
> +
> +	/*
> +	 * Defer restoring the epoll items until the file table is
> +	 * fully restored. Ensures that valid file objrefs will resolve.
> +	 */
> +	ret = deferqueue_add_ptr(ctx->files_deferq, ctx, ep_items_restore, NULL);
> +	if (ret < 0) {
> +fput_out:
> +		fput(epfile);
> +		epfile = ERR_PTR(ret);
> +	}
> +	return epfile;
> +}
> +
> +#endif /* CONFIG_CHECKPOINT */
> +
>  static int __init eventpoll_init(void)
>  {
>  	struct sysinfo si;
> diff --git a/include/linux/checkpoint_hdr.h b/include/linux/checkpoint_hdr.h
> index ca2500d..1a3edab 100644
> --- a/include/linux/checkpoint_hdr.h
> +++ b/include/linux/checkpoint_hdr.h
> @@ -119,6 +119,8 @@ enum {
>  #define CKPT_HDR_TTY CKPT_HDR_TTY
>  	CKPT_HDR_TTY_LDISC,
>  #define CKPT_HDR_TTY_LDISC CKPT_HDR_TTY_LDISC
> +	CKPT_HDR_EPOLL_ITEMS = 391, /* Follows file-table */

What is the comment supposed to mean (other than that such
comments inevitably become stale :)?

-serge

  parent reply	other threads:[~2009-10-21  0:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-19 17:04 [PATCH 1/3] Checkpoint/restart epoll sets Matt Helsley
     [not found] ` <ce2e15faf44e254b80578c6c62e71d8685516896.1255971848.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-19 17:04   ` [PATCH 2/3] epoll: Add support for checkpointing large numbers of epoll items Matt Helsley
     [not found]     ` <d0fd1f3eb4eaa326488f59955e5b4790080f3073.1255971848.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-21 14:59       ` Serge E. Hallyn
     [not found]         ` <20091021145950.GA13327-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-22  6:40           ` Matt Helsley
     [not found]             ` <20091022064007.GG7757-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2009-10-23 23:54               ` Oren Laadan
2009-10-23 23:51       ` Oren Laadan
2009-10-23 23:58       ` Oren Laadan
     [not found]         ` <4AE24340.9030203-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-10-24  4:32           ` Matt Helsley
2009-10-19 17:04   ` [PATCH 3/3] epoll: Add support for restoring many " Matt Helsley
     [not found]     ` <8e4344b801150b95cd54f2d09b660525601de256.1255971848.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-21 15:09       ` Serge E. Hallyn
2009-10-23 23:56       ` Oren Laadan
2009-10-21  0:31   ` Serge E. Hallyn [this message]
     [not found]     ` <20091021003128.GA23721-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-22  6:29       ` [PATCH 1/3] Checkpoint/restart epoll sets Matt Helsley
     [not found]         ` <20091022062909.GF7757-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2009-10-22 14:02           ` Serge E. Hallyn
2009-10-23 23:30       ` Oren Laadan
2009-10-23 23:41   ` Oren Laadan

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=20091021003128.GA23721@us.ibm.com \
    --to=serue-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.