Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1349420

Re: allocate an official device major number for virtio device?

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject Re: allocate an official device major number for virtio device?
Date 2016-03-03 18:20 +0100
Message-ID <r8F4T-1WU-29@gated-at.bofh.it> (permalink)
References <r8pWb-7WC-27@gated-at.bofh.it> <r8qfw-84R-11@gated-at.bofh.it> <r8qyT-8dz-35@gated-at.bofh.it> <r8sAH-1aq-27@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

On Thu, Mar 03, 2016 at 03:52:20AM +0000, Ning, Yu wrote:
> Well, virtio_blk does use dynamic major number allocation, but the
> allocated block major just happens to fall in the "experimental" range
> (240-254)...

That all depends on what else is registered in the system at the moment.

> In more detail:
> 
> virtio_blk calls register_blkdev() with major = 0 in init() (drivers/block/virtio_blk.c:872):
> 
> 	major = register_blkdev(0, "virtblk");
> 
> This line has been there since day one.  And register_blkdev() implements dynamic major allocation pretty straightforwardly:
> 
> 	/* temporary */
> 	if (major == 0) {
> 		for (index = ARRAY_SIZE(major_names)-1; index > 0; index--) {
> 			if (major_names[index] == NULL)
> 				break;
> 		}
> 
> So it goes from index = 254 to 1 and picks the first unused.
> Apparently, there's a good chance that the allocated major is between
> 240-254 (although lower numbers are also possible, theoretically).
> Indeed, we always get 253 for virtio_blk with the x86_64 Android
> emulator kernel.
> 
> But "dynamic" means we can't rely on checking major == 253 to detect
> virtio_blk.

Nor should you, why would you care?

> That's why we are doing a fnmatch() using pattern
> /sys/devices/*/block/vd* instead.  Is that the recommended approach?

Yes, or just look at the device node that is already created in /dev/
for you automatially by devtmpfs.  Doesn't that work as expected today?

I still don't understand the issue you are having here at all, sorry.

greg k-h

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

allocate an official device major number for virtio device? Jin Qian <jinqian@android.com> - 2016-03-03 02:10 +0100
  Re: allocate an official device major number for virtio device? Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-03-03 02:30 +0100
    Re: allocate an official device major number for virtio device? Jin Qian <jinqian@android.com> - 2016-03-03 02:50 +0100
      RE: allocate an official device major number for virtio device? "Ning, Yu" <yu.ning@intel.com> - 2016-03-03 05:00 +0100
        Re: allocate an official device major number for virtio device? One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk> - 2016-03-03 15:50 +0100
        Re: allocate an official device major number for virtio device? Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-03-03 18:20 +0100
          Re: allocate an official device major number for virtio device? Jin Qian <jinqian@android.com> - 2016-03-03 20:40 +0100
            Re: allocate an official device major number for virtio device? Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-03-03 21:10 +0100
              Re: allocate an official device major number for virtio device? Jeff Sharkey <jsharkey@android.com> - 2016-03-03 23:20 +0100
                Re: allocate an official device major number for virtio device? Richard Weinberger <richard.weinberger@gmail.com> - 2016-03-03 23:40 +0100
                Re: allocate an official device major number for virtio device? Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-03-03 23:50 +0100
      Re: allocate an official device major number for virtio device? Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-03-03 18:20 +0100

csiph-web