From: "Michał Mirosław" <mirqus@gmail.com>
To: Martin Sustrik <sustrik@250bpm.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Sha Zhengju <handai.szj@taobao.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org
Subject: Re: [PATCH 1/1] eventfd: implementation of EFD_MASK flag
Date: Fri, 15 Feb 2013 03:45:20 +0100 [thread overview]
Message-ID: <CAHXqBFKpByeeLPD5ibDxTW94wsLA3hSnqhakZ_8YQO_BDT7ruQ@mail.gmail.com> (raw)
In-Reply-To: <1360279763-4768-1-git-send-email-sustrik@250bpm.com>
2013/2/8 Martin Sustrik <sustrik@250bpm.com>:
> When implementing network protocols in user space, one has to implement
> fake user-space file descriptors to represent the sockets for the protocol.
[...]
> This patch implements new EFD_MASK flag which attempts to solve this problem.
[...]
> @@ -55,6 +64,9 @@ __u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n)
> {
> unsigned long flags;
>
> + /* This function should never be used with eventfd in the mask mode. */
> + BUG_ON(ctx->flags & EFD_MASK);
> +
> spin_lock_irqsave(&ctx->wqh.lock, flags);
> if (ULLONG_MAX - ctx->count < n)
> n = ULLONG_MAX - ctx->count;
> @@ -123,12 +135,16 @@ static unsigned int eventfd_poll(struct file *file, poll_table *wait)
> poll_wait(file, &ctx->wqh, wait);
>
> spin_lock_irqsave(&ctx->wqh.lock, flags);
> - if (ctx->count > 0)
> - events |= POLLIN;
> - if (ctx->count == ULLONG_MAX)
> - events |= POLLERR;
> - if (ULLONG_MAX - 1 > ctx->count)
> - events |= POLLOUT;
> + if (ctx->flags & EFD_MASK) {
> + events = ctx->mask.events;
> + } else {
> + if (ctx->count > 0)
> + events |= POLLIN;
> + if (ctx->count == ULLONG_MAX)
> + events |= POLLERR;
> + if (ULLONG_MAX - 1 > ctx->count)
> + events |= POLLOUT;
> + }
> spin_unlock_irqrestore(&ctx->wqh.lock, flags);
>
> return events;
[...]
> @@ -412,7 +464,12 @@ struct file *eventfd_file_create(unsigned int count, int flags)
>
> kref_init(&ctx->kref);
> init_waitqueue_head(&ctx->wqh);
> - ctx->count = count;
> + if (flags & EFD_MASK) {
> + ctx->mask.events = 0;
> + ctx->mask.ptr = NULL;
> + } else {
> + ctx->count = count;
> + }
> ctx->flags = flags;
>
> file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx,
Since EFD_MASK is a persistent flag for a fd's lifetime, maybe you
could instead of all those if/elses and BUG_ON()s use another
file_operations struct for this feature?
Best Regards,
Michał Mirosław
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2013-02-15 2:45 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-07 23:29 [PATCH 1/1] eventfd: implementation of EFD_MASK flag Martin Sustrik
2013-02-15 2:45 ` Michał Mirosław [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-02-07 6:41 Martin Sustrik
2013-02-07 19:12 ` Andy Lutomirski
2013-02-07 20:11 ` Martin Sustrik
2013-02-08 1:03 ` Andy Lutomirski
2013-02-08 5:26 ` Martin Sustrik
2013-02-08 6:36 ` Andy Lutomirski
2013-02-08 6:55 ` Martin Sustrik
2013-02-08 22:08 ` Eric Wong
2013-02-09 3:26 ` Martin Sustrik
2013-02-07 22:44 ` Andrew Morton
2013-02-07 23:30 ` Martin Sustrik
2013-02-08 12:43 ` Martin Sustrik
2013-02-08 22:21 ` Eric Wong
2013-02-09 2:40 ` Martin Sustrik
2013-02-09 3:54 ` Eric Wong
2013-02-09 7:36 ` Martin Sustrik
2013-02-09 11:51 ` Eric Wong
2013-02-09 12:04 ` Martin Sustrik
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=CAHXqBFKpByeeLPD5ibDxTW94wsLA3hSnqhakZ_8YQO_BDT7ruQ@mail.gmail.com \
--to=mirqus@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=handai.szj@taobao.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sustrik@250bpm.com \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).