linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: support mtd:<name> syntax for block devices
@ 2025-05-16  6:51 Joakim Tjernlund
  2025-05-16  7:14 ` Christoph Hellwig
  0 siblings, 1 reply; 14+ messages in thread
From: Joakim Tjernlund @ 2025-05-16  6:51 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Joakim Tjernlund

This is the same name scheme JFFS2 and UBI uses.

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
---
 fs/super.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/fs/super.c b/fs/super.c
index 97a17f9d9023..e603236b3ad8 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -37,6 +37,7 @@
 #include <linux/user_namespace.h>
 #include <linux/fs_context.h>
 #include <uapi/linux/mount.h>
+#include <linux/mtd/mtd.h>
 #include "internal.h"
 
 static int thaw_super_locked(struct super_block *sb, enum freeze_holder who);
@@ -1612,6 +1613,26 @@ int get_tree_bdev_flags(struct fs_context *fc,
 	if (!fc->source)
 		return invalf(fc, "No source specified");
 
+#ifdef CONFIG_MTD_BLOCK
+	if (!strncmp(fc->source, "mtd:", 4)) {
+		struct mtd_info *mtd;
+		char *blk_source;
+
+		/* mount by MTD device name */
+		pr_debug("Block SB: name \"%s\"\n", fc->source);
+
+		mtd = get_mtd_device_nm(fc->source + 4);
+		if (IS_ERR(mtd))
+			return -EINVAL;
+		blk_source = kmalloc(20, GFP_KERNEL);
+		if (!blk_source)
+			return -ENOMEM;
+		sprintf(blk_source, "/dev/mtdblock%d", mtd->index);
+		kfree(fc->source);
+		fc->source = blk_source;
+		pr_debug("MTD device:%s found\n", fc->source);
+	}
+#endif
 	error = lookup_bdev(fc->source, &dev);
 	if (error) {
 		if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))
-- 
2.49.0


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

* Re: [PATCH] block: support mtd:<name> syntax for block devices
  2025-05-16  6:51 [PATCH] block: support mtd:<name> syntax for block devices Joakim Tjernlund
@ 2025-05-16  7:14 ` Christoph Hellwig
  2025-05-16  7:37   ` Joakim Tjernlund (Nokia)
  0 siblings, 1 reply; 14+ messages in thread
From: Christoph Hellwig @ 2025-05-16  7:14 UTC (permalink / raw)
  To: Joakim Tjernlund; +Cc: linux-fsdevel

On Fri, May 16, 2025 at 08:51:56AM +0200, Joakim Tjernlund wrote:
> This is the same name scheme JFFS2 and UBI uses.

Great to know, but compltely fails to explain what you are doing
here given that this is a block device mount helper used by file
systems using block and not mtd devices and thus the only obvious
effect would be to crash the mount if actually used.


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

* Re: [PATCH] block: support mtd:<name> syntax for block devices
  2025-05-16  7:14 ` Christoph Hellwig
@ 2025-05-16  7:37   ` Joakim Tjernlund (Nokia)
  2025-05-16  7:47     ` [PATCH v2] " Joakim Tjernlund
  0 siblings, 1 reply; 14+ messages in thread
From: Joakim Tjernlund (Nokia) @ 2025-05-16  7:37 UTC (permalink / raw)
  To: Christoph Hellwig, Joakim Tjernlund; +Cc: linux-fsdevel@vger.kernel.org

On Fri, 2025-05-16 at 00:14 -0700, Christoph Hellwig wrote:
> [You don't often get email from hch@infradead.org. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> CAUTION: This is an external email. Please be very careful when clicking links or opening attachments. See the URL nok.it/ext for additional information.
> 
> 
> 
> On Fri, May 16, 2025 at 08:51:56AM +0200, Joakim Tjernlund wrote:
> > This is the same name scheme JFFS2 and UBI uses.
> 
> Great to know, but compltely fails to explain what you are doing
> here given that this is a block device mount helper used by file
> systems using block and not mtd devices and thus the only obvious
> effect would be to crash the mount if actually used.

Right, was very brief

This enables mounts like so:

   mount -t squashfs mtd:appfs /tmp

where mtd:appfs comes from:

 # >  cat /proc/mtd 
dev:    size   erasesize  name
...
mtd22: 00750000 00010000 "appfs"

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

* [PATCH v2] block: support mtd:<name> syntax for block devices
  2025-05-16  7:37   ` Joakim Tjernlund (Nokia)
@ 2025-05-16  7:47     ` Joakim Tjernlund
  2025-05-19  8:12       ` Johannes Thumshirn
  0 siblings, 1 reply; 14+ messages in thread
From: Joakim Tjernlund @ 2025-05-16  7:47 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Joakim Tjernlund

This enables mounting, like JFFS2, MTD devices by "label":
   mount -t squashfs mtd:appfs /tmp
where mtd:appfs comes from:
 # >  cat /proc/mtd
dev:    size   erasesize  name
...
mtd22: 00750000 00010000 "appfs"

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
---
 fs/super.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/fs/super.c b/fs/super.c
index 97a17f9d9023..e603236b3ad8 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -37,6 +37,7 @@
 #include <linux/user_namespace.h>
 #include <linux/fs_context.h>
 #include <uapi/linux/mount.h>
+#include <linux/mtd/mtd.h>
 #include "internal.h"
 
 static int thaw_super_locked(struct super_block *sb, enum freeze_holder who);
@@ -1612,6 +1613,26 @@ int get_tree_bdev_flags(struct fs_context *fc,
 	if (!fc->source)
 		return invalf(fc, "No source specified");
 
+#ifdef CONFIG_MTD_BLOCK
+	if (!strncmp(fc->source, "mtd:", 4)) {
+		struct mtd_info *mtd;
+		char *blk_source;
+
+		/* mount by MTD device name */
+		pr_debug("Block SB: name \"%s\"\n", fc->source);
+
+		mtd = get_mtd_device_nm(fc->source + 4);
+		if (IS_ERR(mtd))
+			return -EINVAL;
+		blk_source = kmalloc(20, GFP_KERNEL);
+		if (!blk_source)
+			return -ENOMEM;
+		sprintf(blk_source, "/dev/mtdblock%d", mtd->index);
+		kfree(fc->source);
+		fc->source = blk_source;
+		pr_debug("MTD device:%s found\n", fc->source);
+	}
+#endif
 	error = lookup_bdev(fc->source, &dev);
 	if (error) {
 		if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))
-- 
2.49.0


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

* Re: [PATCH v2] block: support mtd:<name> syntax for block devices
  2025-05-16  7:47     ` [PATCH v2] " Joakim Tjernlund
@ 2025-05-19  8:12       ` Johannes Thumshirn
  2025-05-19 13:11         ` [PATCH v3] " Joakim Tjernlund
  0 siblings, 1 reply; 14+ messages in thread
From: Johannes Thumshirn @ 2025-05-19  8:12 UTC (permalink / raw)
  To: Joakim Tjernlund, linux-fsdevel@vger.kernel.org

On 16.05.25 09:50, Joakim Tjernlund wrote:
> +#ifdef CONFIG_MTD_BLOCK
> +	if (!strncmp(fc->source, "mtd:", 4)) {
> +		struct mtd_info *mtd;
> +		char *blk_source;
> +
> +		/* mount by MTD device name */
> +		pr_debug("Block SB: name \"%s\"\n", fc->source);
> +
> +		mtd = get_mtd_device_nm(fc->source + 4);
> +		if (IS_ERR(mtd))
> +			return -EINVAL;
> +		blk_source = kmalloc(20, GFP_KERNEL);
> +		if (!blk_source)
> +			return -ENOMEM;
> +		sprintf(blk_source, "/dev/mtdblock%d", mtd->index);
> +		kfree(fc->source);
> +		fc->source = blk_source;
> +		pr_debug("MTD device:%s found\n", fc->source);
> +	}
> +#endif
>   	error = lookup_bdev(fc->source, &dev);
>   	if (error) {
>   		if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))

Can you please at least encapsulate the check in a function, so it 
doesn't look that much like a layering violation? That way we don't need 
the #ifdef in get_tree_bdev_flags() as well (and can save a layer of 
indentation).

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

* [PATCH v3] block: support mtd:<name> syntax for block devices
  2025-05-19  8:12       ` Johannes Thumshirn
@ 2025-05-19 13:11         ` Joakim Tjernlund
  2025-05-19 14:37           ` Johannes Thumshirn
  0 siblings, 1 reply; 14+ messages in thread
From: Joakim Tjernlund @ 2025-05-19 13:11 UTC (permalink / raw)
  To: linux-fsdevel, Johannes.Thumshirn; +Cc: Joakim Tjernlund

This enables mounting, like JFFS2, MTD devices by "label":
   mount -t squashfs mtd:appfs /tmp
where mtd:appfs comes from:
 # >  cat /proc/mtd
dev:    size   erasesize  name
...
mtd22: 00750000 00010000 "appfs"

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
---
 fs/super.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/fs/super.c b/fs/super.c
index 97a17f9d9023..8c3aa2f05b42 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -37,6 +37,7 @@
 #include <linux/user_namespace.h>
 #include <linux/fs_context.h>
 #include <uapi/linux/mount.h>
+#include <linux/mtd/mtd.h>
 #include "internal.h"
 
 static int thaw_super_locked(struct super_block *sb, enum freeze_holder who);
@@ -1595,6 +1596,30 @@ int setup_bdev_super(struct super_block *sb, int sb_flags,
 }
 EXPORT_SYMBOL_GPL(setup_bdev_super);
 
+void translate_mtd_name(void)
+{
+#ifdef CONFIG_MTD_BLOCK
+	if (!strncmp(fc->source, "mtd:", 4)) {
+		struct mtd_info *mtd;
+		char *blk_source;
+
+		/* mount by MTD device name */
+		pr_debug("Block SB: name \"%s\"\n", fc->source);
+
+		mtd = get_mtd_device_nm(fc->source + 4);
+		if (IS_ERR(mtd))
+			return -EINVAL;
+		blk_source = kmalloc(20, GFP_KERNEL);
+		if (!blk_source)
+			return -ENOMEM;
+		sprintf(blk_source, "/dev/mtdblock%d", mtd->index);
+		kfree(fc->source);
+		fc->source = blk_source;
+		pr_debug("MTD device:%s found\n", fc->source);
+	}
+#endif
+}
+
 /**
  * get_tree_bdev_flags - Get a superblock based on a single block device
  * @fc: The filesystem context holding the parameters
@@ -1612,6 +1637,7 @@ int get_tree_bdev_flags(struct fs_context *fc,
 	if (!fc->source)
 		return invalf(fc, "No source specified");
 
+	translate_mtd_name();
 	error = lookup_bdev(fc->source, &dev);
 	if (error) {
 		if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))
-- 
2.49.0


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

* Re: [PATCH v3] block: support mtd:<name> syntax for block devices
  2025-05-19 13:11         ` [PATCH v3] " Joakim Tjernlund
@ 2025-05-19 14:37           ` Johannes Thumshirn
  2025-05-19 14:39             ` Joakim Tjernlund (Nokia)
  2025-05-19 15:03             ` [PATCH v4] " Joakim Tjernlund
  0 siblings, 2 replies; 14+ messages in thread
From: Johannes Thumshirn @ 2025-05-19 14:37 UTC (permalink / raw)
  To: Joakim Tjernlund, linux-fsdevel@vger.kernel.org

On 19.05.25 15:12, Joakim Tjernlund wrote:
> This enables mounting, like JFFS2, MTD devices by "label":
>     mount -t squashfs mtd:appfs /tmp
> where mtd:appfs comes from:
>   # >  cat /proc/mtd
> dev:    size   erasesize  name
> ...
> mtd22: 00750000 00010000 "appfs"
> 
> Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> ---
>   fs/super.c | 26 ++++++++++++++++++++++++++
>   1 file changed, 26 insertions(+)
> 
> diff --git a/fs/super.c b/fs/super.c
> index 97a17f9d9023..8c3aa2f05b42 100644
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -37,6 +37,7 @@
>   #include <linux/user_namespace.h>
>   #include <linux/fs_context.h>
>   #include <uapi/linux/mount.h>
> +#include <linux/mtd/mtd.h>
>   #include "internal.h"
>   
>   static int thaw_super_locked(struct super_block *sb, enum freeze_holder who);
> @@ -1595,6 +1596,30 @@ int setup_bdev_super(struct super_block *sb, int sb_flags,
>   }
>   EXPORT_SYMBOL_GPL(setup_bdev_super);
>   
> +void translate_mtd_name(void)

How can that work doesn't it need the fs_context?

> +{
> +#ifdef CONFIG_MTD_BLOCK
> +	if (!strncmp(fc->source, "mtd:", 4)) {
> +		struct mtd_info *mtd;
> +		char *blk_source;
> +
> +		/* mount by MTD device name */
> +		pr_debug("Block SB: name \"%s\"\n", fc->source);
> +
> +		mtd = get_mtd_device_nm(fc->source + 4);
> +		if (IS_ERR(mtd))
> +			return -EINVAL;
> +		blk_source = kmalloc(20, GFP_KERNEL);
> +		if (!blk_source)
> +			return -ENOMEM;
> +		sprintf(blk_source, "/dev/mtdblock%d", mtd->index);
> +		kfree(fc->source);
> +		fc->source = blk_source;
> +		pr_debug("MTD device:%s found\n", fc->source);
> +	}
> +#endif
> +}
> +
>   /**
>    * get_tree_bdev_flags - Get a superblock based on a single block device
>    * @fc: The filesystem context holding the parameters
> @@ -1612,6 +1637,7 @@ int get_tree_bdev_flags(struct fs_context *fc,
>   	if (!fc->source)
>   		return invalf(fc, "No source specified");
>   
> +	translate_mtd_name();
>   	error = lookup_bdev(fc->source, &dev);
>   	if (error) {
>   		if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))


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

* Re: [PATCH v3] block: support mtd:<name> syntax for block devices
  2025-05-19 14:37           ` Johannes Thumshirn
@ 2025-05-19 14:39             ` Joakim Tjernlund (Nokia)
  2025-05-19 15:03             ` [PATCH v4] " Joakim Tjernlund
  1 sibling, 0 replies; 14+ messages in thread
From: Joakim Tjernlund (Nokia) @ 2025-05-19 14:39 UTC (permalink / raw)
  To: Johannes Thumshirn, Joakim Tjernlund,
	linux-fsdevel@vger.kernel.org

On Mon, 2025-05-19 at 14:37 +0000, Johannes Thumshirn wrote:
> [You don't often get email from johannes.thumshirn@wdc.com. Learn why this is important at
> https://aka.ms/LearnAboutSenderIdentification ]
> 
> On 19.05.25 15:12, Joakim Tjernlund wrote:
> > This enables mounting, like JFFS2, MTD devices by "label":
> >     mount -t squashfs mtd:appfs /tmp
> > where mtd:appfs comes from:
> >   # >  cat /proc/mtd
> > dev:    size   erasesize  name
> > ...
> > mtd22: 00750000 00010000 "appfs"
> > 
> > Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> > ---
> >   fs/super.c | 26 ++++++++++++++++++++++++++
> >   1 file changed, 26 insertions(+)
> > 
> > diff --git a/fs/super.c b/fs/super.c
> > index 97a17f9d9023..8c3aa2f05b42 100644
> > --- a/fs/super.c
> > +++ b/fs/super.c
> > @@ -37,6 +37,7 @@
> >   #include <linux/user_namespace.h>
> >   #include <linux/fs_context.h>
> >   #include <uapi/linux/mount.h>
> > +#include <linux/mtd/mtd.h>
> >   #include "internal.h"
> > 
> >   static int thaw_super_locked(struct super_block *sb, enum freeze_holder who);
> > @@ -1595,6 +1596,30 @@ int setup_bdev_super(struct super_block *sb, int sb_flags,
> >   }
> >   EXPORT_SYMBOL_GPL(setup_bdev_super);
> > 
> > +void translate_mtd_name(void)
> 
> How can that work doesn't it need the fs_context?

Dooh ...

> 
> > +{
> > +#ifdef CONFIG_MTD_BLOCK
> > +     if (!strncmp(fc->source, "mtd:", 4)) {
> > +             struct mtd_info *mtd;
> > +             char *blk_source;
> > +
> > +             /* mount by MTD device name */
> > +             pr_debug("Block SB: name \"%s\"\n", fc->source);
> > +
> > +             mtd = get_mtd_device_nm(fc->source + 4);
> > +             if (IS_ERR(mtd))
> > +                     return -EINVAL;
> > +             blk_source = kmalloc(20, GFP_KERNEL);
> > +             if (!blk_source)
> > +                     return -ENOMEM;
> > +             sprintf(blk_source, "/dev/mtdblock%d", mtd->index);
> > +             kfree(fc->source);
> > +             fc->source = blk_source;
> > +             pr_debug("MTD device:%s found\n", fc->source);
> > +     }
> > +#endif
> > +}
> > +
> >   /**
> >    * get_tree_bdev_flags - Get a superblock based on a single block device
> >    * @fc: The filesystem context holding the parameters
> > @@ -1612,6 +1637,7 @@ int get_tree_bdev_flags(struct fs_context *fc,
> >       if (!fc->source)
> >               return invalf(fc, "No source specified");
> > 
> > +     translate_mtd_name();
> >       error = lookup_bdev(fc->source, &dev);
> >       if (error) {
> >               if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))

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

* [PATCH v4] block: support mtd:<name> syntax for block devices
  2025-05-19 14:37           ` Johannes Thumshirn
  2025-05-19 14:39             ` Joakim Tjernlund (Nokia)
@ 2025-05-19 15:03             ` Joakim Tjernlund
  2025-05-27 15:10               ` [PATCH v5] " Joakim Tjernlund
  2025-05-27 15:12               ` [PATCH v4] " Joakim Tjernlund (Nokia)
  1 sibling, 2 replies; 14+ messages in thread
From: Joakim Tjernlund @ 2025-05-19 15:03 UTC (permalink / raw)
  To: linux-fsdevel, Johannes.Thumshirn; +Cc: Joakim Tjernlund

This enables mounting, like JFFS2, MTD devices by "label":
   mount -t squashfs mtd:appfs /tmp
where mtd:appfs comes from:
 # >  cat /proc/mtd
dev:    size   erasesize  name
...
mtd22: 00750000 00010000 "appfs"

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
---
 fs/super.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/fs/super.c b/fs/super.c
index 97a17f9d9023..df7a6cfa34d3 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -37,6 +37,7 @@
 #include <linux/user_namespace.h>
 #include <linux/fs_context.h>
 #include <uapi/linux/mount.h>
+#include <linux/mtd/mtd.h>
 #include "internal.h"
 
 static int thaw_super_locked(struct super_block *sb, enum freeze_holder who);
@@ -1595,6 +1596,32 @@ int setup_bdev_super(struct super_block *sb, int sb_flags,
 }
 EXPORT_SYMBOL_GPL(setup_bdev_super);
 
+static int translate_mtd_name(struct fs_context *fc)
+{
+#ifdef CONFIG_MTD_BLOCK
+	if (!strncmp(fc->source, "mtd:", 4)) {
+		struct mtd_info *mtd;
+		char *blk_source;
+
+		/* mount by MTD device name */
+		pr_debug("Block SB: name \"%s\"\n", fc->source);
+
+		mtd = get_mtd_device_nm(fc->source + 4);
+		if (IS_ERR(mtd))
+			return -EINVAL;
+		blk_source = kmalloc(20, GFP_KERNEL);
+		if (!blk_source)
+			return -ENOMEM;
+		sprintf(blk_source, "/dev/mtdblock%d", mtd->index);
+		kfree(fc->source);
+		fc->source = blk_source;
+		pr_debug("MTD device:%s found\n", fc->source);
+		return 0;
+	}
+#endif
+	return 0;
+}
+
 /**
  * get_tree_bdev_flags - Get a superblock based on a single block device
  * @fc: The filesystem context holding the parameters
@@ -1612,6 +1639,9 @@ int get_tree_bdev_flags(struct fs_context *fc,
 	if (!fc->source)
 		return invalf(fc, "No source specified");
 
+	error = translate_mtd_name(fc);
+	if (error)
+		return error;
 	error = lookup_bdev(fc->source, &dev);
 	if (error) {
 		if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))
-- 
2.49.0


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

* [PATCH v5] block: support mtd:<name> syntax for block devices
  2025-05-19 15:03             ` [PATCH v4] " Joakim Tjernlund
@ 2025-05-27 15:10               ` Joakim Tjernlund
  2025-05-28 13:09                 ` kernel test robot
  2025-05-27 15:12               ` [PATCH v4] " Joakim Tjernlund (Nokia)
  1 sibling, 1 reply; 14+ messages in thread
From: Joakim Tjernlund @ 2025-05-27 15:10 UTC (permalink / raw)
  To: linux-fsdevel, Johannes.Thumshirn; +Cc: Joakim Tjernlund

This enables mounting, like JFFS2, MTD devices by "label":
   mount -t squashfs mtd:appfs /tmp
and cmdline argument:
   root=mtd:rootfs

where mtd:appfs comes from:
 # >  cat /proc/mtd
dev:    size   erasesize  name
 ...
mtd22: 00750000 00010000 "appfs"

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
---
 block/bdev.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/block/bdev.c b/block/bdev.c
index 889ec6e002d7..f276b088eca8 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/blkpg.h>
 #include <linux/magic.h>
+#include <linux/mtd/mtd.h>
 #include <linux/buffer_head.h>
 #include <linux/swap.h>
 #include <linux/writeback.h>
@@ -1075,9 +1076,23 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
 	dev_t dev;
 	int error;
 
-	error = lookup_bdev(path, &dev);
-	if (error)
-		return ERR_PTR(error);
+#ifdef CONFIG_MTD_BLOCK
+       if (!strncmp(path, "mtd:", 4)) {
+               struct mtd_info *mtd;
+
+               /* mount by MTD device name */
+               pr_debug("path name \"%s\"\n", path);
+               mtd = get_mtd_device_nm(path + 4);
+               if (IS_ERR(mtd))
+                       return ERR_PTR(-EINVAL);
+               dev = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
+       } else
+#endif
+       {
+	       error = lookup_bdev(path, &dev);
+	       if (error)
+		       return ERR_PTR(error);
+       }
 
 	file = bdev_file_open_by_dev(dev, mode, holder, hops);
 	if (!IS_ERR(file) && (mode & BLK_OPEN_WRITE)) {
-- 
2.49.0


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

* Re: [PATCH v4] block: support mtd:<name> syntax for block devices
  2025-05-19 15:03             ` [PATCH v4] " Joakim Tjernlund
  2025-05-27 15:10               ` [PATCH v5] " Joakim Tjernlund
@ 2025-05-27 15:12               ` Joakim Tjernlund (Nokia)
  1 sibling, 0 replies; 14+ messages in thread
From: Joakim Tjernlund (Nokia) @ 2025-05-27 15:12 UTC (permalink / raw)
  To: linux-fsdevel@vger.kernel.org, Johannes.Thumshirn@wdc.com

Please disregard <=v4
I have just sent v5

 Joakim
On Mon, 2025-05-19 at 17:03 +0200, Joakim Tjernlund wrote:
> This enables mounting, like JFFS2, MTD devices by "label":
>    mount -t squashfs mtd:appfs /tmp
> where mtd:appfs comes from:
>  # >  cat /proc/mtd
> dev:    size   erasesize  name
> ...
> mtd22: 00750000 00010000 "appfs"
> 
> Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> ---
>  fs/super.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/fs/super.c b/fs/super.c
> index 97a17f9d9023..df7a6cfa34d3 100644
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -37,6 +37,7 @@
>  #include <linux/user_namespace.h>
>  #include <linux/fs_context.h>
>  #include <uapi/linux/mount.h>
> +#include <linux/mtd/mtd.h>
>  #include "internal.h"
>  
>  static int thaw_super_locked(struct super_block *sb, enum freeze_holder who);
> @@ -1595,6 +1596,32 @@ int setup_bdev_super(struct super_block *sb, int sb_flags,
>  }
>  EXPORT_SYMBOL_GPL(setup_bdev_super);
>  
> +static int translate_mtd_name(struct fs_context *fc)
> +{
> +#ifdef CONFIG_MTD_BLOCK
> +	if (!strncmp(fc->source, "mtd:", 4)) {
> +		struct mtd_info *mtd;
> +		char *blk_source;
> +
> +		/* mount by MTD device name */
> +		pr_debug("Block SB: name \"%s\"\n", fc->source);
> +
> +		mtd = get_mtd_device_nm(fc->source + 4);
> +		if (IS_ERR(mtd))
> +			return -EINVAL;
> +		blk_source = kmalloc(20, GFP_KERNEL);
> +		if (!blk_source)
> +			return -ENOMEM;
> +		sprintf(blk_source, "/dev/mtdblock%d", mtd->index);
> +		kfree(fc->source);
> +		fc->source = blk_source;
> +		pr_debug("MTD device:%s found\n", fc->source);
> +		return 0;
> +	}
> +#endif
> +	return 0;
> +}
> +
>  /**
>   * get_tree_bdev_flags - Get a superblock based on a single block device
>   * @fc: The filesystem context holding the parameters
> @@ -1612,6 +1639,9 @@ int get_tree_bdev_flags(struct fs_context *fc,
>  	if (!fc->source)
>  		return invalf(fc, "No source specified");
>  
> +	error = translate_mtd_name(fc);
> +	if (error)
> +		return error;
>  	error = lookup_bdev(fc->source, &dev);
>  	if (error) {
>  		if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))

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

* Re: [PATCH v5] block: support mtd:<name> syntax for block devices
  2025-05-27 15:10               ` [PATCH v5] " Joakim Tjernlund
@ 2025-05-28 13:09                 ` kernel test robot
  2025-06-02  7:50                   ` [PATCH v6] " Joakim Tjernlund
  0 siblings, 1 reply; 14+ messages in thread
From: kernel test robot @ 2025-05-28 13:09 UTC (permalink / raw)
  To: Joakim Tjernlund, linux-fsdevel, Johannes.Thumshirn
  Cc: oe-kbuild-all, Joakim Tjernlund

Hi Joakim,

kernel test robot noticed the following build warnings:

[auto build test WARNING on axboe-block/for-next]
[also build test WARNING on linus/master v6.15 next-20250528]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Joakim-Tjernlund/block-support-mtd-name-syntax-for-block-devices/20250527-231359
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
patch link:    https://lore.kernel.org/r/20250527151134.566571-1-joakim.tjernlund%40infinera.com
patch subject: [PATCH v5] block: support mtd:<name> syntax for block devices
config: i386-randconfig-141-20250528 (https://download.01.org/0day-ci/archive/20250528/202505282035.6vfhJHYl-lkp@intel.com/config)
compiler: clang version 20.1.2 (https://github.com/llvm/llvm-project 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202505282035.6vfhJHYl-lkp@intel.com/

smatch warnings:
block/bdev.c:1097 bdev_file_open_by_path() warn: inconsistent indenting

vim +1097 block/bdev.c

f3a608827d1f8d Christian Brauner 2024-02-08  1070  
f3a608827d1f8d Christian Brauner 2024-02-08  1071  struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
f3a608827d1f8d Christian Brauner 2024-02-08  1072  				    void *holder,
f3a608827d1f8d Christian Brauner 2024-02-08  1073  				    const struct blk_holder_ops *hops)
f3a608827d1f8d Christian Brauner 2024-02-08  1074  {
7c09a4ed6156c6 Christian Brauner 2024-01-23  1075  	struct file *file;
f3a608827d1f8d Christian Brauner 2024-02-08  1076  	dev_t dev;
f3a608827d1f8d Christian Brauner 2024-02-08  1077  	int error;
f3a608827d1f8d Christian Brauner 2024-02-08  1078  
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1079  #ifdef CONFIG_MTD_BLOCK
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1080         if (!strncmp(path, "mtd:", 4)) {
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1081                 struct mtd_info *mtd;
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1082  
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1083                 /* mount by MTD device name */
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1084                 pr_debug("path name \"%s\"\n", path);
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1085                 mtd = get_mtd_device_nm(path + 4);
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1086                 if (IS_ERR(mtd))
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1087                         return ERR_PTR(-EINVAL);
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1088                 dev = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1089         } else
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1090  #endif
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1091         {
f3a608827d1f8d Christian Brauner 2024-02-08  1092  	       error = lookup_bdev(path, &dev);
f3a608827d1f8d Christian Brauner 2024-02-08  1093  	       if (error)
f3a608827d1f8d Christian Brauner 2024-02-08  1094  		       return ERR_PTR(error);
e02c700b2107f3 Joakim Tjernlund  2025-05-27  1095         }
f3a608827d1f8d Christian Brauner 2024-02-08  1096  
7c09a4ed6156c6 Christian Brauner 2024-01-23 @1097  	file = bdev_file_open_by_dev(dev, mode, holder, hops);
7c09a4ed6156c6 Christian Brauner 2024-01-23  1098  	if (!IS_ERR(file) && (mode & BLK_OPEN_WRITE)) {
7c09a4ed6156c6 Christian Brauner 2024-01-23  1099  		if (bdev_read_only(file_bdev(file))) {
7c09a4ed6156c6 Christian Brauner 2024-01-23  1100  			fput(file);
7c09a4ed6156c6 Christian Brauner 2024-01-23  1101  			file = ERR_PTR(-EACCES);
f3a608827d1f8d Christian Brauner 2024-02-08  1102  		}
f3a608827d1f8d Christian Brauner 2024-02-08  1103  	}
f3a608827d1f8d Christian Brauner 2024-02-08  1104  
7c09a4ed6156c6 Christian Brauner 2024-01-23  1105  	return file;
f3a608827d1f8d Christian Brauner 2024-02-08  1106  }
f3a608827d1f8d Christian Brauner 2024-02-08  1107  EXPORT_SYMBOL(bdev_file_open_by_path);
f3a608827d1f8d Christian Brauner 2024-02-08  1108  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* [PATCH v6] block: support mtd:<name> syntax for block devices
  2025-05-28 13:09                 ` kernel test robot
@ 2025-06-02  7:50                   ` Joakim Tjernlund
  2025-06-14 12:43                     ` Joakim Tjernlund (Nokia)
  0 siblings, 1 reply; 14+ messages in thread
From: Joakim Tjernlund @ 2025-06-02  7:50 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Joakim Tjernlund

This enables mounting, like JFFS2, MTD devices by "label":
   mount -t squashfs mtd:appfs /tmp
and cmdline argument:
   root=mtd:rootfs

where mtd:appfs comes from:
 # >  cat /proc/mtd
dev:    size   erasesize  name
 ...
mtd22: 00750000 00010000 "appfs"

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
---

 - kernel test bot found white space issues, fix these.
 block/bdev.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/block/bdev.c b/block/bdev.c
index 889ec6e002d7..0e53ce99481b 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/blkpg.h>
 #include <linux/magic.h>
+#include <linux/mtd/mtd.h>
 #include <linux/buffer_head.h>
 #include <linux/swap.h>
 #include <linux/writeback.h>
@@ -1075,9 +1076,23 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
 	dev_t dev;
 	int error;
 
-	error = lookup_bdev(path, &dev);
-	if (error)
-		return ERR_PTR(error);
+#ifdef CONFIG_MTD_BLOCK
+	if (!strncmp(path, "mtd:", 4)) {
+		struct mtd_info *mtd;
+
+		/* mount by MTD device name */
+		pr_debug("path name \"%s\"\n", path);
+		mtd = get_mtd_device_nm(path + 4);
+		if (IS_ERR(mtd))
+			return ERR_PTR(-EINVAL);
+		dev = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
+	} else
+#endif
+	{
+		error = lookup_bdev(path, &dev);
+		if (error)
+			return ERR_PTR(error);
+	}
 
 	file = bdev_file_open_by_dev(dev, mode, holder, hops);
 	if (!IS_ERR(file) && (mode & BLK_OPEN_WRITE)) {
-- 
2.49.0


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

* Re: [PATCH v6] block: support mtd:<name> syntax for block devices
  2025-06-02  7:50                   ` [PATCH v6] " Joakim Tjernlund
@ 2025-06-14 12:43                     ` Joakim Tjernlund (Nokia)
  0 siblings, 0 replies; 14+ messages in thread
From: Joakim Tjernlund (Nokia) @ 2025-06-14 12:43 UTC (permalink / raw)
  To: Joakim Tjernlund, linux-fsdevel@vger.kernel.org


Ping ?

On Mon, 2025-06-02 at 09:50 +0200, Joakim Tjernlund wrote:
> This enables mounting, like JFFS2, MTD devices by "label":
>    mount -t squashfs mtd:appfs /tmp
> and cmdline argument:
>    root=mtd:rootfs
> 
> where mtd:appfs comes from:
>  # >  cat /proc/mtd
> dev:    size   erasesize  name
>  ...
> mtd22: 00750000 00010000 "appfs"
> 
> Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> ---
> 
>  - kernel test bot found white space issues, fix these.
>  block/bdev.c | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/block/bdev.c b/block/bdev.c
> index 889ec6e002d7..0e53ce99481b 100644
> --- a/block/bdev.c
> +++ b/block/bdev.c
> @@ -17,6 +17,7 @@
>  #include <linux/module.h>
>  #include <linux/blkpg.h>
>  #include <linux/magic.h>
> +#include <linux/mtd/mtd.h>
>  #include <linux/buffer_head.h>
>  #include <linux/swap.h>
>  #include <linux/writeback.h>
> @@ -1075,9 +1076,23 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
>  	dev_t dev;
>  	int error;
>  
> -	error = lookup_bdev(path, &dev);
> -	if (error)
> -		return ERR_PTR(error);
> +#ifdef CONFIG_MTD_BLOCK
> +	if (!strncmp(path, "mtd:", 4)) {
> +		struct mtd_info *mtd;
> +
> +		/* mount by MTD device name */
> +		pr_debug("path name \"%s\"\n", path);
> +		mtd = get_mtd_device_nm(path + 4);
> +		if (IS_ERR(mtd))
> +			return ERR_PTR(-EINVAL);
> +		dev = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
> +	} else
> +#endif
> +	{
> +		error = lookup_bdev(path, &dev);
> +		if (error)
> +			return ERR_PTR(error);
> +	}
>  
>  	file = bdev_file_open_by_dev(dev, mode, holder, hops);
>  	if (!IS_ERR(file) && (mode & BLK_OPEN_WRITE)) {

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

end of thread, other threads:[~2025-06-14 12:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-16  6:51 [PATCH] block: support mtd:<name> syntax for block devices Joakim Tjernlund
2025-05-16  7:14 ` Christoph Hellwig
2025-05-16  7:37   ` Joakim Tjernlund (Nokia)
2025-05-16  7:47     ` [PATCH v2] " Joakim Tjernlund
2025-05-19  8:12       ` Johannes Thumshirn
2025-05-19 13:11         ` [PATCH v3] " Joakim Tjernlund
2025-05-19 14:37           ` Johannes Thumshirn
2025-05-19 14:39             ` Joakim Tjernlund (Nokia)
2025-05-19 15:03             ` [PATCH v4] " Joakim Tjernlund
2025-05-27 15:10               ` [PATCH v5] " Joakim Tjernlund
2025-05-28 13:09                 ` kernel test robot
2025-06-02  7:50                   ` [PATCH v6] " Joakim Tjernlund
2025-06-14 12:43                     ` Joakim Tjernlund (Nokia)
2025-05-27 15:12               ` [PATCH v4] " Joakim Tjernlund (Nokia)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).