* [PATCH v2 1/8] fs: Add for_each_fs_device_safe()
@ 2016-03-10 8:29 Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 2/8] fs: umount based on device path and mount path Markus Pargmann
` (6 more replies)
0 siblings, 7 replies; 10+ messages in thread
From: Markus Pargmann @ 2016-03-10 8:29 UTC (permalink / raw)
To: barebox
We need to be able to umount specific filesystems while iterating all of
them. This helper gives us a safe macro to do so.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
include/fs.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/fs.h b/include/fs.h
index 9ac4552dbacc..6cae157b9df8 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -87,6 +87,7 @@ struct fs_driver_d {
extern struct list_head fs_device_list;
#define for_each_fs_device(f) list_for_each_entry(f, &fs_device_list, list)
+#define for_each_fs_device_safe(tmp, f) list_for_each_entry_safe(f, tmp, &fs_device_list, list)
extern struct bus_type fs_bus;
struct fs_device_d {
--
2.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 2/8] fs: umount based on device path and mount path
2016-03-10 8:29 [PATCH v2 1/8] fs: Add for_each_fs_device_safe() Markus Pargmann
@ 2016-03-10 8:29 ` Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 3/8] ubi: Add getter ubi_volume_get_cdev() Markus Pargmann
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Markus Pargmann @ 2016-03-10 8:29 UTC (permalink / raw)
To: barebox
umount on Linux can be used on a mount pathes and device pathes. This
patch adds this functionality to barebox.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
commands/umount.c | 2 +-
fs/fs.c | 47 ++++++++++++++++++++++++++++++++++++++++++++---
include/fs.h | 1 +
3 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/commands/umount.c b/commands/umount.c
index 84c84e42c6bc..fdf4da95a021 100644
--- a/commands/umount.c
+++ b/commands/umount.c
@@ -37,7 +37,7 @@ BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(umount)
.cmd = do_umount,
BAREBOX_CMD_DESC("umount a filesystem")
- BAREBOX_CMD_OPTS("MOUNTPOINT")
+ BAREBOX_CMD_OPTS("MOUNTPOINT/DEVICEPATH")
BAREBOX_CMD_GROUP(CMD_GRP_PART)
BAREBOX_CMD_HELP(cmd_umount_help)
BAREBOX_CMD_END
diff --git a/fs/fs.c b/fs/fs.c
index 71cb43976d44..b44409bf3e4e 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1329,6 +1329,40 @@ err_free_path:
}
EXPORT_SYMBOL(mount);
+static int fsdev_umount(struct fs_device_d *fsdev)
+{
+ return unregister_device(&fsdev->dev);
+}
+
+/**
+ * umount_by_cdev Use a cdev struct to umount all mounted filesystems
+ * @param cdev cdev to the according device
+ * @return 0 on success or if cdev was not mounted, -errno otherwise
+ */
+int umount_by_cdev(struct cdev *cdev)
+{
+ struct fs_device_d *fs;
+ struct fs_device_d *fs_tmp;
+ int first_error = 0;
+
+ for_each_fs_device_safe(fs_tmp, fs) {
+ int ret;
+
+ if (fs->cdev == cdev) {
+ ret = fsdev_umount(fs);
+ if (ret) {
+ pr_err("Failed umounting %s, %d, continuing anyway\n",
+ fs->path, ret);
+ if (!first_error)
+ first_error = ret;
+ }
+ }
+ }
+
+ return first_error;
+}
+EXPORT_SYMBOL(umount_by_cdev);
+
int umount(const char *pathname)
{
struct fs_device_d *fsdev = NULL, *f;
@@ -1341,6 +1375,15 @@ int umount(const char *pathname)
}
}
+ if (!fsdev) {
+ struct cdev *cdev = cdev_by_path(p);
+
+ if (cdev) {
+ free(p);
+ return umount_by_cdev(cdev);
+ }
+ }
+
free(p);
if (f == fs_dev_root && !list_is_singular(&fs_device_list)) {
@@ -1353,9 +1396,7 @@ int umount(const char *pathname)
return -EFAULT;
}
- unregister_device(&fsdev->dev);
-
- return 0;
+ return fsdev_umount(fsdev);
}
EXPORT_SYMBOL(umount);
diff --git a/include/fs.h b/include/fs.h
index 6cae157b9df8..b7cd128b5ee1 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -147,6 +147,7 @@ int readlink(const char *path, char *buf, size_t bufsiz);
int mount (const char *device, const char *fsname, const char *path,
const char *fsoptions);
int umount(const char *pathname);
+int umount_by_cdev(struct cdev *cdev);
/* not-so-standard functions */
int erase(int fd, size_t count, loff_t offset);
--
2.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 3/8] ubi: Add getter ubi_volume_get_cdev()
2016-03-10 8:29 [PATCH v2 1/8] fs: Add for_each_fs_device_safe() Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 2/8] fs: umount based on device path and mount path Markus Pargmann
@ 2016-03-10 8:29 ` Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 4/8] ubi: Add helper to map a mtd device to a ubi number Markus Pargmann
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Markus Pargmann @ 2016-03-10 8:29 UTC (permalink / raw)
To: barebox
cdev is used in a future commit to find the mounted filesystems.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
drivers/mtd/ubi/kapi.c | 5 +++++
include/linux/mtd/ubi.h | 2 ++
2 files changed, 7 insertions(+)
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 7fc1aa8d70cc..c2e58e865753 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -308,6 +308,11 @@ void ubi_close_volume(struct ubi_volume_desc *desc)
}
EXPORT_SYMBOL_GPL(ubi_close_volume);
+struct cdev *ubi_volume_get_cdev(struct ubi_volume_desc *vol)
+{
+ return &vol->vol->cdev;
+}
+
/**
* ubi_leb_read - read data.
* @desc: volume descriptor
diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
index 0614681d731c..0725b04f9dfd 100644
--- a/include/linux/mtd/ubi.h
+++ b/include/linux/mtd/ubi.h
@@ -218,6 +218,8 @@ int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum);
int ubi_sync(int ubi_num);
int ubi_flush(int ubi_num, int vol_id, int lnum);
+struct cdev *ubi_volume_get_cdev(struct ubi_volume_desc *vol);
+
/*
* This function is the same as the 'ubi_leb_read()' function, but it does not
* provide the checking capability.
--
2.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 4/8] ubi: Add helper to map a mtd device to a ubi number
2016-03-10 8:29 [PATCH v2 1/8] fs: Add for_each_fs_device_safe() Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 2/8] fs: umount based on device path and mount path Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 3/8] ubi: Add getter ubi_volume_get_cdev() Markus Pargmann
@ 2016-03-10 8:29 ` Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 5/8] ubi: Helper to iterate over all ubi volumes Markus Pargmann
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Markus Pargmann @ 2016-03-10 8:29 UTC (permalink / raw)
To: barebox
ubi_num_get_by_mtd() searches for attached ubi devices for the given mtd
and returns the number of the ubi device.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
drivers/mtd/ubi/build.c | 35 ++++++++++++++++++++++++++---------
include/mtd/ubi-user.h | 1 +
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 797022636dcb..f51d10cf0d21 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -482,6 +482,28 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
}
/**
+ * ubi_num_get_by_mtd finds the ubi number to the given mtd
+ * @param mtd mtd_info to the mtd device
+ * @return positive or null for a UBI number, negative errno otherwise
+ */
+int ubi_num_get_by_mtd(struct mtd_info *mtd)
+{
+ int i;
+ struct ubi_device *ubi;
+
+ for (i = 0; i < UBI_MAX_DEVICES; i++) {
+ ubi = ubi_devices[i];
+ if (ubi && mtd == ubi->mtd) {
+ ubi_debug("mtd%d is already attached to ubi%d",
+ mtd->index, i);
+ return ubi->ubi_num;
+ }
+ }
+
+ return -ENOENT;
+}
+
+/**
* ubi_attach_mtd_dev - attach an MTD device.
* @mtd: MTD device description object
* @ubi_num: number to assign to the new UBI device
@@ -501,7 +523,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
int vid_hdr_offset, int max_beb_per1024)
{
struct ubi_device *ubi;
- int i, err, ref = 0;
+ int ubi_id, err, ref = 0;
if (max_beb_per1024 < 0 || max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT)
return -EINVAL;
@@ -515,14 +537,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
* Note, this function assumes that UBI devices creations and deletions
* are serialized, so it does not take the &ubi_devices_lock.
*/
- for (i = 0; i < UBI_MAX_DEVICES; i++) {
- ubi = ubi_devices[i];
- if (ubi && mtd == ubi->mtd) {
- ubi_debug("mtd%d is already attached to ubi%d",
- mtd->index, i);
- return -EEXIST;
- }
- }
+ ubi_id = ubi_num_get_by_mtd(mtd);
+ if (ubi_id >= 0)
+ return -EEXIST;
/*
* Make sure this MTD device is not emulated on top of an UBI volume
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h
index 2000ef2fd00d..ab1a6630f5ee 100644
--- a/include/mtd/ubi-user.h
+++ b/include/mtd/ubi-user.h
@@ -407,5 +407,6 @@ struct ubi_set_vol_prop_req {
int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
int vid_hdr_offset, int max_beb_per1024);
int ubi_detach_mtd_dev(int ubi_num, int anyway);
+int ubi_num_get_by_mtd(struct mtd_info *mtd);
#endif /* __UBI_USER_H__ */
--
2.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 5/8] ubi: Helper to iterate over all ubi volumes
2016-03-10 8:29 [PATCH v2 1/8] fs: Add for_each_fs_device_safe() Markus Pargmann
` (2 preceding siblings ...)
2016-03-10 8:29 ` [PATCH v2 4/8] ubi: Add helper to map a mtd device to a ubi number Markus Pargmann
@ 2016-03-10 8:29 ` Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 6/8] ubi: Add function to detach a UBI by using mtd_info Markus Pargmann
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Markus Pargmann @ 2016-03-10 8:29 UTC (permalink / raw)
To: barebox
To find all the ubi volume ids on a given UBI, we need a helper. The
added functions allow to use ubi_volume_for_each() to get each volume id
of a UBI.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
drivers/mtd/ubi/kapi.c | 42 ++++++++++++++++++++++++++++++++++++++++++
include/linux/mtd/ubi.h | 11 +++++++++++
2 files changed, 53 insertions(+)
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index c2e58e865753..f3b0f0d85d84 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -308,6 +308,48 @@ void ubi_close_volume(struct ubi_volume_desc *desc)
}
EXPORT_SYMBOL_GPL(ubi_close_volume);
+int ubi_volume_first(int ubi_num, struct ubi_device **ubi, int *vol_id)
+{
+ int i;
+
+ /* We keep the device until the last call of ubi_volume_next
+ * or ubi_volume_abort */
+ *ubi = ubi_get_device(ubi_num);
+ if (!*ubi)
+ return -ENODEV;
+
+ for (i = 0; i < (*ubi)->vtbl_slots; ++i) {
+ if ((*ubi)->volumes[i]) {
+ *vol_id = i;
+ return 0;
+ }
+ }
+
+ ubi_put_device(*ubi);
+ return -ENOENT;
+}
+
+int ubi_volume_next(struct ubi_device *ubi, int *vol_id)
+{
+ int i;
+
+ for (i = *vol_id + 1; i < ubi->vtbl_slots; ++i) {
+ if (ubi->volumes[i]) {
+ *vol_id = i;
+ return 0;
+ }
+ }
+
+ ubi_put_device(ubi);
+
+ return -ENOENT;
+}
+
+void ubi_volume_abort(struct ubi_device *ubi)
+{
+ ubi_put_device(ubi);
+}
+
struct cdev *ubi_volume_get_cdev(struct ubi_volume_desc *vol)
{
return &vol->vol->cdev;
diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
index 0725b04f9dfd..344842e4ed97 100644
--- a/include/linux/mtd/ubi.h
+++ b/include/linux/mtd/ubi.h
@@ -220,6 +220,17 @@ int ubi_flush(int ubi_num, int vol_id, int lnum);
struct cdev *ubi_volume_get_cdev(struct ubi_volume_desc *vol);
+struct ubi_device;
+int ubi_volume_first(int ubi_num, struct ubi_device **ubi, int *vol_id);
+int ubi_volume_next(struct ubi_device *ubi, int *vol_id);
+void ubi_volume_abort(struct ubi_device *ubi);
+
+#define ubi_volume_for_each(ubi_num, ubi, vol_id, ret) \
+ for (ret = ubi_volume_first(ubi_num, &(ubi), &(vol_id)); \
+ !ret; \
+ ret = ubi_volume_next(ubi, &(vol_id)))
+
+
/*
* This function is the same as the 'ubi_leb_read()' function, but it does not
* provide the checking capability.
--
2.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 6/8] ubi: Add function to detach a UBI by using mtd_info
2016-03-10 8:29 [PATCH v2 1/8] fs: Add for_each_fs_device_safe() Markus Pargmann
` (3 preceding siblings ...)
2016-03-10 8:29 ` [PATCH v2 5/8] ubi: Helper to iterate over all ubi volumes Markus Pargmann
@ 2016-03-10 8:29 ` Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 7/8] ubi: Let ubidetach umount all filesystems before detaching Markus Pargmann
2016-03-10 8:30 ` [PATCH v2 8/8] ubiformat: Cleanly umount and detach the ubi before formating Markus Pargmann
6 siblings, 0 replies; 10+ messages in thread
From: Markus Pargmann @ 2016-03-10 8:29 UTC (permalink / raw)
To: barebox
We may don't know which UBI is attached on a given MTD device. This adds
a function to detach a UBI given a MTD device.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
drivers/mtd/ubi/build.c | 21 +++++++++++++++++++++
include/mtd/ubi-user.h | 1 +
2 files changed, 22 insertions(+)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index f51d10cf0d21..7ee34bc62f30 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -750,3 +750,24 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
return 0;
}
+
+/**
+ * ubi_detach_by_mtd detaches any ubi that of the given MTD
+ * @param mtd MTD used
+ * @param anyway detach MTD even if device reference count is not zero
+ * @return 0 on success, negative errno otherwise
+ *
+ * This function returns -EINVAL if the device is not attached
+ */
+int ubi_detach_by_mtd(struct mtd_info *mtd, bool anyway)
+{
+ int ubi_num = ubi_num_get_by_mtd(mtd);
+
+ if (ubi_num < 0) {
+ if (ubi_num == -ENOENT)
+ return -EINVAL;
+ return ubi_num;
+ }
+
+ return ubi_detach_mtd_dev(ubi_num, anyway);
+}
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h
index ab1a6630f5ee..90982743cb58 100644
--- a/include/mtd/ubi-user.h
+++ b/include/mtd/ubi-user.h
@@ -407,6 +407,7 @@ struct ubi_set_vol_prop_req {
int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
int vid_hdr_offset, int max_beb_per1024);
int ubi_detach_mtd_dev(int ubi_num, int anyway);
+int ubi_detach_by_mtd(struct mtd_info *mtd, bool anyway);
int ubi_num_get_by_mtd(struct mtd_info *mtd);
#endif /* __UBI_USER_H__ */
--
2.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 7/8] ubi: Let ubidetach umount all filesystems before detaching
2016-03-10 8:29 [PATCH v2 1/8] fs: Add for_each_fs_device_safe() Markus Pargmann
` (4 preceding siblings ...)
2016-03-10 8:29 ` [PATCH v2 6/8] ubi: Add function to detach a UBI by using mtd_info Markus Pargmann
@ 2016-03-10 8:29 ` Markus Pargmann
2016-03-14 7:32 ` Sascha Hauer
2016-03-10 8:30 ` [PATCH v2 8/8] ubiformat: Cleanly umount and detach the ubi before formating Markus Pargmann
6 siblings, 1 reply; 10+ messages in thread
From: Markus Pargmann @ 2016-03-10 8:29 UTC (permalink / raw)
To: barebox
This patch iterates through all ubi volumes and umounts all filesystems
that are mounted.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
drivers/mtd/ubi/build.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 7ee34bc62f30..edaa98b0973c 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -25,6 +25,7 @@
* later using the "UBI control device".
*/
+#include <fs.h>
#include <linux/err.h>
#include <linux/stringify.h>
#include <linux/stat.h>
@@ -713,6 +714,8 @@ out_free:
int ubi_detach_mtd_dev(int ubi_num, int anyway)
{
struct ubi_device *ubi;
+ int vol_id;
+ int ret;
if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES)
return -EINVAL;
@@ -723,6 +726,32 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
ubi->ref_count--;
+ ubi_volume_for_each(ubi_num, ubi, vol_id, ret) {
+ struct ubi_volume_desc *vol;
+
+ vol = ubi_open_volume(ubi_num, vol_id, UBI_READONLY);
+ if (IS_ERR(vol)) {
+ pr_err("Failed to open ubi volume %d %d, %ld\n",
+ ubi_num, vol_id, PTR_ERR(vol));
+ if (anyway)
+ continue;
+
+ ubi_volume_abort(ubi);
+ return PTR_ERR(vol);
+ }
+
+ ret = umount_by_cdev(ubi_volume_get_cdev(vol));
+ ubi_close_volume(vol);
+ if (ret) {
+ pr_err("Failed umounting ubi volume %d %d, %d\n",
+ ubi_num, vol_id, ret);
+ if (anyway)
+ continue;
+ ubi_volume_abort(ubi);
+ return ret;
+ }
+ }
+
if (ubi->ref_count)
return -EBUSY;
--
2.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 8/8] ubiformat: Cleanly umount and detach the ubi before formating
2016-03-10 8:29 [PATCH v2 1/8] fs: Add for_each_fs_device_safe() Markus Pargmann
` (5 preceding siblings ...)
2016-03-10 8:29 ` [PATCH v2 7/8] ubi: Let ubidetach umount all filesystems before detaching Markus Pargmann
@ 2016-03-10 8:30 ` Markus Pargmann
2016-03-14 7:41 ` Sascha Hauer
6 siblings, 1 reply; 10+ messages in thread
From: Markus Pargmann @ 2016-03-10 8:30 UTC (permalink / raw)
To: barebox
This was an open fixme for some time. ubiformat does not care about used
ubi volumes or attached ubis.
This patch adds functionality that umounts all filesystems that are
mounted from this nand device. After that the ubi is detached. Then the
normal ubiformat code reformats the ubi. If a ubi was detached
previously, the code tries to reattach the ubi. Filesystems are not
remounted.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
commands/ubiformat.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/commands/ubiformat.c b/commands/ubiformat.c
index f9c50b7936eb..4a80952dca61 100644
--- a/commands/ubiformat.c
+++ b/commands/ubiformat.c
@@ -42,6 +42,7 @@
#include <libbb.h>
#include <libfile.h>
#include <linux/mtd/mtd.h>
+#include <linux/mtd/ubi.h>
#include <linux/kernel.h>
#include <linux/stat.h>
#include <linux/log2.h>
@@ -555,6 +556,8 @@ int do_ubiformat(int argc, char *argv[])
struct mtd_dev_info mtd;
struct ubigen_info ui;
struct ubi_scan_info *si;
+ int ubi_detached = -1;
+ struct mtd_info_user mtd_info;
err = parse_opt(argc, argv);
if (err)
@@ -614,8 +617,19 @@ int do_ubiformat(int argc, char *argv[])
goto out_close;
}
- /* Make sure this MTD device is not attached to UBI */
- /* FIXME! Find a proper way to do this in barebox! */
+ err = ioctl(args.node_fd, MEMGETINFO, &mtd_info);
+ if (err) {
+ sys_errmsg("Failed to get user info %d\n", err);
+ goto out_close;
+ }
+
+ ubi_detached = ubi_num_get_by_mtd(mtd_info.mtd);
+ err = ubi_detach_by_mtd(mtd_info.mtd, args.yes);
+ if (err) {
+ sys_errmsg("Cannot detach %d\n", err);
+ goto out_close;
+ }
+
if (!args.quiet) {
normsg_cont("%s (%s), size %lld bytes (%s)", mtd.node, mtd.type_str,
@@ -750,6 +764,17 @@ int do_ubiformat(int argc, char *argv[])
libscan_ubi_scan_free(si);
close(args.node_fd);
+
+ /* Reattach the ubi device in case it was attached in the beginning */
+ if (ubi_detached < 0) {
+ err = ubi_attach_mtd_dev(mtd_info.mtd, ubi_detached, 0, 20);
+ if (err) {
+ pr_err("Failed to reattach ubi device to ubi number %d, %d\n",
+ ubi_detached, err);
+ return err;
+ }
+ }
+
return 0;
out_free:
--
2.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 7/8] ubi: Let ubidetach umount all filesystems before detaching
2016-03-10 8:29 ` [PATCH v2 7/8] ubi: Let ubidetach umount all filesystems before detaching Markus Pargmann
@ 2016-03-14 7:32 ` Sascha Hauer
0 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2016-03-14 7:32 UTC (permalink / raw)
To: Markus Pargmann; +Cc: barebox
On Thu, Mar 10, 2016 at 09:29:59AM +0100, Markus Pargmann wrote:
> This patch iterates through all ubi volumes and umounts all filesystems
> that are mounted.
>
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
> ---
> drivers/mtd/ubi/build.c | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
> index 7ee34bc62f30..edaa98b0973c 100644
> --- a/drivers/mtd/ubi/build.c
> +++ b/drivers/mtd/ubi/build.c
> @@ -25,6 +25,7 @@
> * later using the "UBI control device".
> */
>
> +#include <fs.h>
> #include <linux/err.h>
> #include <linux/stringify.h>
> #include <linux/stat.h>
> @@ -713,6 +714,8 @@ out_free:
> int ubi_detach_mtd_dev(int ubi_num, int anyway)
> {
> struct ubi_device *ubi;
> + int vol_id;
> + int ret;
>
> if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES)
> return -EINVAL;
> @@ -723,6 +726,32 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
>
> ubi->ref_count--;
>
> + ubi_volume_for_each(ubi_num, ubi, vol_id, ret) {
> + struct ubi_volume_desc *vol;
> +
> + vol = ubi_open_volume(ubi_num, vol_id, UBI_READONLY);
> + if (IS_ERR(vol)) {
> + pr_err("Failed to open ubi volume %d %d, %ld\n",
> + ubi_num, vol_id, PTR_ERR(vol));
> + if (anyway)
> + continue;
> +
> + ubi_volume_abort(ubi);
> + return PTR_ERR(vol);
> + }
> +
> + ret = umount_by_cdev(ubi_volume_get_cdev(vol));
> + ubi_close_volume(vol);
> + if (ret) {
> + pr_err("Failed umounting ubi volume %d %d, %d\n",
> + ubi_num, vol_id, ret);
> + if (anyway)
> + continue;
> + ubi_volume_abort(ubi);
> + return ret;
> + }
> + }
Wouldn't the following do it?
void ubi_umount_volumes(struct ubi_device *ubi)
{
int i;
for (i = 0; i < ubi->vtbl_slots; i++) {
struct ubi_volume *vol = ubi->volumes[i];
if (!vol)
continue;
umount_by_cdev(vol->cdev);
}
}
We shouldn't change the UBI code too much as it makes updates harder. If
possible, please move the code to cdev.c which is completely barebox
specific (if needed, we may rename cdev.c to barebox.c)
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 8/8] ubiformat: Cleanly umount and detach the ubi before formating
2016-03-10 8:30 ` [PATCH v2 8/8] ubiformat: Cleanly umount and detach the ubi before formating Markus Pargmann
@ 2016-03-14 7:41 ` Sascha Hauer
0 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2016-03-14 7:41 UTC (permalink / raw)
To: Markus Pargmann; +Cc: barebox
On Thu, Mar 10, 2016 at 09:30:00AM +0100, Markus Pargmann wrote:
> This was an open fixme for some time. ubiformat does not care about used
> ubi volumes or attached ubis.
>
> This patch adds functionality that umounts all filesystems that are
> mounted from this nand device. After that the ubi is detached. Then the
> normal ubiformat code reformats the ubi. If a ubi was detached
> previously, the code tries to reattach the ubi. Filesystems are not
> remounted.
>
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
> ---
> commands/ubiformat.c | 29 +++++++++++++++++++++++++++--
> 1 file changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/commands/ubiformat.c b/commands/ubiformat.c
> index f9c50b7936eb..4a80952dca61 100644
> --- a/commands/ubiformat.c
> +++ b/commands/ubiformat.c
> @@ -42,6 +42,7 @@
> #include <libbb.h>
> #include <libfile.h>
> #include <linux/mtd/mtd.h>
> +#include <linux/mtd/ubi.h>
> #include <linux/kernel.h>
> #include <linux/stat.h>
> #include <linux/log2.h>
> @@ -555,6 +556,8 @@ int do_ubiformat(int argc, char *argv[])
> struct mtd_dev_info mtd;
> struct ubigen_info ui;
> struct ubi_scan_info *si;
> + int ubi_detached = -1;
> + struct mtd_info_user mtd_info;
>
> err = parse_opt(argc, argv);
> if (err)
> @@ -614,8 +617,19 @@ int do_ubiformat(int argc, char *argv[])
> goto out_close;
> }
>
> - /* Make sure this MTD device is not attached to UBI */
> - /* FIXME! Find a proper way to do this in barebox! */
> + err = ioctl(args.node_fd, MEMGETINFO, &mtd_info);
> + if (err) {
> + sys_errmsg("Failed to get user info %d\n", err);
> + goto out_close;
> + }
> +
> + ubi_detached = ubi_num_get_by_mtd(mtd_info.mtd);
> + err = ubi_detach_by_mtd(mtd_info.mtd, args.yes);
> + if (err) {
> + sys_errmsg("Cannot detach %d\n", err);
> + goto out_close;
> + }
ubi_detach_by_mtd() returns an error if the mtd device hasn't been
attached to ubi. I think there's a if (ubi_detached >= 0) missing here.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2016-03-14 7:42 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-10 8:29 [PATCH v2 1/8] fs: Add for_each_fs_device_safe() Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 2/8] fs: umount based on device path and mount path Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 3/8] ubi: Add getter ubi_volume_get_cdev() Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 4/8] ubi: Add helper to map a mtd device to a ubi number Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 5/8] ubi: Helper to iterate over all ubi volumes Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 6/8] ubi: Add function to detach a UBI by using mtd_info Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 7/8] ubi: Let ubidetach umount all filesystems before detaching Markus Pargmann
2016-03-14 7:32 ` Sascha Hauer
2016-03-10 8:30 ` [PATCH v2 8/8] ubiformat: Cleanly umount and detach the ubi before formating Markus Pargmann
2016-03-14 7:41 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox