Skip to contentSkip to conversation

mtd: ubiblock: introduce ubiblock_create_dev

PATCH In review Daniel Golle 2 participants 2 messages Aug 27, 2016 – Aug 28, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/3 mtd: ubiblock: introduce ubiblock_create_dev

Define function ubiblock_create_dev(char *name, dev_t *bdev) which returns the created device by setting the point bdev. This is useful for in-kernel users creating a ubiblock device in order to mount the root filesystem.

---
 drivers/mtd/ubi/block.c | 11 ++++++++++-
 drivers/mtd/ubi/ubi.h   |  2 ++
 include/linux/mtd/ubi.h | 16 ++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
drivers/mtd/ubi/block.c +10 -1
index ebf46ad..58b818f 100644
@@ -49,6 +49,7 @@
 #include <linux/hdreg.h>
 #include <linux/scatterlist.h>
 #include <linux/idr.h>
+#include <linux/kdev_t.h>
 #include <asm/div64.h>
 
 #include "ubi-media.h"
@@ -356,7 +357,11 @@ static struct blk_mq_ops ubiblock_mq_ops = {
 
 static DEFINE_IDR(ubiblock_minor_idr);
 
-int ubiblock_create(struct ubi_volume_info *vi)
+int ubiblock_create(struct ubi_volume_info *vi) {
+	return ubiblock_create_dev(vi, NULL);
+}
+
+int ubiblock_create_dev(struct ubi_volume_info *vi, dev_t *bdev)
 {
 	struct ubiblock *dev;
 	struct gendisk *gd;
@@ -448,6 +453,10 @@ int ubiblock_create(struct ubi_volume_info *vi)
 	add_disk(dev->gd);
 	dev_info(disk_to_dev(dev->gd), "created from ubi%d:%d(%s)",
 		 dev->ubi_num, dev->vol_id, vi->name);
+
+	if (bdev)
+		*bdev = MKDEV(gd->major, gd->first_minor);
+
 	return 0;
 
 out_free_queue:
drivers/mtd/ubi/ubi.h +2 -0
index de1ea2e4..7700752 100644
@@ -39,6 +39,7 @@
 #include <linux/notifier.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/ubi.h>
+#include <linux/kdev_t.h>
 #include <asm/pgtable.h>
 
 #include "ubi-media.h"
@@ -917,6 +918,7 @@ static inline int ubi_update_fastmap(struct ubi_device *ubi) { return 0; }
 int ubiblock_init(void);
 void ubiblock_exit(void);
 int ubiblock_create(struct ubi_volume_info *vi);
+int ubiblock_create_dev(struct ubi_volume_info *vi, dev_t *bdev);
 int ubiblock_remove(struct ubi_volume_info *vi);
 #else
 static inline int ubiblock_init(void) { return 0; }
include/linux/mtd/ubi.h +16 -0
index 0b92aa5..3d6444f 100644
@@ -21,7 +21,9 @@
 #ifndef __LINUX_UBI_H__
 #define __LINUX_UBI_H__
 
+#include <linux/errno.h>
 #include <linux/ioctl.h>
+#include <linux/kdev_t.h>
 #include <linux/types.h>
 #include <linux/scatterlist.h>
 #include <mtd/ubi-user.h>
@@ -282,4 +284,18 @@ static inline int ubi_read_sg(struct ubi_volume_desc *desc, int lnum,
 {
 	return ubi_leb_read_sg(desc, lnum, sgl, offset, len, 0);
 }
+
+
+/*
+ * This function allows in-kernel users to create a ubiblock device and
+ * get to know about the created device.
+ */
+#ifdef CONFIG_MTD_UBI_BLOCK
+int ubiblock_create_dev(struct ubi_volume_info *vi, dev_t *bdev);
+#else
+int ubiblock_create_dev(struct ubi_volume_info *vi, dev_t *bdev) {
+	return -ENOTSUPP;
+}
+#endif
+
 #endif /* !__LINUX_UBI_H__ */
Signature · 1 line
2.9.3
#1 lore raw
Quoted 4 lines · On Sat, 27 Aug 2016 21:44:16 +0200 Daniel Golle <[email protected]> wrote:

Define function ubiblock_create_dev(char *name, dev_t *bdev) which returns the created device by setting the point bdev. This is useful for in-kernel users creating a ubiblock device in order to mount the root filesystem.

No specific comment on this one either, since it's only preparing stuff for the real changes done in patch 3.

Quoted 97 lines
---
 drivers/mtd/ubi/block.c | 11 ++++++++++-
 drivers/mtd/ubi/ubi.h   |  2 ++
 include/linux/mtd/ubi.h | 16 ++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
drivers/mtd/ubi/block.c +10 -1
index ebf46ad..58b818f 100644
@@ -49,6 +49,7 @@
 #include <linux/hdreg.h>
 #include <linux/scatterlist.h>
 #include <linux/idr.h>
+#include <linux/kdev_t.h>
 #include <asm/div64.h>
 
 #include "ubi-media.h"
@@ -356,7 +357,11 @@ static struct blk_mq_ops ubiblock_mq_ops = {
 
 static DEFINE_IDR(ubiblock_minor_idr);
 
-int ubiblock_create(struct ubi_volume_info *vi)
+int ubiblock_create(struct ubi_volume_info *vi) {
+	return ubiblock_create_dev(vi, NULL);
+}
+
+int ubiblock_create_dev(struct ubi_volume_info *vi, dev_t *bdev)
 {
 	struct ubiblock *dev;
 	struct gendisk *gd;
@@ -448,6 +453,10 @@ int ubiblock_create(struct ubi_volume_info *vi)
 	add_disk(dev->gd);
 	dev_info(disk_to_dev(dev->gd), "created from ubi%d:%d(%s)",
 		 dev->ubi_num, dev->vol_id, vi->name);
+
+	if (bdev)
+		*bdev = MKDEV(gd->major, gd->first_minor);
+
 	return 0;
 
 out_free_queue:
drivers/mtd/ubi/ubi.h +2 -0
index de1ea2e4..7700752 100644
@@ -39,6 +39,7 @@
 #include <linux/notifier.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/ubi.h>
+#include <linux/kdev_t.h>
 #include <asm/pgtable.h>
 
 #include "ubi-media.h"
@@ -917,6 +918,7 @@ static inline int ubi_update_fastmap(struct ubi_device *ubi) { return 0; }
 int ubiblock_init(void);
 void ubiblock_exit(void);
 int ubiblock_create(struct ubi_volume_info *vi);
+int ubiblock_create_dev(struct ubi_volume_info *vi, dev_t *bdev);
 int ubiblock_remove(struct ubi_volume_info *vi);
 #else
 static inline int ubiblock_init(void) { return 0; }
include/linux/mtd/ubi.h +16 -0
index 0b92aa5..3d6444f 100644
@@ -21,7 +21,9 @@
 #ifndef __LINUX_UBI_H__
 #define __LINUX_UBI_H__
 
+#include <linux/errno.h>
 #include <linux/ioctl.h>
+#include <linux/kdev_t.h>
 #include <linux/types.h>
 #include <linux/scatterlist.h>
 #include <mtd/ubi-user.h>
@@ -282,4 +284,18 @@ static inline int ubi_read_sg(struct ubi_volume_desc *desc, int lnum,
 {
 	return ubi_leb_read_sg(desc, lnum, sgl, offset, len, 0);
 }
+
+
+/*
+ * This function allows in-kernel users to create a ubiblock device and
+ * get to know about the created device.
+ */
+#ifdef CONFIG_MTD_UBI_BLOCK
+int ubiblock_create_dev(struct ubi_volume_info *vi, dev_t *bdev);
+#else
+int ubiblock_create_dev(struct ubi_volume_info *vi, dev_t *bdev) {
+	return -ENOTSUPP;
+}
+#endif
+
 #endif /* !__LINUX_UBI_H__ */