LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: linux-mtd@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, Richard Weinberger <richard@nod.at>
Subject: [PATCH 13/14] ubi: Wire up attach mode selector
Date: Wed, 13 Jun 2018 23:23:43 +0200 [thread overview]
Message-ID: <20180613212344.11608-14-richard@nod.at> (raw)
In-Reply-To: <20180613212344.11608-1-richard@nod.at>
Now userspace can specify how UBI shall attach.
By default UBI decides how to attach, but userspace can
also force a full scan.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/build.c | 15 ++++++++++++---
drivers/mtd/ubi/cdev.c | 7 ++++++-
drivers/mtd/ubi/ubi.h | 3 ++-
3 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 1e3f75ede985..7d08b6498b2a 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -805,6 +805,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
* @ubi_num: number to assign to the new UBI device
* @vid_hdr_offset: VID header offset
* @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs
+ * @attach_mode: selects how to attach
*
* This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number
* to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
@@ -816,10 +817,12 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
* @ubi_devices_mutex.
*/
int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
- int vid_hdr_offset, int max_beb_per1024)
+ int vid_hdr_offset, int max_beb_per1024,
+ int attach_mode)
{
struct ubi_device *ubi;
int i, err;
+ int do_full_scan = false;
if (max_beb_per1024 < 0 || max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT)
return -EINVAL;
@@ -957,7 +960,12 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
if (!ubi->fm_buf)
goto out_free;
#endif
- err = ubi_attach(ubi, force_scan);
+ if (force_scan)
+ do_full_scan = 1;
+ else
+ do_full_scan = !!attach_mode;
+
+ err = ubi_attach(ubi, do_full_scan);
if (err) {
ubi_err(ubi, "failed to attach mtd%d, error %d",
mtd->index, err);
@@ -1240,7 +1248,8 @@ static int __init ubi_init(void)
mutex_lock(&ubi_devices_mutex);
err = ubi_attach_mtd_dev(mtd, p->ubi_num,
- p->vid_hdr_offs, p->max_beb_per1024);
+ p->vid_hdr_offs, p->max_beb_per1024,
+ UBI_ATTACH_MODE_AUTO);
mutex_unlock(&ubi_devices_mutex);
if (err < 0) {
pr_err("UBI error: cannot attach mtd%d\n",
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 45c329694a5e..cf9b2b00e8c5 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -1001,6 +1001,11 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd,
break;
}
+ if (req.attach_mode < 0 || req.attach_mode > UBI_ATTACH_MODE_MAX) {
+ err = -EINVAL;
+ break;
+ }
+
mtd = get_mtd_device(NULL, req.mtd_num);
if (IS_ERR(mtd)) {
err = PTR_ERR(mtd);
@@ -1013,7 +1018,7 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd,
*/
mutex_lock(&ubi_devices_mutex);
err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset,
- req.max_beb_per1024);
+ req.max_beb_per1024, req.attach_mode);
mutex_unlock(&ubi_devices_mutex);
if (err < 0)
put_mtd_device(mtd);
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 28af5115d180..0b2f79f68986 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -949,7 +949,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
/* build.c */
int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
- int vid_hdr_offset, int max_beb_per1024);
+ int vid_hdr_offset, int max_beb_per1024,
+ int attach_mode);
int ubi_detach_mtd_dev(int ubi_num, int anyway);
struct ubi_device *ubi_get_device(int ubi_num);
void ubi_put_device(struct ubi_device *ubi);
--
2.13.6
next prev parent reply other threads:[~2018-06-13 21:25 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-13 21:23 [PATCH 00/14] ubi: Fastmap updates Richard Weinberger
2018-06-13 21:23 ` [PATCH 01/14] ubi: fastmap: Read PEB numbers more carefully Richard Weinberger
2018-06-14 1:04 ` kbuild test robot
2018-06-14 6:23 ` Richard Weinberger
2018-06-20 10:17 ` Boris Brezillon
2018-06-13 21:23 ` [PATCH 02/14] ubi: Fix assert in ubi_wl_init Richard Weinberger
2018-06-20 10:11 ` Boris Brezillon
2018-06-13 21:23 ` [PATCH 03/14] ubi: fastmap: Add support for flags Richard Weinberger
2018-06-24 12:49 ` Boris Brezillon
2018-06-13 21:23 ` [PATCH 04/14] ubi: fastmap: Add UBI_FM_SB_PRESEEDED_FLG flag Richard Weinberger
2018-06-24 12:53 ` Boris Brezillon
2018-06-13 21:23 ` [PATCH 05/14] ubi: fastmap: Implement PEB translation Richard Weinberger
2018-06-13 21:23 ` [PATCH 06/14] ubi: fastmap: Handle bad block count for preseeded fastmap case Richard Weinberger
2018-06-13 21:23 ` [PATCH 07/14] ubi: fastmap: Fixup pool sizes for preseeded fastmaps Richard Weinberger
2018-06-13 21:23 ` [PATCH 08/14] ubi: fastmap: Scan empty space if fastmap is preseeded Richard Weinberger
2018-06-13 21:23 ` [PATCH 09/14] ubi: fastmap: Relax size check Richard Weinberger
2018-06-24 12:55 ` Boris Brezillon
2018-06-13 21:23 ` [PATCH 10/14] ubi: fastmap: Change a WARN_ON() to ubi_err() Richard Weinberger
2018-06-24 13:04 ` Boris Brezillon
2018-06-13 21:23 ` [PATCH 11/14] ubi: Add module parameter to force a full scan Richard Weinberger
2018-06-24 13:09 ` Boris Brezillon
2018-06-13 21:23 ` [PATCH 12/14] ubi: uapi: Add mode selector to attach request Richard Weinberger
2018-06-24 13:12 ` Boris Brezillon
2018-06-13 21:23 ` Richard Weinberger [this message]
2018-06-13 21:23 ` [PATCH 14/14] ubi: Remove experimental stigma from Fastmap Richard Weinberger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180613212344.11608-14-richard@nod.at \
--to=richard@nod.at \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--subject='Re: [PATCH 13/14] ubi: Wire up attach mode selector' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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).