Re: [PATCH v3] mmc: add config and runtime option for number ofmmcblk minors

From: Lei Wen
Date: Wed Sep 08 2010 - 10:26:04 EST


Hi,

On Sat, Aug 21, 2010 at 6:13 AM, Olof Johansson <olof@xxxxxxxxx> wrote:
> The old limit of number of minor numbers per mmcblk device was hardcoded
> at 8. This isn't enough for some of the more elaborate partitioning
> schemes, for example those used by Chrome OS.
>
> Since there might be a bunch of systems out there with static /dev
> contents that relies on the old numbering scheme, let's make it a
> build-time option with the default set to the previous 8.
>
> Also provide a boot/modprobe-time parameter to override the config
> default: mmcblk.perdev_minors.
>
> Signed-off-by: Olof Johansson <olof@xxxxxxxxx>
> Cc: Mandeep Baines <msb@xxxxxxxxxxxx>
>
> ---
>
> Andrew, sorry for the churn but Mandeep had a couple of good points that
> needed addressing.
>
> Changes since v1:
> Â Â Â Â* Runtime override of config default
> Â Â Â Â* Better help text
> Â Â Â Â* DIV_ROUND_UP for max_devices calculation
> Â Â Â Â* Clarify mmcblk device count limitations
>
> Changes since v2 based on feedback from Mandeep Baines:
> Â Â Â Â* DIV_ROUND_UP is doing the wrong thing, we'll end up using
> Â Â Â Â Âthe last fractional range of minors which we shouldn't.
> Â Â Â Â* Documentation/devices.txt update
> Â Â Â Â* No need to compute max_devices twice, just do it at runtime.
> Â Â Â Â* Permission fix for the module_param -- it's readonly.
>
> ÂDocumentation/devices.txt | Â Â6 ++++++
> Âdrivers/mmc/card/Kconfig Â| Â 17 +++++++++++++++++
> Âdrivers/mmc/card/block.c Â| Â 41 ++++++++++++++++++++++++++++++-----------
> Â3 files changed, 53 insertions(+), 11 deletions(-)
>
> diff --git a/Documentation/devices.txt b/Documentation/devices.txt
> index 1d83d12..fdf3821 100644
> --- a/Documentation/devices.txt
> +++ b/Documentation/devices.txt
> @@ -2518,6 +2518,12 @@ Your cooperation is appreciated.
> Â Â Â Â Â Â Â Â Â8 = /dev/mmcblk1 Â Â ÂSecond SD/MMC card
> Â Â Â Â Â Â Â Â Â Â...
>
> + Â Â Â Â Â Â Â The start of next SD/MMC card can be configured with
> + Â Â Â Â Â Â Â CONFIG_MMC_BLOCK_MINORS, or overridden at boot/modprobe
> + Â Â Â Â Â Â Â time using the mmcblk.perdev_minors option. That would
> + Â Â Â Â Â Â Â bump the offset between each card to be the configured
> + Â Â Â Â Â Â Â value instead of the default 8.
> +
> Â179 char    CCube DVXChip-based PCI products
> Â Â Â Â Â Â Â Â Â0 = /dev/dvxirq0 Â Â ÂFirst DVX device
> Â Â Â Â Â Â Â Â Â1 = /dev/dvxirq1 Â Â ÂSecond DVX device
> diff --git a/drivers/mmc/card/Kconfig b/drivers/mmc/card/Kconfig
> index 3f2a912..57e4416 100644
> --- a/drivers/mmc/card/Kconfig
> +++ b/drivers/mmc/card/Kconfig
> @@ -14,6 +14,23 @@ config MMC_BLOCK
> Â Â Â Â Âmount the filesystem. Almost everyone wishing MMC support
> Â Â Â Â Âshould say Y or M here.
>
> +config MMC_BLOCK_MINORS
> + Â Â Â int "Number of minors per block device"
> + Â Â Â range 4 256
> + Â Â Â default 8
> + Â Â Â help
> + Â Â Â Â Number of minors per block device. One is needed for every
> + Â Â Â Â partition on the disk (plus one for the whole disk).
> +
> + Â Â Â Â Number of total MMC minors available is 256, so your number
> + Â Â Â Â of supported block devices will be limited to 256 divided
> + Â Â Â Â by this number.
> +
> + Â Â Â Â Default is 8 to be backwards compatible with previous
> + Â Â Â Â hardwired device numbering.
> +
> + Â Â Â Â If unsure, say 8 here.
> +
> Âconfig MMC_BLOCK_BOUNCE
> Â Â Â Âbool "Use bounce buffer for simple hosts"
> Â Â Â Âdepends on MMC_BLOCK
> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
> index cb9fbc8..ec94f56 100644
> --- a/drivers/mmc/card/block.c
> +++ b/drivers/mmc/card/block.c
> @@ -43,14 +43,26 @@
> Â#include "queue.h"
>
> ÂMODULE_ALIAS("mmc:block");
> +#ifdef MODULE_PARAM_PREFIX
> +#undef MODULE_PARAM_PREFIX
> +#endif
> +#define MODULE_PARAM_PREFIX "mmcblk."
> +
> +
> +/*
> + * The defaults come from config options but can be overriden by module
> + * or bootarg options.
> + */
> +static int perdev_minors = CONFIG_MMC_BLOCK_MINORS;
>
> Â/*
> - * max 8 partitions per card
> + * We've only got one major, so number of mmcblk devices is
> + * limited to 256 / number of minors per device.
> Â*/
> -#define MMC_SHIFT Â Â Â3
> -#define MMC_NUM_MINORS (256 >> MMC_SHIFT)
> +static int max_devices;
>
> -static DECLARE_BITMAP(dev_use, MMC_NUM_MINORS);
> +/* 256 minors, so at most 256 separate devices */
> +static DECLARE_BITMAP(dev_use, 256);
>
> Â/*
> Â* There is one mmc_blk_data per slot.
> @@ -66,6 +78,9 @@ struct mmc_blk_data {
>
> Âstatic DEFINE_MUTEX(open_lock);
>
> +module_param(perdev_minors, int, 0444);
> +MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device");
> +
> Âstatic struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
> Â{
> Â Â Â Âstruct mmc_blk_data *md;
> @@ -87,10 +102,10 @@ static void mmc_blk_put(struct mmc_blk_data *md)
> Â Â Â Âmd->usage--;
> Â Â Â Âif (md->usage == 0) {
> Â Â Â Â Â Â Â Âint devmaj = MAJOR(disk_devt(md->disk));
> - Â Â Â Â Â Â Â int devidx = MINOR(disk_devt(md->disk)) >> MMC_SHIFT;
> + Â Â Â Â Â Â Â int devidx = MINOR(disk_devt(md->disk)) / perdev_minors;
>
> Â Â Â Â Â Â Â Âif (!devmaj)
> - Â Â Â Â Â Â Â Â Â Â Â devidx = md->disk->first_minor >> MMC_SHIFT;
> + Â Â Â Â Â Â Â Â Â Â Â devidx = md->disk->first_minor / perdev_minors;
>
> Â Â Â Â Â Â Â Âblk_cleanup_queue(md->queue.queue);
>
> @@ -482,8 +497,8 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
> Â Â Â Âstruct mmc_blk_data *md;
> Â Â Â Âint devidx, ret;
>
> - Â Â Â devidx = find_first_zero_bit(dev_use, MMC_NUM_MINORS);
> - Â Â Â if (devidx >= MMC_NUM_MINORS)
> + Â Â Â devidx = find_first_zero_bit(dev_use, max_devices);
> + Â Â Â if (devidx >= max_devices)
> Â Â Â Â Â Â Â Âreturn ERR_PTR(-ENOSPC);
> Â Â Â Â__set_bit(devidx, dev_use);
>
> @@ -500,7 +515,7 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
> Â Â Â Â */
> Â Â Â Âmd->read_only = mmc_blk_readonly(card);
>
> - Â Â Â md->disk = alloc_disk(1 << MMC_SHIFT);
> + Â Â Â md->disk = alloc_disk(perdev_minors);
> Â Â Â Âif (md->disk == NULL) {
> Â Â Â Â Â Â Â Âret = -ENOMEM;
> Â Â Â Â Â Â Â Âgoto err_kfree;
> @@ -517,7 +532,7 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
> Â Â Â Âmd->queue.data = md;
>
> Â Â Â Âmd->disk->major = MMC_BLOCK_MAJOR;
> - Â Â Â md->disk->first_minor = devidx << MMC_SHIFT;
> + Â Â Â md->disk->first_minor = devidx * perdev_minors;
> Â Â Â Âmd->disk->fops = &mmc_bdops;
> Â Â Â Âmd->disk->private_data = md;
> Â Â Â Âmd->disk->queue = md->queue.queue;
> @@ -593,7 +608,6 @@ static int mmc_blk_probe(struct mmc_card *card)
> Â{
> Â Â Â Âstruct mmc_blk_data *md;
> Â Â Â Âint err;
> -
> Â Â Â Âchar cap_str[10];
>
> Â Â Â Â/*
> @@ -683,6 +697,11 @@ static int __init mmc_blk_init(void)
> Â{
> Â Â Â Âint res;
>
> + Â Â Â if (perdev_minors != CONFIG_MMC_BLOCK_MINORS)
> + Â Â Â Â Â Â Â pr_info("mmcblk: using %d minors per device\n", perdev_minors);
> +
> + Â Â Â max_devices = 256 / perdev_minors;
> +
> Â Â Â Âres = register_blkdev(MMC_BLOCK_MAJOR, "mmc");
> Â Â Â Âif (res)
> Â Â Â Â Â Â Â Âgoto out;
> --
> 1.5.6.5
>

The patch's purpose is good. As modern sd&mmc is used to host the file
system, the 8 partition limitation is becoming a kind of bottleneck...
But why not just add GENHD_FL_EXT_DEVT flag to allow mmc use extended
partition numbers?

Like this modification?
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 8d2bd24..2e3eeb1 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -557,6 +557,7 @@ static struct mmc_blk_data *mmc_blk_alloc(struct
mmc_card *card)
md->disk->private_data = md;
md->disk->queue = md->queue.queue;
md->disk->driverfs_dev = &card->dev;
+ md->disk->flags |= GENHD_FL_EXT_DEVT;

/*
* As discussed on lkml, GENHD_FL_REMOVABLE should:

Best regards,
Lei
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/