public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: Flaw in the driver-model implementation of attributes
@ 2003-06-19  0:06 Clayton Weaver
  2003-06-19  0:20 ` Kevin P. Fleming
  0 siblings, 1 reply; 46+ messages in thread
From: Clayton Weaver @ 2003-06-19  0:06 UTC (permalink / raw)
  To: linux-kernel

(Doubting that there is a sysfs faq anywhere
yet, ...)

What is a sysfs "class", as in /sys/class/...?

What do sysfs classes have in common? How is
a /sys/class/ different from a /sys/devices,
/sys/bus, etc?

In re: the current discussion, are the "usb-storage" attributes under discussion
something that the vfs would need to know
about(/sys/block/)? Something that a pci
bus would need to know about? Something that
a usb controller would need to know about?

Vfs models are virtual, so vfs having its
own sysfs tree for block devices does not
create any confusion relative to an
organization based on the the hardware
connection tree in the machine.

But when you are considering where to place
attributes meant to be evaluated by low-level
hardware drivers, it is easier to follow if the
organization follows a

  bus (ie pci, for example)
    host-controller/mux
      bus
        device
          [bus
            device...]

organization. (The bracketed branch is for a
cascade or bridge device.)

So how does "class" fit into that model?
Does it signify a domain of buses, a set
of bus attributes (should be under the
"/sysfs/bustype/busnum/" in that case),
a set of controller attributes, a set
of device attributes, or some software
abstraction like block or char device
attributes?

Regards,

Clayton Weaver
<mailto: cgweav@email.com>


-- 
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

CareerBuilder.com has over 400,000 jobs. Be smarter about your job search
http://corp.mail.com/careers



^ permalink raw reply	[flat|nested] 46+ messages in thread
* RE: Flaw in the driver-model implementation of attributes
@ 2003-06-19 21:18 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 46+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-06-19 21:18 UTC (permalink / raw)
  To: 'Alan Stern', 'Patrick Mochel'
  Cc: 'Greg KH',
	'viro@parcelfarce.linux.theplanet.co.uk',
	'Kevin P. Fleming', 'Russell King',
	'Mike Anderson', 'linux-kernel@vger.kernel.org'

> From: Alan Stern [mailto:stern@rowland.harvard.edu]
> 
> On Thu, 19 Jun 2003, Patrick Mochel wrote:
> 
> > SCSI copied USB in this respect. I've always been skeptical about the
> > representation, though Greg had good reason to initially do this. I
wonder
> > if that object could be moved over /sys/class/usb-host/ these days..
> 
> I wonder about the apparent proliferation of entries under /sys/class/.
> If people continue to add things like /sys/class/usb-storage/ right at the
> top level, won't it become rather unwieldy?  What would be a good place to
> put something like that?

That was exactly my point with the "it-should-go-where-the-
physical-device-is" suggestion. /sys/class will become something
as wild as /proc is now IANF.

Iñaky Pérez-González -- Not speaking for Intel -- all opinions are my own
(and my fault)

^ permalink raw reply	[flat|nested] 46+ messages in thread
* RE: Flaw in the driver-model implementation of attributes
@ 2003-06-18 19:52 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 46+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-06-18 19:52 UTC (permalink / raw)
  To: 'viro@parcelfarce.linux.theplanet.co.uk',
	Perez-Gonzalez, Inaky
  Cc: 'Kevin P. Fleming', 'Alan Stern',
	'Patrick Mochel', 'Russell King',
	'Greg KH', 'linux-kernel@vger.kernel.org'

> From: viro@parcelfarce.linux.theplanet.co.uk
[mailto:viro@parcelfarce.linux.theplanet.co.uk]
> 
> > So what? _every_ block device will have some form of physical
> > back-up that can be linked back into sysfs.
> 
> ... except ones that will not.  Wonderful.  I bow to that logics - there
> is nothing it wouldn't cover.

Thank you }:) - we like it or not, data goes somewhere.

> > In the tree structure it makes sense, because each block
> > device, at the end is or a partition (and thus is embedded
> > in a "true" block device) or a true block device on a 1:1
> > relationship with a physical device.
> 
> BS.  There is nothing to stop you from having a block device that talks
> to userland process instead of any form of hardware.  As the matter of
> fact, we already have such a beast - nbd.  There is also RAID - where

Sure, there: /sys/devices/"virtual"/nbd/0

> there fsck is 1:1 here?  There's also such thing as RAID5 over partitions
> that sit on several disks - where do you see 1:1 or 1:n or n:1?

/sys/devices/"virtual"/raid/0

> There is such thing as e.g. encrypted loop over NFS.  There are all
> sorts of interesting things, with all sorts of interesting relationship
> to some pieces of hardware.

/sys/devices/"virtual"/loopback/0

Don't you have to do "-o loop" when you mount a loopback?
... same thing happens with nbd and RAID, you have to 
tell the kernel to create the actual devices (or it 
does); that they show up nowhere in sysfs (yet) is different.

Iñaky Pérez-González -- Not speaking for Intel -- all opinions are my own
(and my fault)

^ permalink raw reply	[flat|nested] 46+ messages in thread
* RE: Flaw in the driver-model implementation of attributes
@ 2003-06-18  7:48 Perez-Gonzalez, Inaky
  2003-06-18  8:12 ` viro
  0 siblings, 1 reply; 46+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-06-18  7:48 UTC (permalink / raw)
  To: 'viro@parcelfarce.linux.theplanet.co.uk',
	Perez-Gonzalez, Inaky
  Cc: 'Kevin P. Fleming', 'Alan Stern',
	'Patrick Mochel', 'Russell King',
	'Greg KH', 'linux-kernel@vger.kernel.org'

> From: viro@parcelfarce.linux.theplanet.co.uk
> On Tue, Jun 17, 2003 at 08:44:50PM -0700, Perez-Gonzalez, Inaky wrote:
> 
> > Maybe this is going to kill my argument as an analogy, but think
> > about a C++ class hierarchy, where belonging to a class means
> > ...
> 
> But there is no inheritance here.  Block device and IDE disk are
> different objects and relation is not "A is B with <...>", it's
> "among other things, A happens to use B in a way <...>".

Well, the device is an IDE disk that is linked through an IDE 
controller that is linked through a PCI controller to the system bus. 

That IDE device presents an interface. The block layer just presents 
the common interface that all block devices present (and that IDE
and SCSI disks are able to provide) - there is no inheritance, but
the concept is the same.
 
> Moreover, there is no such thing as "physical device 
> of that block device". There might be many.  There 
> might be none.  IOW, we have a bunch of constructors 
> for class "block device" and some of them happen to have
> some kinds of physical devices among their arguments. 

[I happen not to know the block layer as well as you and many others 
do, so please correct me where I am wrong ...]

So what? _every_ block device will have some form of physical 
back-up that can be linked back into sysfs.

In cases like this, doesn't it make sense to have some 
/sys/devices/SOMETHING/ hierarchy for those  "logical" or "virtual" 
devices that back-up those block devices? 

You could even say that RAID and ramdisks -as used in the example 
above- would belong to /sys/devices/"virtual"/raid/ and 
...../ramdisks/; after all, you have to create those devices before
being able to attach them (last time I checked):

(using subdirs for each layer for clarity)

/sys/devices/"virtual"/raid/0
  attr1
  attr2     ...   sysfs specific attrs 
  block/    ... block layer specific attrs
    attr1
    attr2
    component1 -> /sys/devices/pci/FOO/block/part1  
    component1 -> /sys/devices/pci/BAR/block/part4  

(I would also love to see the block device node being dropped in 
the corresponding "block" directory, but that's another story).

And extrapolating even more, I'd expect to see something 
like this for the block devices that are part of a physical device 
(partitions, I mean):

/sys/blabla/pci/3.14159/ide0/0.0
  attr1
  attr2     ...   sysfs specific attrs 
  block/    ... block layer specific attrs
    attr1
    attr2  
    part0/  ... partition specific stuff
      attr1
      attr...
    part1/
      attr1
      attr2 ...
  ide/      ... ide layer specific attrs
    attr1
    attr2 

In the tree structure it makes sense, because each block
device, at the end is or a partition (and thus is embedded
in a "true" block device) or a true block device on a 1:1
relationship with a physical device.

Iñaky Pérez-González -- Not speaking for Intel -- all opinions are my own
(and my fault)

^ permalink raw reply	[flat|nested] 46+ messages in thread
* RE: Flaw in the driver-model implementation of attributes
@ 2003-06-18  3:44 Perez-Gonzalez, Inaky
  2003-06-18  4:18 ` viro
  0 siblings, 1 reply; 46+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-06-18  3:44 UTC (permalink / raw)
  To: 'Kevin P. Fleming', 'Alan Stern'
  Cc: 'Patrick Mochel', 'Russell King',
	'Greg KH', 'linux-kernel@vger.kernel.org'

> From: Kevin P. Fleming [mailto:kpfleming@cox.net]
>
> These are two wildly differing views, but yes, they are the same device.
> These differing attributes do _not_ belong in the same directory. An
> application looking at your IDE devices does not really care how the
> block subsystem perceives those devices (i.e. hdparm). Conversely, an
> application looking at your block devices should not care about what
> underlying physical devices (if any :-) they are associated with. 

But that is describing a physical mapping vs. a logical view.

I can think of many different "views" I want to see (IDE, block,
physical, block sorted by size, the ones who are green and sing 
in Basque...) but only one is unique and inherently defined: the
physical one. 

I guess I agree with Alan; I'd prefer something like:

/sys/devices/pci0/0000:00:07.1/ide0/0.0/
  attr1
  attr2 ...   sysfs specific attrs 
  block-attr1
  block-attr2 ... block layer specific attrs
  ide-attr1
  ide-attr2 ... ide layer specific attrs

(or make that TAG- a subdirectory of the device if you wish,
that is just an example). 

This way, for each device I have an *unique* location where to
track it, and an easy way to hunt down attributes specific to
each layer that controls it.

And when, when I want to make logical views (again, by IDE, by
block device ...), I can do that from user space and create a
tree full of symlinks to the unique, physical locations.

Maybe this is going to kill my argument as an analogy, but think
about a C++ class hierarchy, where belonging to a class means
to inherit that class' methods. When an object is instantiated
and its class inherits a lot of other classes, it inherits all
the methods of those classes. Your methods are the attrs, and
you can access them with the same pointer, you don't  need to
look somewhere else ...

Iñaky Pérez-González -- Not speaking for Intel -- all opinions are my own
(and my fault)

^ permalink raw reply	[flat|nested] 46+ messages in thread
[parent not found: <20030616194446.H13312@flint.arm.linux.org.uk>]
* Flaw in the driver-model implementation of attributes
@ 2003-06-15 16:42 Alan Stern
  2003-06-15 17:40 ` Jeremy Fitzhardinge
  2003-06-16 17:08 ` Greg KH
  0 siblings, 2 replies; 46+ messages in thread
From: Alan Stern @ 2003-06-15 16:42 UTC (permalink / raw)
  To: Greg KH, Patrick Mochel; +Cc: linux-kernel

If you're already aware of this, please forgive the intrusion.

There's a general problem in the driver model's implementation of 
attribute files, in connection with loadable kernel modules.  The 
sysfs_ops structure stores function pointers with no means for identifying 
the module that contains the corresponding code.  As a result, it's 
possible to call through one of these pointers even after the module has 
been unloaded, causing an oops.

It's not hard to provoke this sort of situation.  A user process can
open a sysfs device file, for instance, and delay trying to read it until 
the module containing the device driver has been removed.  When the read 
does occur, it runs into trouble.

I don't know enough about the innards of the system to be able to fix this
properly.  One possible approach works like this.  Modify fs/sysfs/file.c
to make fill_read_buffer() and flush_write_buffer() acquire some sort of
read lock on file->f_dentry before they set attr =
file->f_dentry->d_fsdata.  Modify sysfs_remove_file() to acquire a write
lock and have it set file->f_dentry->d_fsdata to NULL.  Then it will only
be necessary to avoid calling ops->show() or ops->store() if attr is NULL.  
This guarantees that no caller will execute the show() or store() methods
after syfs_remove_file() has returned, so a driver that cleans up after 
itself correctly will not be invoked after it has been unloaded.

Alan Stern


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

end of thread, other threads:[~2003-07-03 14:37 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-19  0:06 Flaw in the driver-model implementation of attributes Clayton Weaver
2003-06-19  0:20 ` Kevin P. Fleming
2003-06-19 16:46   ` Patrick Mochel
  -- strict thread matches above, loose matches on Subject: below --
2003-06-19 21:18 Perez-Gonzalez, Inaky
2003-06-18 19:52 Perez-Gonzalez, Inaky
2003-06-18  7:48 Perez-Gonzalez, Inaky
2003-06-18  8:12 ` viro
2003-06-18 14:32   ` Alan Stern
2003-06-18 17:15     ` Greg KH
2003-06-18 19:50       ` Alan Stern
2003-06-19 16:42         ` Patrick Mochel
2003-06-19 21:18           ` Alan Stern
2003-06-19 14:13       ` Alan Stern
2003-06-19 17:07         ` Patrick Mochel
2003-06-19 21:14           ` Alan Stern
2003-06-19 21:31             ` Greg KH
2003-06-20 14:22               ` Alan Stern
2003-06-20 18:32                 ` Greg KH
2003-07-02 22:12                   ` Greg KH
2003-07-03 14:51                     ` Alan Stern
2003-06-19 17:26         ` Mike Anderson
2003-06-18  3:44 Perez-Gonzalez, Inaky
2003-06-18  4:18 ` viro
     [not found] <20030616194446.H13312@flint.arm.linux.org.uk>
2003-06-16 19:36 ` Alan Stern
2003-06-16 20:49   ` Patrick Mochel
2003-06-16 21:29     ` Alan Stern
2003-06-16 22:43       ` Patrick Mochel
2003-06-17 19:49         ` Alan Stern
2003-06-18  1:38           ` Kevin P. Fleming
2003-06-16 23:36       ` Greg KH
2003-06-17 17:29         ` Alan Stern
2003-06-17 17:33           ` Greg KH
2003-06-17 20:20             ` Alan Stern
2003-06-15 16:42 Alan Stern
2003-06-15 17:40 ` Jeremy Fitzhardinge
2003-06-16 14:05   ` Alan Stern
2003-06-16 17:08 ` Greg KH
2003-06-16 17:20   ` Russell King
2003-06-16 17:54     ` Alan Stern
2003-06-16 18:00       ` Patrick Mochel
2003-06-16 18:03       ` viro
2003-06-16 18:23         ` Alan Stern
2003-06-16 18:38           ` Patrick Mochel
2003-06-16 19:06             ` Alan Stern
2003-06-16 18:00     ` Martin Diehl
2003-06-16 18:15       ` viro

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