Skip to content

Commit d4c48e5

Browse files
Zhihao Chengrichardweinberger
authored andcommitted
ubi: fastmap: Add module parameter to control reserving filling pool PEBs
Adding 6th module parameter in 'mtd=xxx' to control whether or not reserving PEBs for filling pool/wl_pool. Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 90e0be5 commit d4c48e5

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

drivers/mtd/ubi/build.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define MTD_PARAM_LEN_MAX 64
3636

3737
/* Maximum number of comma-separated items in the 'mtd=' parameter */
38-
#define MTD_PARAM_MAX_COUNT 5
38+
#define MTD_PARAM_MAX_COUNT 6
3939

4040
/* Maximum value for the number of bad PEBs per 1024 PEBs */
4141
#define MAX_MTD_UBI_BEB_LIMIT 768
@@ -54,13 +54,15 @@
5454
* @vid_hdr_offs: VID header offset
5555
* @max_beb_per1024: maximum expected number of bad PEBs per 1024 PEBs
5656
* @enable_fm: enable fastmap when value is non-zero
57+
* @need_resv_pool: reserve pool->max_size pebs when value is none-zero
5758
*/
5859
struct mtd_dev_param {
5960
char name[MTD_PARAM_LEN_MAX];
6061
int ubi_num;
6162
int vid_hdr_offs;
6263
int max_beb_per1024;
6364
int enable_fm;
65+
int need_resv_pool;
6466
};
6567

6668
/* Numbers of elements set in the @mtd_dev_param array */
@@ -825,6 +827,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
825827
* @vid_hdr_offset: VID header offset
826828
* @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs
827829
* @disable_fm: whether disable fastmap
830+
* @need_resv_pool: whether reserve pebs to fill fm_pool
828831
*
829832
* This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number
830833
* to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
@@ -840,7 +843,8 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
840843
* @ubi_devices_mutex.
841844
*/
842845
int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
843-
int vid_hdr_offset, int max_beb_per1024, bool disable_fm)
846+
int vid_hdr_offset, int max_beb_per1024, bool disable_fm,
847+
bool need_resv_pool)
844848
{
845849
struct ubi_device *ubi;
846850
int i, err;
@@ -951,7 +955,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
951955
UBI_FM_MIN_POOL_SIZE);
952956

953957
ubi->fm_wl_pool.max_size = ubi->fm_pool.max_size / 2;
954-
ubi->fm_pool_rsv_cnt = ubi->fm_pool.max_size;
958+
ubi->fm_pool_rsv_cnt = need_resv_pool ? ubi->fm_pool.max_size : 0;
955959
ubi->fm_disabled = (!fm_autoconvert || disable_fm) ? 1 : 0;
956960
if (fm_debug)
957961
ubi_enable_dbg_chk_fastmap(ubi);
@@ -1274,7 +1278,8 @@ static int __init ubi_init(void)
12741278
mutex_lock(&ubi_devices_mutex);
12751279
err = ubi_attach_mtd_dev(mtd, p->ubi_num,
12761280
p->vid_hdr_offs, p->max_beb_per1024,
1277-
p->enable_fm == 0);
1281+
p->enable_fm == 0,
1282+
p->need_resv_pool != 0);
12781283
mutex_unlock(&ubi_devices_mutex);
12791284
if (err < 0) {
12801285
pr_err("UBI error: cannot attach mtd%d\n",
@@ -1483,6 +1488,18 @@ static int ubi_mtd_param_parse(const char *val, const struct kernel_param *kp)
14831488
} else
14841489
p->enable_fm = 0;
14851490

1491+
token = tokens[5];
1492+
if (token) {
1493+
int err = kstrtoint(token, 10, &p->need_resv_pool);
1494+
1495+
if (err) {
1496+
pr_err("UBI error: bad value for need_resv_pool parameter: %s\n",
1497+
token);
1498+
return -EINVAL;
1499+
}
1500+
} else
1501+
p->need_resv_pool = 0;
1502+
14861503
mtd_devs += 1;
14871504
return 0;
14881505
}
@@ -1496,6 +1513,7 @@ MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|pa
14961513
__stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0)\n"
14971514
"Optional \"ubi_num\" parameter specifies UBI device number which have to be assigned to the newly created UBI device (assigned automatically by default)\n"
14981515
"Optional \"enable_fm\" parameter determines whether to enable fastmap during attach. If the value is non-zero, fastmap is enabled. Default value is 0.\n"
1516+
"Optional \"need_resv_pool\" parameter determines whether to reserve pool->max_size pebs during attach. If the value is non-zero, peb reservation is enabled. Default value is 0.\n"
14991517
"\n"
15001518
"Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n"
15011519
"Example 2: mtd=content,1984 mtd=4 - attach MTD device with name \"content\" using VID header offset 1984, and MTD device number 4 with default VID header offset.\n"

drivers/mtd/ubi/cdev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,8 @@ 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, !!req.disable_fm);
1044+
req.max_beb_per1024, !!req.disable_fm,
1045+
false);
10451046
mutex_unlock(&ubi_devices_mutex);
10461047
if (err < 0)
10471048
put_mtd_device(mtd);

drivers/mtd/ubi/ubi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
944944
/* build.c */
945945
int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
946946
int vid_hdr_offset, int max_beb_per1024,
947-
bool disable_fm);
947+
bool disable_fm, bool need_resv_pool);
948948
int ubi_detach_mtd_dev(int ubi_num, int anyway);
949949
struct ubi_device *ubi_get_device(int ubi_num);
950950
void ubi_put_device(struct ubi_device *ubi);

0 commit comments

Comments
 (0)