linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* sysfs question:  how to map major:minor to name under /sys
@ 2005-12-15  3:14 Neil Brown
  2005-12-16  1:33 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Neil Brown @ 2005-12-15  3:14 UTC (permalink / raw)
  To: Greg KH, linux-kernel


Hi,
 I have a question about sysfs related usage.

 Suppose I have a major:minor number for a block device - maybe from
 fstat of a filedescriptor I was given, or stat of a name in /dev.
 How do I find the directory in /sys/block that contains relevant
 information? 

 It seems to me that there is no direct way, and maybe there should
 be. (I can do a find of 'dev' file and compare, which is fine in a
 one-off shell script, but sub-optimal in general).

 The most obvious solution would be to have a directory somewhere full
 of symlinks:
        /sys/block_dev/8:0 -> ../block/sda
 or whatever.
 Is this reasonable?  Should I try it?

 The particular case that I am interested in involves md.
 In this case I can find the right /sys/block/mdX entry easily enough
 because I *know* how the names are generated.  However when a block
 device is added to an array, it gets an entry like
    /sys/block/md4/md/dev-sda
 I would like to be able to easily find that given just the
 information that 8:0 was added.
 If the above directory of symlinks existed, I could readlink the
 relevant entry, take the basename, and add "md/dev-" to front of
 that. 

 Comments?

NeilBrown

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

* Re: sysfs question:  how to map major:minor to name under /sys
  2005-12-15  3:14 sysfs question: how to map major:minor to name under /sys Neil Brown
@ 2005-12-16  1:33 ` Greg KH
  2005-12-16  3:36   ` Neil Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2005-12-16  1:33 UTC (permalink / raw)
  To: Neil Brown; +Cc: linux-kernel

On Thu, Dec 15, 2005 at 02:14:06PM +1100, Neil Brown wrote:
> 
> Hi,
>  I have a question about sysfs related usage.
> 
>  Suppose I have a major:minor number for a block device - maybe from
>  fstat of a filedescriptor I was given, or stat of a name in /dev.
>  How do I find the directory in /sys/block that contains relevant
>  information? 
> 
>  It seems to me that there is no direct way, and maybe there should
>  be. (I can do a find of 'dev' file and compare, which is fine in a
>  one-off shell script, but sub-optimal in general).

So you want this info from userspace, not from within the kernel, right?

>  The most obvious solution would be to have a directory somewhere full
>  of symlinks:
>         /sys/block_dev/8:0 -> ../block/sda
>  or whatever.
>  Is this reasonable?  Should I try it?

It seems a bit md specific to add a lot of kernel code for something
that can be solved with a userspace shell script :)

But if you want to try it, use a class, and a class_device for this, not
raw kobjects.  It should be a bit easier that way.

thanks,

greg k-h

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

* Re: sysfs question:  how to map major:minor to name under /sys
  2005-12-16  1:33 ` Greg KH
@ 2005-12-16  3:36   ` Neil Brown
  0 siblings, 0 replies; 3+ messages in thread
From: Neil Brown @ 2005-12-16  3:36 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel

On Thursday December 15, greg@kroah.com wrote:
> On Thu, Dec 15, 2005 at 02:14:06PM +1100, Neil Brown wrote:
> > 
> > Hi,
> >  I have a question about sysfs related usage.
> > 
> >  Suppose I have a major:minor number for a block device - maybe from
> >  fstat of a filedescriptor I was given, or stat of a name in /dev.
> >  How do I find the directory in /sys/block that contains relevant
> >  information? 
> > 
> >  It seems to me that there is no direct way, and maybe there should
> >  be. (I can do a find of 'dev' file and compare, which is fine in a
> >  one-off shell script, but sub-optimal in general).
> 
> So you want this info from userspace, not from within the kernel,
> right?

Right.

> 
> >  The most obvious solution would be to have a directory somewhere full
> >  of symlinks:
> >         /sys/block_dev/8:0 -> ../block/sda
> >  or whatever.
> >  Is this reasonable?  Should I try it?
> 
> It seems a bit md specific to add a lot of kernel code for something
> that can be solved with a userspace shell script :)

I don't see it as md specific.  
Suppose I want to change the IO scheduler under the filesystem /foo.
I look that up in mtab and find it is mounted on /dev/blah.
To find the corresponding /sys/block entry I have to search.  That's
fine if I only have a few block devices.  But I keep hearing storing
of people with thousands.  Having to search just feels clumsy.

> 
> But if you want to try it, use a class, and a class_device for this, not
> raw kobjects.  It should be a bit easier that way.

Well, maybe it'll be a good excuse to learn more about 'class' and
'class_device' anyway.
Thanks,
NeilBrown

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

end of thread, other threads:[~2005-12-16  3:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-15  3:14 sysfs question: how to map major:minor to name under /sys Neil Brown
2005-12-16  1:33 ` Greg KH
2005-12-16  3:36   ` Neil Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).