Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755484AbcCCDw0 (ORCPT ); Wed, 2 Mar 2016 22:52:26 -0500 Received: from mga04.intel.com ([192.55.52.120]:21563 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752672AbcCCDwZ (ORCPT ); Wed, 2 Mar 2016 22:52:25 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,531,1449561600"; d="scan'208";a="757155872" From: "Ning, Yu" To: Jin Qian , Greg Kroah-Hartman CC: "linux-kernel@vger.kernel.org" , "Jeff Sharkey" , David Turner , "pprabhu@google.com" Subject: RE: allocate an official device major number for virtio device? Thread-Topic: allocate an official device major number for virtio device? Thread-Index: AQHRdOkqwvOcF/ZLpkS1HKDeEZFuH59GZzcAgAAGZQCAAJF0kA== Date: Thu, 3 Mar 2016 03:52:20 +0000 Message-ID: References: <20160303012530.GA23521@kroah.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNjQxYzY5MGQtZmUxOC00N2U1LWFkN2UtYjM1ZTY0YWY0OTQzIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IldudGVScjljMkg2OFRNNWVIOEhOUkFcL2tkMFBtNnRwcFFXelBIR1pZODdNPSJ9 x-ctpclassification: CTP_IC x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id u233qVql019428 Content-Length: 2730 Lines: 66 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? Thanks, Yu > -----Original Message----- > From: Jin Qian [mailto:jinqian@android.com] > Sent: Thursday, March 3, 2016 9:48 > To: Greg Kroah-Hartman > Cc: linux-kernel@vger.kernel.org; Jeff Sharkey ; David > Turner ; pprabhu@google.com; Ning, Yu > > Subject: Re: allocate an official device major number for virtio device? > > Do you mean detecting device name string as in /dev/...? > > Just checked latest virtio_blk code, it's dynamic but not using anything specific > to experimental range. I guess we're fine here but Yu can confirm. > > Thanks, > jin > > On Wed, Mar 2, 2016 at 5:25 PM, Greg Kroah-Hartman > wrote: > > On Wed, Mar 02, 2016 at 05:08:00PM -0800, Jin Qian wrote: > >> Hi - > >> > >> Can we allocate an official device major number for virtio devices? > >> Currently it's using 240-254 (LOCAL/EXPERIMENTAL USE). The reason we > >> ask for this is because userspace will need to treat virtio block > >> devices differently and need a way to detect such device. For > >> example, it checks major number to detect scsi and mmc device. > >> > >> https://android-review.googlesource.com/#/c/195240 > >> > >> With dynamic major numbers 240-254, we might treat other devices as > >> virtio block device incorrectly. > > > > You shouldn't treat them incorrectly, devtmpfs handles this for you > > automatically, so I'd recommend using the dynamic majors please. > > > > And what in-kernel code is using the "experimental" range today? Do > > you have a pointer to that? We should fix that now... > > > > thanks, > > > > greg k-h