public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* ioctl's suck?
@ 2008-08-02 21:54 Brian Beattie
  2008-08-03  1:18 ` Mikael Pettersson
  2008-08-03 12:56 ` Alan Cox
  0 siblings, 2 replies; 5+ messages in thread
From: Brian Beattie @ 2008-08-02 21:54 UTC (permalink / raw)
  To: linux-kernel

The other day Linus (I think) made the statement, that I don't disagree
with, that I will parapharse as "ioctl's suck".  If I recall correctly
and understand he was saying that a device that uses ioctls is broken.
(this is my paraphrase and if it offends anybody it is my fault not the
original author's).

This got me to thinking about a device driver that I'm working on.
Currently I have some ioctls to handle status and out of band messages
and I'm wondering about eliminating the ioctls.  I'm wondering if
anybody has any ideas or opinions that they would like to share, about
just what i wrong with ioctls and/or how to avoid them.

I can see a number of problems with ioctls that I can'tr quite put into
words.

I could add a control device and pass ascii strings for status and OOB
messages, would that be an improvement?
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting a bad thing?

Brian Beattie   LFS12947 | "Honor isn't about making the right choices.
beattie@beattie-home.net | It's about dealing with the consequences."
www.beattie-home.net     | -- Midori Koto



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ioctl's suck?
  2008-08-02 21:54 Brian Beattie
@ 2008-08-03  1:18 ` Mikael Pettersson
  2008-08-03 12:56 ` Alan Cox
  1 sibling, 0 replies; 5+ messages in thread
From: Mikael Pettersson @ 2008-08-03  1:18 UTC (permalink / raw)
  To: Brian Beattie; +Cc: linux-kernel

Brian Beattie writes:
 > The other day Linus (I think) made the statement, that I don't disagree
 > with, that I will parapharse as "ioctl's suck".  If I recall correctly
 > and understand he was saying that a device that uses ioctls is broken.
...
 > I could add a control device and pass ascii strings for status and OOB
 > messages, would that be an improvement?

The problem is that the classical unix I/O abstraction really only handles
two cases well, viz. "read next chunk of data" and "write this data and
advance position". Anything else is seen as something strange.

ioctls() are the equivalent of device-specific RPCs (remote procedure
calls): you present some arguments and a call code, and you get some
results. Nothing wrong with that.

In practice however there are some pitfalls. For instance, ioctls()
are often abused for quick hacks with little concern for backwards
compatibility. So when someone changes an ioctl, and breaks user-space,
who gets the blame? ioctls in general! I would argue that that is
why, and the main reason why, some people put ioctls() down.

There may be something wrong with people abusing ioctls, but that
is not a problem with ioctls per se. (I can easily design broken
ABIs around read()/write()/open()-only interfaces.)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ioctl's suck?
       [not found] <fa.pDV0CxkUWw00OFrnybFqbUSeaQA@ifi.uio.no>
@ 2008-08-03  1:36 ` Robert Hancock
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Hancock @ 2008-08-03  1:36 UTC (permalink / raw)
  To: Brian Beattie; +Cc: linux-kernel

Brian Beattie wrote:
> The other day Linus (I think) made the statement, that I don't disagree
> with, that I will parapharse as "ioctl's suck".  If I recall correctly
> and understand he was saying that a device that uses ioctls is broken.
> (this is my paraphrase and if it offends anybody it is my fault not the
> original author's).
> 
> This got me to thinking about a device driver that I'm working on.
> Currently I have some ioctls to handle status and out of band messages
> and I'm wondering about eliminating the ioctls.  I'm wondering if
> anybody has any ideas or opinions that they would like to share, about
> just what i wrong with ioctls and/or how to avoid them.

As I see it the main problems are:

-Unless the ioctl parameter structures are laid out carefully, you end 
up with problems like different structure layouts between 32/64-bit 
processes, etc.

-They can't really be used by anything other than a C or C++ program. 
Anything else (shell script, Python, Java, etc.) is pretty much out of 
luck unless it can use a C shim layer of some sort.

> 
> I can see a number of problems with ioctls that I can'tr quite put into
> words.
> 
> I could add a control device and pass ascii strings for status and OOB
> messages, would that be an improvement?

Quite likely. For something like a status that's being read out of the 
device, a sysfs file would seem a more logical choice. If you're sitting 
there waiting for messages to show up, though, a separate device node 
might be better.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ioctl's suck?
  2008-08-02 21:54 Brian Beattie
  2008-08-03  1:18 ` Mikael Pettersson
@ 2008-08-03 12:56 ` Alan Cox
  2008-08-03 17:04   ` Brian Beattie
  1 sibling, 1 reply; 5+ messages in thread
From: Alan Cox @ 2008-08-03 12:56 UTC (permalink / raw)
  To: Brian Beattie; +Cc: linux-kernel

> I could add a control device and pass ascii strings for status and OOB
> messages, would that be an improvement?

Usually not. The idea that ioctl can be replaced with ascii messages is
clueless rubbish that generally gets spouted by people with their head
in the clouds of conceptual elegance and no grasp of reality.

There are certain things you can expose that way usefully via sysfs
- things like general stateless status information. Ioctl however provides
an interface tied to file handle not name (which is essential in a hotplug
environment) and an ordering to events so you know the response you get
matches the query you made.

There are good things to do with ioctls:
- Make sure the size of all the fields are consistent across 32/64bit
(for 32bit binaries on 64bit)
- Use the IOR/IOW/IORW macros

Alan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ioctl's suck?
  2008-08-03 12:56 ` Alan Cox
@ 2008-08-03 17:04   ` Brian Beattie
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Beattie @ 2008-08-03 17:04 UTC (permalink / raw)
  To: Alan Cox; +Cc: linux-kernel

On Sun, 2008-08-03 at 13:56 +0100, Alan Cox wrote:
> > I could add a control device and pass ascii strings for status and OOB
> > messages, would that be an improvement?
> 
> Usually not. The idea that ioctl can be replaced with ascii messages is
> clueless rubbish that generally gets spouted by people with their head
> in the clouds of conceptual elegance and no grasp of reality.

Yeah, I can see that.  Though the case has been made that ioctls are
only usable by C/C++ while I'm sure there are other languages, I'm
working in the embedded space and mostly work with C and sh so my
experience is limited and that is of less direct importance to me.

> 
> There are certain things you can expose that way usefully via sysfs
> - things like general stateless status information. Ioctl however provides
> an interface tied to file handle not name (which is essential in a hotplug
> environment) and an ordering to events so you know the response you get
> matches the query you made.

Yeah coherence (if I'm using that word correctly) would be critical, and
a separate file handle would make that tricky.


> Alan
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting a bad thing?

Brian Beattie   LFS12947 | "Honor isn't about making the right choices.
beattie@beattie-home.net | It's about dealing with the consequences."
www.beattie-home.net     | -- Midori Koto


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-08-03 17:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <fa.pDV0CxkUWw00OFrnybFqbUSeaQA@ifi.uio.no>
2008-08-03  1:36 ` ioctl's suck? Robert Hancock
2008-08-02 21:54 Brian Beattie
2008-08-03  1:18 ` Mikael Pettersson
2008-08-03 12:56 ` Alan Cox
2008-08-03 17:04   ` Brian Beattie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox