From patchwork Mon Mar 16 20:55:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Ehrenberg X-Patchwork-Id: 450738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C64A140140 for ; Tue, 17 Mar 2015 07:58:14 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=google.com header.i=@google.com header.b=bLHKAtjs; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YXc4D-0005fT-AC; Mon, 16 Mar 2015 20:56:53 +0000 Received: from mail-ig0-x22d.google.com ([2607:f8b0:4001:c05::22d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YXc33-0004to-Ou for linux-mtd@lists.infradead.org; Mon, 16 Mar 2015 20:55:46 +0000 Received: by igbue6 with SMTP id ue6so54684017igb.1 for ; Mon, 16 Mar 2015 13:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=XVY6ZUBSvEGOXC+iEaVKfB74yAcB1WX4kY9mbGghvxs=; b=bLHKAtjsnDvTnJvAH8R5WLWd8proOUZ/QDOpEmk6/O31cDQGnVWWf8Tj2M2ihx9Kp+ mShikHqL3pv8Vm4osTrPAM3r8MmIO7i92aQuyUyDi49rVMOwEBxokNjhzBwv17DcsBFh qfjmr8zPwCLTZQyIbVCjX5Oc+DDHuLxZ5I/IMupGGrKYNfL4M+XnyzrcObAjBqLgCjNv c45BA9RHLcaFedC1+d3DwIsE+EVSRgtnDDfYYySPtJZ3B3UIIYSyXyGHmccAq1d8luC4 U0hpfcibgO32+T8P6VZvi8G5MWWLZlesWo5DoBiH5sL/W+2aga5dazA2EQWhRIdTH/Ru XYXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=XVY6ZUBSvEGOXC+iEaVKfB74yAcB1WX4kY9mbGghvxs=; b=hfpfPGNuMKUSIt0XdH7AjK9SHJLUm30y6t8P4lGOiCmZkqlQlPwFxE+C/kb2R4/CB2 +fz/m6LuI3KVXrOJVZ+oKwRr9Q7seLh+L5qHlZTm2OMqcFCr0kHOcCGtiTD5cGVn9dqE CzyuGnCX/3Zwailuslpjirnu8GKYC9w6jm8tji2655grn7QKOFOed8I69SiaLYZUZTjl CpP4E0WZOfOyQ72W2LOoob62tEyX+h9kmqvc86zVMuFrM97q/ZYqpDNb6TaUx8Upq9W0 GLmlyAhj8znmfwQnpNEul+oP1nGO44G/h0JucALApqppp07nL4iPn9T0eYxwVDD+x3/5 z0ww== X-Gm-Message-State: ALoCoQmZhdAEzdt58Mss9eYNzwTMviI8PgSlgwizDx14SA23s1pK1c+l6L3PgGds67vjDhE19+pH X-Received: by 10.50.107.7 with SMTP id gy7mr112850719igb.49.1426539319157; Mon, 16 Mar 2015 13:55:19 -0700 (PDT) Received: from dehrenberg.mtv.corp.google.com ([172.22.65.87]) by mx.google.com with ESMTPSA id c76sm7396909ioc.16.2015.03.16.13.55.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Mar 2015 13:55:18 -0700 (PDT) From: Dan Ehrenberg To: computersforpeace@gmail.com, linux-mtd@lists.infradead.org Subject: [PATCH] UBI: block: Add option for dynamic minor number Date: Mon, 16 Mar 2015 13:55:15 -0700 Message-Id: <1426539315-17392-1-git-send-email-dehrenberg@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150316_135543_374572_BC45704F X-CRM114-Status: GOOD ( 16.40 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:4001:c05:0:0:0:22d listed in] [list.dnswl.org] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record 0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: gwendal@chromium.org, Dan Ehrenberg X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch adds a new config option, MTD_UBI_BLOCK_DYNAMIC_MINOR, which makes minor numbers dynamically allocated for ubiblock devices, starting at 0. From the new Kconfig: This option makes ubiblock devices have minor numbers beginning from 0, allocated dynamically independently of the ubi device/volume number. For users who don't refer to an ubiblock device directly by the major:minor number (e.g., with udev and/or devtmpfs), this option is useful if the device number is rather high (>1) and when executing on a 32-bit platform without LFS enabled in all userspace binaries. While enabling LFS is clearly a nicer solution, it's often difficult to turn on in practice globally as many widely distributed packages don't work with LFS on. While dev_t is 32-bit even without LFS, stat will return -EOVERFLOW with a minor number which doesn't fit in 8 bits for ABI compatability reasons. Other storage systems have their own workarounds, with SCSI making multiple device majors and MMC having a config option for the number of partitions per device. A completely dynamic minor numbering is simpler than these and suitable for the majority of ubiblock users who don't depend on a minor numbering (the major is dynamic anyway). Signed-off-by: Dan Ehrenberg --- drivers/mtd/ubi/Kconfig | 11 +++++++++++ drivers/mtd/ubi/block.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig index f0855ce..c0e9a73 100644 --- a/drivers/mtd/ubi/Kconfig +++ b/drivers/mtd/ubi/Kconfig @@ -103,4 +103,15 @@ config MTD_UBI_BLOCK If in doubt, say "N". +config MTD_UBI_BLOCK_DYNAMIC_MINOR + bool "Dynamically allocate minor numbers for ubiblock" + default n + help + This option makes ubiblock devices have minor numbers beginning from + 0, allocated dynamically independently of the ubi device/volume + number. For users who don't refer to an ubiblock device directly by + the major:minor number (e.g., with udev and/or devtmpfs), this option + is useful if the device number is rather high (>1) and when executing + on a 32-bit platform without LFS. + endif # MTD_UBI diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c index db2c05b..bcd164d 100644 --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include "ubi-media.h" @@ -351,6 +352,20 @@ static struct blk_mq_ops ubiblock_mq_ops = { .map_queue = blk_mq_map_queue, }; +#ifdef CONFIG_MTD_UBI_BLOCK_DYNAMIC_MINOR +static DEFINE_IDR(ubiblock_minor_idr); + +static int ubiblock_alloc_minor(struct ubiblock *dev) +{ + return idr_alloc(&ubiblock_minor_idr, dev, 0, 0, GFP_KERNEL); +} + +static void ubiblock_remove_minor(int minor) +{ + idr_remove(&ubiblock_minor_idr, minor); +} +#endif + int ubiblock_create(struct ubi_volume_info *vi) { struct ubiblock *dev; @@ -388,7 +403,17 @@ int ubiblock_create(struct ubi_volume_info *vi) gd->fops = &ubiblock_ops; gd->major = ubiblock_major; +#ifdef CONFIG_MTD_UBI_BLOCK_DYNAMIC_MINOR + gd->first_minor = ubiblock_alloc_minor(dev); + if (gd->first_minor < 0) { + dev_err(disk_to_dev(gd), + "block: dynamic minor allocation failed"); + ret = -ENODEV; + goto out_put_disk; + } +#else gd->first_minor = dev->ubi_num * UBI_MAX_VOLUMES + dev->vol_id; +#endif gd->private_data = dev; sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id); set_capacity(gd, disk_capacity); @@ -405,7 +430,7 @@ int ubiblock_create(struct ubi_volume_info *vi) ret = blk_mq_alloc_tag_set(&dev->tag_set); if (ret) { dev_err(disk_to_dev(dev->gd), "blk_mq_alloc_tag_set failed"); - goto out_put_disk; + goto out_remove_minor; } dev->rq = blk_mq_init_queue(&dev->tag_set); @@ -443,6 +468,10 @@ out_free_queue: blk_cleanup_queue(dev->rq); out_free_tags: blk_mq_free_tag_set(&dev->tag_set); +out_remove_minor: +#ifdef CONFIG_MTD_UBI_BLOCK_DYNAMIC_MINOR + ubiblock_remove_minor(gd->first_minor); +#endif out_put_disk: put_disk(dev->gd); out_free_dev: @@ -461,6 +490,9 @@ static void ubiblock_cleanup(struct ubiblock *dev) blk_cleanup_queue(dev->rq); blk_mq_free_tag_set(&dev->tag_set); dev_info(disk_to_dev(dev->gd), "released"); +#ifdef CONFIG_MTD_UBI_BLOCK_DYNAMIC_MINOR + ubiblock_remove_minor(dev->gd->first_minor); +#endif put_disk(dev->gd); }