[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAHXqBFKpByeeLPD5ibDxTW94wsLA3hSnqhakZ_8YQO_BDT7ruQ@mail.gmail.com>
Date: Fri, 15 Feb 2013 03:45:20 +0100
From: Michał Mirosław <mirqus@...il.com>
To: Martin Sustrik <sustrik@...bpm.com>
Cc: Alexander Viro <viro@...iv.linux.org.uk>,
Andrew Morton <akpm@...ux-foundation.org>,
Sha Zhengju <handai.szj@...bao.com>,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
netdev@...r.kernel.org
Subject: Re: [PATCH 1/1] eventfd: implementation of EFD_MASK flag
2013/2/8 Martin Sustrik <sustrik@...bpm.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 netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists