public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Andi Kleen <andi@firstfloor.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	viro@ZenIV.linux.org.uk, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] ioctl: generic ioctl dispatcher
Date: Tue, 30 Sep 2008 12:08:32 +0300	[thread overview]
Message-ID: <48E1EC90.9010301@redhat.com> (raw)
In-Reply-To: <87od26q3d8.fsf@basil.nowhere.org>

Andi Kleen wrote:
> Avi Kivity <avi@redhat.com> writes:
>
>   
>> +long dispatch_ioctl(struct inode *inode, struct file *filp,
>> +		    unsigned cmd, unsigned long arg,
>> +		    const struct ioctl_handler *handlers,
>> +		    long (*fallback)(const struct ioctl_arg *arg))
>>     
>
> The basic idea is good, but i don't like the proliferation of callbacks,
> which tends to make complicated code and is ugly for simple code
> (which a lot of ioctls are)
>
>   

If the simple calls mostly don't use the argument as a pointer, they are 
better off using a plain switch.  For my own code, I usually leave the 
boilerplate within the switch and the app-specific code in a separate 
function anyway, so there's no big change in style.

The main motivation here was the extensibility (patch 2), which becomes 
much more difficult with a switch.

> How about you make it return an number that can index a switch() instead?
> Then everything could be still kept in the same function.
>
>   

We need to execute code both before and after the handler, so it would 
look pretty ugly:

long my_ioctl_handler(...)
{
    struct ioctl_arg iarg;
    ...
    long ret;

    ret = dispatch_ioctl_begin(&iarg, ...);
    if (ret < 0)
        return ret;
    switch (ret) {
          case _IOC_KEY(MY_IOCTL):
               // your stuff goes here
               break;
          ...
    }
    dispatch_ioctl_end(&iarg, ret);
    return ret;
}

The only clean way to do this without callbacks is with 
constructors/destructors, but we don't have those in C.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


  reply	other threads:[~2008-09-30  9:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-27 15:43 [PATCH 0/3][RFC] ioctl dispatcher Avi Kivity
2008-09-27 15:44 ` [PATCH 1/3] ioctl: generic " Avi Kivity
2008-09-29 17:16   ` Andi Kleen
2008-09-30  9:08     ` Avi Kivity [this message]
2008-09-27 15:44 ` [PATCH 2/3] ioctl: extensible ioctl dispatch Avi Kivity
2008-09-27 15:44 ` [PATCH 3/3] KVM: Convert x86 vcpu ioctls to use dispatch_ioctl_extensible() Avi Kivity
2008-09-27 16:13 ` [PATCH 0/3][RFC] ioctl dispatcher Arjan van de Ven
2008-09-27 17:40   ` Avi Kivity

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=48E1EC90.9010301@redhat.com \
    --to=avi@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    --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