Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932286AbcCCOqp (ORCPT ); Thu, 3 Mar 2016 09:46:45 -0500 Received: from lxorguk.ukuu.org.uk ([81.2.110.251]:49558 "EHLO lxorguk.ukuu.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752921AbcCCOqo (ORCPT ); Thu, 3 Mar 2016 09:46:44 -0500 Date: Thu, 3 Mar 2016 14:46:25 +0000 From: One Thousand Gnomes To: "Ning, Yu" Cc: Jin Qian , Greg Kroah-Hartman , "linux-kernel@vger.kernel.org" , "Jeff Sharkey" , David Turner , "pprabhu@google.com" Subject: Re: allocate an official device major number for virtio device? Message-ID: <20160303144625.21410e3c@lxorguk.ukuu.org.uk> In-Reply-To: References: <20160303012530.GA23521@kroah.com> Organization: Intel Corporation X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.29; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1292 Lines: 28 On Thu, 3 Mar 2016 03:52:20 +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)... > > 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. That's why we are doing a fnmatch() using pattern /sys/devices/*/block/vd* instead. Is that the recommended approach? That sounds fine to me - if you desperately need to know the assigned major you can look in /proc/devices Alan