User: Password:
|
|
Subscribe / Log in / New account

Can we admit that sysfs was a really bad idea?

Can we admit that sysfs was a really bad idea?

Posted Mar 17, 2010 19:25 UTC (Wed) by quotemstr (subscriber, #45331)
Parent article: A critical look at sysfs attribute values

This article identifies more problems with sysfs, mainly that it's beginning to suffer from the kind of cancer that afflicted procfs. Between the inconsistent formatting, atomicity problems, and awkward shell use*, can we finally concede that sysfs was a Bad Idea, and that something like sysctl works just as well while being safer, more consistent, and more elegant?

* Try using sudo to modify a sysctl value: you have to use something like sudo sh -c 'echo foo > /sys/bar' instead of a nice simple sudo sysctl bar=5'


(Log in to post comments)

Can we admit that sysfs was a really bad idea?

Posted Mar 17, 2010 20:27 UTC (Wed) by daniel (guest, #3181) [Link]

"Try using sudo to modify a sysctl value: you have to use something like sudo sh -c 'echo foo > /sys/bar' instead of a nice simple sudo sysctl bar=5'"

maybe try: echo foo | sudo tee /sys/bar

Can we admit that sysfs was a really bad idea?

Posted Mar 17, 2010 20:29 UTC (Wed) by farnz (subscriber, #17727) [Link]

FWIW (and this isn't a disagreement), I use echo foo | sudo tee /sys/bar to do that job. It's still not elegant, but it's a little easier to type than sudo sh -c 'echo foo > /sys/bar'.

Can we admit that sysfs was a really bad idea?

Posted Mar 18, 2010 0:05 UTC (Thu) by mpee (subscriber, #37530) [Link]

No. It's a pretty good idea, with a few warts.

If typing all those extra characters is really causing you pain, you can
write yourself a "sysfssyctl" script in about 4 lines.

Can we admit that sysfs was a really bad idea?

Posted Mar 18, 2010 2:39 UTC (Thu) by glikely (subscriber, #39601) [Link]

There is another aspect to sysfs which this article doesn't address, and that is the purpose of sysfs in the first place. Sysfs' primary job is to provide a user space readable representation of the Linux object model, and methods to manipulate it. udev in particular uses it to make decisions about what to do when new device are registered into the system (ie. add device files). The sysfs design reflects the boundaries of the problem it is intended to solve.

Sysfs is not intended to be the primary interface to a device. Nor is it intended to be a kernel configuration mechanism. A fair few drivers do use it in that capacity and a lot of the time there isn't anything strictly evil about that, but that usage is peripheral to the primary purpose. It certainly doesn't replace sysctl.

If questions about access atomicity or formatting of large data arise then I strongly suspect that the sysfs interface is being abused and that a char device or debugfs file would be a more appropriate choice.

Can we admit that sysfs was a really bad idea?

Posted Mar 18, 2010 11:13 UTC (Thu) by dgm (subscriber, #49227) [Link]

> It certainly doesn't replace sysctl.

Well, according to Wikipedia it does indeed. sysctl is implemented on top of sysfs and procfs.

Can we admit that sysfs was a really bad idea?

Posted Mar 22, 2010 22:02 UTC (Mon) by neilbrown (subscriber, #359) [Link]

The wikipedia article is wrong in several respects. "sysctl" and "sysfs" are independent concepts that attempt to address somewhat similar goals. sysctl is a "mangement information base" to which access is provided through the /proc filesystem. It may be that some values accessible through sysctl (i.e. /proc/sys) are also accessible through /sys, but that is certainly not the norm.

Can we admit that sysfs was a really bad idea?

Posted Mar 18, 2010 11:16 UTC (Thu) by michaeljt (subscriber, #39183) [Link]

>Sysfs is not intended to be the primary interface to a device. Nor is it intended to be a kernel
>configuration mechanism.
[snip]
>If questions about access atomicity or formatting of large data arise then I strongly suspect
>that the sysfs interface is being abused and that a char device or debugfs file would be a
>more appropriate choice.
As someone who has had to fiddle with sysfs in userspace recently I can only second that.

Can we admit that sysfs was a really bad idea?

Posted Mar 22, 2010 22:08 UTC (Mon) by neilbrown (subscriber, #359) [Link]

I would genuinely like to hear more about the problems and issues you experienced. My own belief is that, independent of any intentions to the contrary, sysfs is the de-facto primary interface to devices for configuration (though not for data transfer), and we would be well served by making it fit that role well. To do that we need to understand the problems.

Can we admit that sysfs was a really bad idea?

Posted Mar 25, 2010 4:34 UTC (Thu) by glikely (subscriber, #39601) [Link]

Heh. I was writing a driver a few years back (not mainlined) and completely ignored all the good advice I got about using a normal char dev to control my simple device. Instead I implemented a novel set of sysfs files for obtaining the state of the device. One file was written to chose the channel to read, and another file to read the measurement back. Nice and simple to manipulate from the shell for debug, but a complete disaster in real-world use cases. (ie. two processes cannot read from the device at the same time).

I completely abused sysfs in my driver. It was the wrong interface for actually interacting with the device, and I ended up rewriting the interface in the end. In this case the problems and issues were very much of my own making. :-)

Anytime I hear complaints about sysfs atomicity it raises a red flag for me and I wonder if it is a similar situation of using sysfs for IO instead of mere configuration. Using sysfs for IO is in a lot of cases broken.

I spoke to quickly in my earlier comment. Yes, you're right. sysfs has become the natural configuration interface for a lot of devices, and it suits that job very well. However, I still say that it doesn't replace sysctl for the non-device-centric configuration knobs (ie. the ip stack).

Can we admit that sysfs was a really bad idea?

Posted Mar 25, 2010 10:03 UTC (Thu) by michaeljt (subscriber, #39183) [Link]

I suppose my usage case was a bit special - I had to write code that would
enumerate and get information on devices that would run on as wide a
range of Linux-based systems as possible. Getting information out of sysfs
in a way that is fully backwards-compatible while still being future-proof
proved to be rather hard. In the end, by minimising the use I made of sysfs
to just the most basic device enumeration - the original purpose of sysfs
after all - I was able to write code that worked from early single-digit 2.6
kernels up to current ones, and with some slightly hacky extensions even
worked on all 2.4 series kernels I tried.

Can we admit that sysfs was a really bad idea?

Posted Mar 22, 2010 21:54 UTC (Mon) by neilbrown (subscriber, #359) [Link]

I think that it is a very big step to go from "it has some problems" to "it is a bad idea". To my mind sysfs has a lot of strengths.

And sysctl really isn't measurably better. check out dev/cdrom/info (in /proc/sys). If sysctl has fewer problems it is only because it has substantially less content.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds