Skip to content

Commit 669d204

Browse files
Zhihao Chengrichardweinberger
authored andcommitted
ubi: fastmap: Add fastmap control support for 'UBI_IOCATT' ioctl
[1] suggests that fastmap is suitable for large flash devices. Module parameter 'fm_autoconvert' is a coarse grained switch to enable all ubi devices to generate fastmap, which may turn on fastmap even for small flash devices. This patch imports a new field 'disable_fm' in struct 'ubi_attach_req' to support following situations by ioctl 'UBI_IOCATT'. [old functions] A. Disable 'fm_autoconvert': Disbable fastmap for all ubi devices B. Enable 'fm_autoconvert': Enable fastmap for all ubi devices [new function] C. Enable 'fm_autoconvert', set 'disable_fm' for given device: Don't create new fastmap and do full scan (existed fastmap will be destroyed) for the given ubi device. A simple test case in [2]. [1] http://www.linux-mtd.infradead.org/doc/ubi.html#L_fastmap [2] https://bugzilla.kernel.org/show_bug.cgi?id=216278 Signed-off-by: Zhihao Cheng <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent e7f35da commit 669d204

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

drivers/mtd/ubi/build.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,18 +807,23 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
807807
* @ubi_num: number to assign to the new UBI device
808808
* @vid_hdr_offset: VID header offset
809809
* @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs
810+
* @disable_fm: whether disable fastmap
810811
*
811812
* This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number
812813
* to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
813814
* which case this function finds a vacant device number and assigns it
814815
* automatically. Returns the new UBI device number in case of success and a
815816
* negative error code in case of failure.
816817
*
818+
* If @disable_fm is true, ubi doesn't create new fastmap even the module param
819+
* 'fm_autoconvert' is set, and existed old fastmap will be destroyed after
820+
* doing full scanning.
821+
*
817822
* Note, the invocations of this function has to be serialized by the
818823
* @ubi_devices_mutex.
819824
*/
820825
int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
821-
int vid_hdr_offset, int max_beb_per1024)
826+
int vid_hdr_offset, int max_beb_per1024, bool disable_fm)
822827
{
823828
struct ubi_device *ubi;
824829
int i, err;
@@ -921,7 +926,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
921926
UBI_FM_MIN_POOL_SIZE);
922927

923928
ubi->fm_wl_pool.max_size = ubi->fm_pool.max_size / 2;
924-
ubi->fm_disabled = !fm_autoconvert;
929+
ubi->fm_disabled = (!fm_autoconvert || disable_fm) ? 1 : 0;
925930
if (fm_debug)
926931
ubi_enable_dbg_chk_fastmap(ubi);
927932

@@ -962,7 +967,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
962967
if (!ubi->fm_buf)
963968
goto out_free;
964969
#endif
965-
err = ubi_attach(ubi, 0);
970+
err = ubi_attach(ubi, disable_fm ? 1 : 0);
966971
if (err) {
967972
ubi_err(ubi, "failed to attach mtd%d, error %d",
968973
mtd->index, err);
@@ -1242,7 +1247,8 @@ static int __init ubi_init(void)
12421247

12431248
mutex_lock(&ubi_devices_mutex);
12441249
err = ubi_attach_mtd_dev(mtd, p->ubi_num,
1245-
p->vid_hdr_offs, p->max_beb_per1024);
1250+
p->vid_hdr_offs, p->max_beb_per1024,
1251+
false);
12461252
mutex_unlock(&ubi_devices_mutex);
12471253
if (err < 0) {
12481254
pr_err("UBI error: cannot attach mtd%d\n",

drivers/mtd/ubi/cdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd,
10411041
*/
10421042
mutex_lock(&ubi_devices_mutex);
10431043
err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset,
1044-
req.max_beb_per1024);
1044+
req.max_beb_per1024, !!req.disable_fm);
10451045
mutex_unlock(&ubi_devices_mutex);
10461046
if (err < 0)
10471047
put_mtd_device(mtd);

drivers/mtd/ubi/ubi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
937937

938938
/* build.c */
939939
int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
940-
int vid_hdr_offset, int max_beb_per1024);
940+
int vid_hdr_offset, int max_beb_per1024,
941+
bool disable_fm);
941942
int ubi_detach_mtd_dev(int ubi_num, int anyway);
942943
struct ubi_device *ubi_get_device(int ubi_num);
943944
void ubi_put_device(struct ubi_device *ubi);

include/uapi/mtd/ubi-user.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ enum {
247247
* @vid_hdr_offset: VID header offset (use defaults if %0)
248248
* @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs
249249
* @padding: reserved for future, not used, has to be zeroed
250+
* @disable_fm: whether disable fastmap
250251
*
251252
* This data structure is used to specify MTD device UBI has to attach and the
252253
* parameters it has to use. The number which should be assigned to the new UBI
@@ -281,13 +282,18 @@ enum {
281282
* eraseblocks for new bad eraseblocks, but attempts to use available
282283
* eraseblocks (if any). The accepted range is 0-768. If 0 is given, the
283284
* default kernel value of %CONFIG_MTD_UBI_BEB_LIMIT will be used.
285+
*
286+
* If @disable_fm is not zero, ubi doesn't create new fastmap even the module
287+
* param 'fm_autoconvert' is set, and existed old fastmap will be destroyed
288+
* after doing full scanning.
284289
*/
285290
struct ubi_attach_req {
286291
__s32 ubi_num;
287292
__s32 mtd_num;
288293
__s32 vid_hdr_offset;
289294
__s16 max_beb_per1024;
290-
__s8 padding[10];
295+
__s8 disable_fm;
296+
__s8 padding[9];
291297
};
292298

293299
/*

0 commit comments

Comments
 (0)