All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block2mtd: mtd: Present block2mtd timely on boot time
       [not found] <371358190.34795877.1410204429882.JavaMail.zimbra@redhat.com>
@ 2014-09-08 20:04 ` Rodrigo Freire
  2014-09-09 17:02     ` Jörn Engel
  0 siblings, 1 reply; 63+ messages in thread
From: Rodrigo Freire @ 2014-09-08 20:04 UTC (permalink / raw)
  To: joern, dwmw2; +Cc: linux-mtd, linux-kernel

From: Felix Fietkau <nbd@openwrt.org>

block2mtd: Ensure that block2mtd is presented in a timely fashion 

Currently, a block MTD device is not presented to the system on time, in 
order to start mounting the filesystems. This patch ensures that block2mtd 
is presented at the right time, so filesystems can be mounted on boot time.
This issue was seen on BCM2708 (Raspberry Pi) systems when mounting JFFS2 
block2mtd filesystems.
This patchset also adds a MTD device name and a timeout option to the driver.
Original patchset:
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Rodrigo Freire <rfreire@redhat.com> 

--- a/drivers/mtd/devices/block2mtd.c	2014-09-05 11:13:39.143698413 -0300
+++ b/drivers/mtd/devices/block2mtd.c	2014-09-05 17:50:28.107366433 -0300
@@ -9,7 +9,15 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+/*
+* When the first attempt at device initialization fails, we may need to
+* wait a little bit and retry. This timeout, by default 3 seconds, gives
+* device time to start up. Required on BCM2708 and a few other chipsets.
+*/
+#define MTD_DEFAULT_TIMEOUT	3
+
 #include <linux/module.h>
+#include <linux/delay.h>
 #include <linux/fs.h>
 #include <linux/blkdev.h>
 #include <linux/bio.h>
@@ -17,6 +25,7 @@
 #include <linux/list.h>
 #include <linux/init.h>
 #include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
 #include <linux/mutex.h>
 #include <linux/mount.h>
 #include <linux/slab.h>
@@ -209,12 +218,14 @@ static void block2mtd_free_device(struct
 }
 
 
-static struct block2mtd_dev *add_device(char *devname, int erase_size)
+static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout)
 {
 	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
-	struct block_device *bdev;
+	struct block_device *bdev = ERR_PTR(-ENODEV);
 	struct block2mtd_dev *dev;
+	struct mtd_partition *part;
 	char *name;
+	int i;
 
 	if (!devname)
 		return NULL;
@@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device(
 
 	/* Get a handle on the device */
 	bdev = blkdev_get_by_path(devname, mode, dev);
-#ifndef MODULE
-	if (IS_ERR(bdev)) {
 
-		/* We might not have rootfs mounted at this point. Try
-		   to resolve the device name by other means. */
-
-		dev_t devt = name_to_dev_t(devname);
-		if (devt)
-			bdev = blkdev_get_by_dev(devt, mode, dev);
+#ifndef MODULE
+/*
+* We might not have the root device mounted at this point.
+* Try to resolve the device name by other means.
+*/
+	for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
+		dev_t devt;
+
+		if (i)
+			/*
+			 * Calling wait_for_device_probe in the first loop 
+			 * was not enough, sleep for a bit in subsequent
+			 * go-arounds.
+			*/
+			msleep(1000);
+		wait_for_device_probe();
+
+		devt = name_to_dev_t(devname);
+		if (!devt)
+			continue;
+		bdev = blkdev_get_by_dev(devt, mode, dev);
 	}
 #endif
 
@@ -257,13 +281,15 @@ static struct block2mtd_dev *add_device(
 
 	/* Setup the MTD structure */
 	/* make the name contain the block device in */
-	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
+	if (!mtdname)
+		mtdname = devname;
+	name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
 	if (!name)
 		goto err_destroy_mutex;
 
+	strcpy(name, mtdname);
 	dev->mtd.name = name;
-
-	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
+	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
 	dev->mtd.erasesize = erase_size;
 	dev->mtd.writesize = 1;
 	dev->mtd.writebufsize = PAGE_SIZE;
@@ -276,15 +302,19 @@ static struct block2mtd_dev *add_device(
 	dev->mtd.priv = dev;
 	dev->mtd.owner = THIS_MODULE;
 
-	if (mtd_device_register(&dev->mtd, NULL, 0)) {
+	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
+	part->name = name;
+	part->offset = 0;
+	part->size = dev->mtd.size;
+	if (mtd_device_register(&dev->mtd, part, 1)) {
 		/* Device didn't get added, so free the entry */
 		goto err_destroy_mutex;
 	}
+
 	list_add(&dev->list, &blkmtd_device_list);
 	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
 		dev->mtd.index,
-		dev->mtd.name + strlen("block2mtd: "),
-		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
+		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
 	return dev;
 
 err_destroy_mutex:
@@ -353,11 +383,12 @@ static char block2mtd_paramline[80 + 12]
 
 static int block2mtd_setup2(const char *val)
 {
-	char buf[80 + 12]; /* 80 for device, 12 for erase size */
+	char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
 	char *str = buf;
-	char *token[2];
+	char *token[4];
 	char *name;
 	size_t erase_size = PAGE_SIZE;
+	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
 	int i, ret;
 
 	if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
@@ -368,7 +399,7 @@ static int block2mtd_setup2(const char *
 	strcpy(str, val);
 	kill_final_newline(str);
 
-	for (i = 0; i < 2; i++)
+	for (i = 0; i < 4; i++)
 		token[i] = strsep(&str, ",");
 
 	if (str) {
@@ -395,7 +426,13 @@ static int block2mtd_setup2(const char *
 		}
 	}
 
-	add_device(name, erase_size);
+	if (token[2] && (strlen(token[2]) + 1 > 80))
+		pr_err("mtd device name too long");
+
+
+	if (token[3] && kstrtoul(token[3], 0, &timeout))
+		pr_err("invalid timeout");
+	add_device(name, erase_size, token[2], timeout);
 
 	return 0;
 }
@@ -429,7 +466,7 @@ static int block2mtd_setup(const char *v
 
 
 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
 
 static int __init block2mtd_init(void)
 {
@@ -463,8 +500,7 @@ static void block2mtd_exit(void)
 	}
 }
 
-
-module_init(block2mtd_init);
+late_initcall(block2mtd_init);
 module_exit(block2mtd_exit);
 
 MODULE_LICENSE("GPL");

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH] block2mtd: mtd: Present block2mtd timely on boot time
  2014-09-08 20:04 ` [PATCH] block2mtd: mtd: Present block2mtd timely on boot time Rodrigo Freire
@ 2014-09-09 17:02     ` Jörn Engel
  0 siblings, 0 replies; 63+ messages in thread
From: Jörn Engel @ 2014-09-09 17:02 UTC (permalink / raw)
  To: Rodrigo Freire; +Cc: dwmw2, Felix Fietkau, linux-mtd, linux-kernel

On Mon, 8 September 2014 16:04:40 -0400, Rodrigo Freire wrote:
> 
> From: Felix Fietkau <nbd@openwrt.org>
> 
> block2mtd: Ensure that block2mtd is presented in a timely fashion 
> 
> Currently, a block MTD device is not presented to the system on time, in 
> order to start mounting the filesystems. This patch ensures that block2mtd 
> is presented at the right time, so filesystems can be mounted on boot time.
> This issue was seen on BCM2708 (Raspberry Pi) systems when mounting JFFS2 
> block2mtd filesystems.
> This patchset also adds a MTD device name and a timeout option to the driver.

Looks fine once the comments below are addressed.

> Original patchset:
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com> 
> 
> --- a/drivers/mtd/devices/block2mtd.c	2014-09-05 11:13:39.143698413 -0300
> +++ b/drivers/mtd/devices/block2mtd.c	2014-09-05 17:50:28.107366433 -0300
> @@ -9,7 +9,15 @@
>  
>  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>  
> +/*
> +* When the first attempt at device initialization fails, we may need to
> +* wait a little bit and retry. This timeout, by default 3 seconds, gives
> +* device time to start up. Required on BCM2708 and a few other chipsets.
> +*/
> +#define MTD_DEFAULT_TIMEOUT	3
> +
>  #include <linux/module.h>
> +#include <linux/delay.h>
>  #include <linux/fs.h>
>  #include <linux/blkdev.h>
>  #include <linux/bio.h>
> @@ -17,6 +25,7 @@
>  #include <linux/list.h>
>  #include <linux/init.h>
>  #include <linux/mtd/mtd.h>
> +#include <linux/mtd/partitions.h>
>  #include <linux/mutex.h>
>  #include <linux/mount.h>
>  #include <linux/slab.h>
> @@ -209,12 +218,14 @@ static void block2mtd_free_device(struct
>  }
>  
>  
> -static struct block2mtd_dev *add_device(char *devname, int erase_size)
> +static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout)
>  {
>  	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
> -	struct block_device *bdev;
> +	struct block_device *bdev = ERR_PTR(-ENODEV);
>  	struct block2mtd_dev *dev;
> +	struct mtd_partition *part;
>  	char *name;
> +	int i;
>  
>  	if (!devname)
>  		return NULL;
> @@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Get a handle on the device */
>  	bdev = blkdev_get_by_path(devname, mode, dev);
> -#ifndef MODULE
> -	if (IS_ERR(bdev)) {
>  
> -		/* We might not have rootfs mounted at this point. Try
> -		   to resolve the device name by other means. */
> -
> -		dev_t devt = name_to_dev_t(devname);
> -		if (devt)
> -			bdev = blkdev_get_by_dev(devt, mode, dev);
> +#ifndef MODULE
> +/*
> +* We might not have the root device mounted at this point.
> +* Try to resolve the device name by other means.
> +*/
> +	for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
> +		dev_t devt;
> +
> +		if (i)
> +			/*
> +			 * Calling wait_for_device_probe in the first loop 
> +			 * was not enough, sleep for a bit in subsequent
> +			 * go-arounds.
> +			*/
> +			msleep(1000);
> +		wait_for_device_probe();
> +
> +		devt = name_to_dev_t(devname);
> +		if (!devt)
> +			continue;
> +		bdev = blkdev_get_by_dev(devt, mode, dev);
>  	}
>  #endif
>  
> @@ -257,13 +281,15 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Setup the MTD structure */
>  	/* make the name contain the block device in */
> -	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
> +	if (!mtdname)
> +		mtdname = devname;
> +	name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
>  	if (!name)
>  		goto err_destroy_mutex;
>  
> +	strcpy(name, mtdname);

kstrdup.

And see below for the ABI change.

>  	dev->mtd.name = name;
> -
> -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> +	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);

PAGE_MASK is no longer needed with the new term.  Or does anyone
seriously want to support erase_size < PAGE_SIZE?

>  	dev->mtd.erasesize = erase_size;
>  	dev->mtd.writesize = 1;
>  	dev->mtd.writebufsize = PAGE_SIZE;
> @@ -276,15 +302,19 @@ static struct block2mtd_dev *add_device(
>  	dev->mtd.priv = dev;
>  	dev->mtd.owner = THIS_MODULE;
>  
> -	if (mtd_device_register(&dev->mtd, NULL, 0)) {
> +	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
> +	part->name = name;
> +	part->offset = 0;
> +	part->size = dev->mtd.size;
> +	if (mtd_device_register(&dev->mtd, part, 1)) {
>  		/* Device didn't get added, so free the entry */
>  		goto err_destroy_mutex;
>  	}
> +
>  	list_add(&dev->list, &blkmtd_device_list);
>  	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
>  		dev->mtd.index,
> -		dev->mtd.name + strlen("block2mtd: "),
> -		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
> +		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
>  	return dev;
>  
>  err_destroy_mutex:
> @@ -353,11 +383,12 @@ static char block2mtd_paramline[80 + 12]
>  
>  static int block2mtd_setup2(const char *val)
>  {
> -	char buf[80 + 12]; /* 80 for device, 12 for erase size */
> +	char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
>  	char *str = buf;
> -	char *token[2];
> +	char *token[4];
>  	char *name;
>  	size_t erase_size = PAGE_SIZE;
> +	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
>  	int i, ret;
>  
>  	if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
> @@ -368,7 +399,7 @@ static int block2mtd_setup2(const char *
>  	strcpy(str, val);
>  	kill_final_newline(str);
>  
> -	for (i = 0; i < 2; i++)
> +	for (i = 0; i < 4; i++)
>  		token[i] = strsep(&str, ",");
>  
>  	if (str) {
> @@ -395,7 +426,13 @@ static int block2mtd_setup2(const char *
>  		}
>  	}
>  
> -	add_device(name, erase_size);
> +	if (token[2] && (strlen(token[2]) + 1 > 80))
> +		pr_err("mtd device name too long");

Timeout has a default value, but name defaults to NULL.  Add three
devices without specifying the name and you get funny results.

If we handled the NULL case by doing what the driver used to do before
this patch, I think this would be fine.

> +
> +	if (token[3] && kstrtoul(token[3], 0, &timeout))
> +		pr_err("invalid timeout");
> +	add_device(name, erase_size, token[2], timeout);
>  
>  	return 0;
>  }
> @@ -429,7 +466,7 @@ static int block2mtd_setup(const char *v
>  
>  
>  module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
> -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
> +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
>  
>  static int __init block2mtd_init(void)
>  {
> @@ -463,8 +500,7 @@ static void block2mtd_exit(void)
>  	}
>  }
>  
> -
> -module_init(block2mtd_init);
> +late_initcall(block2mtd_init);
>  module_exit(block2mtd_exit);
>  
>  MODULE_LICENSE("GPL");

Jörn

--
Most compromises I've seen have been have been a result of gross stupidity,
not incredible technical skill on the part of the attacker.
-- pr0f

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH] block2mtd: mtd: Present block2mtd timely on boot time
@ 2014-09-09 17:02     ` Jörn Engel
  0 siblings, 0 replies; 63+ messages in thread
From: Jörn Engel @ 2014-09-09 17:02 UTC (permalink / raw)
  To: Rodrigo Freire; +Cc: linux-mtd, Felix Fietkau, dwmw2, linux-kernel

On Mon, 8 September 2014 16:04:40 -0400, Rodrigo Freire wrote:
> 
> From: Felix Fietkau <nbd@openwrt.org>
> 
> block2mtd: Ensure that block2mtd is presented in a timely fashion 
> 
> Currently, a block MTD device is not presented to the system on time, in 
> order to start mounting the filesystems. This patch ensures that block2mtd 
> is presented at the right time, so filesystems can be mounted on boot time.
> This issue was seen on BCM2708 (Raspberry Pi) systems when mounting JFFS2 
> block2mtd filesystems.
> This patchset also adds a MTD device name and a timeout option to the driver.

Looks fine once the comments below are addressed.

> Original patchset:
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com> 
> 
> --- a/drivers/mtd/devices/block2mtd.c	2014-09-05 11:13:39.143698413 -0300
> +++ b/drivers/mtd/devices/block2mtd.c	2014-09-05 17:50:28.107366433 -0300
> @@ -9,7 +9,15 @@
>  
>  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>  
> +/*
> +* When the first attempt at device initialization fails, we may need to
> +* wait a little bit and retry. This timeout, by default 3 seconds, gives
> +* device time to start up. Required on BCM2708 and a few other chipsets.
> +*/
> +#define MTD_DEFAULT_TIMEOUT	3
> +
>  #include <linux/module.h>
> +#include <linux/delay.h>
>  #include <linux/fs.h>
>  #include <linux/blkdev.h>
>  #include <linux/bio.h>
> @@ -17,6 +25,7 @@
>  #include <linux/list.h>
>  #include <linux/init.h>
>  #include <linux/mtd/mtd.h>
> +#include <linux/mtd/partitions.h>
>  #include <linux/mutex.h>
>  #include <linux/mount.h>
>  #include <linux/slab.h>
> @@ -209,12 +218,14 @@ static void block2mtd_free_device(struct
>  }
>  
>  
> -static struct block2mtd_dev *add_device(char *devname, int erase_size)
> +static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout)
>  {
>  	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
> -	struct block_device *bdev;
> +	struct block_device *bdev = ERR_PTR(-ENODEV);
>  	struct block2mtd_dev *dev;
> +	struct mtd_partition *part;
>  	char *name;
> +	int i;
>  
>  	if (!devname)
>  		return NULL;
> @@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Get a handle on the device */
>  	bdev = blkdev_get_by_path(devname, mode, dev);
> -#ifndef MODULE
> -	if (IS_ERR(bdev)) {
>  
> -		/* We might not have rootfs mounted at this point. Try
> -		   to resolve the device name by other means. */
> -
> -		dev_t devt = name_to_dev_t(devname);
> -		if (devt)
> -			bdev = blkdev_get_by_dev(devt, mode, dev);
> +#ifndef MODULE
> +/*
> +* We might not have the root device mounted at this point.
> +* Try to resolve the device name by other means.
> +*/
> +	for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
> +		dev_t devt;
> +
> +		if (i)
> +			/*
> +			 * Calling wait_for_device_probe in the first loop 
> +			 * was not enough, sleep for a bit in subsequent
> +			 * go-arounds.
> +			*/
> +			msleep(1000);
> +		wait_for_device_probe();
> +
> +		devt = name_to_dev_t(devname);
> +		if (!devt)
> +			continue;
> +		bdev = blkdev_get_by_dev(devt, mode, dev);
>  	}
>  #endif
>  
> @@ -257,13 +281,15 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Setup the MTD structure */
>  	/* make the name contain the block device in */
> -	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
> +	if (!mtdname)
> +		mtdname = devname;
> +	name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
>  	if (!name)
>  		goto err_destroy_mutex;
>  
> +	strcpy(name, mtdname);

kstrdup.

And see below for the ABI change.

>  	dev->mtd.name = name;
> -
> -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> +	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);

PAGE_MASK is no longer needed with the new term.  Or does anyone
seriously want to support erase_size < PAGE_SIZE?

>  	dev->mtd.erasesize = erase_size;
>  	dev->mtd.writesize = 1;
>  	dev->mtd.writebufsize = PAGE_SIZE;
> @@ -276,15 +302,19 @@ static struct block2mtd_dev *add_device(
>  	dev->mtd.priv = dev;
>  	dev->mtd.owner = THIS_MODULE;
>  
> -	if (mtd_device_register(&dev->mtd, NULL, 0)) {
> +	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
> +	part->name = name;
> +	part->offset = 0;
> +	part->size = dev->mtd.size;
> +	if (mtd_device_register(&dev->mtd, part, 1)) {
>  		/* Device didn't get added, so free the entry */
>  		goto err_destroy_mutex;
>  	}
> +
>  	list_add(&dev->list, &blkmtd_device_list);
>  	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
>  		dev->mtd.index,
> -		dev->mtd.name + strlen("block2mtd: "),
> -		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
> +		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
>  	return dev;
>  
>  err_destroy_mutex:
> @@ -353,11 +383,12 @@ static char block2mtd_paramline[80 + 12]
>  
>  static int block2mtd_setup2(const char *val)
>  {
> -	char buf[80 + 12]; /* 80 for device, 12 for erase size */
> +	char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
>  	char *str = buf;
> -	char *token[2];
> +	char *token[4];
>  	char *name;
>  	size_t erase_size = PAGE_SIZE;
> +	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
>  	int i, ret;
>  
>  	if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
> @@ -368,7 +399,7 @@ static int block2mtd_setup2(const char *
>  	strcpy(str, val);
>  	kill_final_newline(str);
>  
> -	for (i = 0; i < 2; i++)
> +	for (i = 0; i < 4; i++)
>  		token[i] = strsep(&str, ",");
>  
>  	if (str) {
> @@ -395,7 +426,13 @@ static int block2mtd_setup2(const char *
>  		}
>  	}
>  
> -	add_device(name, erase_size);
> +	if (token[2] && (strlen(token[2]) + 1 > 80))
> +		pr_err("mtd device name too long");

Timeout has a default value, but name defaults to NULL.  Add three
devices without specifying the name and you get funny results.

If we handled the NULL case by doing what the driver used to do before
this patch, I think this would be fine.

> +
> +	if (token[3] && kstrtoul(token[3], 0, &timeout))
> +		pr_err("invalid timeout");
> +	add_device(name, erase_size, token[2], timeout);
>  
>  	return 0;
>  }
> @@ -429,7 +466,7 @@ static int block2mtd_setup(const char *v
>  
>  
>  module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
> -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
> +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
>  
>  static int __init block2mtd_init(void)
>  {
> @@ -463,8 +500,7 @@ static void block2mtd_exit(void)
>  	}
>  }
>  
> -
> -module_init(block2mtd_init);
> +late_initcall(block2mtd_init);
>  module_exit(block2mtd_exit);
>  
>  MODULE_LICENSE("GPL");

Jörn

--
Most compromises I've seen have been have been a result of gross stupidity,
not incredible technical skill on the part of the attacker.
-- pr0f

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH] block2mtd: mtd: Present block2mtd timely on boot time
  2014-09-09 17:02     ` Jörn Engel
@ 2014-09-17 20:18       ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-09-17 20:18 UTC (permalink / raw)
  To: Jörn Engel
  Cc: dwmw2, nbd, computersforpeace, linux-kernel, herton, linux-mtd

Hi Jörn,

----- Original Message ----- 
From: "Jörn Engel" <joern@logfs.org> 
> On Mon, 8 September 2014 16:04:40 -0400, Rodrigo Freire wrote: 
> > 
> > @@ -257,13 +281,15 @@ static struct block2mtd_dev *add_device( 
> > 
> > /* Setup the MTD structure */ 
> > /* make the name contain the block device in */ 
> > - name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname); 
> > + if (!mtdname) 
> > + mtdname = devname; 
> > + name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL); 
> > if (!name) 
> > goto err_destroy_mutex; 
> > 
> > + strcpy(name, mtdname); 
> kstrdup. 
> And see below for the ABI change. 

Thanks for pointing. Fixed.


> >  	dev->mtd.name = name;
> > -
> > -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > +	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
> 
> PAGE_MASK is no longer needed with the new term.  Or does anyone
> seriously want to support erase_size < PAGE_SIZE?

Makes sense. I was talking to Felix and indeed there are some MTD devices 
which have 4k erase page size. Unheard of something smaller.
But it is on the MTD land and not block2mtd.


> Timeout has a default value, but name defaults to NULL. Add three 
> devices without specifying the name and you get funny results. 
> If we handled the NULL case by doing what the driver used to do before 
> this patch, I think this would be fine. 

Please see the fragment below:

@@ -257,13 +281,15 @@ static struct block2mtd_dev *add_device(
 
 	/* Setup the MTD structure */
 	/* make the name contain the block device in */
-	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
+	if (!mtdname)
+		mtdname = devname;
+	name = kstrdup(mtdname, GFP_KERNEL);
 	if (!name)
 		goto err_destroy_mutex;

If the name is a NULL or not provided, the mtdname will then become the mtd device name.
I also tried mounting several partitions, with both specified name and not and everything seemed to work nicely.

See a V2 patch on the next message.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH] block2mtd: mtd: Present block2mtd timely on boot time
@ 2014-09-17 20:18       ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-09-17 20:18 UTC (permalink / raw)
  To: Jörn Engel
  Cc: nbd, herton, linux-kernel, linux-mtd, computersforpeace, dwmw2

Hi Jörn,

----- Original Message ----- 
From: "Jörn Engel" <joern@logfs.org> 
> On Mon, 8 September 2014 16:04:40 -0400, Rodrigo Freire wrote: 
> > 
> > @@ -257,13 +281,15 @@ static struct block2mtd_dev *add_device( 
> > 
> > /* Setup the MTD structure */ 
> > /* make the name contain the block device in */ 
> > - name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname); 
> > + if (!mtdname) 
> > + mtdname = devname; 
> > + name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL); 
> > if (!name) 
> > goto err_destroy_mutex; 
> > 
> > + strcpy(name, mtdname); 
> kstrdup. 
> And see below for the ABI change. 

Thanks for pointing. Fixed.


> >  	dev->mtd.name = name;
> > -
> > -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > +	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
> 
> PAGE_MASK is no longer needed with the new term.  Or does anyone
> seriously want to support erase_size < PAGE_SIZE?

Makes sense. I was talking to Felix and indeed there are some MTD devices 
which have 4k erase page size. Unheard of something smaller.
But it is on the MTD land and not block2mtd.


> Timeout has a default value, but name defaults to NULL. Add three 
> devices without specifying the name and you get funny results. 
> If we handled the NULL case by doing what the driver used to do before 
> this patch, I think this would be fine. 

Please see the fragment below:

@@ -257,13 +281,15 @@ static struct block2mtd_dev *add_device(
 
 	/* Setup the MTD structure */
 	/* make the name contain the block device in */
-	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
+	if (!mtdname)
+		mtdname = devname;
+	name = kstrdup(mtdname, GFP_KERNEL);
 	if (!name)
 		goto err_destroy_mutex;

If the name is a NULL or not provided, the mtdname will then become the mtd device name.
I also tried mounting several partitions, with both specified name and not and everything seemed to work nicely.

See a V2 patch on the next message.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-09-09 17:02     ` Jörn Engel
@ 2014-09-17 20:28       ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-09-17 20:28 UTC (permalink / raw)
  To: Jörn Engel
  Cc: dwmw2, Felix Fietkau, linux-mtd, linux-kernel, Herton Krzesinski

From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion

Currently, a block MTD device is not presented to the system on time, in
order to start mounting the filesystems. This patch ensures that block2mtd
is presented at the right time, so filesystems can be mounted on boot time.
This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
block2mtd filesystems.
This patchset also adds a MTD device name and a timeout option to the driver.
Original patchset:
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
Signed-off-by: Herton Krzesinski <herton@redhat.com>
---
V2: Uses kstrdup, removed PAGE_MASK.
--- a/drivers/mtd/devices/block2mtd.c	2014-09-16 21:38:12.543952627 -0300
+++ b/drivers/mtd/devices/block2mtd.c	2014-09-17 17:43:21.424944394 -0300
@@ -9,7 +9,15 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+/*
+* When the first attempt at device initialization fails, we may need to
+* wait a little bit and retry. This timeout, by default 3 seconds, gives
+* device time to start up. Required on BCM2708 and a few other chipsets.
+*/
+#define MTD_DEFAULT_TIMEOUT	3
+
 #include <linux/module.h>
+#include <linux/delay.h>
 #include <linux/fs.h>
 #include <linux/blkdev.h>
 #include <linux/bio.h>
@@ -17,6 +25,7 @@
 #include <linux/list.h>
 #include <linux/init.h>
 #include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
 #include <linux/mutex.h>
 #include <linux/mount.h>
 #include <linux/slab.h>
@@ -209,12 +218,14 @@ static void block2mtd_free_device(struct
 }
 
 
-static struct block2mtd_dev *add_device(char *devname, int erase_size)
+static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout)
 {
 	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
-	struct block_device *bdev;
+	struct block_device *bdev = ERR_PTR(-ENODEV);
 	struct block2mtd_dev *dev;
+	struct mtd_partition *part;
 	char *name;
+	int i;
 
 	if (!devname)
 		return NULL;
@@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device(
 
 	/* Get a handle on the device */
 	bdev = blkdev_get_by_path(devname, mode, dev);
-#ifndef MODULE
-	if (IS_ERR(bdev)) {
 
-		/* We might not have rootfs mounted at this point. Try
-		   to resolve the device name by other means. */
-
-		dev_t devt = name_to_dev_t(devname);
-		if (devt)
-			bdev = blkdev_get_by_dev(devt, mode, dev);
+#ifndef MODULE
+/*
+* We might not have the root device mounted at this point.
+* Try to resolve the device name by other means.
+*/
+	for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
+		dev_t devt;
+
+		if (i)
+			/*
+			 * Calling wait_for_device_probe in the first loop 
+			 * was not enough, sleep for a bit in subsequent
+			 * go-arounds.
+			*/
+			msleep(1000);
+		wait_for_device_probe();
+
+		devt = name_to_dev_t(devname);
+		if (!devt)
+			continue;
+		bdev = blkdev_get_by_dev(devt, mode, dev);
 	}
 #endif
 
@@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device(
 
 	/* Setup the MTD structure */
 	/* make the name contain the block device in */
-	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
+	if (!mtdname)
+		mtdname = devname;
+	name = kstrdup (mtdname, GFP_KERNEL);
 	if (!name)
 		goto err_destroy_mutex;
 
 	dev->mtd.name = name;
-
-	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
+	dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
 	dev->mtd.erasesize = erase_size;
 	dev->mtd.writesize = 1;
 	dev->mtd.writebufsize = PAGE_SIZE;
@@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device(
 	dev->mtd.priv = dev;
 	dev->mtd.owner = THIS_MODULE;
 
-	if (mtd_device_register(&dev->mtd, NULL, 0)) {
+	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
+	part->name = name;
+	part->offset = 0;
+	part->size = dev->mtd.size;
+	if (mtd_device_register(&dev->mtd, part, 1)) {
 		/* Device didn't get added, so free the entry */
 		goto err_destroy_mutex;
 	}
+
 	list_add(&dev->list, &blkmtd_device_list);
 	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
 		dev->mtd.index,
-		dev->mtd.name + strlen("block2mtd: "),
-		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
+		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
 	return dev;
 
 err_destroy_mutex:
@@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12]
 
 static int block2mtd_setup2(const char *val)
 {
-	char buf[80 + 12]; /* 80 for device, 12 for erase size */
+	char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
 	char *str = buf;
-	char *token[2];
+	char *token[4];
 	char *name;
 	size_t erase_size = PAGE_SIZE;
+	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
 	int i, ret;
 
 	if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
@@ -368,7 +398,7 @@ static int block2mtd_setup2(const char *
 	strcpy(str, val);
 	kill_final_newline(str);
 
-	for (i = 0; i < 2; i++)
+	for (i = 0; i < 4; i++)
 		token[i] = strsep(&str, ",");
 
 	if (str) {
@@ -395,7 +425,13 @@ static int block2mtd_setup2(const char *
 		}
 	}
 
-	add_device(name, erase_size);
+	if (token[2] && (strlen(token[2]) + 1 > 80))
+		pr_err("mtd device name too long");
+
+
+	if (token[3] && kstrtoul(token[3], 0, &timeout))
+		pr_err("invalid timeout");
+	add_device(name, erase_size, token[2], timeout);
 
 	return 0;
 }
@@ -429,7 +465,7 @@ static int block2mtd_setup(const char *v
 
 
 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
 
 static int __init block2mtd_init(void)
 {
@@ -463,8 +499,7 @@ static void block2mtd_exit(void)
 	}
 }
 
-
-module_init(block2mtd_init);
+late_initcall(block2mtd_init);
 module_exit(block2mtd_exit);
 
 MODULE_LICENSE("GPL");
---
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-09-17 20:28       ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-09-17 20:28 UTC (permalink / raw)
  To: Jörn Engel
  Cc: linux-mtd, Felix Fietkau, dwmw2, linux-kernel, Herton Krzesinski

From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion

Currently, a block MTD device is not presented to the system on time, in
order to start mounting the filesystems. This patch ensures that block2mtd
is presented at the right time, so filesystems can be mounted on boot time.
This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
block2mtd filesystems.
This patchset also adds a MTD device name and a timeout option to the driver.
Original patchset:
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
Signed-off-by: Herton Krzesinski <herton@redhat.com>
---
V2: Uses kstrdup, removed PAGE_MASK.
--- a/drivers/mtd/devices/block2mtd.c	2014-09-16 21:38:12.543952627 -0300
+++ b/drivers/mtd/devices/block2mtd.c	2014-09-17 17:43:21.424944394 -0300
@@ -9,7 +9,15 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+/*
+* When the first attempt at device initialization fails, we may need to
+* wait a little bit and retry. This timeout, by default 3 seconds, gives
+* device time to start up. Required on BCM2708 and a few other chipsets.
+*/
+#define MTD_DEFAULT_TIMEOUT	3
+
 #include <linux/module.h>
+#include <linux/delay.h>
 #include <linux/fs.h>
 #include <linux/blkdev.h>
 #include <linux/bio.h>
@@ -17,6 +25,7 @@
 #include <linux/list.h>
 #include <linux/init.h>
 #include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
 #include <linux/mutex.h>
 #include <linux/mount.h>
 #include <linux/slab.h>
@@ -209,12 +218,14 @@ static void block2mtd_free_device(struct
 }
 
 
-static struct block2mtd_dev *add_device(char *devname, int erase_size)
+static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout)
 {
 	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
-	struct block_device *bdev;
+	struct block_device *bdev = ERR_PTR(-ENODEV);
 	struct block2mtd_dev *dev;
+	struct mtd_partition *part;
 	char *name;
+	int i;
 
 	if (!devname)
 		return NULL;
@@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device(
 
 	/* Get a handle on the device */
 	bdev = blkdev_get_by_path(devname, mode, dev);
-#ifndef MODULE
-	if (IS_ERR(bdev)) {
 
-		/* We might not have rootfs mounted at this point. Try
-		   to resolve the device name by other means. */
-
-		dev_t devt = name_to_dev_t(devname);
-		if (devt)
-			bdev = blkdev_get_by_dev(devt, mode, dev);
+#ifndef MODULE
+/*
+* We might not have the root device mounted at this point.
+* Try to resolve the device name by other means.
+*/
+	for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
+		dev_t devt;
+
+		if (i)
+			/*
+			 * Calling wait_for_device_probe in the first loop 
+			 * was not enough, sleep for a bit in subsequent
+			 * go-arounds.
+			*/
+			msleep(1000);
+		wait_for_device_probe();
+
+		devt = name_to_dev_t(devname);
+		if (!devt)
+			continue;
+		bdev = blkdev_get_by_dev(devt, mode, dev);
 	}
 #endif
 
@@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device(
 
 	/* Setup the MTD structure */
 	/* make the name contain the block device in */
-	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
+	if (!mtdname)
+		mtdname = devname;
+	name = kstrdup (mtdname, GFP_KERNEL);
 	if (!name)
 		goto err_destroy_mutex;
 
 	dev->mtd.name = name;
-
-	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
+	dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
 	dev->mtd.erasesize = erase_size;
 	dev->mtd.writesize = 1;
 	dev->mtd.writebufsize = PAGE_SIZE;
@@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device(
 	dev->mtd.priv = dev;
 	dev->mtd.owner = THIS_MODULE;
 
-	if (mtd_device_register(&dev->mtd, NULL, 0)) {
+	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
+	part->name = name;
+	part->offset = 0;
+	part->size = dev->mtd.size;
+	if (mtd_device_register(&dev->mtd, part, 1)) {
 		/* Device didn't get added, so free the entry */
 		goto err_destroy_mutex;
 	}
+
 	list_add(&dev->list, &blkmtd_device_list);
 	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
 		dev->mtd.index,
-		dev->mtd.name + strlen("block2mtd: "),
-		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
+		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
 	return dev;
 
 err_destroy_mutex:
@@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12]
 
 static int block2mtd_setup2(const char *val)
 {
-	char buf[80 + 12]; /* 80 for device, 12 for erase size */
+	char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
 	char *str = buf;
-	char *token[2];
+	char *token[4];
 	char *name;
 	size_t erase_size = PAGE_SIZE;
+	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
 	int i, ret;
 
 	if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
@@ -368,7 +398,7 @@ static int block2mtd_setup2(const char *
 	strcpy(str, val);
 	kill_final_newline(str);
 
-	for (i = 0; i < 2; i++)
+	for (i = 0; i < 4; i++)
 		token[i] = strsep(&str, ",");
 
 	if (str) {
@@ -395,7 +425,13 @@ static int block2mtd_setup2(const char *
 		}
 	}
 
-	add_device(name, erase_size);
+	if (token[2] && (strlen(token[2]) + 1 > 80))
+		pr_err("mtd device name too long");
+
+
+	if (token[3] && kstrtoul(token[3], 0, &timeout))
+		pr_err("invalid timeout");
+	add_device(name, erase_size, token[2], timeout);
 
 	return 0;
 }
@@ -429,7 +465,7 @@ static int block2mtd_setup(const char *v
 
 
 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
 
 static int __init block2mtd_init(void)
 {
@@ -463,8 +499,7 @@ static void block2mtd_exit(void)
 	}
 }
 
-
-module_init(block2mtd_init);
+late_initcall(block2mtd_init);
 module_exit(block2mtd_exit);
 
 MODULE_LICENSE("GPL");
---
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-09-17 20:28       ` Rodrigo Freire
@ 2014-09-17 21:21         ` Ezequiel Garcia
  -1 siblings, 0 replies; 63+ messages in thread
From: Ezequiel Garcia @ 2014-09-17 21:21 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Jörn Engel, linux-mtd, Felix Fietkau, David Woodhouse,
	linux-kernel, Herton Krzesinski

On 17 September 2014 21:28, Rodrigo Freire <rfreire@redhat.com> wrote:
>
> mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion
>

Using block2mtd sounds a bit unusual. I see that you are trying to get
a more robust fs.... have you tried using f2fs instead of jffs2?

> Currently, a block MTD device is not presented to the system on time, in
> order to start mounting the filesystems. This patch ensures that block2mtd
> is presented at the right time, so filesystems can be mounted on boot time.

It worries me a bit to add such a long delay to the boot. If for some
reason the SD is not working, then the kernel will wait (by default) 3
seconds now?
-- 
Ezequiel García, VanguardiaSur
www.vanguardiasur.com.ar

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-09-17 21:21         ` Ezequiel Garcia
  0 siblings, 0 replies; 63+ messages in thread
From: Ezequiel Garcia @ 2014-09-17 21:21 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, David Woodhouse

On 17 September 2014 21:28, Rodrigo Freire <rfreire@redhat.com> wrote:
>
> mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion
>

Using block2mtd sounds a bit unusual. I see that you are trying to get
a more robust fs.... have you tried using f2fs instead of jffs2?

> Currently, a block MTD device is not presented to the system on time, in
> order to start mounting the filesystems. This patch ensures that block2mtd
> is presented at the right time, so filesystems can be mounted on boot time.

It worries me a bit to add such a long delay to the boot. If for some
reason the SD is not working, then the kernel will wait (by default) 3
seconds now?
-- 
Ezequiel García, VanguardiaSur
www.vanguardiasur.com.ar

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-09-17 21:21         ` Ezequiel Garcia
@ 2014-09-17 21:41           ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-09-17 21:41 UTC (permalink / raw)
  To: Ezequiel Garcia
  Cc: Jörn Engel, linux-mtd, Felix Fietkau, David Woodhouse,
	linux-kernel, Herton Krzesinski

Holas Ezequiel,

----- Original Message ----- 
From: "Ezequiel Garcia" <ezequiel@vanguardiasur.com.ar> 
> On 17 September 2014 21:28, Rodrigo Freire <rfreire@redhat.com> wrote: 
> 
> Using block2mtd sounds a bit unusual. I see that you are trying to get 
> a more robust fs.... have you tried using f2fs instead of jffs2? 

I see that it is still marked as Experimental as of latest (3.17-RC5)
kernel. But will take a look in the future, thanks for pointing.


> > Currently, a block MTD device is not presented to the system on time, in 
> > order to start mounting the filesystems. This patch ensures that block2mtd 
> > is presented at the right time, so filesystems can be mounted on boot time. 
> 
> It worries me a bit to add such a long delay to the boot. If for some 
> reason the SD is not working, then the kernel will wait (by default) 3 
> seconds now? 

Not really; see the decision path:
IF block2mtd is not a module (is builtin), AND
   IF there is a valid block2mtd= clause on kernel cmdline, AND
      IF the device specified device on block2mtd= clause is still not present
      THEN wait *up to* 3 seconds (or seconds=n if specified on block2mtd=
           cmdline) to the device to show up. If the device shows up earlier,
           the device is created and boot proceeds.
      ELSE Fail to create the block2mtd device.
ELSE keep booting the kernel normally, without any further delays.

Best regards,

- RF.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-09-17 21:41           ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-09-17 21:41 UTC (permalink / raw)
  To: Ezequiel Garcia
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, David Woodhouse

Holas Ezequiel,

----- Original Message ----- 
From: "Ezequiel Garcia" <ezequiel@vanguardiasur.com.ar> 
> On 17 September 2014 21:28, Rodrigo Freire <rfreire@redhat.com> wrote: 
> 
> Using block2mtd sounds a bit unusual. I see that you are trying to get 
> a more robust fs.... have you tried using f2fs instead of jffs2? 

I see that it is still marked as Experimental as of latest (3.17-RC5)
kernel. But will take a look in the future, thanks for pointing.


> > Currently, a block MTD device is not presented to the system on time, in 
> > order to start mounting the filesystems. This patch ensures that block2mtd 
> > is presented at the right time, so filesystems can be mounted on boot time. 
> 
> It worries me a bit to add such a long delay to the boot. If for some 
> reason the SD is not working, then the kernel will wait (by default) 3 
> seconds now? 

Not really; see the decision path:
IF block2mtd is not a module (is builtin), AND
   IF there is a valid block2mtd= clause on kernel cmdline, AND
      IF the device specified device on block2mtd= clause is still not present
      THEN wait *up to* 3 seconds (or seconds=n if specified on block2mtd=
           cmdline) to the device to show up. If the device shows up earlier,
           the device is created and boot proceeds.
      ELSE Fail to create the block2mtd device.
ELSE keep booting the kernel normally, without any further delays.

Best regards,

- RF.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-09-17 20:28       ` Rodrigo Freire
@ 2014-10-09 15:07         ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-10-09 15:07 UTC (permalink / raw)
  To: Jörn Engel
  Cc: dwmw2, Felix Fietkau, linux-mtd, linux-kernel, Herton Krzesinski

From: Felix Fietkau <nbd@openwrt.org> 

mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion 

Currently, a block MTD device is not presented to the system on time, in 
order to start mounting the filesystems. This patch ensures that block2mtd 
is presented at the right time, so filesystems can be mounted on boot time. 
This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
block2mtd filesystems. 
This patchset also adds a MTD device name and a timeout option to the driver. 
Original patchset: 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444 

Signed-off-by: Felix Fietkau <nbd@openwrt.org> 
Signed-off-by: Rodrigo Freire <rfreire@redhat.com> 
Signed-off-by: Herton Krzesinski <herton@redhat.com> 
--- 
V2: Uses kstrdup, removed PAGE_MASK. 
--- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
+++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
@@ -9,7 +9,15 @@ 

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 

+/* 
+* When the first attempt at device initialization fails, we may need to 
+* wait a little bit and retry. This timeout, by default 3 seconds, gives 
+* device time to start up. Required on BCM2708 and a few other chipsets. 
+*/ 
+#define MTD_DEFAULT_TIMEOUT 3 
+ 
#include <linux/module.h> 
+#include <linux/delay.h> 
#include <linux/fs.h> 
#include <linux/blkdev.h> 
#include <linux/bio.h> 
@@ -17,6 +25,7 @@ 
#include <linux/list.h> 
#include <linux/init.h> 
#include <linux/mtd/mtd.h> 
+#include <linux/mtd/partitions.h> 
#include <linux/mutex.h> 
#include <linux/mount.h> 
#include <linux/slab.h> 
@@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
} 


-static struct block2mtd_dev *add_device(char *devname, int erase_size) 
+static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout) 
{ 
const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL; 
- struct block_device *bdev; 
+ struct block_device *bdev = ERR_PTR(-ENODEV); 
struct block2mtd_dev *dev; 
+ struct mtd_partition *part; 
char *name; 
+ int i; 

if (!devname) 
return NULL; 
@@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device( 

/* Get a handle on the device */ 
bdev = blkdev_get_by_path(devname, mode, dev); 
-#ifndef MODULE 
- if (IS_ERR(bdev)) { 

- /* We might not have rootfs mounted at this point. Try 
- to resolve the device name by other means. */ 
- 
- dev_t devt = name_to_dev_t(devname); 
- if (devt) 
- bdev = blkdev_get_by_dev(devt, mode, dev); 
+#ifndef MODULE 
+/* 
+* We might not have the root device mounted at this point. 
+* Try to resolve the device name by other means. 
+*/ 
+ for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { 
+ dev_t devt; 
+ 
+ if (i) 
+ /* 
+ * Calling wait_for_device_probe in the first loop 
+ * was not enough, sleep for a bit in subsequent 
+ * go-arounds. 
+ */ 
+ msleep(1000); 
+ wait_for_device_probe(); 
+ 
+ devt = name_to_dev_t(devname); 
+ if (!devt) 
+ continue; 
+ bdev = blkdev_get_by_dev(devt, mode, dev); 
} 
#endif 

@@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 

/* Setup the MTD structure */ 
/* make the name contain the block device in */ 
- name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname); 
+ if (!mtdname) 
+ mtdname = devname; 
+ name = kstrdup (mtdname, GFP_KERNEL); 
if (!name) 
goto err_destroy_mutex; 

dev->mtd.name = name; 
- 
- dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK; 
+ dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1); 
dev->mtd.erasesize = erase_size; 
dev->mtd.writesize = 1; 
dev->mtd.writebufsize = PAGE_SIZE; 
@@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
dev->mtd.priv = dev; 
dev->mtd.owner = THIS_MODULE; 

- if (mtd_device_register(&dev->mtd, NULL, 0)) { 
+ part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
+ part->name = name; 
+ part->offset = 0; 
+ part->size = dev->mtd.size; 
+ if (mtd_device_register(&dev->mtd, part, 1)) { 
/* Device didn't get added, so free the entry */ 
goto err_destroy_mutex; 
} 
+ 
list_add(&dev->list, &blkmtd_device_list); 
pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n", 
dev->mtd.index, 
- dev->mtd.name + strlen("block2mtd: "), 
- dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
+ mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
return dev; 

err_destroy_mutex: 
@@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 

static int block2mtd_setup2(const char *val) 
{ 
- char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
+ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */ 
char *str = buf; 
- char *token[2]; 
+ char *token[4]; 
char *name; 
size_t erase_size = PAGE_SIZE; 
+ unsigned long timeout = MTD_DEFAULT_TIMEOUT; 
int i, ret; 

if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { 
@@ -368,7 +398,7 @@ static int block2mtd_setup2(const char * 
strcpy(str, val); 
kill_final_newline(str); 

- for (i = 0; i < 2; i++) 
+ for (i = 0; i < 4; i++) 
token[i] = strsep(&str, ","); 

if (str) { 
@@ -395,7 +425,13 @@ static int block2mtd_setup2(const char * 
} 
} 

- add_device(name, erase_size); 
+ if (token[2] && (strlen(token[2]) + 1 > 80)) 
+ pr_err("mtd device name too long"); 
+ 
+ 
+ if (token[3] && kstrtoul(token[3], 0, &timeout)) 
+ pr_err("invalid timeout"); 
+ add_device(name, erase_size, token[2], timeout); 

return 0; 
} 
@@ -429,7 +465,7 @@ static int block2mtd_setup(const char *v 


module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200); 
-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\""); 
+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\""); 

static int __init block2mtd_init(void) 
{ 
@@ -463,8 +499,7 @@ static void block2mtd_exit(void) 
} 
} 

- 
-module_init(block2mtd_init); 
+late_initcall(block2mtd_init); 
module_exit(block2mtd_exit); 

MODULE_LICENSE("GPL"); 
--- 
1.7.1 

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-10-09 15:07         ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-10-09 15:07 UTC (permalink / raw)
  To: Jörn Engel
  Cc: linux-mtd, Felix Fietkau, dwmw2, linux-kernel, Herton Krzesinski

From: Felix Fietkau <nbd@openwrt.org> 

mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion 

Currently, a block MTD device is not presented to the system on time, in 
order to start mounting the filesystems. This patch ensures that block2mtd 
is presented at the right time, so filesystems can be mounted on boot time. 
This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
block2mtd filesystems. 
This patchset also adds a MTD device name and a timeout option to the driver. 
Original patchset: 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444 

Signed-off-by: Felix Fietkau <nbd@openwrt.org> 
Signed-off-by: Rodrigo Freire <rfreire@redhat.com> 
Signed-off-by: Herton Krzesinski <herton@redhat.com> 
--- 
V2: Uses kstrdup, removed PAGE_MASK. 
--- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
+++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
@@ -9,7 +9,15 @@ 

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 

+/* 
+* When the first attempt at device initialization fails, we may need to 
+* wait a little bit and retry. This timeout, by default 3 seconds, gives 
+* device time to start up. Required on BCM2708 and a few other chipsets. 
+*/ 
+#define MTD_DEFAULT_TIMEOUT 3 
+ 
#include <linux/module.h> 
+#include <linux/delay.h> 
#include <linux/fs.h> 
#include <linux/blkdev.h> 
#include <linux/bio.h> 
@@ -17,6 +25,7 @@ 
#include <linux/list.h> 
#include <linux/init.h> 
#include <linux/mtd/mtd.h> 
+#include <linux/mtd/partitions.h> 
#include <linux/mutex.h> 
#include <linux/mount.h> 
#include <linux/slab.h> 
@@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
} 


-static struct block2mtd_dev *add_device(char *devname, int erase_size) 
+static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout) 
{ 
const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL; 
- struct block_device *bdev; 
+ struct block_device *bdev = ERR_PTR(-ENODEV); 
struct block2mtd_dev *dev; 
+ struct mtd_partition *part; 
char *name; 
+ int i; 

if (!devname) 
return NULL; 
@@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device( 

/* Get a handle on the device */ 
bdev = blkdev_get_by_path(devname, mode, dev); 
-#ifndef MODULE 
- if (IS_ERR(bdev)) { 

- /* We might not have rootfs mounted at this point. Try 
- to resolve the device name by other means. */ 
- 
- dev_t devt = name_to_dev_t(devname); 
- if (devt) 
- bdev = blkdev_get_by_dev(devt, mode, dev); 
+#ifndef MODULE 
+/* 
+* We might not have the root device mounted at this point. 
+* Try to resolve the device name by other means. 
+*/ 
+ for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { 
+ dev_t devt; 
+ 
+ if (i) 
+ /* 
+ * Calling wait_for_device_probe in the first loop 
+ * was not enough, sleep for a bit in subsequent 
+ * go-arounds. 
+ */ 
+ msleep(1000); 
+ wait_for_device_probe(); 
+ 
+ devt = name_to_dev_t(devname); 
+ if (!devt) 
+ continue; 
+ bdev = blkdev_get_by_dev(devt, mode, dev); 
} 
#endif 

@@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 

/* Setup the MTD structure */ 
/* make the name contain the block device in */ 
- name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname); 
+ if (!mtdname) 
+ mtdname = devname; 
+ name = kstrdup (mtdname, GFP_KERNEL); 
if (!name) 
goto err_destroy_mutex; 

dev->mtd.name = name; 
- 
- dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK; 
+ dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1); 
dev->mtd.erasesize = erase_size; 
dev->mtd.writesize = 1; 
dev->mtd.writebufsize = PAGE_SIZE; 
@@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
dev->mtd.priv = dev; 
dev->mtd.owner = THIS_MODULE; 

- if (mtd_device_register(&dev->mtd, NULL, 0)) { 
+ part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
+ part->name = name; 
+ part->offset = 0; 
+ part->size = dev->mtd.size; 
+ if (mtd_device_register(&dev->mtd, part, 1)) { 
/* Device didn't get added, so free the entry */ 
goto err_destroy_mutex; 
} 
+ 
list_add(&dev->list, &blkmtd_device_list); 
pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n", 
dev->mtd.index, 
- dev->mtd.name + strlen("block2mtd: "), 
- dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
+ mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
return dev; 

err_destroy_mutex: 
@@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 

static int block2mtd_setup2(const char *val) 
{ 
- char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
+ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */ 
char *str = buf; 
- char *token[2]; 
+ char *token[4]; 
char *name; 
size_t erase_size = PAGE_SIZE; 
+ unsigned long timeout = MTD_DEFAULT_TIMEOUT; 
int i, ret; 

if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { 
@@ -368,7 +398,7 @@ static int block2mtd_setup2(const char * 
strcpy(str, val); 
kill_final_newline(str); 

- for (i = 0; i < 2; i++) 
+ for (i = 0; i < 4; i++) 
token[i] = strsep(&str, ","); 

if (str) { 
@@ -395,7 +425,13 @@ static int block2mtd_setup2(const char * 
} 
} 

- add_device(name, erase_size); 
+ if (token[2] && (strlen(token[2]) + 1 > 80)) 
+ pr_err("mtd device name too long"); 
+ 
+ 
+ if (token[3] && kstrtoul(token[3], 0, &timeout)) 
+ pr_err("invalid timeout"); 
+ add_device(name, erase_size, token[2], timeout); 

return 0; 
} 
@@ -429,7 +465,7 @@ static int block2mtd_setup(const char *v 


module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200); 
-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\""); 
+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\""); 

static int __init block2mtd_init(void) 
{ 
@@ -463,8 +499,7 @@ static void block2mtd_exit(void) 
} 
} 

- 
-module_init(block2mtd_init); 
+late_initcall(block2mtd_init); 
module_exit(block2mtd_exit); 

MODULE_LICENSE("GPL"); 
--- 
1.7.1 

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-10-09 15:07         ` Rodrigo Freire
@ 2014-11-01 13:33           ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-01 13:33 UTC (permalink / raw)
  To: Jörn Engel
  Cc: dwmw2, Felix Fietkau, linux-mtd, linux-kernel, Herton Krzesinski

From: Felix Fietkau <nbd@openwrt.org> 

mtd: block2mtd: Ensure that block2mtd is presented timely on boot time

Currently, a block MTD device is not presented to the system on time, in 
order to start mounting the filesystems. This patch ensures that block2mtd 
is presented at the right time, so filesystems can be mounted on boot time. 
This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
over block2mtd devices as the root filesystem.
This patchset also adds a MTD device name and a timeout option to the driver. 
Original patchset: 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444 

Signed-off-by: Felix Fietkau <nbd@openwrt.org> 
Signed-off-by: Herton Ronaldo Krzesinski <herton@redhat.com> 
Signed-off-by: Rodrigo Freire <rfreire@redhat.com> 
--- 
V2: Uses kstrdup, removed PAGE_MASK. 
--- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
+++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
@@ -9,7 +9,15 @@ 

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 

+/* 
+* When the first attempt at device initialization fails, we may need to 
+* wait a little bit and retry. This timeout, by default 3 seconds, gives 
+* device time to start up. Required on BCM2835.
+*/ 
+#define MTD_DEFAULT_TIMEOUT 3 
+ 
#include <linux/module.h> 
+#include <linux/delay.h> 
#include <linux/fs.h> 
#include <linux/blkdev.h> 
#include <linux/bio.h> 
@@ -17,6 +25,7 @@ 
#include <linux/list.h> 
#include <linux/init.h> 
#include <linux/mtd/mtd.h> 
+#include <linux/mtd/partitions.h> 
#include <linux/mutex.h> 
#include <linux/mount.h> 
#include <linux/slab.h> 
@@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
} 


-static struct block2mtd_dev *add_device(char *devname, int erase_size) 
+static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout) 
{ 
const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL; 
- struct block_device *bdev; 
+ struct block_device *bdev = ERR_PTR(-ENODEV); 
struct block2mtd_dev *dev; 
+ struct mtd_partition *part; 
char *name; 
+ int i; 

if (!devname) 
return NULL; 
@@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device( 

/* Get a handle on the device */ 
bdev = blkdev_get_by_path(devname, mode, dev); 
-#ifndef MODULE 
- if (IS_ERR(bdev)) { 

- /* We might not have rootfs mounted at this point. Try 
- to resolve the device name by other means. */ 
- 
- dev_t devt = name_to_dev_t(devname); 
- if (devt) 
- bdev = blkdev_get_by_dev(devt, mode, dev); 
+#ifndef MODULE 
+/* 
+* We might not have the root device mounted at this point. 
+* Try to resolve the device name by other means. 
+*/ 
+ for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { 
+ dev_t devt; 
+ 
+ if (i) 
+ /* 
+ * Calling wait_for_device_probe in the first loop 
+ * was not enough, sleep for a bit in subsequent 
+ * go-arounds. 
+ */ 
+ msleep(1000); 
+ wait_for_device_probe(); 
+ 
+ devt = name_to_dev_t(devname); 
+ if (!devt) 
+ continue; 
+ bdev = blkdev_get_by_dev(devt, mode, dev); 
} 
#endif 

@@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 

/* Setup the MTD structure */ 
/* make the name contain the block device in */ 
- name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname); 
+ if (!mtdname) 
+ mtdname = devname; 
+ name = kstrdup (mtdname, GFP_KERNEL); 
if (!name) 
goto err_destroy_mutex; 

dev->mtd.name = name; 
- 
- dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK; 
+ dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1); 
dev->mtd.erasesize = erase_size; 
dev->mtd.writesize = 1; 
dev->mtd.writebufsize = PAGE_SIZE; 
@@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
dev->mtd.priv = dev; 
dev->mtd.owner = THIS_MODULE; 

- if (mtd_device_register(&dev->mtd, NULL, 0)) { 
+ part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
+ part->name = name; 
+ part->offset = 0; 
+ part->size = dev->mtd.size; 
+ if (mtd_device_register(&dev->mtd, part, 1)) { 
/* Device didn't get added, so free the entry */ 
goto err_destroy_mutex; 
} 
+ 
list_add(&dev->list, &blkmtd_device_list); 
pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n", 
dev->mtd.index, 
- dev->mtd.name + strlen("block2mtd: "), 
- dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
+ mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
return dev; 

err_destroy_mutex: 
@@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 

static int block2mtd_setup2(const char *val) 
{ 
- char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
+ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */ 
char *str = buf; 
- char *token[2]; 
+ char *token[4]; 
char *name; 
size_t erase_size = PAGE_SIZE; 
+ unsigned long timeout = MTD_DEFAULT_TIMEOUT; 
int i, ret; 

if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { 
@@ -368,7 +398,7 @@ static int block2mtd_setup2(const char * 
strcpy(str, val); 
kill_final_newline(str); 

- for (i = 0; i < 2; i++) 
+ for (i = 0; i < 4; i++) 
token[i] = strsep(&str, ","); 

if (str) { 
@@ -395,7 +425,13 @@ static int block2mtd_setup2(const char * 
} 
} 

- add_device(name, erase_size); 
+ if (token[2] && (strlen(token[2]) + 1 > 80)) 
+ pr_err("mtd device name too long"); 
+ 
+ 
+ if (token[3] && kstrtoul(token[3], 0, &timeout)) 
+ pr_err("invalid timeout"); 
+ add_device(name, erase_size, token[2], timeout); 

return 0; 
} 
@@ -429,7 +465,7 @@ static int block2mtd_setup(const char *v 


module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200); 
-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\""); 
+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\""); 

static int __init block2mtd_init(void) 
{ 
@@ -463,8 +499,7 @@ static void block2mtd_exit(void) 
} 
} 

- 
-module_init(block2mtd_init); 
+late_initcall(block2mtd_init); 
module_exit(block2mtd_exit); 

MODULE_LICENSE("GPL"); 
--- 
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-11-01 13:33           ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-01 13:33 UTC (permalink / raw)
  To: Jörn Engel
  Cc: linux-mtd, Felix Fietkau, dwmw2, linux-kernel, Herton Krzesinski

From: Felix Fietkau <nbd@openwrt.org> 

mtd: block2mtd: Ensure that block2mtd is presented timely on boot time

Currently, a block MTD device is not presented to the system on time, in 
order to start mounting the filesystems. This patch ensures that block2mtd 
is presented at the right time, so filesystems can be mounted on boot time. 
This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
over block2mtd devices as the root filesystem.
This patchset also adds a MTD device name and a timeout option to the driver. 
Original patchset: 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444 

Signed-off-by: Felix Fietkau <nbd@openwrt.org> 
Signed-off-by: Herton Ronaldo Krzesinski <herton@redhat.com> 
Signed-off-by: Rodrigo Freire <rfreire@redhat.com> 
--- 
V2: Uses kstrdup, removed PAGE_MASK. 
--- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
+++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
@@ -9,7 +9,15 @@ 

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 

+/* 
+* When the first attempt at device initialization fails, we may need to 
+* wait a little bit and retry. This timeout, by default 3 seconds, gives 
+* device time to start up. Required on BCM2835.
+*/ 
+#define MTD_DEFAULT_TIMEOUT 3 
+ 
#include <linux/module.h> 
+#include <linux/delay.h> 
#include <linux/fs.h> 
#include <linux/blkdev.h> 
#include <linux/bio.h> 
@@ -17,6 +25,7 @@ 
#include <linux/list.h> 
#include <linux/init.h> 
#include <linux/mtd/mtd.h> 
+#include <linux/mtd/partitions.h> 
#include <linux/mutex.h> 
#include <linux/mount.h> 
#include <linux/slab.h> 
@@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
} 


-static struct block2mtd_dev *add_device(char *devname, int erase_size) 
+static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout) 
{ 
const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL; 
- struct block_device *bdev; 
+ struct block_device *bdev = ERR_PTR(-ENODEV); 
struct block2mtd_dev *dev; 
+ struct mtd_partition *part; 
char *name; 
+ int i; 

if (!devname) 
return NULL; 
@@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device( 

/* Get a handle on the device */ 
bdev = blkdev_get_by_path(devname, mode, dev); 
-#ifndef MODULE 
- if (IS_ERR(bdev)) { 

- /* We might not have rootfs mounted at this point. Try 
- to resolve the device name by other means. */ 
- 
- dev_t devt = name_to_dev_t(devname); 
- if (devt) 
- bdev = blkdev_get_by_dev(devt, mode, dev); 
+#ifndef MODULE 
+/* 
+* We might not have the root device mounted at this point. 
+* Try to resolve the device name by other means. 
+*/ 
+ for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { 
+ dev_t devt; 
+ 
+ if (i) 
+ /* 
+ * Calling wait_for_device_probe in the first loop 
+ * was not enough, sleep for a bit in subsequent 
+ * go-arounds. 
+ */ 
+ msleep(1000); 
+ wait_for_device_probe(); 
+ 
+ devt = name_to_dev_t(devname); 
+ if (!devt) 
+ continue; 
+ bdev = blkdev_get_by_dev(devt, mode, dev); 
} 
#endif 

@@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 

/* Setup the MTD structure */ 
/* make the name contain the block device in */ 
- name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname); 
+ if (!mtdname) 
+ mtdname = devname; 
+ name = kstrdup (mtdname, GFP_KERNEL); 
if (!name) 
goto err_destroy_mutex; 

dev->mtd.name = name; 
- 
- dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK; 
+ dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1); 
dev->mtd.erasesize = erase_size; 
dev->mtd.writesize = 1; 
dev->mtd.writebufsize = PAGE_SIZE; 
@@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
dev->mtd.priv = dev; 
dev->mtd.owner = THIS_MODULE; 

- if (mtd_device_register(&dev->mtd, NULL, 0)) { 
+ part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
+ part->name = name; 
+ part->offset = 0; 
+ part->size = dev->mtd.size; 
+ if (mtd_device_register(&dev->mtd, part, 1)) { 
/* Device didn't get added, so free the entry */ 
goto err_destroy_mutex; 
} 
+ 
list_add(&dev->list, &blkmtd_device_list); 
pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n", 
dev->mtd.index, 
- dev->mtd.name + strlen("block2mtd: "), 
- dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
+ mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
return dev; 

err_destroy_mutex: 
@@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 

static int block2mtd_setup2(const char *val) 
{ 
- char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
+ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */ 
char *str = buf; 
- char *token[2]; 
+ char *token[4]; 
char *name; 
size_t erase_size = PAGE_SIZE; 
+ unsigned long timeout = MTD_DEFAULT_TIMEOUT; 
int i, ret; 

if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { 
@@ -368,7 +398,7 @@ static int block2mtd_setup2(const char * 
strcpy(str, val); 
kill_final_newline(str); 

- for (i = 0; i < 2; i++) 
+ for (i = 0; i < 4; i++) 
token[i] = strsep(&str, ","); 

if (str) { 
@@ -395,7 +425,13 @@ static int block2mtd_setup2(const char * 
} 
} 

- add_device(name, erase_size); 
+ if (token[2] && (strlen(token[2]) + 1 > 80)) 
+ pr_err("mtd device name too long"); 
+ 
+ 
+ if (token[3] && kstrtoul(token[3], 0, &timeout)) 
+ pr_err("invalid timeout"); 
+ add_device(name, erase_size, token[2], timeout); 

return 0; 
} 
@@ -429,7 +465,7 @@ static int block2mtd_setup(const char *v 


module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200); 
-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\""); 
+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\""); 

static int __init block2mtd_init(void) 
{ 
@@ -463,8 +499,7 @@ static void block2mtd_exit(void) 
} 
} 

- 
-module_init(block2mtd_init); 
+late_initcall(block2mtd_init); 
module_exit(block2mtd_exit); 

MODULE_LICENSE("GPL"); 
--- 
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-10-09 15:07         ` Rodrigo Freire
@ 2014-11-05 20:01           ` Brian Norris
  -1 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2014-11-05 20:01 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Jörn Engel, linux-mtd, Felix Fietkau, dwmw2, linux-kernel,
	Herton Krzesinski

On Thu, Oct 09, 2014 at 11:07:31AM -0400, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org> 
> 
> mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion 
> 
> Currently, a block MTD device is not presented to the system on time, in 
> order to start mounting the filesystems. This patch ensures that block2mtd 
> is presented at the right time, so filesystems can be mounted on boot time. 
> This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
> block2mtd filesystems. 
> This patchset also adds a MTD device name and a timeout option to the driver. 
> Original patchset: 
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444 
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444 
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org> 
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com> 
> Signed-off-by: Herton Krzesinski <herton@redhat.com> 
> --- 
> V2: Uses kstrdup, removed PAGE_MASK. 

FYI, this copy was malformed. All the indentation and formatting is
wrong, so it doesn't apply. I'll look at the previous copy you sent, but
please fix this in the future.

Brian

> --- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
> +++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
> @@ -9,7 +9,15 @@ 
> 
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 
> 
> +/* 
> +* When the first attempt at device initialization fails, we may need to 
> +* wait a little bit and retry. This timeout, by default 3 seconds, gives 
> +* device time to start up. Required on BCM2708 and a few other chipsets. 
> +*/ 
> +#define MTD_DEFAULT_TIMEOUT 3 
> + 
> #include <linux/module.h> 
> +#include <linux/delay.h> 
> #include <linux/fs.h> 
> #include <linux/blkdev.h> 
> #include <linux/bio.h> 
> @@ -17,6 +25,7 @@ 
> #include <linux/list.h> 
> #include <linux/init.h> 
> #include <linux/mtd/mtd.h> 
> +#include <linux/mtd/partitions.h> 
> #include <linux/mutex.h> 
> #include <linux/mount.h> 
> #include <linux/slab.h> 
> @@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
> } 
> 
> 
> -static struct block2mtd_dev *add_device(char *devname, int erase_size) 
> +static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout) 
> { 
> const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL; 
> - struct block_device *bdev; 
> + struct block_device *bdev = ERR_PTR(-ENODEV); 
> struct block2mtd_dev *dev; 
> + struct mtd_partition *part; 
> char *name; 
> + int i; 
> 
> if (!devname) 
> return NULL; 
> @@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device( 
> 
> /* Get a handle on the device */ 
> bdev = blkdev_get_by_path(devname, mode, dev); 
> -#ifndef MODULE 
> - if (IS_ERR(bdev)) { 
> 
> - /* We might not have rootfs mounted at this point. Try 
> - to resolve the device name by other means. */ 
> - 
> - dev_t devt = name_to_dev_t(devname); 
> - if (devt) 
> - bdev = blkdev_get_by_dev(devt, mode, dev); 
> +#ifndef MODULE 
> +/* 
> +* We might not have the root device mounted at this point. 
> +* Try to resolve the device name by other means. 
> +*/ 
> + for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { 
> + dev_t devt; 
> + 
> + if (i) 
> + /* 
> + * Calling wait_for_device_probe in the first loop 
> + * was not enough, sleep for a bit in subsequent 
> + * go-arounds. 
> + */ 
> + msleep(1000); 
> + wait_for_device_probe(); 
> + 
> + devt = name_to_dev_t(devname); 
> + if (!devt) 
> + continue; 
> + bdev = blkdev_get_by_dev(devt, mode, dev); 
> } 
> #endif 
> 
> @@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 
> 
> /* Setup the MTD structure */ 
> /* make the name contain the block device in */ 
> - name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname); 
> + if (!mtdname) 
> + mtdname = devname; 
> + name = kstrdup (mtdname, GFP_KERNEL); 
> if (!name) 
> goto err_destroy_mutex; 
> 
> dev->mtd.name = name; 
> - 
> - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK; 
> + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1); 
> dev->mtd.erasesize = erase_size; 
> dev->mtd.writesize = 1; 
> dev->mtd.writebufsize = PAGE_SIZE; 
> @@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
> dev->mtd.priv = dev; 
> dev->mtd.owner = THIS_MODULE; 
> 
> - if (mtd_device_register(&dev->mtd, NULL, 0)) { 
> + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
> + part->name = name; 
> + part->offset = 0; 
> + part->size = dev->mtd.size; 
> + if (mtd_device_register(&dev->mtd, part, 1)) { 
> /* Device didn't get added, so free the entry */ 
> goto err_destroy_mutex; 
> } 
> + 
> list_add(&dev->list, &blkmtd_device_list); 
> pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n", 
> dev->mtd.index, 
> - dev->mtd.name + strlen("block2mtd: "), 
> - dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
> + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
> return dev; 
> 
> err_destroy_mutex: 
> @@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 
> 
> static int block2mtd_setup2(const char *val) 
> { 
> - char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
> + char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */ 
> char *str = buf; 
> - char *token[2]; 
> + char *token[4]; 
> char *name; 
> size_t erase_size = PAGE_SIZE; 
> + unsigned long timeout = MTD_DEFAULT_TIMEOUT; 
> int i, ret; 
> 
> if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { 
> @@ -368,7 +398,7 @@ static int block2mtd_setup2(const char * 
> strcpy(str, val); 
> kill_final_newline(str); 
> 
> - for (i = 0; i < 2; i++) 
> + for (i = 0; i < 4; i++) 
> token[i] = strsep(&str, ","); 
> 
> if (str) { 
> @@ -395,7 +425,13 @@ static int block2mtd_setup2(const char * 
> } 
> } 
> 
> - add_device(name, erase_size); 
> + if (token[2] && (strlen(token[2]) + 1 > 80)) 
> + pr_err("mtd device name too long"); 
> + 
> + 
> + if (token[3] && kstrtoul(token[3], 0, &timeout)) 
> + pr_err("invalid timeout"); 
> + add_device(name, erase_size, token[2], timeout); 
> 
> return 0; 
> } 
> @@ -429,7 +465,7 @@ static int block2mtd_setup(const char *v 
> 
> 
> module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200); 
> -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\""); 
> +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\""); 
> 
> static int __init block2mtd_init(void) 
> { 
> @@ -463,8 +499,7 @@ static void block2mtd_exit(void) 
> } 
> } 
> 
> - 
> -module_init(block2mtd_init); 
> +late_initcall(block2mtd_init); 
> module_exit(block2mtd_exit); 
> 
> MODULE_LICENSE("GPL"); 
> --- 
> 1.7.1 
> 
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-11-05 20:01           ` Brian Norris
  0 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2014-11-05 20:01 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

On Thu, Oct 09, 2014 at 11:07:31AM -0400, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org> 
> 
> mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion 
> 
> Currently, a block MTD device is not presented to the system on time, in 
> order to start mounting the filesystems. This patch ensures that block2mtd 
> is presented at the right time, so filesystems can be mounted on boot time. 
> This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
> block2mtd filesystems. 
> This patchset also adds a MTD device name and a timeout option to the driver. 
> Original patchset: 
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444 
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444 
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org> 
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com> 
> Signed-off-by: Herton Krzesinski <herton@redhat.com> 
> --- 
> V2: Uses kstrdup, removed PAGE_MASK. 

FYI, this copy was malformed. All the indentation and formatting is
wrong, so it doesn't apply. I'll look at the previous copy you sent, but
please fix this in the future.

Brian

> --- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
> +++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
> @@ -9,7 +9,15 @@ 
> 
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 
> 
> +/* 
> +* When the first attempt at device initialization fails, we may need to 
> +* wait a little bit and retry. This timeout, by default 3 seconds, gives 
> +* device time to start up. Required on BCM2708 and a few other chipsets. 
> +*/ 
> +#define MTD_DEFAULT_TIMEOUT 3 
> + 
> #include <linux/module.h> 
> +#include <linux/delay.h> 
> #include <linux/fs.h> 
> #include <linux/blkdev.h> 
> #include <linux/bio.h> 
> @@ -17,6 +25,7 @@ 
> #include <linux/list.h> 
> #include <linux/init.h> 
> #include <linux/mtd/mtd.h> 
> +#include <linux/mtd/partitions.h> 
> #include <linux/mutex.h> 
> #include <linux/mount.h> 
> #include <linux/slab.h> 
> @@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
> } 
> 
> 
> -static struct block2mtd_dev *add_device(char *devname, int erase_size) 
> +static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout) 
> { 
> const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL; 
> - struct block_device *bdev; 
> + struct block_device *bdev = ERR_PTR(-ENODEV); 
> struct block2mtd_dev *dev; 
> + struct mtd_partition *part; 
> char *name; 
> + int i; 
> 
> if (!devname) 
> return NULL; 
> @@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device( 
> 
> /* Get a handle on the device */ 
> bdev = blkdev_get_by_path(devname, mode, dev); 
> -#ifndef MODULE 
> - if (IS_ERR(bdev)) { 
> 
> - /* We might not have rootfs mounted at this point. Try 
> - to resolve the device name by other means. */ 
> - 
> - dev_t devt = name_to_dev_t(devname); 
> - if (devt) 
> - bdev = blkdev_get_by_dev(devt, mode, dev); 
> +#ifndef MODULE 
> +/* 
> +* We might not have the root device mounted at this point. 
> +* Try to resolve the device name by other means. 
> +*/ 
> + for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { 
> + dev_t devt; 
> + 
> + if (i) 
> + /* 
> + * Calling wait_for_device_probe in the first loop 
> + * was not enough, sleep for a bit in subsequent 
> + * go-arounds. 
> + */ 
> + msleep(1000); 
> + wait_for_device_probe(); 
> + 
> + devt = name_to_dev_t(devname); 
> + if (!devt) 
> + continue; 
> + bdev = blkdev_get_by_dev(devt, mode, dev); 
> } 
> #endif 
> 
> @@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 
> 
> /* Setup the MTD structure */ 
> /* make the name contain the block device in */ 
> - name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname); 
> + if (!mtdname) 
> + mtdname = devname; 
> + name = kstrdup (mtdname, GFP_KERNEL); 
> if (!name) 
> goto err_destroy_mutex; 
> 
> dev->mtd.name = name; 
> - 
> - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK; 
> + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1); 
> dev->mtd.erasesize = erase_size; 
> dev->mtd.writesize = 1; 
> dev->mtd.writebufsize = PAGE_SIZE; 
> @@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
> dev->mtd.priv = dev; 
> dev->mtd.owner = THIS_MODULE; 
> 
> - if (mtd_device_register(&dev->mtd, NULL, 0)) { 
> + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
> + part->name = name; 
> + part->offset = 0; 
> + part->size = dev->mtd.size; 
> + if (mtd_device_register(&dev->mtd, part, 1)) { 
> /* Device didn't get added, so free the entry */ 
> goto err_destroy_mutex; 
> } 
> + 
> list_add(&dev->list, &blkmtd_device_list); 
> pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n", 
> dev->mtd.index, 
> - dev->mtd.name + strlen("block2mtd: "), 
> - dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
> + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
> return dev; 
> 
> err_destroy_mutex: 
> @@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 
> 
> static int block2mtd_setup2(const char *val) 
> { 
> - char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
> + char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */ 
> char *str = buf; 
> - char *token[2]; 
> + char *token[4]; 
> char *name; 
> size_t erase_size = PAGE_SIZE; 
> + unsigned long timeout = MTD_DEFAULT_TIMEOUT; 
> int i, ret; 
> 
> if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { 
> @@ -368,7 +398,7 @@ static int block2mtd_setup2(const char * 
> strcpy(str, val); 
> kill_final_newline(str); 
> 
> - for (i = 0; i < 2; i++) 
> + for (i = 0; i < 4; i++) 
> token[i] = strsep(&str, ","); 
> 
> if (str) { 
> @@ -395,7 +425,13 @@ static int block2mtd_setup2(const char * 
> } 
> } 
> 
> - add_device(name, erase_size); 
> + if (token[2] && (strlen(token[2]) + 1 > 80)) 
> + pr_err("mtd device name too long"); 
> + 
> + 
> + if (token[3] && kstrtoul(token[3], 0, &timeout)) 
> + pr_err("invalid timeout"); 
> + add_device(name, erase_size, token[2], timeout); 
> 
> return 0; 
> } 
> @@ -429,7 +465,7 @@ static int block2mtd_setup(const char *v 
> 
> 
> module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200); 
> -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\""); 
> +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\""); 
> 
> static int __init block2mtd_init(void) 
> { 
> @@ -463,8 +499,7 @@ static void block2mtd_exit(void) 
> } 
> } 
> 
> - 
> -module_init(block2mtd_init); 
> +late_initcall(block2mtd_init); 
> module_exit(block2mtd_exit); 
> 
> MODULE_LICENSE("GPL"); 
> --- 
> 1.7.1 
> 
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-09-17 20:28       ` Rodrigo Freire
@ 2014-11-05 20:23         ` Brian Norris
  -1 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2014-11-05 20:23 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Jörn Engel, linux-mtd, Felix Fietkau, dwmw2, linux-kernel,
	Herton Krzesinski

On Wed, Sep 17, 2014 at 04:28:03PM -0400, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org>
> 
> mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion
> 
> Currently, a block MTD device is not presented to the system on time, in
> order to start mounting the filesystems. This patch ensures that block2mtd
> is presented at the right time, so filesystems can be mounted on boot time.
> This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
> block2mtd filesystems.

This still seems like a bad idea (using a block device + block2mtd +
JFFS2). Why are you doing this? See comments here:

  http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2

> This patchset also adds a MTD device name and a timeout option to the driver.
> Original patchset:
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444

You're stating right up front that this patch is doing several different
things. Please split these up into separate commits which get their own
description.

> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> Signed-off-by: Herton Krzesinski <herton@redhat.com>
> ---
> V2: Uses kstrdup, removed PAGE_MASK.

You have several checkpatch warnings. Please fix them.

WARNING:LONG_LINE: line over 80 characters
#57: FILE: drivers/mtd/devices/block2mtd.c:221:
+static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout)

WARNING:SPACING: space prohibited between function name and open parenthesis '('
#111: FILE: drivers/mtd/devices/block2mtd.c:286:
+	name = kstrdup (mtdname, GFP_KERNEL);

WARNING:LONG_LINE: line over 80 characters
#150: FILE: drivers/mtd/devices/block2mtd.c:385:
+	char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */

total: 0 errors, 3 warnings, 164 lines checked

> --- a/drivers/mtd/devices/block2mtd.c	2014-09-16 21:38:12.543952627 -0300
> +++ b/drivers/mtd/devices/block2mtd.c	2014-09-17 17:43:21.424944394 -0300
> @@ -9,7 +9,15 @@
>  
>  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>  
> +/*
> +* When the first attempt at device initialization fails, we may need to
> +* wait a little bit and retry. This timeout, by default 3 seconds, gives
> +* device time to start up. Required on BCM2708 and a few other chipsets.
> +*/
> +#define MTD_DEFAULT_TIMEOUT	3
> +
>  #include <linux/module.h>
> +#include <linux/delay.h>
>  #include <linux/fs.h>
>  #include <linux/blkdev.h>
>  #include <linux/bio.h>
> @@ -17,6 +25,7 @@
>  #include <linux/list.h>
>  #include <linux/init.h>
>  #include <linux/mtd/mtd.h>
> +#include <linux/mtd/partitions.h>
>  #include <linux/mutex.h>
>  #include <linux/mount.h>
>  #include <linux/slab.h>
> @@ -209,12 +218,14 @@ static void block2mtd_free_device(struct
>  }
>  
>  
> -static struct block2mtd_dev *add_device(char *devname, int erase_size)
> +static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout)

The addition of this name parameter should definitely be its own patch.

>  {
>  	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
> -	struct block_device *bdev;
> +	struct block_device *bdev = ERR_PTR(-ENODEV);
>  	struct block2mtd_dev *dev;
> +	struct mtd_partition *part;
>  	char *name;
> +	int i;

This variable produces a warning when built as a module:

   drivers/mtd/devices/block2mtd.c: In function ‘add_device’:
   drivers/mtd/devices/block2mtd.c:228:6: warning: unused variable ‘i’ [-Wunused-variable]
     int i;
         ^

>  
>  	if (!devname)
>  		return NULL;
> @@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Get a handle on the device */
>  	bdev = blkdev_get_by_path(devname, mode, dev);
> -#ifndef MODULE
> -	if (IS_ERR(bdev)) {
>  
> -		/* We might not have rootfs mounted at this point. Try
> -		   to resolve the device name by other means. */
> -
> -		dev_t devt = name_to_dev_t(devname);
> -		if (devt)
> -			bdev = blkdev_get_by_dev(devt, mode, dev);
> +#ifndef MODULE
> +/*
> +* We might not have the root device mounted at this point.
> +* Try to resolve the device name by other means.
> +*/

These lines should start with a space, so the asterisks line up.

> +	for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
> +		dev_t devt;
> +
> +		if (i)
> +			/*
> +			 * Calling wait_for_device_probe in the first loop 
> +			 * was not enough, sleep for a bit in subsequent
> +			 * go-arounds.
> +			*/
> +			msleep(1000);
> +		wait_for_device_probe();
> +
> +		devt = name_to_dev_t(devname);
> +		if (!devt)
> +			continue;
> +		bdev = blkdev_get_by_dev(devt, mode, dev);
>  	}
>  #endif
>  
> @@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Setup the MTD structure */
>  	/* make the name contain the block device in */
> -	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
> +	if (!mtdname)
> +		mtdname = devname;
> +	name = kstrdup (mtdname, GFP_KERNEL);
>  	if (!name)
>  		goto err_destroy_mutex;
>  
>  	dev->mtd.name = name;
> -
> -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> +	dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);

This deserves its own patch, or at least some explanation of why you're
doing this. I guess you're seeing cases where the provided erasesize is
not aligned with the size of the block device?

>  	dev->mtd.erasesize = erase_size;
>  	dev->mtd.writesize = 1;
>  	dev->mtd.writebufsize = PAGE_SIZE;
> @@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device(
>  	dev->mtd.priv = dev;
>  	dev->mtd.owner = THIS_MODULE;
>  
> -	if (mtd_device_register(&dev->mtd, NULL, 0)) {
> +	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
> +	part->name = name;
> +	part->offset = 0;
> +	part->size = dev->mtd.size;

Why are you doing this? This also does not fit the description of this
patch. And what's wrong with using the default partitioning options?
Won't we (if not specified in some other way) default to an
unpartitioned MTD, which covers the entire device?

> +	if (mtd_device_register(&dev->mtd, part, 1)) {
>  		/* Device didn't get added, so free the entry */
>  		goto err_destroy_mutex;
>  	}
> +
>  	list_add(&dev->list, &blkmtd_device_list);
>  	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
>  		dev->mtd.index,
> -		dev->mtd.name + strlen("block2mtd: "),
> -		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
> +		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
>  	return dev;
>  
>  err_destroy_mutex:
> @@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12]
>  
>  static int block2mtd_setup2(const char *val)
>  {
> -	char buf[80 + 12]; /* 80 for device, 12 for erase size */
> +	char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
>  	char *str = buf;
> -	char *token[2];
> +	char *token[4];
>  	char *name;
>  	size_t erase_size = PAGE_SIZE;
> +	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
>  	int i, ret;
>  
>  	if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
> @@ -368,7 +398,7 @@ static int block2mtd_setup2(const char *
>  	strcpy(str, val);
>  	kill_final_newline(str);
>  
> -	for (i = 0; i < 2; i++)
> +	for (i = 0; i < 4; i++)
>  		token[i] = strsep(&str, ",");
>  
>  	if (str) {
> @@ -395,7 +425,13 @@ static int block2mtd_setup2(const char *
>  		}
>  	}
>  
> -	add_device(name, erase_size);
> +	if (token[2] && (strlen(token[2]) + 1 > 80))
> +		pr_err("mtd device name too long");
> +
> +
> +	if (token[3] && kstrtoul(token[3], 0, &timeout))
> +		pr_err("invalid timeout");
> +	add_device(name, erase_size, token[2], timeout);
>  
>  	return 0;
>  }
> @@ -429,7 +465,7 @@ static int block2mtd_setup(const char *v
>  
>  
>  module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
> -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
> +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
>  
>  static int __init block2mtd_init(void)
>  {
> @@ -463,8 +499,7 @@ static void block2mtd_exit(void)
>  	}
>  }
>  
> -
> -module_init(block2mtd_init);
> +late_initcall(block2mtd_init);
>  module_exit(block2mtd_exit);
>  
>  MODULE_LICENSE("GPL");

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-11-05 20:23         ` Brian Norris
  0 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2014-11-05 20:23 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

On Wed, Sep 17, 2014 at 04:28:03PM -0400, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org>
> 
> mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion
> 
> Currently, a block MTD device is not presented to the system on time, in
> order to start mounting the filesystems. This patch ensures that block2mtd
> is presented at the right time, so filesystems can be mounted on boot time.
> This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
> block2mtd filesystems.

This still seems like a bad idea (using a block device + block2mtd +
JFFS2). Why are you doing this? See comments here:

  http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2

> This patchset also adds a MTD device name and a timeout option to the driver.
> Original patchset:
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444

You're stating right up front that this patch is doing several different
things. Please split these up into separate commits which get their own
description.

> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> Signed-off-by: Herton Krzesinski <herton@redhat.com>
> ---
> V2: Uses kstrdup, removed PAGE_MASK.

You have several checkpatch warnings. Please fix them.

WARNING:LONG_LINE: line over 80 characters
#57: FILE: drivers/mtd/devices/block2mtd.c:221:
+static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout)

WARNING:SPACING: space prohibited between function name and open parenthesis '('
#111: FILE: drivers/mtd/devices/block2mtd.c:286:
+	name = kstrdup (mtdname, GFP_KERNEL);

WARNING:LONG_LINE: line over 80 characters
#150: FILE: drivers/mtd/devices/block2mtd.c:385:
+	char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */

total: 0 errors, 3 warnings, 164 lines checked

> --- a/drivers/mtd/devices/block2mtd.c	2014-09-16 21:38:12.543952627 -0300
> +++ b/drivers/mtd/devices/block2mtd.c	2014-09-17 17:43:21.424944394 -0300
> @@ -9,7 +9,15 @@
>  
>  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>  
> +/*
> +* When the first attempt at device initialization fails, we may need to
> +* wait a little bit and retry. This timeout, by default 3 seconds, gives
> +* device time to start up. Required on BCM2708 and a few other chipsets.
> +*/
> +#define MTD_DEFAULT_TIMEOUT	3
> +
>  #include <linux/module.h>
> +#include <linux/delay.h>
>  #include <linux/fs.h>
>  #include <linux/blkdev.h>
>  #include <linux/bio.h>
> @@ -17,6 +25,7 @@
>  #include <linux/list.h>
>  #include <linux/init.h>
>  #include <linux/mtd/mtd.h>
> +#include <linux/mtd/partitions.h>
>  #include <linux/mutex.h>
>  #include <linux/mount.h>
>  #include <linux/slab.h>
> @@ -209,12 +218,14 @@ static void block2mtd_free_device(struct
>  }
>  
>  
> -static struct block2mtd_dev *add_device(char *devname, int erase_size)
> +static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout)

The addition of this name parameter should definitely be its own patch.

>  {
>  	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
> -	struct block_device *bdev;
> +	struct block_device *bdev = ERR_PTR(-ENODEV);
>  	struct block2mtd_dev *dev;
> +	struct mtd_partition *part;
>  	char *name;
> +	int i;

This variable produces a warning when built as a module:

   drivers/mtd/devices/block2mtd.c: In function ‘add_device’:
   drivers/mtd/devices/block2mtd.c:228:6: warning: unused variable ‘i’ [-Wunused-variable]
     int i;
         ^

>  
>  	if (!devname)
>  		return NULL;
> @@ -225,15 +236,28 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Get a handle on the device */
>  	bdev = blkdev_get_by_path(devname, mode, dev);
> -#ifndef MODULE
> -	if (IS_ERR(bdev)) {
>  
> -		/* We might not have rootfs mounted at this point. Try
> -		   to resolve the device name by other means. */
> -
> -		dev_t devt = name_to_dev_t(devname);
> -		if (devt)
> -			bdev = blkdev_get_by_dev(devt, mode, dev);
> +#ifndef MODULE
> +/*
> +* We might not have the root device mounted at this point.
> +* Try to resolve the device name by other means.
> +*/

These lines should start with a space, so the asterisks line up.

> +	for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
> +		dev_t devt;
> +
> +		if (i)
> +			/*
> +			 * Calling wait_for_device_probe in the first loop 
> +			 * was not enough, sleep for a bit in subsequent
> +			 * go-arounds.
> +			*/
> +			msleep(1000);
> +		wait_for_device_probe();
> +
> +		devt = name_to_dev_t(devname);
> +		if (!devt)
> +			continue;
> +		bdev = blkdev_get_by_dev(devt, mode, dev);
>  	}
>  #endif
>  
> @@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Setup the MTD structure */
>  	/* make the name contain the block device in */
> -	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
> +	if (!mtdname)
> +		mtdname = devname;
> +	name = kstrdup (mtdname, GFP_KERNEL);
>  	if (!name)
>  		goto err_destroy_mutex;
>  
>  	dev->mtd.name = name;
> -
> -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> +	dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);

This deserves its own patch, or at least some explanation of why you're
doing this. I guess you're seeing cases where the provided erasesize is
not aligned with the size of the block device?

>  	dev->mtd.erasesize = erase_size;
>  	dev->mtd.writesize = 1;
>  	dev->mtd.writebufsize = PAGE_SIZE;
> @@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device(
>  	dev->mtd.priv = dev;
>  	dev->mtd.owner = THIS_MODULE;
>  
> -	if (mtd_device_register(&dev->mtd, NULL, 0)) {
> +	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
> +	part->name = name;
> +	part->offset = 0;
> +	part->size = dev->mtd.size;

Why are you doing this? This also does not fit the description of this
patch. And what's wrong with using the default partitioning options?
Won't we (if not specified in some other way) default to an
unpartitioned MTD, which covers the entire device?

> +	if (mtd_device_register(&dev->mtd, part, 1)) {
>  		/* Device didn't get added, so free the entry */
>  		goto err_destroy_mutex;
>  	}
> +
>  	list_add(&dev->list, &blkmtd_device_list);
>  	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
>  		dev->mtd.index,
> -		dev->mtd.name + strlen("block2mtd: "),
> -		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
> +		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
>  	return dev;
>  
>  err_destroy_mutex:
> @@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12]
>  
>  static int block2mtd_setup2(const char *val)
>  {
> -	char buf[80 + 12]; /* 80 for device, 12 for erase size */
> +	char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
>  	char *str = buf;
> -	char *token[2];
> +	char *token[4];
>  	char *name;
>  	size_t erase_size = PAGE_SIZE;
> +	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
>  	int i, ret;
>  
>  	if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
> @@ -368,7 +398,7 @@ static int block2mtd_setup2(const char *
>  	strcpy(str, val);
>  	kill_final_newline(str);
>  
> -	for (i = 0; i < 2; i++)
> +	for (i = 0; i < 4; i++)
>  		token[i] = strsep(&str, ",");
>  
>  	if (str) {
> @@ -395,7 +425,13 @@ static int block2mtd_setup2(const char *
>  		}
>  	}
>  
> -	add_device(name, erase_size);
> +	if (token[2] && (strlen(token[2]) + 1 > 80))
> +		pr_err("mtd device name too long");
> +
> +
> +	if (token[3] && kstrtoul(token[3], 0, &timeout))
> +		pr_err("invalid timeout");
> +	add_device(name, erase_size, token[2], timeout);
>  
>  	return 0;
>  }
> @@ -429,7 +465,7 @@ static int block2mtd_setup(const char *v
>  
>  
>  module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
> -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
> +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
>  
>  static int __init block2mtd_init(void)
>  {
> @@ -463,8 +499,7 @@ static void block2mtd_exit(void)
>  	}
>  }
>  
> -
> -module_init(block2mtd_init);
> +late_initcall(block2mtd_init);
>  module_exit(block2mtd_exit);
>  
>  MODULE_LICENSE("GPL");

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-11-01 13:33           ` Rodrigo Freire
@ 2014-11-07  9:44             ` Artem Bityutskiy
  -1 siblings, 0 replies; 63+ messages in thread
From: Artem Bityutskiy @ 2014-11-07  9:44 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Jörn Engel, linux-mtd, Felix Fietkau, dwmw2, linux-kernel,
	Herton Krzesinski

On Sat, 2014-11-01 at 09:33 -0400, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org> 
> 
> mtd: block2mtd: Ensure that block2mtd is presented timely on boot time
> 
> Currently, a block MTD device is not presented to the system on time, in 
> order to start mounting the filesystems. This patch ensures that block2mtd 
> is presented at the right time, so filesystems can be mounted on boot time. 
> This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
> over block2mtd devices as the root filesystem.
> This patchset also adds a MTD device name and a timeout option to the driver. 
> Original patchset: 
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444 
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444 

I  think you can mount jffs2 using /dev/mtdX, you do not need the block
driver.


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-11-07  9:44             ` Artem Bityutskiy
  0 siblings, 0 replies; 63+ messages in thread
From: Artem Bityutskiy @ 2014-11-07  9:44 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

On Sat, 2014-11-01 at 09:33 -0400, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org> 
> 
> mtd: block2mtd: Ensure that block2mtd is presented timely on boot time
> 
> Currently, a block MTD device is not presented to the system on time, in 
> order to start mounting the filesystems. This patch ensures that block2mtd 
> is presented at the right time, so filesystems can be mounted on boot time. 
> This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
> over block2mtd devices as the root filesystem.
> This patchset also adds a MTD device name and a timeout option to the driver. 
> Original patchset: 
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444 
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444 

I  think you can mount jffs2 using /dev/mtdX, you do not need the block
driver.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-11-05 20:23         ` Brian Norris
@ 2014-11-07 14:59           ` Artem Bityutskiy
  -1 siblings, 0 replies; 63+ messages in thread
From: Artem Bityutskiy @ 2014-11-07 14:59 UTC (permalink / raw)
  To: Brian Norris
  Cc: Rodrigo Freire, Felix Fietkau, Jörn Engel,
	Herton Krzesinski, linux-kernel, linux-mtd, dwmw2

On Wed, 2014-11-05 at 12:23 -0800, Brian Norris wrote:
> On Wed, Sep 17, 2014 at 04:28:03PM -0400, Rodrigo Freire wrote:
> > From: Felix Fietkau <nbd@openwrt.org>
> > 
> > mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion
> > 
> > Currently, a block MTD device is not presented to the system on time, in
> > order to start mounting the filesystems. This patch ensures that block2mtd
> > is presented at the right time, so filesystems can be mounted on boot time.
> > This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
> > block2mtd filesystems.
> 
> This still seems like a bad idea (using a block device + block2mtd +
> JFFS2). Why are you doing this? See comments here:
> 
>   http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2

At old days it was impossible to mount character devices, only block
devices. So people ware using mtdblock to mount jffs2. This is just a
work-around.

I did not look at this code for long time, and may have forgotten
something, but I believe you do not need mtdblock anymore for this. You
just mount the mtd device.

This driver should not be used for this.

The only usage of this driver is emulating a block device on top of NOR
flash, and in most cases, only for debugging / research purposes. This
is because (a) this driver does not handle bad blocks (and hence,
NAND-incompatible) and (b) it does read-erase-write when you modify a
block, so it is extremely slow and does not handle power cuts at all.

Therefore,

Nack for this patch so far.

Artem.


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-11-07 14:59           ` Artem Bityutskiy
  0 siblings, 0 replies; 63+ messages in thread
From: Artem Bityutskiy @ 2014-11-07 14:59 UTC (permalink / raw)
  To: Brian Norris
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, Rodrigo Freire, dwmw2

On Wed, 2014-11-05 at 12:23 -0800, Brian Norris wrote:
> On Wed, Sep 17, 2014 at 04:28:03PM -0400, Rodrigo Freire wrote:
> > From: Felix Fietkau <nbd@openwrt.org>
> > 
> > mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion
> > 
> > Currently, a block MTD device is not presented to the system on time, in
> > order to start mounting the filesystems. This patch ensures that block2mtd
> > is presented at the right time, so filesystems can be mounted on boot time.
> > This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
> > block2mtd filesystems.
> 
> This still seems like a bad idea (using a block device + block2mtd +
> JFFS2). Why are you doing this? See comments here:
> 
>   http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2

At old days it was impossible to mount character devices, only block
devices. So people ware using mtdblock to mount jffs2. This is just a
work-around.

I did not look at this code for long time, and may have forgotten
something, but I believe you do not need mtdblock anymore for this. You
just mount the mtd device.

This driver should not be used for this.

The only usage of this driver is emulating a block device on top of NOR
flash, and in most cases, only for debugging / research purposes. This
is because (a) this driver does not handle bad blocks (and hence,
NAND-incompatible) and (b) it does read-erase-write when you modify a
block, so it is extremely slow and does not handle power cuts at all.

Therefore,

Nack for this patch so far.

Artem.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-11-07 14:59           ` Artem Bityutskiy
@ 2014-11-07 15:20             ` Felix Fietkau
  -1 siblings, 0 replies; 63+ messages in thread
From: Felix Fietkau @ 2014-11-07 15:20 UTC (permalink / raw)
  To: dedekind1, Brian Norris
  Cc: Rodrigo Freire, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

On 2014-11-07 15:59, Artem Bityutskiy wrote:
> On Wed, 2014-11-05 at 12:23 -0800, Brian Norris wrote:
>> On Wed, Sep 17, 2014 at 04:28:03PM -0400, Rodrigo Freire wrote:
>> > From: Felix Fietkau <nbd@openwrt.org>
>> > 
>> > mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion
>> > 
>> > Currently, a block MTD device is not presented to the system on time, in
>> > order to start mounting the filesystems. This patch ensures that block2mtd
>> > is presented at the right time, so filesystems can be mounted on boot time.
>> > This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
>> > block2mtd filesystems.
>> 
>> This still seems like a bad idea (using a block device + block2mtd +
>> JFFS2). Why are you doing this? See comments here:
>> 
>>   http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2
> 
> At old days it was impossible to mount character devices, only block
> devices. So people ware using mtdblock to mount jffs2. This is just a
> work-around.
> 
> I did not look at this code for long time, and may have forgotten
> something, but I believe you do not need mtdblock anymore for this. You
> just mount the mtd device.
> 
> This driver should not be used for this.
> 
> The only usage of this driver is emulating a block device on top of NOR
> flash, and in most cases, only for debugging / research purposes. This
> is because (a) this driver does not handle bad blocks (and hence,
> NAND-incompatible) and (b) it does read-erase-write when you modify a
> block, so it is extremely slow and does not handle power cuts at all.
I think you got things mixed up a bit. This is not about emulating a
block device on top of NOR flash. This is about emulating NOR flash on
top of a regular block device - e.g. USB sticks, SD cards.

Now why would we want to use jffs2 on something that has enough storage
for running a regular file system?
It's simple: JFFS2 is very robust when dealing with sudden loss of
power. Block device based filesystems such as ext4, or even f2fs are not
nearly as good at dealing with that.

I realize that the emulation is a bit wasteful, and a lot of the things
that jffs2 was designed for are useless here - but the end result is
still much more reliable this way than with the alternative solutions.

In OpenWrt we've been using this approach for some x86 routers and for
the Raspberry Pi for a long time now, and it has served us quite well.

- Felix

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-11-07 15:20             ` Felix Fietkau
  0 siblings, 0 replies; 63+ messages in thread
From: Felix Fietkau @ 2014-11-07 15:20 UTC (permalink / raw)
  To: dedekind1, Brian Norris
  Cc: Jörn Engel, Herton Krzesinski, linux-kernel, linux-mtd,
	Rodrigo Freire, dwmw2

On 2014-11-07 15:59, Artem Bityutskiy wrote:
> On Wed, 2014-11-05 at 12:23 -0800, Brian Norris wrote:
>> On Wed, Sep 17, 2014 at 04:28:03PM -0400, Rodrigo Freire wrote:
>> > From: Felix Fietkau <nbd@openwrt.org>
>> > 
>> > mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion
>> > 
>> > Currently, a block MTD device is not presented to the system on time, in
>> > order to start mounting the filesystems. This patch ensures that block2mtd
>> > is presented at the right time, so filesystems can be mounted on boot time.
>> > This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
>> > block2mtd filesystems.
>> 
>> This still seems like a bad idea (using a block device + block2mtd +
>> JFFS2). Why are you doing this? See comments here:
>> 
>>   http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2
> 
> At old days it was impossible to mount character devices, only block
> devices. So people ware using mtdblock to mount jffs2. This is just a
> work-around.
> 
> I did not look at this code for long time, and may have forgotten
> something, but I believe you do not need mtdblock anymore for this. You
> just mount the mtd device.
> 
> This driver should not be used for this.
> 
> The only usage of this driver is emulating a block device on top of NOR
> flash, and in most cases, only for debugging / research purposes. This
> is because (a) this driver does not handle bad blocks (and hence,
> NAND-incompatible) and (b) it does read-erase-write when you modify a
> block, so it is extremely slow and does not handle power cuts at all.
I think you got things mixed up a bit. This is not about emulating a
block device on top of NOR flash. This is about emulating NOR flash on
top of a regular block device - e.g. USB sticks, SD cards.

Now why would we want to use jffs2 on something that has enough storage
for running a regular file system?
It's simple: JFFS2 is very robust when dealing with sudden loss of
power. Block device based filesystems such as ext4, or even f2fs are not
nearly as good at dealing with that.

I realize that the emulation is a bit wasteful, and a lot of the things
that jffs2 was designed for are useless here - but the end result is
still much more reliable this way than with the alternative solutions.

In OpenWrt we've been using this approach for some x86 routers and for
the Raspberry Pi for a long time now, and it has served us quite well.

- Felix

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-11-07 15:20             ` Felix Fietkau
@ 2014-11-07 15:30               ` Artem Bityutskiy
  -1 siblings, 0 replies; 63+ messages in thread
From: Artem Bityutskiy @ 2014-11-07 15:30 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Brian Norris, Rodrigo Freire, Jörn Engel, Herton Krzesinski,
	linux-kernel, linux-mtd, dwmw2

On Fri, 2014-11-07 at 16:20 +0100, Felix Fietkau wrote:
> > The only usage of this driver is emulating a block device on top of NOR
> > flash, and in most cases, only for debugging / research purposes. This
> > is because (a) this driver does not handle bad blocks (and hence,
> > NAND-incompatible) and (b) it does read-erase-write when you modify a
> > block, so it is extremely slow and does not handle power cuts at all.
> I think you got things mixed up a bit. This is not about emulating a
> block device on top of NOR flash. This is about emulating NOR flash on
> top of a regular block device - e.g. USB sticks, SD cards.

Gosh, I'm sorry, you are right. I did mix things up, please, ignore my
e-mail.


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-11-07 15:30               ` Artem Bityutskiy
  0 siblings, 0 replies; 63+ messages in thread
From: Artem Bityutskiy @ 2014-11-07 15:30 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Jörn Engel, Herton Krzesinski, linux-kernel, linux-mtd,
	Rodrigo Freire, Brian Norris, dwmw2

On Fri, 2014-11-07 at 16:20 +0100, Felix Fietkau wrote:
> > The only usage of this driver is emulating a block device on top of NOR
> > flash, and in most cases, only for debugging / research purposes. This
> > is because (a) this driver does not handle bad blocks (and hence,
> > NAND-incompatible) and (b) it does read-erase-write when you modify a
> > block, so it is extremely slow and does not handle power cuts at all.
> I think you got things mixed up a bit. This is not about emulating a
> block device on top of NOR flash. This is about emulating NOR flash on
> top of a regular block device - e.g. USB sticks, SD cards.

Gosh, I'm sorry, you are right. I did mix things up, please, ignore my
e-mail.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-11-07  9:44             ` Artem Bityutskiy
@ 2014-11-07 20:05               ` Brian Norris
  -1 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2014-11-07 20:05 UTC (permalink / raw)
  To: Artem Bityutskiy
  Cc: Rodrigo Freire, Felix Fietkau, Jörn Engel,
	Herton Krzesinski, linux-kernel, linux-mtd, dwmw2

On Fri, Nov 07, 2014 at 11:44:40AM +0200, Artem Bityutskiy wrote:
> On Sat, 2014-11-01 at 09:33 -0400, Rodrigo Freire wrote:
> > From: Felix Fietkau <nbd@openwrt.org> 
> > 
> > mtd: block2mtd: Ensure that block2mtd is presented timely on boot time
> > 
> > Currently, a block MTD device is not presented to the system on time, in 
> > order to start mounting the filesystems. This patch ensures that block2mtd 
> > is presented at the right time, so filesystems can be mounted on boot time. 
> > This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
> > over block2mtd devices as the root filesystem.
> > This patchset also adds a MTD device name and a timeout option to the driver. 
> > Original patchset: 
> > https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444 
> > https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444 
> 
> I  think you can mount jffs2 using /dev/mtdX, you do not need the block
> driver.

I realize you acknowledged your misunderstanding here, but for
posterity -- this point is addressed in the FAQ:

http://www.linux-mtd.infradead.org/faq/jffs2.html#L_mtdblock

Last I checked, the statement about busybox is still true. I think the
rootfs comment may be stale; I think the rootfstype= parameter can help
you.

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-11-07 20:05               ` Brian Norris
  0 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2014-11-07 20:05 UTC (permalink / raw)
  To: Artem Bityutskiy
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, Rodrigo Freire, dwmw2

On Fri, Nov 07, 2014 at 11:44:40AM +0200, Artem Bityutskiy wrote:
> On Sat, 2014-11-01 at 09:33 -0400, Rodrigo Freire wrote:
> > From: Felix Fietkau <nbd@openwrt.org> 
> > 
> > mtd: block2mtd: Ensure that block2mtd is presented timely on boot time
> > 
> > Currently, a block MTD device is not presented to the system on time, in 
> > order to start mounting the filesystems. This patch ensures that block2mtd 
> > is presented at the right time, so filesystems can be mounted on boot time. 
> > This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
> > over block2mtd devices as the root filesystem.
> > This patchset also adds a MTD device name and a timeout option to the driver. 
> > Original patchset: 
> > https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444 
> > https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444 
> 
> I  think you can mount jffs2 using /dev/mtdX, you do not need the block
> driver.

I realize you acknowledged your misunderstanding here, but for
posterity -- this point is addressed in the FAQ:

http://www.linux-mtd.infradead.org/faq/jffs2.html#L_mtdblock

Last I checked, the statement about busybox is still true. I think the
rootfs comment may be stale; I think the rootfstype= parameter can help
you.

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-11-05 20:23         ` Brian Norris
@ 2014-11-09 12:18           ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-09 12:18 UTC (permalink / raw)
  To: Brian Norris
  Cc: Jörn Engel, linux-mtd, Felix Fietkau, dwmw2, linux-kernel,
	Herton Krzesinski

Hi Brian,

> From: "Brian Norris" <computersforpeace@gmail.com>
> Sent: Wednesday, November 5, 2014 6:23:03 PM

> On Wed, Sep 17, 2014 at 04:28:03PM -0400, Rodrigo Freire wrote:
> > Currently, a block MTD device is not presented to the system on time, in
> > order to start mounting the filesystems. This patch ensures that block2mtd
> > is presented at the right time, so filesystems can be mounted on boot time.
> > This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
> > block2mtd filesystems.

> This still seems like a bad idea (using a block device + block2mtd +
> JFFS2). Why are you doing this? See comments here:
> http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2

As Felix stated on a previous message to the thread, I am using JFFS2 over
block2mtd where regular filesystems failed to do so well. There are several
[1] threads pointing this issue, and JFFS2 over block2mtd works like a charm
on more harsh scenarios. The block2mtd behavior was not working correctly on
BCM2835 architecture (the kernel waited for the block device prior to its
actual enumeration by the kernel) and this patch ensures that block2mtd
kicks in _after_ the block devices was enumerated or after a user-defined
timeout. 
The patchset also enables block2mtd to define a MTD name (a MTD supports it
natively, the block2mtd had its name hard-coded to its block device name).

> You're stating right up front that this patch is doing several different
> things. Please split these up into separate commits which get their own
> description.

Done. I'll send a new split V3 patchset.

> You have several checkpatch warnings. Please fix them.

Thanks for pointing. Done.

> The addition of this name parameter should definitely be its own patch.

I agree. Done.

> This variable produces a warning when built as a module:

> drivers/mtd/devices/block2mtd.c: In function ‘add_device’:
> drivers/mtd/devices/block2mtd.c:228:6: warning: unused variable ‘i’
> [-Wunused-variable]
> int i;
> ^

Oooops. Fixed.

> > +#ifndef MODULE
> > +/*
> > +* We might not have the root device mounted at this point.
> > +* Try to resolve the device name by other means.
> > +*/

> These lines should start with a space, so the asterisks line up.

Fixed, and also fixed other non-aligned asterisks as well.

> > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);

> This deserves its own patch, or at least some explanation of why you're
> doing this. I guess you're seeing cases where the provided erasesize is
> not aligned with the size of the block device?

Jörg pointed it on https://lkml.org/lkml/2014/9/9/680. Now, we just keep
it aligned with erase_size. Separated on a 3rd patch.

> > dev->mtd.erasesize = erase_size;
> > dev->mtd.writesize = 1;
> > dev->mtd.writebufsize = PAGE_SIZE;
> > @@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device(
> > dev->mtd.priv = dev;
> > dev->mtd.owner = THIS_MODULE;
> >
> > - if (mtd_device_register(&dev->mtd, NULL, 0)) {
> > + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
> > + part->name = name;
> > + part->offset = 0;
> > + part->size = dev->mtd.size;

> Why are you doing this? This also does not fit the description of this
> patch. And what's wrong with using the default partitioning options?
> Won't we (if not specified in some other way) default to an
> unpartitioned MTD, which covers the entire device?

This code was changed in order to support a MTD name.

Thanks for your dilligent review.

Best regards,

- RF.

[1] - http://bit.ly/1smGvwa

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-11-09 12:18           ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-09 12:18 UTC (permalink / raw)
  To: Brian Norris
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

Hi Brian,

> From: "Brian Norris" <computersforpeace@gmail.com>
> Sent: Wednesday, November 5, 2014 6:23:03 PM

> On Wed, Sep 17, 2014 at 04:28:03PM -0400, Rodrigo Freire wrote:
> > Currently, a block MTD device is not presented to the system on time, in
> > order to start mounting the filesystems. This patch ensures that block2mtd
> > is presented at the right time, so filesystems can be mounted on boot time.
> > This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
> > block2mtd filesystems.

> This still seems like a bad idea (using a block device + block2mtd +
> JFFS2). Why are you doing this? See comments here:
> http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2

As Felix stated on a previous message to the thread, I am using JFFS2 over
block2mtd where regular filesystems failed to do so well. There are several
[1] threads pointing this issue, and JFFS2 over block2mtd works like a charm
on more harsh scenarios. The block2mtd behavior was not working correctly on
BCM2835 architecture (the kernel waited for the block device prior to its
actual enumeration by the kernel) and this patch ensures that block2mtd
kicks in _after_ the block devices was enumerated or after a user-defined
timeout. 
The patchset also enables block2mtd to define a MTD name (a MTD supports it
natively, the block2mtd had its name hard-coded to its block device name).

> You're stating right up front that this patch is doing several different
> things. Please split these up into separate commits which get their own
> description.

Done. I'll send a new split V3 patchset.

> You have several checkpatch warnings. Please fix them.

Thanks for pointing. Done.

> The addition of this name parameter should definitely be its own patch.

I agree. Done.

> This variable produces a warning when built as a module:

> drivers/mtd/devices/block2mtd.c: In function ‘add_device’:
> drivers/mtd/devices/block2mtd.c:228:6: warning: unused variable ‘i’
> [-Wunused-variable]
> int i;
> ^

Oooops. Fixed.

> > +#ifndef MODULE
> > +/*
> > +* We might not have the root device mounted at this point.
> > +* Try to resolve the device name by other means.
> > +*/

> These lines should start with a space, so the asterisks line up.

Fixed, and also fixed other non-aligned asterisks as well.

> > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);

> This deserves its own patch, or at least some explanation of why you're
> doing this. I guess you're seeing cases where the provided erasesize is
> not aligned with the size of the block device?

Jörg pointed it on https://lkml.org/lkml/2014/9/9/680. Now, we just keep
it aligned with erase_size. Separated on a 3rd patch.

> > dev->mtd.erasesize = erase_size;
> > dev->mtd.writesize = 1;
> > dev->mtd.writebufsize = PAGE_SIZE;
> > @@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device(
> > dev->mtd.priv = dev;
> > dev->mtd.owner = THIS_MODULE;
> >
> > - if (mtd_device_register(&dev->mtd, NULL, 0)) {
> > + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
> > + part->name = name;
> > + part->offset = 0;
> > + part->size = dev->mtd.size;

> Why are you doing this? This also does not fit the description of this
> patch. And what's wrong with using the default partitioning options?
> Won't we (if not specified in some other way) default to an
> unpartitioned MTD, which covers the entire device?

This code was changed in order to support a MTD name.

Thanks for your dilligent review.

Best regards,

- RF.

[1] - http://bit.ly/1smGvwa

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v3 0/3] mtd: block2mtd: wait for device enumeration, add name support
  2014-11-05 20:23         ` Brian Norris
@ 2014-11-09 12:18           ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-09 12:18 UTC (permalink / raw)
  To: linux-mtd, linux-kernel
  Cc: Jörn Engel, Felix Fietkau, dwmw2, Herton Krzesinski, Brian Norris

From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: wait for device enumeration, add name support

Currently, a block MTD device is not presented timely on boot time, in
order to start mounting the filesystems, causing the system to not boot
or panic because of lack of rootfs. This patch ensures that block2mtd
is presented at the right time, so the filesystems can be mounted on boot
time.
This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
block2mtd filesystems.
This patchset also adds a MTD device name and a timeout option to the driver
and deprecates PAGE_MASK when calculating the device size.
Original patchset:
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444

V3: Split the changes on 3 different patches, fixes a compile warning
V2: Uses kstrdup, removed PAGE_MASK.

 drivers/mtd/devices/block2mtd.c |   57 ++++++++++++++++++++++++++++----------
 1 files changed, 42 insertions(+), 15 deletions(-)
 drivers/mtd/devices/block2mtd.c |   32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)
 drivers/mtd/devices/block2mtd.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
---
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v3 0/3] mtd: block2mtd: wait for device enumeration, add name support
@ 2014-11-09 12:18           ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-09 12:18 UTC (permalink / raw)
  To: linux-mtd, linux-kernel
  Cc: Herton Krzesinski, Jörn Engel, Brian Norris, dwmw2, Felix Fietkau

From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: wait for device enumeration, add name support

Currently, a block MTD device is not presented timely on boot time, in
order to start mounting the filesystems, causing the system to not boot
or panic because of lack of rootfs. This patch ensures that block2mtd
is presented at the right time, so the filesystems can be mounted on boot
time.
This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
block2mtd filesystems.
This patchset also adds a MTD device name and a timeout option to the driver
and deprecates PAGE_MASK when calculating the device size.
Original patchset:
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444

V3: Split the changes on 3 different patches, fixes a compile warning
V2: Uses kstrdup, removed PAGE_MASK.

 drivers/mtd/devices/block2mtd.c |   57 ++++++++++++++++++++++++++++----------
 1 files changed, 42 insertions(+), 15 deletions(-)
 drivers/mtd/devices/block2mtd.c |   32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)
 drivers/mtd/devices/block2mtd.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
---
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v3 1/3] mtd: block2mtd: Ensure that block2mtd is triggered after block devices are presented.
  2014-11-09 12:18           ` Rodrigo Freire
@ 2014-11-09 12:21             ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-09 12:21 UTC (permalink / raw)
  To: linux-mtd, linux-kernel
  Cc: Jörn Engel, Felix Fietkau, dwmw2, Herton Krzesinski, Brian Norris

From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: Ensure that block2mtd is triggered after block devices are presented.

Ensures that block2mtd is triggered after the block devices are enumerated
at boot time.
This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
block2mtd filesystems, probably because of the delay on enumerating a USB
MMC card reader.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
Signed-off-by: Herton Krzesinski <herton@redhat.com>
---
V3: Separated on a single patch, fixes a compiling warning, cosmethic changes
V2: Uses kstrdup, removed PAGE_MASK.
--- a/drivers/mtd/devices/block2mtd.c	2014-11-07 16:40:14.638676860 -0200
+++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:44:45.277769924 -0200
@@ -9,7 +9,15 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+/*
+ * When the first attempt at device initialization fails, we may need to
+ * wait a little bit and retry. This timeout, by default 3 seconds, gives
+ * device time to start up. Required on BCM2708 and a few other chipsets.
+ */
+#define MTD_DEFAULT_TIMEOUT	3
+
 #include <linux/module.h>
+#include <linux/delay.h>
 #include <linux/fs.h>
 #include <linux/blkdev.h>
 #include <linux/bio.h>
@@ -209,10 +217,14 @@ static void block2mtd_free_device(struct
 }
 
 
-static struct block2mtd_dev *add_device(char *devname, int erase_size)
+static struct block2mtd_dev *add_device(char *devname, int erase_size,
+		int timeout)
 {
+#ifndef MODULE
+	int i;
+#endif
 	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
-	struct block_device *bdev;
+	struct block_device *bdev = ERR_PTR(-ENODEV);
 	struct block2mtd_dev *dev;
 	char *name;
 
@@ -225,15 +237,28 @@ static struct block2mtd_dev *add_device(
 
 	/* Get a handle on the device */
 	bdev = blkdev_get_by_path(devname, mode, dev);
-#ifndef MODULE
-	if (IS_ERR(bdev)) {
 
-		/* We might not have rootfs mounted at this point. Try
-		   to resolve the device name by other means. */
+#ifndef MODULE
+/*
+ * We might not have the root device mounted at this point.
+ * Try to resolve the device name by other means.
+ */
+	for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
+		dev_t devt;
 
-		dev_t devt = name_to_dev_t(devname);
-		if (devt)
-			bdev = blkdev_get_by_dev(devt, mode, dev);
+		if (i)
+			/*
+			 * Calling wait_for_device_probe in the first loop
+			 * was not enough, sleep for a bit in subsequent
+			 * go-arounds.
+			 */
+			msleep(1000);
+		wait_for_device_probe();
+
+		devt = name_to_dev_t(devname);
+		if (!devt)
+			continue;
+		bdev = blkdev_get_by_dev(devt, mode, dev);
 	}
 #endif
 
@@ -280,6 +305,7 @@ static struct block2mtd_dev *add_device(
 		/* Device didn't get added, so free the entry */
 		goto err_destroy_mutex;
 	}
+
 	list_add(&dev->list, &blkmtd_device_list);
 	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
 		dev->mtd.index,
@@ -348,16 +374,19 @@ static inline void kill_final_newline(ch
 
 #ifndef MODULE
 static int block2mtd_init_called = 0;
-static char block2mtd_paramline[80 + 12]; /* 80 for device, 12 for erase size */
+/* 80 for device, 12 for erase size */
+static char block2mtd_paramline[80 + 12];
 #endif
 
 static int block2mtd_setup2(const char *val)
 {
-	char buf[80 + 12]; /* 80 for device, 12 for erase size */
+	/* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
+	char buf[80 + 12 + 80 + 8];
 	char *str = buf;
 	char *token[2];
 	char *name;
 	size_t erase_size = PAGE_SIZE;
+	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
 	int i, ret;
 
 	if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
@@ -395,7 +424,7 @@ static int block2mtd_setup2(const char *
 		}
 	}
 
-	add_device(name, erase_size);
+	add_device(name, erase_size, timeout);
 
 	return 0;
 }
@@ -463,8 +492,7 @@ static void block2mtd_exit(void)
 	}
 }
 
-
-module_init(block2mtd_init);
+late_initcall(block2mtd_init);
 module_exit(block2mtd_exit);
 
 MODULE_LICENSE("GPL");
---
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v3 1/3] mtd: block2mtd: Ensure that block2mtd is triggered after block devices are presented.
@ 2014-11-09 12:21             ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-09 12:21 UTC (permalink / raw)
  To: linux-mtd, linux-kernel
  Cc: Herton Krzesinski, Jörn Engel, Brian Norris, dwmw2, Felix Fietkau

From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: Ensure that block2mtd is triggered after block devices are presented.

Ensures that block2mtd is triggered after the block devices are enumerated
at boot time.
This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
block2mtd filesystems, probably because of the delay on enumerating a USB
MMC card reader.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
Signed-off-by: Herton Krzesinski <herton@redhat.com>
---
V3: Separated on a single patch, fixes a compiling warning, cosmethic changes
V2: Uses kstrdup, removed PAGE_MASK.
--- a/drivers/mtd/devices/block2mtd.c	2014-11-07 16:40:14.638676860 -0200
+++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:44:45.277769924 -0200
@@ -9,7 +9,15 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+/*
+ * When the first attempt at device initialization fails, we may need to
+ * wait a little bit and retry. This timeout, by default 3 seconds, gives
+ * device time to start up. Required on BCM2708 and a few other chipsets.
+ */
+#define MTD_DEFAULT_TIMEOUT	3
+
 #include <linux/module.h>
+#include <linux/delay.h>
 #include <linux/fs.h>
 #include <linux/blkdev.h>
 #include <linux/bio.h>
@@ -209,10 +217,14 @@ static void block2mtd_free_device(struct
 }
 
 
-static struct block2mtd_dev *add_device(char *devname, int erase_size)
+static struct block2mtd_dev *add_device(char *devname, int erase_size,
+		int timeout)
 {
+#ifndef MODULE
+	int i;
+#endif
 	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
-	struct block_device *bdev;
+	struct block_device *bdev = ERR_PTR(-ENODEV);
 	struct block2mtd_dev *dev;
 	char *name;
 
@@ -225,15 +237,28 @@ static struct block2mtd_dev *add_device(
 
 	/* Get a handle on the device */
 	bdev = blkdev_get_by_path(devname, mode, dev);
-#ifndef MODULE
-	if (IS_ERR(bdev)) {
 
-		/* We might not have rootfs mounted at this point. Try
-		   to resolve the device name by other means. */
+#ifndef MODULE
+/*
+ * We might not have the root device mounted at this point.
+ * Try to resolve the device name by other means.
+ */
+	for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
+		dev_t devt;
 
-		dev_t devt = name_to_dev_t(devname);
-		if (devt)
-			bdev = blkdev_get_by_dev(devt, mode, dev);
+		if (i)
+			/*
+			 * Calling wait_for_device_probe in the first loop
+			 * was not enough, sleep for a bit in subsequent
+			 * go-arounds.
+			 */
+			msleep(1000);
+		wait_for_device_probe();
+
+		devt = name_to_dev_t(devname);
+		if (!devt)
+			continue;
+		bdev = blkdev_get_by_dev(devt, mode, dev);
 	}
 #endif
 
@@ -280,6 +305,7 @@ static struct block2mtd_dev *add_device(
 		/* Device didn't get added, so free the entry */
 		goto err_destroy_mutex;
 	}
+
 	list_add(&dev->list, &blkmtd_device_list);
 	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
 		dev->mtd.index,
@@ -348,16 +374,19 @@ static inline void kill_final_newline(ch
 
 #ifndef MODULE
 static int block2mtd_init_called = 0;
-static char block2mtd_paramline[80 + 12]; /* 80 for device, 12 for erase size */
+/* 80 for device, 12 for erase size */
+static char block2mtd_paramline[80 + 12];
 #endif
 
 static int block2mtd_setup2(const char *val)
 {
-	char buf[80 + 12]; /* 80 for device, 12 for erase size */
+	/* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
+	char buf[80 + 12 + 80 + 8];
 	char *str = buf;
 	char *token[2];
 	char *name;
 	size_t erase_size = PAGE_SIZE;
+	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
 	int i, ret;
 
 	if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
@@ -395,7 +424,7 @@ static int block2mtd_setup2(const char *
 		}
 	}
 
-	add_device(name, erase_size);
+	add_device(name, erase_size, timeout);
 
 	return 0;
 }
@@ -463,8 +492,7 @@ static void block2mtd_exit(void)
 	}
 }
 
-
-module_init(block2mtd_init);
+late_initcall(block2mtd_init);
 module_exit(block2mtd_exit);
 
 MODULE_LICENSE("GPL");
---
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v3 2/3] mtd: block2mtd: Adds a mtd name and a block device timeout option
  2014-11-09 12:18           ` Rodrigo Freire
@ 2014-11-09 12:22             ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-09 12:22 UTC (permalink / raw)
  To: linux-mtd, linux-kernel
  Cc: Jörn Engel, Felix Fietkau, dwmw2, Herton Krzesinski, Brian Norris

From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: Adds a mtd name and a block device timeout option

This patch adds support to a block2mtd MTD name and allows to specify
a block device timeout when adding a block2mtd MTD drive.
Usage: block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]
The devices will be identified the following way:
[root@server01 ~]# cat /proc/mtd
dev:    size   erasesize  name
mtd0: a0000000 00010000 "rootfs"
mtd1: 265080000 00010000 "anothername"
mtd2: acd00000 00010000 "/dev/mmcblk0p2"
Notice that the device mtd2 was added without specifying a name.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
Signed-off-by: Herton Krzesinski <herton@redhat.com>
---
V3: Separated on a single patch
--- a/drivers/mtd/devices/block2mtd.c	2014-11-07 17:16:11.711479312 -0200
+++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:15:14.255464054 -0200
@@ -25,6 +25,7 @@
 #include <linux/list.h>
 #include <linux/init.h>
 #include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
 #include <linux/mutex.h>
 #include <linux/mount.h>
 #include <linux/slab.h>
@@ -218,7 +219,7 @@ static void block2mtd_free_device(struct
 
 
 static struct block2mtd_dev *add_device(char *devname, int erase_size,
-		int timeout)
+		const char *mtdname, int timeout)
 {
 #ifndef MODULE
 	int i;
@@ -226,6 +227,7 @@ static struct block2mtd_dev *add_device(
 	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
 	struct block_device *bdev = ERR_PTR(-ENODEV);
 	struct block2mtd_dev *dev;
+	struct mtd_partition *part;
 	char *name;
 
 	if (!devname)
@@ -282,7 +284,9 @@ static struct block2mtd_dev *add_device(
 
 	/* Setup the MTD structure */
 	/* make the name contain the block device in */
-	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
+	if (!mtdname)
+		mtdname = devname;
+	name = kstrdup(mtdname, GFP_KERNEL);
 	if (!name)
 		goto err_destroy_mutex;
 
@@ -301,7 +305,11 @@ static struct block2mtd_dev *add_device(
 	dev->mtd.priv = dev;
 	dev->mtd.owner = THIS_MODULE;
 
-	if (mtd_device_register(&dev->mtd, NULL, 0)) {
+	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
+	part->name = name;
+	part->offset = 0;
+	part->size = dev->mtd.size;
+	if (mtd_device_register(&dev->mtd, part, 1)) {
 		/* Device didn't get added, so free the entry */
 		goto err_destroy_mutex;
 	}
@@ -309,8 +317,7 @@ static struct block2mtd_dev *add_device(
 	list_add(&dev->list, &blkmtd_device_list);
 	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
 		dev->mtd.index,
-		dev->mtd.name + strlen("block2mtd: "),
-		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
+		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
 	return dev;
 
 err_destroy_mutex:
@@ -383,7 +390,7 @@ static int block2mtd_setup2(const char *
 	/* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
 	char buf[80 + 12 + 80 + 8];
 	char *str = buf;
-	char *token[2];
+	char *token[4];
 	char *name;
 	size_t erase_size = PAGE_SIZE;
 	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
@@ -397,7 +404,7 @@ static int block2mtd_setup2(const char *
 	strcpy(str, val);
 	kill_final_newline(str);
 
-	for (i = 0; i < 2; i++)
+	for (i = 0; i < 4; i++)
 		token[i] = strsep(&str, ",");
 
 	if (str) {
@@ -424,7 +431,13 @@ static int block2mtd_setup2(const char *
 		}
 	}
 
-	add_device(name, erase_size, timeout);
+	if (token[2] && (strlen(token[2]) + 1 > 80))
+		pr_err("mtd device name too long");
+
+
+	if (token[3] && kstrtoul(token[3], 0, &timeout))
+		pr_err("invalid timeout");
+	add_device(name, erase_size, token[2], timeout);
 
 	return 0;
 }
@@ -458,7 +471,7 @@ static int block2mtd_setup(const char *v
 
 
 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
 
 static int __init block2mtd_init(void)
 {
---
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v3 2/3] mtd: block2mtd: Adds a mtd name and a block device timeout option
@ 2014-11-09 12:22             ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-09 12:22 UTC (permalink / raw)
  To: linux-mtd, linux-kernel
  Cc: Herton Krzesinski, Jörn Engel, Brian Norris, dwmw2, Felix Fietkau

From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: Adds a mtd name and a block device timeout option

This patch adds support to a block2mtd MTD name and allows to specify
a block device timeout when adding a block2mtd MTD drive.
Usage: block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]
The devices will be identified the following way:
[root@server01 ~]# cat /proc/mtd
dev:    size   erasesize  name
mtd0: a0000000 00010000 "rootfs"
mtd1: 265080000 00010000 "anothername"
mtd2: acd00000 00010000 "/dev/mmcblk0p2"
Notice that the device mtd2 was added without specifying a name.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
Signed-off-by: Herton Krzesinski <herton@redhat.com>
---
V3: Separated on a single patch
--- a/drivers/mtd/devices/block2mtd.c	2014-11-07 17:16:11.711479312 -0200
+++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:15:14.255464054 -0200
@@ -25,6 +25,7 @@
 #include <linux/list.h>
 #include <linux/init.h>
 #include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
 #include <linux/mutex.h>
 #include <linux/mount.h>
 #include <linux/slab.h>
@@ -218,7 +219,7 @@ static void block2mtd_free_device(struct
 
 
 static struct block2mtd_dev *add_device(char *devname, int erase_size,
-		int timeout)
+		const char *mtdname, int timeout)
 {
 #ifndef MODULE
 	int i;
@@ -226,6 +227,7 @@ static struct block2mtd_dev *add_device(
 	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
 	struct block_device *bdev = ERR_PTR(-ENODEV);
 	struct block2mtd_dev *dev;
+	struct mtd_partition *part;
 	char *name;
 
 	if (!devname)
@@ -282,7 +284,9 @@ static struct block2mtd_dev *add_device(
 
 	/* Setup the MTD structure */
 	/* make the name contain the block device in */
-	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
+	if (!mtdname)
+		mtdname = devname;
+	name = kstrdup(mtdname, GFP_KERNEL);
 	if (!name)
 		goto err_destroy_mutex;
 
@@ -301,7 +305,11 @@ static struct block2mtd_dev *add_device(
 	dev->mtd.priv = dev;
 	dev->mtd.owner = THIS_MODULE;
 
-	if (mtd_device_register(&dev->mtd, NULL, 0)) {
+	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
+	part->name = name;
+	part->offset = 0;
+	part->size = dev->mtd.size;
+	if (mtd_device_register(&dev->mtd, part, 1)) {
 		/* Device didn't get added, so free the entry */
 		goto err_destroy_mutex;
 	}
@@ -309,8 +317,7 @@ static struct block2mtd_dev *add_device(
 	list_add(&dev->list, &blkmtd_device_list);
 	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
 		dev->mtd.index,
-		dev->mtd.name + strlen("block2mtd: "),
-		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
+		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
 	return dev;
 
 err_destroy_mutex:
@@ -383,7 +390,7 @@ static int block2mtd_setup2(const char *
 	/* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
 	char buf[80 + 12 + 80 + 8];
 	char *str = buf;
-	char *token[2];
+	char *token[4];
 	char *name;
 	size_t erase_size = PAGE_SIZE;
 	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
@@ -397,7 +404,7 @@ static int block2mtd_setup2(const char *
 	strcpy(str, val);
 	kill_final_newline(str);
 
-	for (i = 0; i < 2; i++)
+	for (i = 0; i < 4; i++)
 		token[i] = strsep(&str, ",");
 
 	if (str) {
@@ -424,7 +431,13 @@ static int block2mtd_setup2(const char *
 		}
 	}
 
-	add_device(name, erase_size, timeout);
+	if (token[2] && (strlen(token[2]) + 1 > 80))
+		pr_err("mtd device name too long");
+
+
+	if (token[3] && kstrtoul(token[3], 0, &timeout))
+		pr_err("invalid timeout");
+	add_device(name, erase_size, token[2], timeout);
 
 	return 0;
 }
@@ -458,7 +471,7 @@ static int block2mtd_setup(const char *v
 
 
 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
 
 static int __init block2mtd_init(void)
 {
---
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
  2014-11-09 12:18           ` Rodrigo Freire
@ 2014-11-09 12:23             ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-09 12:23 UTC (permalink / raw)
  To: linux-mtd, linux-kernel
  Cc: Jörn Engel, Felix Fietkau, dwmw2, Herton Krzesinski, Brian Norris

From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: Removes PAGE_MASK as a index to partition size

PAGE_MASK is no longer needed with the new term.
This patch keeps the device size aligned with the erase_size.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
Signed-off-by: Herton Krzesinski <herton@redhat.com>
---
V3: Separated on a single patch
--- a/drivers/mtd/devices/block2mtd.c	2014-11-07 17:40:58.688747820 -0200
+++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:41:28.054750893 -0200
@@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
 		goto err_destroy_mutex;
 
 	dev->mtd.name = name;
-
-	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
+	dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
 	dev->mtd.erasesize = erase_size;
 	dev->mtd.writesize = 1;
 	dev->mtd.writebufsize = PAGE_SIZE;
---
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
@ 2014-11-09 12:23             ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-09 12:23 UTC (permalink / raw)
  To: linux-mtd, linux-kernel
  Cc: Herton Krzesinski, Jörn Engel, Brian Norris, dwmw2, Felix Fietkau

From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: Removes PAGE_MASK as a index to partition size

PAGE_MASK is no longer needed with the new term.
This patch keeps the device size aligned with the erase_size.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
Signed-off-by: Herton Krzesinski <herton@redhat.com>
---
V3: Separated on a single patch
--- a/drivers/mtd/devices/block2mtd.c	2014-11-07 17:40:58.688747820 -0200
+++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:41:28.054750893 -0200
@@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
 		goto err_destroy_mutex;
 
 	dev->mtd.name = name;
-
-	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
+	dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
 	dev->mtd.erasesize = erase_size;
 	dev->mtd.writesize = 1;
 	dev->mtd.writebufsize = PAGE_SIZE;
---
1.7.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-11-09 12:18           ` Rodrigo Freire
@ 2014-11-26  3:33             ` Brian Norris
  -1 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2014-11-26  3:33 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Jörn Engel, linux-mtd, Felix Fietkau, dwmw2, linux-kernel,
	Herton Krzesinski

On Sun, Nov 09, 2014 at 07:18:05AM -0500, Rodrigo Freire wrote:
> > From: "Brian Norris" <computersforpeace@gmail.com>
> > Sent: Wednesday, November 5, 2014 6:23:03 PM
> 
> > This still seems like a bad idea (using a block device + block2mtd +
> > JFFS2). Why are you doing this? See comments here:
> > http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2
> 
> As Felix stated on a previous message to the thread, I am using JFFS2 over
> block2mtd where regular filesystems failed to do so well. There are several
> [1] threads pointing this issue, and JFFS2 over block2mtd works like a charm
> on more harsh scenarios.
[...]
> [1] - http://bit.ly/1smGvwa

OK, so there are definitely problems with cheap SD card power cut
tolerance. That's not news. But that doesn't mean block2mtd + JFFS2 is a
good solution. In fact, when I add 'jffs2' to your Google search query
of 'raspberry pi corrupt sd card', the only mentions I see are those who
agree that this is not the right choice.

But anyway, we can look at supporting block2mtd (since you provided the
patches), even if we don't agree how it should be used. And in fact, I
might argue there are no good (production) uses for block2mtd, so I
suppose I don't have much stake in it :)

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-11-26  3:33             ` Brian Norris
  0 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2014-11-26  3:33 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

On Sun, Nov 09, 2014 at 07:18:05AM -0500, Rodrigo Freire wrote:
> > From: "Brian Norris" <computersforpeace@gmail.com>
> > Sent: Wednesday, November 5, 2014 6:23:03 PM
> 
> > This still seems like a bad idea (using a block device + block2mtd +
> > JFFS2). Why are you doing this? See comments here:
> > http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2
> 
> As Felix stated on a previous message to the thread, I am using JFFS2 over
> block2mtd where regular filesystems failed to do so well. There are several
> [1] threads pointing this issue, and JFFS2 over block2mtd works like a charm
> on more harsh scenarios.
[...]
> [1] - http://bit.ly/1smGvwa

OK, so there are definitely problems with cheap SD card power cut
tolerance. That's not news. But that doesn't mean block2mtd + JFFS2 is a
good solution. In fact, when I add 'jffs2' to your Google search query
of 'raspberry pi corrupt sd card', the only mentions I see are those who
agree that this is not the right choice.

But anyway, we can look at supporting block2mtd (since you provided the
patches), even if we don't agree how it should be used. And in fact, I
might argue there are no good (production) uses for block2mtd, so I
suppose I don't have much stake in it :)

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
  2014-11-09 12:23             ` Rodrigo Freire
@ 2014-11-26  7:21               ` Brian Norris
  -1 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2014-11-26  7:21 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: linux-mtd, linux-kernel, Jörn Engel, Felix Fietkau, dwmw2,
	Herton Krzesinski

On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org>
> 
> mtd: block2mtd: Removes PAGE_MASK as a index to partition size

You don't need to repeat the subject here.

> 
> PAGE_MASK is no longer needed with the new term.

This isn't too descriptive. What you probably mean is that we assume the
erase size is always larger than PAGE_SIZE.

> This patch keeps the device size aligned with the erase_size.
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> Signed-off-by: Herton Krzesinski <herton@redhat.com>
> ---
> V3: Separated on a single patch
> --- a/drivers/mtd/devices/block2mtd.c	2014-11-07 17:40:58.688747820 -0200
> +++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:41:28.054750893 -0200
> @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
>  		goto err_destroy_mutex;
>  
>  	dev->mtd.name = name;
> -
> -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> +	dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);

You never guaranteed that erase_size is a power of two, so this doesn't
necessarily mask the way you'd like...

But also, why is this even necessary? I see that we should already have
errored out if this was actually significant, since we have above:

	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
		pr_err("erasesize must be a divisor of device size\n");
		goto err_free_block2mtd;
	}

>  	dev->mtd.erasesize = erase_size;
>  	dev->mtd.writesize = 1;
>  	dev->mtd.writebufsize = PAGE_SIZE;

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
@ 2014-11-26  7:21               ` Brian Norris
  0 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2014-11-26  7:21 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org>
> 
> mtd: block2mtd: Removes PAGE_MASK as a index to partition size

You don't need to repeat the subject here.

> 
> PAGE_MASK is no longer needed with the new term.

This isn't too descriptive. What you probably mean is that we assume the
erase size is always larger than PAGE_SIZE.

> This patch keeps the device size aligned with the erase_size.
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> Signed-off-by: Herton Krzesinski <herton@redhat.com>
> ---
> V3: Separated on a single patch
> --- a/drivers/mtd/devices/block2mtd.c	2014-11-07 17:40:58.688747820 -0200
> +++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:41:28.054750893 -0200
> @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
>  		goto err_destroy_mutex;
>  
>  	dev->mtd.name = name;
> -
> -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> +	dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);

You never guaranteed that erase_size is a power of two, so this doesn't
necessarily mask the way you'd like...

But also, why is this even necessary? I see that we should already have
errored out if this was actually significant, since we have above:

	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
		pr_err("erasesize must be a divisor of device size\n");
		goto err_free_block2mtd;
	}

>  	dev->mtd.erasesize = erase_size;
>  	dev->mtd.writesize = 1;
>  	dev->mtd.writebufsize = PAGE_SIZE;

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
  2014-11-26  7:21               ` Brian Norris
@ 2014-11-26 13:19                 ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-26 13:19 UTC (permalink / raw)
  To: Brian Norris
  Cc: linux-mtd, linux-kernel, Jörn Engel, Felix Fietkau, dwmw2,
	Herton Krzesinski

From: "Brian Norris" <computersforpeace@gmail.com>
Sent: Wednesday, November 26, 2014 5:21:47 AM
Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
partition size

> On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> > PAGE_MASK is no longer needed with the new term.

> This isn't too descriptive. What you probably mean is that we assume the
> erase size is always larger than PAGE_SIZE.

> > This patch keeps the device size aligned with the erase_size.
> >
> > Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> > Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> > Signed-off-by: Herton Krzesinski <herton@redhat.com>
> > ---
> > V3: Separated on a single patch
> > --- a/drivers/mtd/devices/block2mtd.c 2014-11-07 17:40:58.688747820 -0200
> > +++ b/drivers/mtd/devices/block2mtd.c 2014-11-07 17:41:28.054750893 -0200
> > @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
> > goto err_destroy_mutex;
> >
> > dev->mtd.name = name;
> > -
> > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);

> You never guaranteed that erase_size is a power of two, so this doesn't
> necessarily mask the way you'd like...

> But also, why is this even necessary? I see that we should already have
> errored out if this was actually significant, since we have above:

> if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> pr_err("erasesize must be a divisor of device size\n");
> goto err_free_block2mtd;
> }

Hello Brian, and thanks for the review.

Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680

I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
@ 2014-11-26 13:19                 ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-26 13:19 UTC (permalink / raw)
  To: Brian Norris
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

From: "Brian Norris" <computersforpeace@gmail.com>
Sent: Wednesday, November 26, 2014 5:21:47 AM
Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
partition size

> On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> > PAGE_MASK is no longer needed with the new term.

> This isn't too descriptive. What you probably mean is that we assume the
> erase size is always larger than PAGE_SIZE.

> > This patch keeps the device size aligned with the erase_size.
> >
> > Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> > Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> > Signed-off-by: Herton Krzesinski <herton@redhat.com>
> > ---
> > V3: Separated on a single patch
> > --- a/drivers/mtd/devices/block2mtd.c 2014-11-07 17:40:58.688747820 -0200
> > +++ b/drivers/mtd/devices/block2mtd.c 2014-11-07 17:41:28.054750893 -0200
> > @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
> > goto err_destroy_mutex;
> >
> > dev->mtd.name = name;
> > -
> > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);

> You never guaranteed that erase_size is a power of two, so this doesn't
> necessarily mask the way you'd like...

> But also, why is this even necessary? I see that we should already have
> errored out if this was actually significant, since we have above:

> if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> pr_err("erasesize must be a divisor of device size\n");
> goto err_free_block2mtd;
> }

Hello Brian, and thanks for the review.

Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680

I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-11-26  3:33             ` Brian Norris
@ 2014-11-26 13:32               ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-26 13:32 UTC (permalink / raw)
  To: Brian Norris
  Cc: Jörn Engel, linux-mtd, Felix Fietkau, dwmw2, linux-kernel,
	Herton Krzesinski

From: "Brian Norris" <computersforpeace@gmail.com>
Sent: Wednesday, November 26, 2014 1:33:04 AM
Subject: Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

> On Sun, Nov 09, 2014 at 07:18:05AM -0500, Rodrigo Freire wrote:
> > > From: "Brian Norris" <computersforpeace@gmail.com>
> > > Sent: Wednesday, November 5, 2014 6:23:03 PM
> >
> > > This still seems like a bad idea (using a block device + block2mtd +
> > > JFFS2). Why are you doing this? See comments here:
> > > http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2
> >
> > As Felix stated on a previous message to the thread, I am using JFFS2 over
> > block2mtd where regular filesystems failed to do so well. There are several
> > [1] threads pointing this issue, and JFFS2 over block2mtd works like a
> > charm
> > on more harsh scenarios.
> [...]
> > [1] - http://bit.ly/1smGvwa

> OK, so there are definitely problems with cheap SD card power cut
> tolerance. That's not news. But that doesn't mean block2mtd + JFFS2 is a
> good solution. In fact, when I add 'jffs2' to your Google search query
> of 'raspberry pi corrupt sd card', the only mentions I see are those who
> agree that this is not the right choice.

> But anyway, we can look at supporting block2mtd (since you provided the
> patches), even if we don't agree how it should be used. And in fact, I
> might argue there are no good (production) uses for block2mtd, so I
> suppose I don't have much stake in it :)

Hi there Brian,

This patchset primarily aims to fix a block2mtd behavior, and not introduce new features (well, the device name and a timeout option are indeed new options, but they're actually enhancements). block2mtd already exists, works nicely as boot root device on several architectures, but fails on BCM2835 arch. Our patchset only aims to get it fixed. We just want to block2mtd work on BCM2835 the way it works on different architectures. So, this is a fix.

As a side note, WRT the SD card corruption; it also happens on good quality SD cards too. The main culprit for the corruption is bad mains / power supply issues / abrupt poweroff.

Thanks for the thorough review.

Looking forward for the ACK ;-)

My best regards,

- RF.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2014-11-26 13:32               ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2014-11-26 13:32 UTC (permalink / raw)
  To: Brian Norris
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

From: "Brian Norris" <computersforpeace@gmail.com>
Sent: Wednesday, November 26, 2014 1:33:04 AM
Subject: Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

> On Sun, Nov 09, 2014 at 07:18:05AM -0500, Rodrigo Freire wrote:
> > > From: "Brian Norris" <computersforpeace@gmail.com>
> > > Sent: Wednesday, November 5, 2014 6:23:03 PM
> >
> > > This still seems like a bad idea (using a block device + block2mtd +
> > > JFFS2). Why are you doing this? See comments here:
> > > http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2
> >
> > As Felix stated on a previous message to the thread, I am using JFFS2 over
> > block2mtd where regular filesystems failed to do so well. There are several
> > [1] threads pointing this issue, and JFFS2 over block2mtd works like a
> > charm
> > on more harsh scenarios.
> [...]
> > [1] - http://bit.ly/1smGvwa

> OK, so there are definitely problems with cheap SD card power cut
> tolerance. That's not news. But that doesn't mean block2mtd + JFFS2 is a
> good solution. In fact, when I add 'jffs2' to your Google search query
> of 'raspberry pi corrupt sd card', the only mentions I see are those who
> agree that this is not the right choice.

> But anyway, we can look at supporting block2mtd (since you provided the
> patches), even if we don't agree how it should be used. And in fact, I
> might argue there are no good (production) uses for block2mtd, so I
> suppose I don't have much stake in it :)

Hi there Brian,

This patchset primarily aims to fix a block2mtd behavior, and not introduce new features (well, the device name and a timeout option are indeed new options, but they're actually enhancements). block2mtd already exists, works nicely as boot root device on several architectures, but fails on BCM2835 arch. Our patchset only aims to get it fixed. We just want to block2mtd work on BCM2835 the way it works on different architectures. So, this is a fix.

As a side note, WRT the SD card corruption; it also happens on good quality SD cards too. The main culprit for the corruption is bad mains / power supply issues / abrupt poweroff.

Thanks for the thorough review.

Looking forward for the ACK ;-)

My best regards,

- RF.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
  2014-11-26 13:32               ` Rodrigo Freire
@ 2015-02-11 15:09                 ` Rodrigo Freire
  -1 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2015-02-11 15:09 UTC (permalink / raw)
  To: Brian Norris
  Cc: Jörn Engel, linux-mtd, Felix Fietkau, dwmw2, linux-kernel,
	Herton Krzesinski

From: "Brian Norris" <computersforpeace@gmail.com> 
Sent: Wednesday, November 26, 2014 1:33:04 AM 
Subject: Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time 

> On Sun, Nov 09, 2014 at 07:18:05AM -0500, Rodrigo Freire wrote: 
> > > From: "Brian Norris" <computersforpeace@gmail.com> 
> > > Sent: Wednesday, November 5, 2014 6:23:03 PM 
> > 
> > > This still seems like a bad idea (using a block device + block2mtd + 
> > > JFFS2). Why are you doing this? See comments here: 
> > > http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2 
> > 
> > As Felix stated on a previous message to the thread, I am using JFFS2 over 
> > block2mtd where regular filesystems failed to do so well. There are several
> > [1] threads pointing this issue, and JFFS2 over block2mtd works like a 
> > charm 
> > on more harsh scenarios. 
> [...] 
> > [1] - http://bit.ly/1smGvwa 

> OK, so there are definitely problems with cheap SD card power cut 
> tolerance. That's not news. But that doesn't mean block2mtd + JFFS2 is a 
> good solution. In fact, when I add 'jffs2' to your Google search query 
> of 'raspberry pi corrupt sd card', the only mentions I see are those who 
> agree that this is not the right choice. 

> But anyway, we can look at supporting block2mtd (since you provided the 
> patches), even if we don't agree how it should be used. And in fact, I 
> might argue there are no good (production) uses for block2mtd, so I 
> suppose I don't have much stake in it :) 

Hi there Brian, 

This patchset primarily aims to fix a block2mtd behavior, and not introduce
new features (well, the device name and a timeout option are indeed new
options, but they're actually enhancements). block2mtd already exists, works
 nicely as boot root device on several architectures, but fails on BCM2835
arch. Our patchset only aims to get it fixed. We just want to block2mtd work
on BCM2835 the way it works on different architectures. So, this is a fix. 

As a side note, WRT the SD card corruption; it also happens on good quality
SD cards too. The main culprit for the corruption is bad mains / power supply
issues / abrupt poweroff. And there's also the wear leveling...

Thanks for the thorough review. 

Looking forward for the ACK ;-) 

My best regards, 

- RF. 

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time
@ 2015-02-11 15:09                 ` Rodrigo Freire
  0 siblings, 0 replies; 63+ messages in thread
From: Rodrigo Freire @ 2015-02-11 15:09 UTC (permalink / raw)
  To: Brian Norris
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

From: "Brian Norris" <computersforpeace@gmail.com> 
Sent: Wednesday, November 26, 2014 1:33:04 AM 
Subject: Re: [PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time 

> On Sun, Nov 09, 2014 at 07:18:05AM -0500, Rodrigo Freire wrote: 
> > > From: "Brian Norris" <computersforpeace@gmail.com> 
> > > Sent: Wednesday, November 5, 2014 6:23:03 PM 
> > 
> > > This still seems like a bad idea (using a block device + block2mtd + 
> > > JFFS2). Why are you doing this? See comments here: 
> > > http://www.linux-mtd.infradead.org/faq/jffs2.html#L_hdd_jffs2 
> > 
> > As Felix stated on a previous message to the thread, I am using JFFS2 over 
> > block2mtd where regular filesystems failed to do so well. There are several
> > [1] threads pointing this issue, and JFFS2 over block2mtd works like a 
> > charm 
> > on more harsh scenarios. 
> [...] 
> > [1] - http://bit.ly/1smGvwa 

> OK, so there are definitely problems with cheap SD card power cut 
> tolerance. That's not news. But that doesn't mean block2mtd + JFFS2 is a 
> good solution. In fact, when I add 'jffs2' to your Google search query 
> of 'raspberry pi corrupt sd card', the only mentions I see are those who 
> agree that this is not the right choice. 

> But anyway, we can look at supporting block2mtd (since you provided the 
> patches), even if we don't agree how it should be used. And in fact, I 
> might argue there are no good (production) uses for block2mtd, so I 
> suppose I don't have much stake in it :) 

Hi there Brian, 

This patchset primarily aims to fix a block2mtd behavior, and not introduce
new features (well, the device name and a timeout option are indeed new
options, but they're actually enhancements). block2mtd already exists, works
 nicely as boot root device on several architectures, but fails on BCM2835
arch. Our patchset only aims to get it fixed. We just want to block2mtd work
on BCM2835 the way it works on different architectures. So, this is a fix. 

As a side note, WRT the SD card corruption; it also happens on good quality
SD cards too. The main culprit for the corruption is bad mains / power supply
issues / abrupt poweroff. And there's also the wear leveling...

Thanks for the thorough review. 

Looking forward for the ACK ;-) 

My best regards, 

- RF. 

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 1/3] mtd: block2mtd: Ensure that block2mtd is triggered after block devices are presented.
  2014-11-09 12:21             ` Rodrigo Freire
@ 2015-02-24  7:45               ` Brian Norris
  -1 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2015-02-24  7:45 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: linux-mtd, linux-kernel, Jörn Engel, Felix Fietkau, dwmw2,
	Herton Krzesinski

You asked for review again... I guess I forgot about this patch series
for some time. I think this patch is OK, except for a trivial comment
below. But I have some comments on the next few.

On Sun, Nov 09, 2014 at 07:21:13AM -0500, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org>
> 
> mtd: block2mtd: Ensure that block2mtd is triggered after block devices are presented.
> 
> Ensures that block2mtd is triggered after the block devices are enumerated
> at boot time.
> This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
> block2mtd filesystems, probably because of the delay on enumerating a USB
> MMC card reader.
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> Signed-off-by: Herton Krzesinski <herton@redhat.com>
> ---
> V3: Separated on a single patch, fixes a compiling warning, cosmethic changes
> V2: Uses kstrdup, removed PAGE_MASK.
> --- a/drivers/mtd/devices/block2mtd.c	2014-11-07 16:40:14.638676860 -0200
> +++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:44:45.277769924 -0200
[...]
> @@ -225,15 +237,28 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Get a handle on the device */
>  	bdev = blkdev_get_by_path(devname, mode, dev);
> -#ifndef MODULE
> -	if (IS_ERR(bdev)) {
>  
> -		/* We might not have rootfs mounted at this point. Try
> -		   to resolve the device name by other means. */
> +#ifndef MODULE
> +/*
> + * We might not have the root device mounted at this point.
> + * Try to resolve the device name by other means.
> + */

That's some interesting comment indentation.

> +	for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
> +		dev_t devt;
>  
> -		dev_t devt = name_to_dev_t(devname);
> -		if (devt)
> -			bdev = blkdev_get_by_dev(devt, mode, dev);
> +		if (i)
> +			/*
> +			 * Calling wait_for_device_probe in the first loop
> +			 * was not enough, sleep for a bit in subsequent
> +			 * go-arounds.
> +			 */
> +			msleep(1000);
> +		wait_for_device_probe();
> +
> +		devt = name_to_dev_t(devname);
> +		if (!devt)
> +			continue;
> +		bdev = blkdev_get_by_dev(devt, mode, dev);
>  	}
>  #endif
>  
> @@ -280,6 +305,7 @@ static struct block2mtd_dev *add_device(
>  		/* Device didn't get added, so free the entry */
>  		goto err_destroy_mutex;
>  	}
> +
>  	list_add(&dev->list, &blkmtd_device_list);
>  	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
>  		dev->mtd.index,
> @@ -348,16 +374,19 @@ static inline void kill_final_newline(ch
>  
>  #ifndef MODULE
>  static int block2mtd_init_called = 0;
> -static char block2mtd_paramline[80 + 12]; /* 80 for device, 12 for erase size */
> +/* 80 for device, 12 for erase size */
> +static char block2mtd_paramline[80 + 12];
>  #endif
>  
>  static int block2mtd_setup2(const char *val)
>  {
> -	char buf[80 + 12]; /* 80 for device, 12 for erase size */
> +	/* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
> +	char buf[80 + 12 + 80 + 8];
>  	char *str = buf;
>  	char *token[2];
>  	char *name;
>  	size_t erase_size = PAGE_SIZE;
> +	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
>  	int i, ret;
>  
>  	if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
> @@ -395,7 +424,7 @@ static int block2mtd_setup2(const char *
>  		}
>  	}
>  
> -	add_device(name, erase_size);
> +	add_device(name, erase_size, timeout);
>  
>  	return 0;
>  }
> @@ -463,8 +492,7 @@ static void block2mtd_exit(void)
>  	}
>  }
>  
> -
> -module_init(block2mtd_init);
> +late_initcall(block2mtd_init);

This technically could have problems if you want to use block2mtd with
UBI, now, since it also uses late_initcall(), and it can add UBI
attachments via module parameters too (ubi.mtd=<mtd-name>).

I'm not too worried about this, though, since block2mtd is really not
meant for serious use (despite your usage here).

>  module_exit(block2mtd_exit);
>  
>  MODULE_LICENSE("GPL");

Pushed this patch to l2-mtd.git, with comment fixups.

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 1/3] mtd: block2mtd: Ensure that block2mtd is triggered after block devices are presented.
@ 2015-02-24  7:45               ` Brian Norris
  0 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2015-02-24  7:45 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

You asked for review again... I guess I forgot about this patch series
for some time. I think this patch is OK, except for a trivial comment
below. But I have some comments on the next few.

On Sun, Nov 09, 2014 at 07:21:13AM -0500, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org>
> 
> mtd: block2mtd: Ensure that block2mtd is triggered after block devices are presented.
> 
> Ensures that block2mtd is triggered after the block devices are enumerated
> at boot time.
> This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2
> block2mtd filesystems, probably because of the delay on enumerating a USB
> MMC card reader.
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> Signed-off-by: Herton Krzesinski <herton@redhat.com>
> ---
> V3: Separated on a single patch, fixes a compiling warning, cosmethic changes
> V2: Uses kstrdup, removed PAGE_MASK.
> --- a/drivers/mtd/devices/block2mtd.c	2014-11-07 16:40:14.638676860 -0200
> +++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:44:45.277769924 -0200
[...]
> @@ -225,15 +237,28 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Get a handle on the device */
>  	bdev = blkdev_get_by_path(devname, mode, dev);
> -#ifndef MODULE
> -	if (IS_ERR(bdev)) {
>  
> -		/* We might not have rootfs mounted at this point. Try
> -		   to resolve the device name by other means. */
> +#ifndef MODULE
> +/*
> + * We might not have the root device mounted at this point.
> + * Try to resolve the device name by other means.
> + */

That's some interesting comment indentation.

> +	for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
> +		dev_t devt;
>  
> -		dev_t devt = name_to_dev_t(devname);
> -		if (devt)
> -			bdev = blkdev_get_by_dev(devt, mode, dev);
> +		if (i)
> +			/*
> +			 * Calling wait_for_device_probe in the first loop
> +			 * was not enough, sleep for a bit in subsequent
> +			 * go-arounds.
> +			 */
> +			msleep(1000);
> +		wait_for_device_probe();
> +
> +		devt = name_to_dev_t(devname);
> +		if (!devt)
> +			continue;
> +		bdev = blkdev_get_by_dev(devt, mode, dev);
>  	}
>  #endif
>  
> @@ -280,6 +305,7 @@ static struct block2mtd_dev *add_device(
>  		/* Device didn't get added, so free the entry */
>  		goto err_destroy_mutex;
>  	}
> +
>  	list_add(&dev->list, &blkmtd_device_list);
>  	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
>  		dev->mtd.index,
> @@ -348,16 +374,19 @@ static inline void kill_final_newline(ch
>  
>  #ifndef MODULE
>  static int block2mtd_init_called = 0;
> -static char block2mtd_paramline[80 + 12]; /* 80 for device, 12 for erase size */
> +/* 80 for device, 12 for erase size */
> +static char block2mtd_paramline[80 + 12];
>  #endif
>  
>  static int block2mtd_setup2(const char *val)
>  {
> -	char buf[80 + 12]; /* 80 for device, 12 for erase size */
> +	/* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
> +	char buf[80 + 12 + 80 + 8];
>  	char *str = buf;
>  	char *token[2];
>  	char *name;
>  	size_t erase_size = PAGE_SIZE;
> +	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
>  	int i, ret;
>  
>  	if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
> @@ -395,7 +424,7 @@ static int block2mtd_setup2(const char *
>  		}
>  	}
>  
> -	add_device(name, erase_size);
> +	add_device(name, erase_size, timeout);
>  
>  	return 0;
>  }
> @@ -463,8 +492,7 @@ static void block2mtd_exit(void)
>  	}
>  }
>  
> -
> -module_init(block2mtd_init);
> +late_initcall(block2mtd_init);

This technically could have problems if you want to use block2mtd with
UBI, now, since it also uses late_initcall(), and it can add UBI
attachments via module parameters too (ubi.mtd=<mtd-name>).

I'm not too worried about this, though, since block2mtd is really not
meant for serious use (despite your usage here).

>  module_exit(block2mtd_exit);
>  
>  MODULE_LICENSE("GPL");

Pushed this patch to l2-mtd.git, with comment fixups.

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 2/3] mtd: block2mtd: Adds a mtd name and a block device timeout option
  2014-11-09 12:22             ` Rodrigo Freire
@ 2015-02-24  8:05               ` Brian Norris
  -1 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2015-02-24  8:05 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: linux-mtd, linux-kernel, Jörn Engel, Felix Fietkau, dwmw2,
	Herton Krzesinski

On Sun, Nov 09, 2014 at 07:22:27AM -0500, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org>
> 
> mtd: block2mtd: Adds a mtd name and a block device timeout option
> 
> This patch adds support to a block2mtd MTD name and allows to specify
> a block device timeout when adding a block2mtd MTD drive.
> Usage: block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]

Hmm, are all 4 required in this order? What if I want to set the timeout
without the erasesize or name? I suppose it's not a requirement for this
patch, but it's probably not hard to handle that as a future
enhancement. e.g. block2mtd=<dev[,[<erasesize>][,[<name>][,<timeout>]]]
so I could do

	block2mtd=/dev/mmcblk0p2,,,4

to set the timeout to 4 seconds.

> The devices will be identified the following way:
> [root@server01 ~]# cat /proc/mtd
> dev:    size   erasesize  name
> mtd0: a0000000 00010000 "rootfs"
> mtd1: 265080000 00010000 "anothername"
> mtd2: acd00000 00010000 "/dev/mmcblk0p2"
> Notice that the device mtd2 was added without specifying a name.
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> Signed-off-by: Herton Krzesinski <herton@redhat.com>
> ---
> V3: Separated on a single patch
> --- a/drivers/mtd/devices/block2mtd.c	2014-11-07 17:16:11.711479312 -0200
> +++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:15:14.255464054 -0200
> @@ -25,6 +25,7 @@
>  #include <linux/list.h>
>  #include <linux/init.h>
>  #include <linux/mtd/mtd.h>
> +#include <linux/mtd/partitions.h>
>  #include <linux/mutex.h>
>  #include <linux/mount.h>
>  #include <linux/slab.h>
> @@ -218,7 +219,7 @@ static void block2mtd_free_device(struct
>  
>  
>  static struct block2mtd_dev *add_device(char *devname, int erase_size,
> -		int timeout)
> +		const char *mtdname, int timeout)
>  {
>  #ifndef MODULE
>  	int i;
> @@ -226,6 +227,7 @@ static struct block2mtd_dev *add_device(
>  	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
>  	struct block_device *bdev = ERR_PTR(-ENODEV);
>  	struct block2mtd_dev *dev;
> +	struct mtd_partition *part;
>  	char *name;
>  
>  	if (!devname)
> @@ -282,7 +284,9 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Setup the MTD structure */
>  	/* make the name contain the block device in */
> -	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
> +	if (!mtdname)
> +		mtdname = devname;
> +	name = kstrdup(mtdname, GFP_KERNEL);
>  	if (!name)
>  		goto err_destroy_mutex;
>  
> @@ -301,7 +305,11 @@ static struct block2mtd_dev *add_device(
>  	dev->mtd.priv = dev;
>  	dev->mtd.owner = THIS_MODULE;
>  
> -	if (mtd_device_register(&dev->mtd, NULL, 0)) {
> +	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);

                       sizeof(*part)

> +	part->name = name;
> +	part->offset = 0;
> +	part->size = dev->mtd.size;
> +	if (mtd_device_register(&dev->mtd, part, 1)) {
>  		/* Device didn't get added, so free the entry */
>  		goto err_destroy_mutex;
>  	}
> @@ -309,8 +317,7 @@ static struct block2mtd_dev *add_device(
>  	list_add(&dev->list, &blkmtd_device_list);
>  	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
>  		dev->mtd.index,
> -		dev->mtd.name + strlen("block2mtd: "),
> -		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
> +		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
>  	return dev;
>  
>  err_destroy_mutex:
> @@ -383,7 +390,7 @@ static int block2mtd_setup2(const char *
>  	/* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
>  	char buf[80 + 12 + 80 + 8];
>  	char *str = buf;
> -	char *token[2];
> +	char *token[4];
>  	char *name;
>  	size_t erase_size = PAGE_SIZE;
>  	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
> @@ -397,7 +404,7 @@ static int block2mtd_setup2(const char *
>  	strcpy(str, val);
>  	kill_final_newline(str);
>  
> -	for (i = 0; i < 2; i++)
> +	for (i = 0; i < 4; i++)

Maybe use ARRAY_SIZE(token)?

>  		token[i] = strsep(&str, ",");
>  
>  	if (str) {
> @@ -424,7 +431,13 @@ static int block2mtd_setup2(const char *
>  		}
>  	}
>  
> -	add_device(name, erase_size, timeout);
> +	if (token[2] && (strlen(token[2]) + 1 > 80))
> +		pr_err("mtd device name too long");

Hmm, so it's too long, but you continue? Shouldn't we return here?

> +
> +
> +	if (token[3] && kstrtoul(token[3], 0, &timeout))
> +		pr_err("invalid timeout");

Again, shouldn't we return here? It's best not to just ignore invalid
input.

> +	add_device(name, erase_size, token[2], timeout);
>  
>  	return 0;
>  }
> @@ -458,7 +471,7 @@ static int block2mtd_setup(const char *v
>  
>  
>  module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
> -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
> +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
>  
>  static int __init block2mtd_init(void)
>  {

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 2/3] mtd: block2mtd: Adds a mtd name and a block device timeout option
@ 2015-02-24  8:05               ` Brian Norris
  0 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2015-02-24  8:05 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

On Sun, Nov 09, 2014 at 07:22:27AM -0500, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org>
> 
> mtd: block2mtd: Adds a mtd name and a block device timeout option
> 
> This patch adds support to a block2mtd MTD name and allows to specify
> a block device timeout when adding a block2mtd MTD drive.
> Usage: block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]

Hmm, are all 4 required in this order? What if I want to set the timeout
without the erasesize or name? I suppose it's not a requirement for this
patch, but it's probably not hard to handle that as a future
enhancement. e.g. block2mtd=<dev[,[<erasesize>][,[<name>][,<timeout>]]]
so I could do

	block2mtd=/dev/mmcblk0p2,,,4

to set the timeout to 4 seconds.

> The devices will be identified the following way:
> [root@server01 ~]# cat /proc/mtd
> dev:    size   erasesize  name
> mtd0: a0000000 00010000 "rootfs"
> mtd1: 265080000 00010000 "anothername"
> mtd2: acd00000 00010000 "/dev/mmcblk0p2"
> Notice that the device mtd2 was added without specifying a name.
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> Signed-off-by: Herton Krzesinski <herton@redhat.com>
> ---
> V3: Separated on a single patch
> --- a/drivers/mtd/devices/block2mtd.c	2014-11-07 17:16:11.711479312 -0200
> +++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:15:14.255464054 -0200
> @@ -25,6 +25,7 @@
>  #include <linux/list.h>
>  #include <linux/init.h>
>  #include <linux/mtd/mtd.h>
> +#include <linux/mtd/partitions.h>
>  #include <linux/mutex.h>
>  #include <linux/mount.h>
>  #include <linux/slab.h>
> @@ -218,7 +219,7 @@ static void block2mtd_free_device(struct
>  
>  
>  static struct block2mtd_dev *add_device(char *devname, int erase_size,
> -		int timeout)
> +		const char *mtdname, int timeout)
>  {
>  #ifndef MODULE
>  	int i;
> @@ -226,6 +227,7 @@ static struct block2mtd_dev *add_device(
>  	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
>  	struct block_device *bdev = ERR_PTR(-ENODEV);
>  	struct block2mtd_dev *dev;
> +	struct mtd_partition *part;
>  	char *name;
>  
>  	if (!devname)
> @@ -282,7 +284,9 @@ static struct block2mtd_dev *add_device(
>  
>  	/* Setup the MTD structure */
>  	/* make the name contain the block device in */
> -	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
> +	if (!mtdname)
> +		mtdname = devname;
> +	name = kstrdup(mtdname, GFP_KERNEL);
>  	if (!name)
>  		goto err_destroy_mutex;
>  
> @@ -301,7 +305,11 @@ static struct block2mtd_dev *add_device(
>  	dev->mtd.priv = dev;
>  	dev->mtd.owner = THIS_MODULE;
>  
> -	if (mtd_device_register(&dev->mtd, NULL, 0)) {
> +	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);

                       sizeof(*part)

> +	part->name = name;
> +	part->offset = 0;
> +	part->size = dev->mtd.size;
> +	if (mtd_device_register(&dev->mtd, part, 1)) {
>  		/* Device didn't get added, so free the entry */
>  		goto err_destroy_mutex;
>  	}
> @@ -309,8 +317,7 @@ static struct block2mtd_dev *add_device(
>  	list_add(&dev->list, &blkmtd_device_list);
>  	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
>  		dev->mtd.index,
> -		dev->mtd.name + strlen("block2mtd: "),
> -		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
> +		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
>  	return dev;
>  
>  err_destroy_mutex:
> @@ -383,7 +390,7 @@ static int block2mtd_setup2(const char *
>  	/* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
>  	char buf[80 + 12 + 80 + 8];
>  	char *str = buf;
> -	char *token[2];
> +	char *token[4];
>  	char *name;
>  	size_t erase_size = PAGE_SIZE;
>  	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
> @@ -397,7 +404,7 @@ static int block2mtd_setup2(const char *
>  	strcpy(str, val);
>  	kill_final_newline(str);
>  
> -	for (i = 0; i < 2; i++)
> +	for (i = 0; i < 4; i++)

Maybe use ARRAY_SIZE(token)?

>  		token[i] = strsep(&str, ",");
>  
>  	if (str) {
> @@ -424,7 +431,13 @@ static int block2mtd_setup2(const char *
>  		}
>  	}
>  
> -	add_device(name, erase_size, timeout);
> +	if (token[2] && (strlen(token[2]) + 1 > 80))
> +		pr_err("mtd device name too long");

Hmm, so it's too long, but you continue? Shouldn't we return here?

> +
> +
> +	if (token[3] && kstrtoul(token[3], 0, &timeout))
> +		pr_err("invalid timeout");

Again, shouldn't we return here? It's best not to just ignore invalid
input.

> +	add_device(name, erase_size, token[2], timeout);
>  
>  	return 0;
>  }
> @@ -458,7 +471,7 @@ static int block2mtd_setup(const char *v
>  
>  
>  module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
> -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
> +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
>  
>  static int __init block2mtd_init(void)
>  {

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
  2014-11-26 13:19                 ` Rodrigo Freire
@ 2015-02-24  8:07                   ` Brian Norris
  -1 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2015-02-24  8:07 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: linux-mtd, linux-kernel, Jörn Engel, Felix Fietkau, dwmw2,
	Herton Krzesinski

On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
> From: "Brian Norris" <computersforpeace@gmail.com>
> Sent: Wednesday, November 26, 2014 5:21:47 AM
> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
> partition size
> 
> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> > > PAGE_MASK is no longer needed with the new term.
> 
> > This isn't too descriptive. What you probably mean is that we assume the
> > erase size is always larger than PAGE_SIZE.
> 
> > > This patch keeps the device size aligned with the erase_size.
> > >
> > > Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> > > Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> > > Signed-off-by: Herton Krzesinski <herton@redhat.com>
> > > ---
> > > V3: Separated on a single patch
> > > --- a/drivers/mtd/devices/block2mtd.c 2014-11-07 17:40:58.688747820 -0200
> > > +++ b/drivers/mtd/devices/block2mtd.c 2014-11-07 17:41:28.054750893 -0200
> > > @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
> > > goto err_destroy_mutex;
> > >
> > > dev->mtd.name = name;
> > > -
> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
> 
> > You never guaranteed that erase_size is a power of two, so this doesn't
> > necessarily mask the way you'd like...
> 
> > But also, why is this even necessary? I see that we should already have
> > errored out if this was actually significant, since we have above:
> 
> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> > pr_err("erasesize must be a divisor of device size\n");
> > goto err_free_block2mtd;
> > }
> 
> Hello Brian, and thanks for the review.
> 
> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
> 
> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.

OK let's drop this patch from the series. At best, we could just do
something like this instead:

-	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
+	dev->mtd.size = dev->blkdev->bd_inode->i_size;

But that's really just an unnecessary change.

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
@ 2015-02-24  8:07                   ` Brian Norris
  0 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2015-02-24  8:07 UTC (permalink / raw)
  To: Rodrigo Freire
  Cc: Felix Fietkau, Jörn Engel, Herton Krzesinski, linux-kernel,
	linux-mtd, dwmw2

On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
> From: "Brian Norris" <computersforpeace@gmail.com>
> Sent: Wednesday, November 26, 2014 5:21:47 AM
> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
> partition size
> 
> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> > > PAGE_MASK is no longer needed with the new term.
> 
> > This isn't too descriptive. What you probably mean is that we assume the
> > erase size is always larger than PAGE_SIZE.
> 
> > > This patch keeps the device size aligned with the erase_size.
> > >
> > > Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> > > Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> > > Signed-off-by: Herton Krzesinski <herton@redhat.com>
> > > ---
> > > V3: Separated on a single patch
> > > --- a/drivers/mtd/devices/block2mtd.c 2014-11-07 17:40:58.688747820 -0200
> > > +++ b/drivers/mtd/devices/block2mtd.c 2014-11-07 17:41:28.054750893 -0200
> > > @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
> > > goto err_destroy_mutex;
> > >
> > > dev->mtd.name = name;
> > > -
> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
> 
> > You never guaranteed that erase_size is a power of two, so this doesn't
> > necessarily mask the way you'd like...
> 
> > But also, why is this even necessary? I see that we should already have
> > errored out if this was actually significant, since we have above:
> 
> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> > pr_err("erasesize must be a divisor of device size\n");
> > goto err_free_block2mtd;
> > }
> 
> Hello Brian, and thanks for the review.
> 
> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
> 
> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.

OK let's drop this patch from the series. At best, we could just do
something like this instead:

-	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
+	dev->mtd.size = dev->blkdev->bd_inode->i_size;

But that's really just an unnecessary change.

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
  2015-02-24  8:07                   ` Brian Norris
@ 2015-02-24  8:20                     ` Felix Fietkau
  -1 siblings, 0 replies; 63+ messages in thread
From: Felix Fietkau @ 2015-02-24  8:20 UTC (permalink / raw)
  To: Brian Norris, Rodrigo Freire
  Cc: linux-mtd, linux-kernel, Jörn Engel, dwmw2, Herton Krzesinski

On 2015-02-24 21:07, Brian Norris wrote:
> On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
>> From: "Brian Norris" <computersforpeace@gmail.com>
>> Sent: Wednesday, November 26, 2014 5:21:47 AM
>> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
>> partition size
>> 
>> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
>> > > PAGE_MASK is no longer needed with the new term.
>> 
>> > This isn't too descriptive. What you probably mean is that we assume the
>> > erase size is always larger than PAGE_SIZE.
>> 
>> > > This patch keeps the device size aligned with the erase_size.
>> > >
>> > > Signed-off-by: Felix Fietkau <nbd@openwrt.org>
>> > > Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
>> > > Signed-off-by: Herton Krzesinski <herton@redhat.com>
>> > > ---
>> > > V3: Separated on a single patch
>> > > --- a/drivers/mtd/devices/block2mtd.c 2014-11-07 17:40:58.688747820 -0200
>> > > +++ b/drivers/mtd/devices/block2mtd.c 2014-11-07 17:41:28.054750893 -0200
>> > > @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
>> > > goto err_destroy_mutex;
>> > >
>> > > dev->mtd.name = name;
>> > > -
>> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
>> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
>> 
>> > You never guaranteed that erase_size is a power of two, so this doesn't
>> > necessarily mask the way you'd like...
>> 
>> > But also, why is this even necessary? I see that we should already have
>> > errored out if this was actually significant, since we have above:
>> 
>> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
>> > pr_err("erasesize must be a divisor of device size\n");
>> > goto err_free_block2mtd;
>> > }
>> 
>> Hello Brian, and thanks for the review.
>> 
>> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
>> 
>> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.
> 
> OK let's drop this patch from the series. At best, we could just do
> something like this instead:
> 
> -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
> 
> But that's really just an unnecessary change.
If I remember correctly, it was problematic to have a dev->mtd.size
value which is not a multiple of the erase size. I think that was the
reason for patch 3.

- Felix

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
@ 2015-02-24  8:20                     ` Felix Fietkau
  0 siblings, 0 replies; 63+ messages in thread
From: Felix Fietkau @ 2015-02-24  8:20 UTC (permalink / raw)
  To: Brian Norris, Rodrigo Freire
  Cc: dwmw2, Jörn Engel, linux-mtd, linux-kernel, Herton Krzesinski

On 2015-02-24 21:07, Brian Norris wrote:
> On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
>> From: "Brian Norris" <computersforpeace@gmail.com>
>> Sent: Wednesday, November 26, 2014 5:21:47 AM
>> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
>> partition size
>> 
>> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
>> > > PAGE_MASK is no longer needed with the new term.
>> 
>> > This isn't too descriptive. What you probably mean is that we assume the
>> > erase size is always larger than PAGE_SIZE.
>> 
>> > > This patch keeps the device size aligned with the erase_size.
>> > >
>> > > Signed-off-by: Felix Fietkau <nbd@openwrt.org>
>> > > Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
>> > > Signed-off-by: Herton Krzesinski <herton@redhat.com>
>> > > ---
>> > > V3: Separated on a single patch
>> > > --- a/drivers/mtd/devices/block2mtd.c 2014-11-07 17:40:58.688747820 -0200
>> > > +++ b/drivers/mtd/devices/block2mtd.c 2014-11-07 17:41:28.054750893 -0200
>> > > @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
>> > > goto err_destroy_mutex;
>> > >
>> > > dev->mtd.name = name;
>> > > -
>> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
>> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
>> 
>> > You never guaranteed that erase_size is a power of two, so this doesn't
>> > necessarily mask the way you'd like...
>> 
>> > But also, why is this even necessary? I see that we should already have
>> > errored out if this was actually significant, since we have above:
>> 
>> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
>> > pr_err("erasesize must be a divisor of device size\n");
>> > goto err_free_block2mtd;
>> > }
>> 
>> Hello Brian, and thanks for the review.
>> 
>> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
>> 
>> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.
> 
> OK let's drop this patch from the series. At best, we could just do
> something like this instead:
> 
> -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
> 
> But that's really just an unnecessary change.
If I remember correctly, it was problematic to have a dev->mtd.size
value which is not a multiple of the erase size. I think that was the
reason for patch 3.

- Felix

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
  2015-02-24  8:20                     ` Felix Fietkau
@ 2015-02-24  8:27                       ` Brian Norris
  -1 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2015-02-24  8:27 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Rodrigo Freire, linux-mtd, linux-kernel, Jörn Engel, dwmw2,
	Herton Krzesinski

On Tue, Feb 24, 2015 at 09:20:31PM +1300, Felix Fietkau wrote:
> On 2015-02-24 21:07, Brian Norris wrote:
> > On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
> >> From: "Brian Norris" <computersforpeace@gmail.com>
> >> Sent: Wednesday, November 26, 2014 5:21:47 AM
> >> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
> >> partition size
> >> 
> >> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> >> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> >> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
> >> 
> >> > You never guaranteed that erase_size is a power of two, so this doesn't
> >> > necessarily mask the way you'd like...
> >> 
> >> > But also, why is this even necessary? I see that we should already have
> >> > errored out if this was actually significant, since we have above:
> >> 
> >> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> >> > pr_err("erasesize must be a divisor of device size\n");
> >> > goto err_free_block2mtd;
> >> > }
> >> 
> >> Hello Brian, and thanks for the review.
> >> 
> >> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
> >> 
> >> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.
> > 
> > OK let's drop this patch from the series. At best, we could just do
> > something like this instead:
> > 
> > -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
> > 
> > But that's really just an unnecessary change.
> If I remember correctly, it was problematic to have a dev->mtd.size
> value which is not a multiple of the erase size. I think that was the
> reason for patch 3.

The what's this for?

	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
		pr_err("erasesize must be a divisor of device size\n");
		goto err_free_block2mtd;
	}

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
@ 2015-02-24  8:27                       ` Brian Norris
  0 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2015-02-24  8:27 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Jörn Engel, Herton Krzesinski, linux-kernel, linux-mtd,
	Rodrigo Freire, dwmw2

On Tue, Feb 24, 2015 at 09:20:31PM +1300, Felix Fietkau wrote:
> On 2015-02-24 21:07, Brian Norris wrote:
> > On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
> >> From: "Brian Norris" <computersforpeace@gmail.com>
> >> Sent: Wednesday, November 26, 2014 5:21:47 AM
> >> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
> >> partition size
> >> 
> >> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> >> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> >> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
> >> 
> >> > You never guaranteed that erase_size is a power of two, so this doesn't
> >> > necessarily mask the way you'd like...
> >> 
> >> > But also, why is this even necessary? I see that we should already have
> >> > errored out if this was actually significant, since we have above:
> >> 
> >> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> >> > pr_err("erasesize must be a divisor of device size\n");
> >> > goto err_free_block2mtd;
> >> > }
> >> 
> >> Hello Brian, and thanks for the review.
> >> 
> >> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
> >> 
> >> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.
> > 
> > OK let's drop this patch from the series. At best, we could just do
> > something like this instead:
> > 
> > -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
> > 
> > But that's really just an unnecessary change.
> If I remember correctly, it was problematic to have a dev->mtd.size
> value which is not a multiple of the erase size. I think that was the
> reason for patch 3.

The what's this for?

	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
		pr_err("erasesize must be a divisor of device size\n");
		goto err_free_block2mtd;
	}

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
  2015-02-24  8:27                       ` Brian Norris
@ 2015-02-24  8:30                         ` Felix Fietkau
  -1 siblings, 0 replies; 63+ messages in thread
From: Felix Fietkau @ 2015-02-24  8:30 UTC (permalink / raw)
  To: Brian Norris
  Cc: Rodrigo Freire, linux-mtd, linux-kernel, Jörn Engel, dwmw2,
	Herton Krzesinski

On 2015-02-24 21:27, Brian Norris wrote:
> On Tue, Feb 24, 2015 at 09:20:31PM +1300, Felix Fietkau wrote:
>> On 2015-02-24 21:07, Brian Norris wrote:
>> > On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
>> >> From: "Brian Norris" <computersforpeace@gmail.com>
>> >> Sent: Wednesday, November 26, 2014 5:21:47 AM
>> >> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
>> >> partition size
>> >> 
>> >> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
>> >> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
>> >> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
>> >> 
>> >> > You never guaranteed that erase_size is a power of two, so this doesn't
>> >> > necessarily mask the way you'd like...
>> >> 
>> >> > But also, why is this even necessary? I see that we should already have
>> >> > errored out if this was actually significant, since we have above:
>> >> 
>> >> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
>> >> > pr_err("erasesize must be a divisor of device size\n");
>> >> > goto err_free_block2mtd;
>> >> > }
>> >> 
>> >> Hello Brian, and thanks for the review.
>> >> 
>> >> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
>> >> 
>> >> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.
>> > 
>> > OK let's drop this patch from the series. At best, we could just do
>> > something like this instead:
>> > 
>> > -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
>> > +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
>> > 
>> > But that's really just an unnecessary change.
>> If I remember correctly, it was problematic to have a dev->mtd.size
>> value which is not a multiple of the erase size. I think that was the
>> reason for patch 3.
> 
> The what's this for?
> 
> 	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> 		pr_err("erasesize must be a divisor of device size\n");
> 		goto err_free_block2mtd;
> 	}
I think we should just trim the mtd size to a multiple of erase size and
remove this check. It is a bit impractical for many cases.

- Felix

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
@ 2015-02-24  8:30                         ` Felix Fietkau
  0 siblings, 0 replies; 63+ messages in thread
From: Felix Fietkau @ 2015-02-24  8:30 UTC (permalink / raw)
  To: Brian Norris
  Cc: Jörn Engel, Herton Krzesinski, linux-kernel, linux-mtd,
	Rodrigo Freire, dwmw2

On 2015-02-24 21:27, Brian Norris wrote:
> On Tue, Feb 24, 2015 at 09:20:31PM +1300, Felix Fietkau wrote:
>> On 2015-02-24 21:07, Brian Norris wrote:
>> > On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
>> >> From: "Brian Norris" <computersforpeace@gmail.com>
>> >> Sent: Wednesday, November 26, 2014 5:21:47 AM
>> >> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
>> >> partition size
>> >> 
>> >> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
>> >> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
>> >> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
>> >> 
>> >> > You never guaranteed that erase_size is a power of two, so this doesn't
>> >> > necessarily mask the way you'd like...
>> >> 
>> >> > But also, why is this even necessary? I see that we should already have
>> >> > errored out if this was actually significant, since we have above:
>> >> 
>> >> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
>> >> > pr_err("erasesize must be a divisor of device size\n");
>> >> > goto err_free_block2mtd;
>> >> > }
>> >> 
>> >> Hello Brian, and thanks for the review.
>> >> 
>> >> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
>> >> 
>> >> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.
>> > 
>> > OK let's drop this patch from the series. At best, we could just do
>> > something like this instead:
>> > 
>> > -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
>> > +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
>> > 
>> > But that's really just an unnecessary change.
>> If I remember correctly, it was problematic to have a dev->mtd.size
>> value which is not a multiple of the erase size. I think that was the
>> reason for patch 3.
> 
> The what's this for?
> 
> 	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> 		pr_err("erasesize must be a divisor of device size\n");
> 		goto err_free_block2mtd;
> 	}
I think we should just trim the mtd size to a multiple of erase size and
remove this check. It is a bit impractical for many cases.

- Felix

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
  2015-02-24  8:30                         ` Felix Fietkau
@ 2015-02-24  8:40                           ` Brian Norris
  -1 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2015-02-24  8:40 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Rodrigo Freire, linux-mtd, linux-kernel, Jörn Engel, dwmw2,
	Herton Krzesinski

On Tue, Feb 24, 2015 at 09:30:21PM +1300, Felix Fietkau wrote:
> On 2015-02-24 21:27, Brian Norris wrote:
> > On Tue, Feb 24, 2015 at 09:20:31PM +1300, Felix Fietkau wrote:
> >> On 2015-02-24 21:07, Brian Norris wrote:
> >> > OK let's drop this patch from the series. At best, we could just do
> >> > something like this instead:
> >> > 
> >> > -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> >> > +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
> >> > 
> >> > But that's really just an unnecessary change.
> >> If I remember correctly, it was problematic to have a dev->mtd.size
> >> value which is not a multiple of the erase size. I think that was the
> >> reason for patch 3.
> > 
> > The what's this for?
> > 
> > 	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> > 		pr_err("erasesize must be a divisor of device size\n");
> > 		goto err_free_block2mtd;
> > 	}
> I think we should just trim the mtd size to a multiple of erase size and
> remove this check. It is a bit impractical for many cases.

Well that's not the subject of anything in this series, and this patch
does not stand alone well, so I'm not taking it. Feel free to send a
different patch if you have good reason to.

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size
@ 2015-02-24  8:40                           ` Brian Norris
  0 siblings, 0 replies; 63+ messages in thread
From: Brian Norris @ 2015-02-24  8:40 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Jörn Engel, Herton Krzesinski, linux-kernel, linux-mtd,
	Rodrigo Freire, dwmw2

On Tue, Feb 24, 2015 at 09:30:21PM +1300, Felix Fietkau wrote:
> On 2015-02-24 21:27, Brian Norris wrote:
> > On Tue, Feb 24, 2015 at 09:20:31PM +1300, Felix Fietkau wrote:
> >> On 2015-02-24 21:07, Brian Norris wrote:
> >> > OK let's drop this patch from the series. At best, we could just do
> >> > something like this instead:
> >> > 
> >> > -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> >> > +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
> >> > 
> >> > But that's really just an unnecessary change.
> >> If I remember correctly, it was problematic to have a dev->mtd.size
> >> value which is not a multiple of the erase size. I think that was the
> >> reason for patch 3.
> > 
> > The what's this for?
> > 
> > 	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> > 		pr_err("erasesize must be a divisor of device size\n");
> > 		goto err_free_block2mtd;
> > 	}
> I think we should just trim the mtd size to a multiple of erase size and
> remove this check. It is a bit impractical for many cases.

Well that's not the subject of anything in this series, and this patch
does not stand alone well, so I'm not taking it. Feel free to send a
different patch if you have good reason to.

Brian

^ permalink raw reply	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2015-02-24  8:41 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <371358190.34795877.1410204429882.JavaMail.zimbra@redhat.com>
2014-09-08 20:04 ` [PATCH] block2mtd: mtd: Present block2mtd timely on boot time Rodrigo Freire
2014-09-09 17:02   ` Jörn Engel
2014-09-09 17:02     ` Jörn Engel
2014-09-17 20:18     ` Rodrigo Freire
2014-09-17 20:18       ` Rodrigo Freire
2014-09-17 20:28     ` [PATCH V2] mtd: block2mtd: " Rodrigo Freire
2014-09-17 20:28       ` Rodrigo Freire
2014-09-17 21:21       ` Ezequiel Garcia
2014-09-17 21:21         ` Ezequiel Garcia
2014-09-17 21:41         ` Rodrigo Freire
2014-09-17 21:41           ` Rodrigo Freire
2014-10-09 15:07       ` [RESEND PATCH " Rodrigo Freire
2014-10-09 15:07         ` Rodrigo Freire
2014-11-01 13:33         ` Rodrigo Freire
2014-11-01 13:33           ` Rodrigo Freire
2014-11-07  9:44           ` Artem Bityutskiy
2014-11-07  9:44             ` Artem Bityutskiy
2014-11-07 20:05             ` Brian Norris
2014-11-07 20:05               ` Brian Norris
2014-11-05 20:01         ` Brian Norris
2014-11-05 20:01           ` Brian Norris
2014-11-05 20:23       ` [PATCH " Brian Norris
2014-11-05 20:23         ` Brian Norris
2014-11-07 14:59         ` Artem Bityutskiy
2014-11-07 14:59           ` Artem Bityutskiy
2014-11-07 15:20           ` Felix Fietkau
2014-11-07 15:20             ` Felix Fietkau
2014-11-07 15:30             ` Artem Bityutskiy
2014-11-07 15:30               ` Artem Bityutskiy
2014-11-09 12:18         ` Rodrigo Freire
2014-11-09 12:18           ` Rodrigo Freire
2014-11-26  3:33           ` Brian Norris
2014-11-26  3:33             ` Brian Norris
2014-11-26 13:32             ` Rodrigo Freire
2014-11-26 13:32               ` Rodrigo Freire
2015-02-11 15:09               ` Rodrigo Freire
2015-02-11 15:09                 ` Rodrigo Freire
2014-11-09 12:18         ` [PATCH v3 0/3] mtd: block2mtd: wait for device enumeration, add name support Rodrigo Freire
2014-11-09 12:18           ` Rodrigo Freire
2014-11-09 12:21           ` [PATCH v3 1/3] mtd: block2mtd: Ensure that block2mtd is triggered after block devices are presented Rodrigo Freire
2014-11-09 12:21             ` Rodrigo Freire
2015-02-24  7:45             ` Brian Norris
2015-02-24  7:45               ` Brian Norris
2014-11-09 12:22           ` [PATCH v3 2/3] mtd: block2mtd: Adds a mtd name and a block device timeout option Rodrigo Freire
2014-11-09 12:22             ` Rodrigo Freire
2015-02-24  8:05             ` Brian Norris
2015-02-24  8:05               ` Brian Norris
2014-11-09 12:23           ` [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size Rodrigo Freire
2014-11-09 12:23             ` Rodrigo Freire
2014-11-26  7:21             ` Brian Norris
2014-11-26  7:21               ` Brian Norris
2014-11-26 13:19               ` Rodrigo Freire
2014-11-26 13:19                 ` Rodrigo Freire
2015-02-24  8:07                 ` Brian Norris
2015-02-24  8:07                   ` Brian Norris
2015-02-24  8:20                   ` Felix Fietkau
2015-02-24  8:20                     ` Felix Fietkau
2015-02-24  8:27                     ` Brian Norris
2015-02-24  8:27                       ` Brian Norris
2015-02-24  8:30                       ` Felix Fietkau
2015-02-24  8:30                         ` Felix Fietkau
2015-02-24  8:40                         ` Brian Norris
2015-02-24  8:40                           ` Brian Norris

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.