Re: [PATCH 1/3] ioctl: generic ioctl dispatcher

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Avi Kivity
Date: Tuesday, September 30, 2008 - 2:08 am

Andi Kleen wrote:

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.


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.

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/3][RFC] ioctl dispatcher, Avi Kivity, (Sat Sep 27, 8:43 am)
[PATCH 1/3] ioctl: generic ioctl dispatcher, Avi Kivity, (Sat Sep 27, 8:44 am)
[PATCH 2/3] ioctl: extensible ioctl dispatch, Avi Kivity, (Sat Sep 27, 8:44 am)
Re: [PATCH 0/3][RFC] ioctl dispatcher, Arjan van de Ven, (Sat Sep 27, 9:13 am)
Re: [PATCH 0/3][RFC] ioctl dispatcher, Avi Kivity, (Sat Sep 27, 10:40 am)
Re: [PATCH 1/3] ioctl: generic ioctl dispatcher, Andi Kleen, (Mon Sep 29, 10:16 am)
Re: [PATCH 1/3] ioctl: generic ioctl dispatcher, Avi Kivity, (Tue Sep 30, 2:08 am)