2013/2/8 Martin Sustrik <sustrik@xxxxxxxxxx>: > 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@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html