aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-04-15 16:43:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-15 16:43:40 -0400
commitd613896926be608796bb80454256a07b55fe0e87 (patch)
treee741ea9477e013a319d3dedceb0aea66c8c3606d
parentfa927894bbb4a4c7669c72bad1924991022fda38 (diff)
parent502690674281a047abd45f81e64c498bc23a8bb3 (diff)
Merge tag 'upstream-4.1-rc1' of git://git.infradead.org/linux-ubifs
Pull UBI/UBIFS updates from Richard Weinberger: "This pull request includes the following UBI/UBIFS changes: - powercut emulation for UBI - a huge update to UBI Fastmap - cleanups and bugfixes all over UBI and UBIFS" * tag 'upstream-4.1-rc1' of git://git.infradead.org/linux-ubifs: (50 commits) UBI: power cut emulation for testing UBIFS: fix output format of INUM_WATERMARK UBI: Fastmap: Fall back to scanning mode after ECC error UBI: Fastmap: Remove is_fm_block() UBI: Fastmap: Add blank line after declarations UBI: Fastmap: Remove else after return. UBI: Fastmap: Introduce may_reserve_for_fm() UBI: Fastmap: Introduce ubi_fastmap_init() UBI: Fastmap: Wire up WL accessor functions UBI: Add accessor functions for WL data structures UBI: Move fastmap specific functions out of wl.c UBI: Fastmap: Add new module parameter fm_debug UBI: Fastmap: Make self_check_eba() depend on fastmap self checking UBI: Fastmap: Add self check to detect absent PEBs UBI: Fix stale pointers in ubi->lookuptbl UBI: Fastmap: Enhance fastmap checking UBI: Add initial support for fastmap self checks UBI: Fastmap: Rework fastmap error paths UBI: Fastmap: Prepare for variable sized fastmaps UBI: Fastmap: Locking updates ...
-rw-r--r--drivers/mtd/ubi/attach.c73
-rw-r--r--drivers/mtd/ubi/build.c29
-rw-r--r--drivers/mtd/ubi/cdev.c2
-rw-r--r--drivers/mtd/ubi/debug.c100
-rw-r--r--drivers/mtd/ubi/debug.h12
-rw-r--r--drivers/mtd/ubi/eba.c54
-rw-r--r--drivers/mtd/ubi/fastmap-wl.c362
-rw-r--r--drivers/mtd/ubi/fastmap.c443
-rw-r--r--drivers/mtd/ubi/io.c6
-rw-r--r--drivers/mtd/ubi/ubi-media.h2
-rw-r--r--drivers/mtd/ubi/ubi.h85
-rw-r--r--drivers/mtd/ubi/wl.c587
-rw-r--r--drivers/mtd/ubi/wl.h28
-rw-r--r--fs/ubifs/budget.c2
-rw-r--r--fs/ubifs/commit.c12
-rw-r--r--fs/ubifs/compress.c22
-rw-r--r--fs/ubifs/debug.c186
-rw-r--r--fs/ubifs/dir.c23
-rw-r--r--fs/ubifs/file.c17
-rw-r--r--fs/ubifs/io.c40
-rw-r--r--fs/ubifs/ioctl.c2
-rw-r--r--fs/ubifs/journal.c17
-rw-r--r--fs/ubifs/log.c4
-rw-r--r--fs/ubifs/lprops.c62
-rw-r--r--fs/ubifs/lpt.c59
-rw-r--r--fs/ubifs/lpt_commit.c34
-rw-r--r--fs/ubifs/master.c6
-rw-r--r--fs/ubifs/orphan.c26
-rw-r--r--fs/ubifs/recovery.c44
-rw-r--r--fs/ubifs/replay.c34
-rw-r--r--fs/ubifs/sb.c30
-rw-r--r--fs/ubifs/scan.c24
-rw-r--r--fs/ubifs/super.c107
-rw-r--r--fs/ubifs/tnc.c20
-rw-r--r--fs/ubifs/tnc_commit.c12
-rw-r--r--fs/ubifs/tnc_misc.c24
-rw-r--r--fs/ubifs/ubifs.h40
-rw-r--r--fs/ubifs/xattr.c18
38 files changed, 1507 insertions, 1141 deletions
diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 9d2e16f3150a..68eea5befaf1 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -410,7 +410,7 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
410 second_is_newer = !second_is_newer; 410 second_is_newer = !second_is_newer;
411 } else { 411 } else {
412 dbg_bld("PEB %d CRC is OK", pnum); 412 dbg_bld("PEB %d CRC is OK", pnum);
413 bitflips = !!err; 413 bitflips |= !!err;
414 } 414 }
415 mutex_unlock(&ubi->buf_mutex); 415 mutex_unlock(&ubi->buf_mutex);
416 416
@@ -1301,6 +1301,30 @@ out_ech:
1301 return err; 1301 return err;
1302} 1302}
1303 1303
1304static struct ubi_attach_info *alloc_ai(void)
1305{
1306 struct ubi_attach_info *ai;
1307
1308 ai = kzalloc(sizeof(struct ubi_attach_info), GFP_KERNEL);
1309 if (!ai)
1310 return ai;
1311
1312 INIT_LIST_HEAD(&ai->corr);
1313 INIT_LIST_HEAD(&ai->free);
1314 INIT_LIST_HEAD(&ai->erase);
1315 INIT_LIST_HEAD(&ai->alien);
1316 ai->volumes = RB_ROOT;
1317 ai->aeb_slab_cache = kmem_cache_create("ubi_aeb_slab_cache",
1318 sizeof(struct ubi_ainf_peb),
1319 0, 0, NULL);
1320 if (!ai->aeb_slab_cache) {
1321 kfree(ai);
1322 ai = NULL;
1323 }
1324
1325 return ai;
1326}
1327
1304#ifdef CONFIG_MTD_UBI_FASTMAP 1328#ifdef CONFIG_MTD_UBI_FASTMAP
1305 1329
1306/** 1330/**
@@ -1313,7 +1337,7 @@ out_ech:
1313 * UBI_NO_FASTMAP denotes that no fastmap was found. 1337 * UBI_NO_FASTMAP denotes that no fastmap was found.
1314 * UBI_BAD_FASTMAP denotes that the found fastmap was invalid. 1338 * UBI_BAD_FASTMAP denotes that the found fastmap was invalid.
1315 */ 1339 */
1316static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info *ai) 1340static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info **ai)
1317{ 1341{
1318 int err, pnum, fm_anchor = -1; 1342 int err, pnum, fm_anchor = -1;
1319 unsigned long long max_sqnum = 0; 1343 unsigned long long max_sqnum = 0;
@@ -1334,7 +1358,7 @@ static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info *ai)
1334 cond_resched(); 1358 cond_resched();
1335 1359
1336 dbg_gen("process PEB %d", pnum); 1360 dbg_gen("process PEB %d", pnum);
1337 err = scan_peb(ubi, ai, pnum, &vol_id, &sqnum); 1361 err = scan_peb(ubi, *ai, pnum, &vol_id, &sqnum);
1338 if (err < 0) 1362 if (err < 0)
1339 goto out_vidh; 1363 goto out_vidh;
1340 1364
@@ -1350,7 +1374,12 @@ static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info *ai)
1350 if (fm_anchor < 0) 1374 if (fm_anchor < 0)
1351 return UBI_NO_FASTMAP; 1375 return UBI_NO_FASTMAP;
1352 1376
1353 return ubi_scan_fastmap(ubi, ai, fm_anchor); 1377 destroy_ai(*ai);
1378 *ai = alloc_ai();
1379 if (!*ai)
1380 return -ENOMEM;
1381
1382 return ubi_scan_fastmap(ubi, *ai, fm_anchor);
1354 1383
1355out_vidh: 1384out_vidh:
1356 ubi_free_vid_hdr(ubi, vidh); 1385 ubi_free_vid_hdr(ubi, vidh);
@@ -1362,30 +1391,6 @@ out:
1362 1391
1363#endif 1392#endif
1364 1393
1365static struct ubi_attach_info *alloc_ai(const char *slab_name)
1366{
1367 struct ubi_attach_info *ai;
1368
1369 ai = kzalloc(sizeof(struct ubi_attach_info), GFP_KERNEL);
1370 if (!ai)
1371 return ai;
1372
1373 INIT_LIST_HEAD(&ai->corr);
1374 INIT_LIST_HEAD(&ai->free);
1375 INIT_LIST_HEAD(&ai->erase);
1376 INIT_LIST_HEAD(&ai->alien);
1377 ai->volumes = RB_ROOT;
1378 ai->aeb_slab_cache = kmem_cache_create(slab_name,
1379 sizeof(struct ubi_ainf_peb),
1380 0, 0, NULL);
1381 if (!ai->aeb_slab_cache) {
1382 kfree(ai);
1383 ai = NULL;
1384 }
1385
1386 return ai;
1387}
1388
1389/** 1394/**
1390 * ubi_attach - attach an MTD device. 1395 * ubi_attach - attach an MTD device.
1391 * @ubi: UBI device descriptor 1396 * @ubi: UBI device descriptor
@@ -1399,7 +1404,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
1399 int err; 1404 int err;
1400 struct ubi_attach_info *ai; 1405 struct ubi_attach_info *ai;
1401 1406
1402 ai = alloc_ai("ubi_aeb_slab_cache"); 1407 ai = alloc_ai();
1403 if (!ai) 1408 if (!ai)
1404 return -ENOMEM; 1409 return -ENOMEM;
1405 1410
@@ -1413,11 +1418,11 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
1413 if (force_scan) 1418 if (force_scan)
1414 err = scan_all(ubi, ai, 0); 1419 err = scan_all(ubi, ai, 0);
1415 else { 1420 else {
1416 err = scan_fast(ubi, ai); 1421 err = scan_fast(ubi, &ai);
1417 if (err > 0) { 1422 if (err > 0 || mtd_is_eccerr(err)) {
1418 if (err != UBI_NO_FASTMAP) { 1423 if (err != UBI_NO_FASTMAP) {
1419 destroy_ai(ai); 1424 destroy_ai(ai);
1420 ai = alloc_ai("ubi_aeb_slab_cache2"); 1425 ai = alloc_ai();
1421 if (!ai) 1426 if (!ai)
1422 return -ENOMEM; 1427 return -ENOMEM;
1423 1428
@@ -1453,10 +1458,10 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
1453 goto out_wl; 1458 goto out_wl;
1454 1459
1455#ifdef CONFIG_MTD_UBI_FASTMAP 1460#ifdef CONFIG_MTD_UBI_FASTMAP
1456 if (ubi->fm && ubi_dbg_chk_gen(ubi)) { 1461 if (ubi->fm && ubi_dbg_chk_fastmap(ubi)) {
1457 struct ubi_attach_info *scan_ai; 1462 struct ubi_attach_info *scan_ai;
1458 1463
1459 scan_ai = alloc_ai("ubi_ckh_aeb_slab_cache"); 1464 scan_ai = alloc_ai();
1460 if (!scan_ai) { 1465 if (!scan_ai) {
1461 err = -ENOMEM; 1466 err = -ENOMEM;
1462 goto out_wl; 1467 goto out_wl;
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index ba01a8d22d28..9690cf9aaef5 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -81,6 +81,7 @@ static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES];
81#ifdef CONFIG_MTD_UBI_FASTMAP 81#ifdef CONFIG_MTD_UBI_FASTMAP
82/* UBI module parameter to enable fastmap automatically on non-fastmap images */ 82/* UBI module parameter to enable fastmap automatically on non-fastmap images */
83static bool fm_autoconvert; 83static bool fm_autoconvert;
84static bool fm_debug;
84#endif 85#endif
85/* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */ 86/* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */
86struct class *ubi_class; 87struct class *ubi_class;
@@ -154,23 +155,22 @@ static struct device_attribute dev_mtd_num =
154 */ 155 */
155int ubi_volume_notify(struct ubi_device *ubi, struct ubi_volume *vol, int ntype) 156int ubi_volume_notify(struct ubi_device *ubi, struct ubi_volume *vol, int ntype)
156{ 157{
158 int ret;
157 struct ubi_notification nt; 159 struct ubi_notification nt;
158 160
159 ubi_do_get_device_info(ubi, &nt.di); 161 ubi_do_get_device_info(ubi, &nt.di);
160 ubi_do_get_volume_info(ubi, vol, &nt.vi); 162 ubi_do_get_volume_info(ubi, vol, &nt.vi);
161 163
162#ifdef CONFIG_MTD_UBI_FASTMAP
163 switch (ntype) { 164 switch (ntype) {
164 case UBI_VOLUME_ADDED: 165 case UBI_VOLUME_ADDED:
165 case UBI_VOLUME_REMOVED: 166 case UBI_VOLUME_REMOVED:
166 case UBI_VOLUME_RESIZED: 167 case UBI_VOLUME_RESIZED:
167 case UBI_VOLUME_RENAMED: 168 case UBI_VOLUME_RENAMED:
168 if (ubi_update_fastmap(ubi)) { 169 ret = ubi_update_fastmap(ubi);
169 ubi_err(ubi, "Unable to update fastmap!"); 170 if (ret)
170 ubi_ro_mode(ubi); 171 ubi_msg(ubi, "Unable to write a new fastmap: %i", ret);
171 }
172 } 172 }
173#endif 173
174 return blocking_notifier_call_chain(&ubi_notifiers, ntype, &nt); 174 return blocking_notifier_call_chain(&ubi_notifiers, ntype, &nt);
175} 175}
176 176
@@ -950,8 +950,10 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
950 if (ubi->fm_pool.max_size < UBI_FM_MIN_POOL_SIZE) 950 if (ubi->fm_pool.max_size < UBI_FM_MIN_POOL_SIZE)
951 ubi->fm_pool.max_size = UBI_FM_MIN_POOL_SIZE; 951 ubi->fm_pool.max_size = UBI_FM_MIN_POOL_SIZE;
952 952
953 ubi->fm_wl_pool.max_size = UBI_FM_WL_POOL_SIZE; 953 ubi->fm_wl_pool.max_size = ubi->fm_pool.max_size / 2;
954 ubi->fm_disabled = !fm_autoconvert; 954 ubi->fm_disabled = !fm_autoconvert;
955 if (fm_debug)
956 ubi_enable_dbg_chk_fastmap(ubi);
955 957
956 if (!ubi->fm_disabled && (int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd) 958 if (!ubi->fm_disabled && (int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd)
957 <= UBI_FM_MAX_START) { 959 <= UBI_FM_MAX_START) {
@@ -970,8 +972,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
970 mutex_init(&ubi->ckvol_mutex); 972 mutex_init(&ubi->ckvol_mutex);
971 mutex_init(&ubi->device_mutex); 973 mutex_init(&ubi->device_mutex);
972 spin_lock_init(&ubi->volumes_lock); 974 spin_lock_init(&ubi->volumes_lock);
973 mutex_init(&ubi->fm_mutex); 975 init_rwsem(&ubi->fm_protect);
974 init_rwsem(&ubi->fm_sem); 976 init_rwsem(&ubi->fm_eba_sem);
975 977
976 ubi_msg(ubi, "attaching mtd%d", mtd->index); 978 ubi_msg(ubi, "attaching mtd%d", mtd->index);
977 979
@@ -1115,8 +1117,11 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1115 ubi_msg(ubi, "detaching mtd%d", ubi->mtd->index); 1117 ubi_msg(ubi, "detaching mtd%d", ubi->mtd->index);
1116#ifdef CONFIG_MTD_UBI_FASTMAP 1118#ifdef CONFIG_MTD_UBI_FASTMAP
1117 /* If we don't write a new fastmap at detach time we lose all 1119 /* If we don't write a new fastmap at detach time we lose all
1118 * EC updates that have been made since the last written fastmap. */ 1120 * EC updates that have been made since the last written fastmap.
1119 ubi_update_fastmap(ubi); 1121 * In case of fastmap debugging we omit the update to simulate an
1122 * unclean shutdown. */
1123 if (!ubi_dbg_chk_fastmap(ubi))
1124 ubi_update_fastmap(ubi);
1120#endif 1125#endif
1121 /* 1126 /*
1122 * Before freeing anything, we have to stop the background thread to 1127 * Before freeing anything, we have to stop the background thread to
@@ -1501,6 +1506,8 @@ MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|pa
1501#ifdef CONFIG_MTD_UBI_FASTMAP 1506#ifdef CONFIG_MTD_UBI_FASTMAP
1502module_param(fm_autoconvert, bool, 0644); 1507module_param(fm_autoconvert, bool, 0644);
1503MODULE_PARM_DESC(fm_autoconvert, "Set this parameter to enable fastmap automatically on images without a fastmap."); 1508MODULE_PARM_DESC(fm_autoconvert, "Set this parameter to enable fastmap automatically on images without a fastmap.");
1509module_param(fm_debug, bool, 0);
1510MODULE_PARM_DESC(fm_debug, "Set this parameter to enable fastmap debugging by default. Warning, this will make fastmap slow!");
1504#endif 1511#endif
1505MODULE_VERSION(__stringify(UBI_VERSION)); 1512MODULE_VERSION(__stringify(UBI_VERSION));
1506MODULE_DESCRIPTION("UBI - Unsorted Block Images"); 1513MODULE_DESCRIPTION("UBI - Unsorted Block Images");
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index d647e504f9b1..d16fccf79179 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -455,7 +455,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
455 /* Validate the request */ 455 /* Validate the request */
456 err = -EINVAL; 456 err = -EINVAL;
457 if (req.lnum < 0 || req.lnum >= vol->reserved_pebs || 457 if (req.lnum < 0 || req.lnum >= vol->reserved_pebs ||
458 req.bytes < 0 || req.lnum >= vol->usable_leb_size) 458 req.bytes < 0 || req.bytes > vol->usable_leb_size)
459 break; 459 break;
460 460
461 err = get_exclusive(desc); 461 err = get_exclusive(desc);
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
index 7335c9ff9d99..b077e43b5ba9 100644
--- a/drivers/mtd/ubi/debug.c
+++ b/drivers/mtd/ubi/debug.c
@@ -263,7 +263,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
263 struct dentry *dent = file->f_path.dentry; 263 struct dentry *dent = file->f_path.dentry;
264 struct ubi_device *ubi; 264 struct ubi_device *ubi;
265 struct ubi_debug_info *d; 265 struct ubi_debug_info *d;
266 char buf[3]; 266 char buf[8];
267 int val; 267 int val;
268 268
269 ubi = ubi_get_device(ubi_num); 269 ubi = ubi_get_device(ubi_num);
@@ -275,12 +275,30 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
275 val = d->chk_gen; 275 val = d->chk_gen;
276 else if (dent == d->dfs_chk_io) 276 else if (dent == d->dfs_chk_io)
277 val = d->chk_io; 277 val = d->chk_io;
278 else if (dent == d->dfs_chk_fastmap)
279 val = d->chk_fastmap;
278 else if (dent == d->dfs_disable_bgt) 280 else if (dent == d->dfs_disable_bgt)
279 val = d->disable_bgt; 281 val = d->disable_bgt;
280 else if (dent == d->dfs_emulate_bitflips) 282 else if (dent == d->dfs_emulate_bitflips)
281 val = d->emulate_bitflips; 283 val = d->emulate_bitflips;
282 else if (dent == d->dfs_emulate_io_failures) 284 else if (dent == d->dfs_emulate_io_failures)
283 val = d->emulate_io_failures; 285 val = d->emulate_io_failures;
286 else if (dent == d->dfs_emulate_power_cut) {
287 snprintf(buf, sizeof(buf), "%u\n", d->emulate_power_cut);
288 count = simple_read_from_buffer(user_buf, count, ppos,
289 buf, strlen(buf));
290 goto out;
291 } else if (dent == d->dfs_power_cut_min) {
292 snprintf(buf, sizeof(buf), "%u\n", d->power_cut_min);
293 count = simple_read_from_buffer(user_buf, count, ppos,
294 buf, strlen(buf));
295 goto out;
296 } else if (dent == d->dfs_power_cut_max) {
297 snprintf(buf, sizeof(buf), "%u\n", d->power_cut_max);
298 count = simple_read_from_buffer(user_buf, count, ppos,
299 buf, strlen(buf));
300 goto out;
301 }
284 else { 302 else {
285 count = -EINVAL; 303 count = -EINVAL;
286 goto out; 304 goto out;
@@ -309,7 +327,7 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
309 struct ubi_device *ubi; 327 struct ubi_device *ubi;
310 struct ubi_debug_info *d; 328 struct ubi_debug_info *d;
311 size_t buf_size; 329 size_t buf_size;
312 char buf[8]; 330 char buf[8] = {0};
313 int val; 331 int val;
314 332
315 ubi = ubi_get_device(ubi_num); 333 ubi = ubi_get_device(ubi_num);
@@ -323,6 +341,21 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
323 goto out; 341 goto out;
324 } 342 }
325 343
344 if (dent == d->dfs_power_cut_min) {
345 if (kstrtouint(buf, 0, &d->power_cut_min) != 0)
346 count = -EINVAL;
347 goto out;
348 } else if (dent == d->dfs_power_cut_max) {
349 if (kstrtouint(buf, 0, &d->power_cut_max) != 0)
350 count = -EINVAL;
351 goto out;
352 } else if (dent == d->dfs_emulate_power_cut) {
353 if (kstrtoint(buf, 0, &val) != 0)
354 count = -EINVAL;
355 d->emulate_power_cut = val;
356 goto out;
357 }
358
326 if (buf[0] == '1') 359 if (buf[0] == '1')
327 val = 1; 360 val = 1;
328 else if (buf[0] == '0') 361 else if (buf[0] == '0')
@@ -336,6 +369,8 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
336 d->chk_gen = val; 369 d->chk_gen = val;
337 else if (dent == d->dfs_chk_io) 370 else if (dent == d->dfs_chk_io)
338 d->chk_io = val; 371 d->chk_io = val;
372 else if (dent == d->dfs_chk_fastmap)
373 d->chk_fastmap = val;
339 else if (dent == d->dfs_disable_bgt) 374 else if (dent == d->dfs_disable_bgt)
340 d->disable_bgt = val; 375 d->disable_bgt = val;
341 else if (dent == d->dfs_emulate_bitflips) 376 else if (dent == d->dfs_emulate_bitflips)
@@ -406,6 +441,13 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
406 goto out_remove; 441 goto out_remove;
407 d->dfs_chk_io = dent; 442 d->dfs_chk_io = dent;
408 443
444 fname = "chk_fastmap";
445 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
446 &dfs_fops);
447 if (IS_ERR_OR_NULL(dent))
448 goto out_remove;
449 d->dfs_chk_fastmap = dent;
450
409 fname = "tst_disable_bgt"; 451 fname = "tst_disable_bgt";
410 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, 452 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
411 &dfs_fops); 453 &dfs_fops);
@@ -427,6 +469,27 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
427 goto out_remove; 469 goto out_remove;
428 d->dfs_emulate_io_failures = dent; 470 d->dfs_emulate_io_failures = dent;
429 471
472 fname = "tst_emulate_power_cut";
473 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
474 &dfs_fops);
475 if (IS_ERR_OR_NULL(dent))
476 goto out_remove;
477 d->dfs_emulate_power_cut = dent;
478
479 fname = "tst_emulate_power_cut_min";
480 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
481 &dfs_fops);
482 if (IS_ERR_OR_NULL(dent))
483 goto out_remove;
484 d->dfs_power_cut_min = dent;
485
486 fname = "tst_emulate_power_cut_max";
487 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
488 &dfs_fops);
489 if (IS_ERR_OR_NULL(dent))
490 goto out_remove;
491 d->dfs_power_cut_max = dent;
492
430 return 0; 493 return 0;
431 494
432out_remove: 495out_remove:
@@ -447,3 +510,36 @@ void ubi_debugfs_exit_dev(struct ubi_device *ubi)
447 if (IS_ENABLED(CONFIG_DEBUG_FS)) 510 if (IS_ENABLED(CONFIG_DEBUG_FS))
448 debugfs_remove_recursive(ubi->dbg.dfs_dir); 511 debugfs_remove_recursive(ubi->dbg.dfs_dir);
449} 512}
513
514/**
515 * ubi_dbg_power_cut - emulate a power cut if it is time to do so
516 * @ubi: UBI device description object
517 * @caller: Flags set to indicate from where the function is being called
518 *
519 * Returns non-zero if a power cut was emulated, zero if not.
520 */
521int ubi_dbg_power_cut(struct ubi_device *ubi, int caller)
522{
523 unsigned int range;
524
525 if ((ubi->dbg.emulate_power_cut & caller) == 0)
526 return 0;
527
528 if (ubi->dbg.power_cut_counter == 0) {
529 ubi->dbg.power_cut_counter = ubi->dbg.power_cut_min;
530
531 if (ubi->dbg.power_cut_max > ubi->dbg.power_cut_min) {
532 range = ubi->dbg.power_cut_max - ubi->dbg.power_cut_min;
533 ubi->dbg.power_cut_counter += prandom_u32() % range;
534 }
535 return 0;
536 }
537
538 ubi->dbg.power_cut_counter--;
539 if (ubi->dbg.power_cut_counter)
540 return 0;
541
542 ubi_msg(ubi, "XXXXXXXXXXXXXXX emulating a power cut XXXXXXXXXXXXXXXX");
543 ubi_ro_mode(ubi);
544 return 1;
545}
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index cba89fcd1587..eb8985e5c178 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -127,4 +127,16 @@ static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi)
127{ 127{
128 return ubi->dbg.chk_gen; 128 return ubi->dbg.chk_gen;
129} 129}
130
131static inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi)
132{
133 return ubi->dbg.chk_fastmap;
134}
135
136static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi)
137{
138 ubi->dbg.chk_fastmap = 1;
139}
140
141int ubi_dbg_power_cut(struct ubi_device *ubi, int caller);
130#endif /* !__UBI_DEBUG_H__ */ 142#endif /* !__UBI_DEBUG_H__ */
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 16e34b37d134..51bca035cd83 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -340,9 +340,9 @@ int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
340 340
341 dbg_eba("erase LEB %d:%d, PEB %d", vol_id, lnum, pnum); 341 dbg_eba("erase LEB %d:%d, PEB %d", vol_id, lnum, pnum);
342 342
343 down_read(&ubi->fm_sem); 343 down_read(&ubi->fm_eba_sem);
344 vol->eba_tbl[lnum] = UBI_LEB_UNMAPPED; 344 vol->eba_tbl[lnum] = UBI_LEB_UNMAPPED;
345 up_read(&ubi->fm_sem); 345 up_read(&ubi->fm_eba_sem);
346 err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 0); 346 err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 0);
347 347
348out_unlock: 348out_unlock:
@@ -567,6 +567,7 @@ retry:
567 new_pnum = ubi_wl_get_peb(ubi); 567 new_pnum = ubi_wl_get_peb(ubi);
568 if (new_pnum < 0) { 568 if (new_pnum < 0) {
569 ubi_free_vid_hdr(ubi, vid_hdr); 569 ubi_free_vid_hdr(ubi, vid_hdr);
570 up_read(&ubi->fm_eba_sem);
570 return new_pnum; 571 return new_pnum;
571 } 572 }
572 573
@@ -577,13 +578,16 @@ retry:
577 if (err && err != UBI_IO_BITFLIPS) { 578 if (err && err != UBI_IO_BITFLIPS) {
578 if (err > 0) 579 if (err > 0)
579 err = -EIO; 580 err = -EIO;
581 up_read(&ubi->fm_eba_sem);
580 goto out_put; 582 goto out_put;
581 } 583 }
582 584
583 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); 585 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
584 err = ubi_io_write_vid_hdr(ubi, new_pnum, vid_hdr); 586 err = ubi_io_write_vid_hdr(ubi, new_pnum, vid_hdr);
585 if (err) 587 if (err) {
588 up_read(&ubi->fm_eba_sem);
586 goto write_error; 589 goto write_error;
590 }
587 591
588 data_size = offset + len; 592 data_size = offset + len;
589 mutex_lock(&ubi->buf_mutex); 593 mutex_lock(&ubi->buf_mutex);
@@ -592,8 +596,10 @@ retry:
592 /* Read everything before the area where the write failure happened */ 596 /* Read everything before the area where the write failure happened */
593 if (offset > 0) { 597 if (offset > 0) {
594 err = ubi_io_read_data(ubi, ubi->peb_buf, pnum, 0, offset); 598 err = ubi_io_read_data(ubi, ubi->peb_buf, pnum, 0, offset);
595 if (err && err != UBI_IO_BITFLIPS) 599 if (err && err != UBI_IO_BITFLIPS) {
600 up_read(&ubi->fm_eba_sem);
596 goto out_unlock; 601 goto out_unlock;
602 }
597 } 603 }
598 604
599 memcpy(ubi->peb_buf + offset, buf, len); 605 memcpy(ubi->peb_buf + offset, buf, len);
@@ -601,15 +607,15 @@ retry:
601 err = ubi_io_write_data(ubi, ubi->peb_buf, new_pnum, 0, data_size); 607 err = ubi_io_write_data(ubi, ubi->peb_buf, new_pnum, 0, data_size);
602 if (err) { 608 if (err) {
603 mutex_unlock(&ubi->buf_mutex); 609 mutex_unlock(&ubi->buf_mutex);
610 up_read(&ubi->fm_eba_sem);
604 goto write_error; 611 goto write_error;
605 } 612 }
606 613
607 mutex_unlock(&ubi->buf_mutex); 614 mutex_unlock(&ubi->buf_mutex);
608 ubi_free_vid_hdr(ubi, vid_hdr); 615 ubi_free_vid_hdr(ubi, vid_hdr);
609 616
610 down_read(&ubi->fm_sem);
611 vol->eba_tbl[lnum] = new_pnum; 617 vol->eba_tbl[lnum] = new_pnum;
612 up_read(&ubi->fm_sem); 618 up_read(&ubi->fm_eba_sem);
613 ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1); 619 ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1);
614 620
615 ubi_msg(ubi, "data was successfully recovered"); 621 ubi_msg(ubi, "data was successfully recovered");
@@ -704,6 +710,7 @@ retry:
704 if (pnum < 0) { 710 if (pnum < 0) {
705 ubi_free_vid_hdr(ubi, vid_hdr); 711 ubi_free_vid_hdr(ubi, vid_hdr);
706 leb_write_unlock(ubi, vol_id, lnum); 712 leb_write_unlock(ubi, vol_id, lnum);
713 up_read(&ubi->fm_eba_sem);
707 return pnum; 714 return pnum;
708 } 715 }
709 716
@@ -714,6 +721,7 @@ retry:
714 if (err) { 721 if (err) {
715 ubi_warn(ubi, "failed to write VID header to LEB %d:%d, PEB %d", 722 ubi_warn(ubi, "failed to write VID header to LEB %d:%d, PEB %d",
716 vol_id, lnum, pnum); 723 vol_id, lnum, pnum);
724 up_read(&ubi->fm_eba_sem);
717 goto write_error; 725 goto write_error;
718 } 726 }
719 727
@@ -722,13 +730,13 @@ retry:
722 if (err) { 730 if (err) {
723 ubi_warn(ubi, "failed to write %d bytes at offset %d of LEB %d:%d, PEB %d", 731 ubi_warn(ubi, "failed to write %d bytes at offset %d of LEB %d:%d, PEB %d",
724 len, offset, vol_id, lnum, pnum); 732 len, offset, vol_id, lnum, pnum);
733 up_read(&ubi->fm_eba_sem);
725 goto write_error; 734 goto write_error;
726 } 735 }
727 } 736 }
728 737
729 down_read(&ubi->fm_sem);
730 vol->eba_tbl[lnum] = pnum; 738 vol->eba_tbl[lnum] = pnum;
731 up_read(&ubi->fm_sem); 739 up_read(&ubi->fm_eba_sem);
732 740
733 leb_write_unlock(ubi, vol_id, lnum); 741 leb_write_unlock(ubi, vol_id, lnum);
734 ubi_free_vid_hdr(ubi, vid_hdr); 742 ubi_free_vid_hdr(ubi, vid_hdr);
@@ -825,6 +833,7 @@ retry:
825 if (pnum < 0) { 833 if (pnum < 0) {
826 ubi_free_vid_hdr(ubi, vid_hdr); 834 ubi_free_vid_hdr(ubi, vid_hdr);
827 leb_write_unlock(ubi, vol_id, lnum); 835 leb_write_unlock(ubi, vol_id, lnum);
836 up_read(&ubi->fm_eba_sem);
828 return pnum; 837 return pnum;
829 } 838 }
830 839
@@ -835,6 +844,7 @@ retry:
835 if (err) { 844 if (err) {
836 ubi_warn(ubi, "failed to write VID header to LEB %d:%d, PEB %d", 845 ubi_warn(ubi, "failed to write VID header to LEB %d:%d, PEB %d",
837 vol_id, lnum, pnum); 846 vol_id, lnum, pnum);
847 up_read(&ubi->fm_eba_sem);
838 goto write_error; 848 goto write_error;
839 } 849 }
840 850
@@ -842,13 +852,13 @@ retry:
842 if (err) { 852 if (err) {
843 ubi_warn(ubi, "failed to write %d bytes of data to PEB %d", 853 ubi_warn(ubi, "failed to write %d bytes of data to PEB %d",
844 len, pnum); 854 len, pnum);
855 up_read(&ubi->fm_eba_sem);
845 goto write_error; 856 goto write_error;
846 } 857 }
847 858
848 ubi_assert(vol->eba_tbl[lnum] < 0); 859 ubi_assert(vol->eba_tbl[lnum] < 0);
849 down_read(&ubi->fm_sem);
850 vol->eba_tbl[lnum] = pnum; 860 vol->eba_tbl[lnum] = pnum;
851 up_read(&ubi->fm_sem); 861 up_read(&ubi->fm_eba_sem);
852 862
853 leb_write_unlock(ubi, vol_id, lnum); 863 leb_write_unlock(ubi, vol_id, lnum);
854 ubi_free_vid_hdr(ubi, vid_hdr); 864 ubi_free_vid_hdr(ubi, vid_hdr);
@@ -900,7 +910,7 @@ write_error:
900int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, 910int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
901 int lnum, const void *buf, int len) 911 int lnum, const void *buf, int len)
902{ 912{
903 int err, pnum, tries = 0, vol_id = vol->vol_id; 913 int err, pnum, old_pnum, tries = 0, vol_id = vol->vol_id;
904 struct ubi_vid_hdr *vid_hdr; 914 struct ubi_vid_hdr *vid_hdr;
905 uint32_t crc; 915 uint32_t crc;
906 916
@@ -943,6 +953,7 @@ retry:
943 pnum = ubi_wl_get_peb(ubi); 953 pnum = ubi_wl_get_peb(ubi);
944 if (pnum < 0) { 954 if (pnum < 0) {
945 err = pnum; 955 err = pnum;
956 up_read(&ubi->fm_eba_sem);
946 goto out_leb_unlock; 957 goto out_leb_unlock;
947 } 958 }
948 959
@@ -953,6 +964,7 @@ retry:
953 if (err) { 964 if (err) {
954 ubi_warn(ubi, "failed to write VID header to LEB %d:%d, PEB %d", 965 ubi_warn(ubi, "failed to write VID header to LEB %d:%d, PEB %d",
955 vol_id, lnum, pnum); 966 vol_id, lnum, pnum);
967 up_read(&ubi->fm_eba_sem);
956 goto write_error; 968 goto write_error;
957 } 969 }
958 970
@@ -960,19 +972,20 @@ retry:
960 if (err) { 972 if (err) {
961 ubi_warn(ubi, "failed to write %d bytes of data to PEB %d", 973 ubi_warn(ubi, "failed to write %d bytes of data to PEB %d",
962 len, pnum); 974 len, pnum);
975 up_read(&ubi->fm_eba_sem);
963 goto write_error; 976 goto write_error;
964 } 977 }
965 978
966 if (vol->eba_tbl[lnum] >= 0) { 979 old_pnum = vol->eba_tbl[lnum];
967 err = ubi_wl_put_peb(ubi, vol_id, lnum, vol->eba_tbl[lnum], 0); 980 vol->eba_tbl[lnum] = pnum;
981 up_read(&ubi->fm_eba_sem);
982
983 if (old_pnum >= 0) {
984 err = ubi_wl_put_peb(ubi, vol_id, lnum, old_pnum, 0);
968 if (err) 985 if (err)
969 goto out_leb_unlock; 986 goto out_leb_unlock;
970 } 987 }
971 988
972 down_read(&ubi->fm_sem);
973 vol->eba_tbl[lnum] = pnum;
974 up_read(&ubi->fm_sem);
975
976out_leb_unlock: 989out_leb_unlock:
977 leb_write_unlock(ubi, vol_id, lnum); 990 leb_write_unlock(ubi, vol_id, lnum);
978out_mutex: 991out_mutex:
@@ -1218,9 +1231,9 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
1218 } 1231 }
1219 1232
1220 ubi_assert(vol->eba_tbl[lnum] == from); 1233 ubi_assert(vol->eba_tbl[lnum] == from);
1221 down_read(&ubi->fm_sem); 1234 down_read(&ubi->fm_eba_sem);
1222 vol->eba_tbl[lnum] = to; 1235 vol->eba_tbl[lnum] = to;
1223 up_read(&ubi->fm_sem); 1236 up_read(&ubi->fm_eba_sem);
1224 1237
1225out_unlock_buf: 1238out_unlock_buf:
1226 mutex_unlock(&ubi->buf_mutex); 1239 mutex_unlock(&ubi->buf_mutex);
@@ -1419,7 +1432,8 @@ int ubi_eba_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
1419 * during re-size. 1432 * during re-size.
1420 */ 1433 */
1421 ubi_move_aeb_to_list(av, aeb, &ai->erase); 1434 ubi_move_aeb_to_list(av, aeb, &ai->erase);
1422 vol->eba_tbl[aeb->lnum] = aeb->pnum; 1435 else
1436 vol->eba_tbl[aeb->lnum] = aeb->pnum;
1423 } 1437 }
1424 } 1438 }
1425 1439
diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
new file mode 100644
index 000000000000..b2a665398bca
--- /dev/null
+++ b/drivers/mtd/ubi/fastmap-wl.c
@@ -0,0 +1,362 @@
1/*
2 * Copyright (c) 2012 Linutronix GmbH
3 * Copyright (c) 2014 sigma star gmbh
4 * Author: Richard Weinberger <richard@nod.at>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 */
16
17/**
18 * update_fastmap_work_fn - calls ubi_update_fastmap from a work queue
19 * @wrk: the work description object
20 */
21static void update_fastmap_work_fn(struct work_struct *wrk)
22{
23 struct ubi_device *ubi = container_of(wrk, struct ubi_device, fm_work);
24
25 ubi_update_fastmap(ubi);
26 spin_lock(&ubi->wl_lock);
27 ubi->fm_work_scheduled = 0;
28 spin_unlock(&ubi->wl_lock);
29}
30
31/**
32 * find_anchor_wl_entry - find wear-leveling entry to used as anchor PEB.
33 * @root: the RB-tree where to look for
34 */
35static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root)
36{
37 struct rb_node *p;
38 struct ubi_wl_entry *e, *victim = NULL;
39 int max_ec = UBI_MAX_ERASECOUNTER;
40
41 ubi_rb_for_each_entry(p, e, root, u.rb) {
42 if (e->pnum < UBI_FM_MAX_START && e->ec < max_ec) {
43 victim = e;
44 max_ec = e->ec;
45 }
46 }
47
48 return victim;
49}
50
51/**
52 * return_unused_pool_pebs - returns unused PEB to the free tree.
53 * @ubi: UBI device description object
54 * @pool: fastmap pool description object
55 */
56static void return_unused_pool_pebs(struct ubi_device *ubi,
57 struct ubi_fm_pool *pool)
58{
59 int i;
60 struct ubi_wl_entry *e;
61
62 for (i = pool->used; i < pool->size; i++) {
63 e = ubi->lookuptbl[pool->pebs[i]];
64 wl_tree_add(e, &ubi->free);
65 ubi->free_count++;
66 }
67}
68
69static int anchor_pebs_avalible(struct rb_root *root)
70{
71 struct rb_node *p;
72 struct ubi_wl_entry *e;
73
74 ubi_rb_for_each_entry(p, e, root, u.rb)
75 if (e->pnum < UBI_FM_MAX_START)
76 return 1;
77
78 return 0;
79}
80
81/**
82 * ubi_wl_get_fm_peb - find a physical erase block with a given maximal number.
83 * @ubi: UBI device description object
84 * @anchor: This PEB will be used as anchor PEB by fastmap
85 *
86 * The function returns a physical erase block with a given maximal number
87 * and removes it from the wl subsystem.
88 * Must be called with wl_lock held!
89 */
90struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int anchor)
91{
92 struct ubi_wl_entry *e = NULL;
93
94 if (!ubi->free.rb_node || (ubi->free_count - ubi->beb_rsvd_pebs < 1))
95 goto out;
96
97 if (anchor)
98 e = find_anchor_wl_entry(&ubi->free);
99 else
100 e = find_mean_wl_entry(ubi, &ubi->free);
101
102 if (!e)
103 goto out;
104
105 self_check_in_wl_tree(ubi, e, &ubi->free);
106
107 /* remove it from the free list,
108 * the wl subsystem does no longer know this erase block */
109 rb_erase(&e->u.rb, &ubi->free);
110 ubi->free_count--;
111out:
112 return e;
113}
114
115/**
116 * ubi_refill_pools - refills all fastmap PEB pools.
117 * @ubi: UBI device description object
118 */
119void ubi_refill_pools(struct ubi_device *ubi)
120{
121 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool;
122 struct ubi_fm_pool *pool = &ubi->fm_pool;
123 struct ubi_wl_entry *e;
124 int enough;
125
126 spin_lock(&ubi->wl_lock);
127
128 return_unused_pool_pebs(ubi, wl_pool);
129 return_unused_pool_pebs(ubi, pool);
130
131 wl_pool->size = 0;
132 pool->size = 0;
133
134 for (;;) {
135 enough = 0;
136 if (pool->size < pool->max_size) {
137 if (!ubi->free.rb_node)
138 break;
139
140 e = wl_get_wle(ubi);
141 if (!e)
142 break;
143
144 pool->pebs[pool->size] = e->pnum;
145 pool->size++;
146 } else
147 enough++;
148
149 if (wl_pool->size < wl_pool->max_size) {
150 if (!ubi->free.rb_node ||
151 (ubi->free_count - ubi->beb_rsvd_pebs < 5))
152 break;
153
154 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
155 self_check_in_wl_tree(ubi, e, &ubi->free);
156 rb_erase(&e->u.rb, &ubi->free);
157 ubi->free_count--;
158
159 wl_pool->pebs[wl_pool->size] = e->pnum;
160 wl_pool->size++;
161 } else
162 enough++;
163
164 if (enough == 2)
165 break;
166 }
167
168 wl_pool->used = 0;
169 pool->used = 0;
170
171 spin_unlock(&ubi->wl_lock);
172}
173
174/**
175 * ubi_wl_get_peb - get a physical eraseblock.
176 * @ubi: UBI device description object
177 *
178 * This function returns a physical eraseblock in case of success and a
179 * negative error code in case of failure.
180 * Returns with ubi->fm_eba_sem held in read mode!
181 */
182int ubi_wl_get_peb(struct ubi_device *ubi)
183{
184 int ret, retried = 0;
185 struct ubi_fm_pool *pool = &ubi->fm_pool;
186 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool;
187
188again:
189 down_read(&ubi->fm_eba_sem);
190 spin_lock(&ubi->wl_lock);
191
192 /* We check here also for the WL pool because at this point we can
193 * refill the WL pool synchronous. */
194 if (pool->used == pool->size || wl_pool->used == wl_pool->size) {
195 spin_unlock(&ubi->wl_lock);
196 up_read(&ubi->fm_eba_sem);
197 ret = ubi_update_fastmap(ubi);
198 if (ret) {
199 ubi_msg(ubi, "Unable to write a new fastmap: %i", ret);
200 down_read(&ubi->fm_eba_sem);
201 return -ENOSPC;
202 }
203 down_read(&ubi->fm_eba_sem);
204 spin_lock(&ubi->wl_lock);
205 }
206
207 if (pool->used == pool->size) {
208 spin_unlock(&ubi->wl_lock);
209 if (retried) {
210 ubi_err(ubi, "Unable to get a free PEB from user WL pool");
211 ret = -ENOSPC;
212 goto out;
213 }
214 retried = 1;
215 up_read(&ubi->fm_eba_sem);
216 goto again;
217 }
218
219 ubi_assert(pool->used < pool->size);
220 ret = pool->pebs[pool->used++];
221 prot_queue_add(ubi, ubi->lookuptbl[ret]);
222 spin_unlock(&ubi->wl_lock);
223out:
224 return ret;
225}
226
227/* get_peb_for_wl - returns a PEB to be used internally by the WL sub-system.
228 *
229 * @ubi: UBI device description object
230 */
231static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)
232{
233 struct ubi_fm_pool *pool = &ubi->fm_wl_pool;
234 int pnum;
235
236 if (pool->used == pool->size) {
237 /* We cannot update the fastmap here because this
238 * function is called in atomic context.
239 * Let's fail here and refill/update it as soon as possible. */
240 if (!ubi->fm_work_scheduled) {
241 ubi->fm_work_scheduled = 1;
242 schedule_work(&ubi->fm_work);
243 }
244 return NULL;
245 }
246
247 pnum = pool->pebs[pool->used++];
248 return ubi->lookuptbl[pnum];
249}
250
251/**
252 * ubi_ensure_anchor_pebs - schedule wear-leveling to produce an anchor PEB.
253 * @ubi: UBI device description object
254 */
255int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
256{
257 struct ubi_work *wrk;
258
259 spin_lock(&ubi->wl_lock);
260 if (ubi->wl_scheduled) {
261 spin_unlock(&ubi->wl_lock);
262 return 0;
263 }
264 ubi->wl_scheduled = 1;
265 spin_unlock(&ubi->wl_lock);
266
267 wrk = kmalloc(sizeof(struct ubi_work), GFP_NOFS);
268 if (!wrk) {
269 spin_lock(&ubi->wl_lock);
270 ubi->wl_scheduled = 0;
271 spin_unlock(&ubi->wl_lock);
272 return -ENOMEM;
273 }
274
275 wrk->anchor = 1;
276 wrk->func = &wear_leveling_worker;
277 schedule_ubi_work(ubi, wrk);
278 return 0;
279}
280
281/**
282 * ubi_wl_put_fm_peb - returns a PEB used in a fastmap to the wear-leveling
283 * sub-system.
284 * see: ubi_wl_put_peb()
285 *
286 * @ubi: UBI device description object
287 * @fm_e: physical eraseblock to return
288 * @lnum: the last used logical eraseblock number for the PEB
289 * @torture: if this physical eraseblock has to be tortured
290 */
291int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *fm_e,
292 int lnum, int torture)
293{
294 struct ubi_wl_entry *e;
295 int vol_id, pnum = fm_e->pnum;
296
297 dbg_wl("PEB %d", pnum);
298
299 ubi_assert(pnum >= 0);
300 ubi_assert(pnum < ubi->peb_count);
301
302 spin_lock(&ubi->wl_lock);
303 e = ubi->lookuptbl[pnum];
304
305 /* This can happen if we recovered from a fastmap the very
306 * first time and writing now a new one. In this case the wl system
307 * has never seen any PEB used by the original fastmap.
308 */
309 if (!e) {
310 e = fm_e;
311 ubi_assert(e->ec >= 0);
312 ubi->lookuptbl[pnum] = e;
313 }
314
315 spin_unlock(&ubi->wl_lock);
316
317 vol_id = lnum ? UBI_FM_DATA_VOLUME_ID : UBI_FM_SB_VOLUME_ID;
318 return schedule_erase(ubi, e, vol_id, lnum, torture);
319}
320
321/**
322 * ubi_is_erase_work - checks whether a work is erase work.
323 * @wrk: The work object to be checked
324 */
325int ubi_is_erase_work(struct ubi_work *wrk)
326{
327 return wrk->func == erase_worker;
328}
329
330static void ubi_fastmap_close(struct ubi_device *ubi)
331{
332 int i;
333
334 flush_work(&ubi->fm_work);
335 return_unused_pool_pebs(ubi, &ubi->fm_pool);
336 return_unused_pool_pebs(ubi, &ubi->fm_wl_pool);
337
338 if (ubi->fm) {
339 for (i = 0; i < ubi->fm->used_blocks; i++)
340 kfree(ubi->fm->e[i]);
341 }
342 kfree(ubi->fm);
343}
344
345/**
346 * may_reserve_for_fm - tests whether a PEB shall be reserved for fastmap.
347 * See find_mean_wl_entry()
348 *
349 * @ubi: UBI device description object
350 * @e: physical eraseblock to return
351 * @root: RB tree to test against.
352 */
353static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi,
354 struct ubi_wl_entry *e,
355 struct rb_root *root) {
356 if (e && !ubi->fm_disabled && !ubi->fm &&
357 e->pnum < UBI_FM_MAX_START)
358 e = rb_entry(rb_next(root->rb_node),
359 struct ubi_wl_entry, u.rb);
360
361 return e;
362}
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index db3defdfc3c0..02a6de2f53ee 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2012 Linutronix GmbH 2 * Copyright (c) 2012 Linutronix GmbH
3 * Copyright (c) 2014 sigma star gmbh
3 * Author: Richard Weinberger <richard@nod.at> 4 * Author: Richard Weinberger <richard@nod.at>
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
@@ -17,6 +18,69 @@
17#include "ubi.h" 18#include "ubi.h"
18 19
19/** 20/**
21 * init_seen - allocate memory for used for debugging.
22 * @ubi: UBI device description object
23 */
24static inline int *init_seen(struct ubi_device *ubi)
25{
26 int *ret;
27
28 if (!ubi_dbg_chk_fastmap(ubi))
29 return NULL;
30
31 ret = kcalloc(ubi->peb_count, sizeof(int), GFP_KERNEL);
32 if (!ret)
33 return ERR_PTR(-ENOMEM);
34
35 return ret;
36}
37
38/**
39 * free_seen - free the seen logic integer array.
40 * @seen: integer array of @ubi->peb_count size
41 */
42static inline void free_seen(int *seen)
43{
44 kfree(seen);
45}
46
47/**
48 * set_seen - mark a PEB as seen.
49 * @ubi: UBI device description object
50 * @pnum: The PEB to be makred as seen
51 * @seen: integer array of @ubi->peb_count size
52 */
53static inline void set_seen(struct ubi_device *ubi, int pnum, int *seen)
54{
55 if (!ubi_dbg_chk_fastmap(ubi) || !seen)
56 return;
57
58 seen[pnum] = 1;
59}
60
61/**
62 * self_check_seen - check whether all PEB have been seen by fastmap.
63 * @ubi: UBI device description object
64 * @seen: integer array of @ubi->peb_count size
65 */
66static int self_check_seen(struct ubi_device *ubi, int *seen)
67{
68 int pnum, ret = 0;
69
70 if (!ubi_dbg_chk_fastmap(ubi) || !seen)
71 return 0;
72
73 for (pnum = 0; pnum < ubi->peb_count; pnum++) {
74 if (!seen[pnum] && ubi->lookuptbl[pnum]) {
75 ubi_err(ubi, "self-check failed for PEB %d, fastmap didn't see it", pnum);
76 ret = -EINVAL;
77 }
78 }
79
80 return ret;
81}
82
83/**
20 * ubi_calc_fm_size - calculates the fastmap size in bytes for an UBI device. 84 * ubi_calc_fm_size - calculates the fastmap size in bytes for an UBI device.
21 * @ubi: UBI device description object 85 * @ubi: UBI device description object
22 */ 86 */
@@ -136,14 +200,15 @@ static struct ubi_ainf_volume *add_vol(struct ubi_attach_info *ai, int vol_id,
136 if (!av) 200 if (!av)
137 goto out; 201 goto out;
138 202
139 av->highest_lnum = av->leb_count = 0; 203 av->highest_lnum = av->leb_count = av->used_ebs = 0;
140 av->vol_id = vol_id; 204 av->vol_id = vol_id;
141 av->used_ebs = used_ebs;
142 av->data_pad = data_pad; 205 av->data_pad = data_pad;
143 av->last_data_size = last_eb_bytes; 206 av->last_data_size = last_eb_bytes;
144 av->compat = 0; 207 av->compat = 0;
145 av->vol_type = vol_type; 208 av->vol_type = vol_type;
146 av->root = RB_ROOT; 209 av->root = RB_ROOT;
210 if (av->vol_type == UBI_STATIC_VOLUME)
211 av->used_ebs = used_ebs;
147 212
148 dbg_bld("found volume (ID %i)", vol_id); 213 dbg_bld("found volume (ID %i)", vol_id);
149 214
@@ -362,6 +427,7 @@ static void unmap_peb(struct ubi_attach_info *ai, int pnum)
362 aeb = rb_entry(node2, struct ubi_ainf_peb, u.rb); 427 aeb = rb_entry(node2, struct ubi_ainf_peb, u.rb);
363 if (aeb->pnum == pnum) { 428 if (aeb->pnum == pnum) {
364 rb_erase(&aeb->u.rb, &av->root); 429 rb_erase(&aeb->u.rb, &av->root);
430 av->leb_count--;
365 kmem_cache_free(ai->aeb_slab_cache, aeb); 431 kmem_cache_free(ai->aeb_slab_cache, aeb);
366 return; 432 return;
367 } 433 }
@@ -376,7 +442,6 @@ static void unmap_peb(struct ubi_attach_info *ai, int pnum)
376 * @pebs: an array of all PEB numbers in the to be scanned pool 442 * @pebs: an array of all PEB numbers in the to be scanned pool
377 * @pool_size: size of the pool (number of entries in @pebs) 443 * @pool_size: size of the pool (number of entries in @pebs)
378 * @max_sqnum: pointer to the maximal sequence number 444 * @max_sqnum: pointer to the maximal sequence number
379 * @eba_orphans: list of PEBs which need to be scanned
380 * @free: list of PEBs which are most likely free (and go into @ai->free) 445 * @free: list of PEBs which are most likely free (and go into @ai->free)
381 * 446 *
382 * Returns 0 on success, if the pool is unusable UBI_BAD_FASTMAP is returned. 447 * Returns 0 on success, if the pool is unusable UBI_BAD_FASTMAP is returned.
@@ -384,12 +449,12 @@ static void unmap_peb(struct ubi_attach_info *ai, int pnum)
384 */ 449 */
385static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai, 450static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
386 int *pebs, int pool_size, unsigned long long *max_sqnum, 451 int *pebs, int pool_size, unsigned long long *max_sqnum,
387 struct list_head *eba_orphans, struct list_head *free) 452 struct list_head *free)
388{ 453{
389 struct ubi_vid_hdr *vh; 454 struct ubi_vid_hdr *vh;
390 struct ubi_ec_hdr *ech; 455 struct ubi_ec_hdr *ech;
391 struct ubi_ainf_peb *new_aeb, *tmp_aeb; 456 struct ubi_ainf_peb *new_aeb;
392 int i, pnum, err, found_orphan, ret = 0; 457 int i, pnum, err, ret = 0;
393 458
394 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); 459 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
395 if (!ech) 460 if (!ech)
@@ -457,18 +522,6 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
457 if (err == UBI_IO_BITFLIPS) 522 if (err == UBI_IO_BITFLIPS)
458 scrub = 1; 523 scrub = 1;
459 524
460 found_orphan = 0;
461 list_for_each_entry(tmp_aeb, eba_orphans, u.list) {
462 if (tmp_aeb->pnum == pnum) {
463 found_orphan = 1;
464 break;
465 }
466 }
467 if (found_orphan) {
468 list_del(&tmp_aeb->u.list);
469 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
470 }
471
472 new_aeb = kmem_cache_alloc(ai->aeb_slab_cache, 525 new_aeb = kmem_cache_alloc(ai->aeb_slab_cache,
473 GFP_KERNEL); 526 GFP_KERNEL);
474 if (!new_aeb) { 527 if (!new_aeb) {
@@ -543,10 +596,9 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
543 struct ubi_attach_info *ai, 596 struct ubi_attach_info *ai,
544 struct ubi_fastmap_layout *fm) 597 struct ubi_fastmap_layout *fm)
545{ 598{
546 struct list_head used, eba_orphans, free; 599 struct list_head used, free;
547 struct ubi_ainf_volume *av; 600 struct ubi_ainf_volume *av;
548 struct ubi_ainf_peb *aeb, *tmp_aeb, *_tmp_aeb; 601 struct ubi_ainf_peb *aeb, *tmp_aeb, *_tmp_aeb;
549 struct ubi_ec_hdr *ech;
550 struct ubi_fm_sb *fmsb; 602 struct ubi_fm_sb *fmsb;
551 struct ubi_fm_hdr *fmhdr; 603 struct ubi_fm_hdr *fmhdr;
552 struct ubi_fm_scan_pool *fmpl1, *fmpl2; 604 struct ubi_fm_scan_pool *fmpl1, *fmpl2;
@@ -560,22 +612,8 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
560 612
561 INIT_LIST_HEAD(&used); 613 INIT_LIST_HEAD(&used);
562 INIT_LIST_HEAD(&free); 614 INIT_LIST_HEAD(&free);
563 INIT_LIST_HEAD(&eba_orphans);
564 INIT_LIST_HEAD(&ai->corr);
565 INIT_LIST_HEAD(&ai->free);
566 INIT_LIST_HEAD(&ai->erase);
567 INIT_LIST_HEAD(&ai->alien);
568 ai->volumes = RB_ROOT;
569 ai->min_ec = UBI_MAX_ERASECOUNTER; 615 ai->min_ec = UBI_MAX_ERASECOUNTER;
570 616
571 ai->aeb_slab_cache = kmem_cache_create("ubi_ainf_peb_slab",
572 sizeof(struct ubi_ainf_peb),
573 0, 0, NULL);
574 if (!ai->aeb_slab_cache) {
575 ret = -ENOMEM;
576 goto fail;
577 }
578
579 fmsb = (struct ubi_fm_sb *)(fm_raw); 617 fmsb = (struct ubi_fm_sb *)(fm_raw);
580 ai->max_sqnum = fmsb->sqnum; 618 ai->max_sqnum = fmsb->sqnum;
581 fm_pos += sizeof(struct ubi_fm_sb); 619 fm_pos += sizeof(struct ubi_fm_sb);
@@ -741,28 +779,9 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
741 } 779 }
742 } 780 }
743 781
744 /* This can happen if a PEB is already in an EBA known
745 * by this fastmap but the PEB itself is not in the used
746 * list.
747 * In this case the PEB can be within the fastmap pool
748 * or while writing the fastmap it was in the protection
749 * queue.
750 */
751 if (!aeb) { 782 if (!aeb) {
752 aeb = kmem_cache_alloc(ai->aeb_slab_cache, 783 ubi_err(ubi, "PEB %i is in EBA but not in used list", pnum);
753 GFP_KERNEL); 784 goto fail_bad;
754 if (!aeb) {
755 ret = -ENOMEM;
756
757 goto fail;
758 }
759
760 aeb->lnum = j;
761 aeb->pnum = be32_to_cpu(fm_eba->pnum[j]);
762 aeb->ec = -1;
763 aeb->scrub = aeb->copy_flag = aeb->sqnum = 0;
764 list_add_tail(&aeb->u.list, &eba_orphans);
765 continue;
766 } 785 }
767 786
768 aeb->lnum = j; 787 aeb->lnum = j;
@@ -775,49 +794,13 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
775 dbg_bld("inserting PEB:%i (LEB %i) to vol %i", 794 dbg_bld("inserting PEB:%i (LEB %i) to vol %i",
776 aeb->pnum, aeb->lnum, av->vol_id); 795 aeb->pnum, aeb->lnum, av->vol_id);
777 } 796 }
778
779 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
780 if (!ech) {
781 ret = -ENOMEM;
782 goto fail;
783 }
784
785 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans,
786 u.list) {
787 int err;
788
789 if (ubi_io_is_bad(ubi, tmp_aeb->pnum)) {
790 ubi_err(ubi, "bad PEB in fastmap EBA orphan list");
791 ret = UBI_BAD_FASTMAP;
792 kfree(ech);
793 goto fail;
794 }
795
796 err = ubi_io_read_ec_hdr(ubi, tmp_aeb->pnum, ech, 0);
797 if (err && err != UBI_IO_BITFLIPS) {
798 ubi_err(ubi, "unable to read EC header! PEB:%i err:%i",
799 tmp_aeb->pnum, err);
800 ret = err > 0 ? UBI_BAD_FASTMAP : err;
801 kfree(ech);
802
803 goto fail;
804 } else if (err == UBI_IO_BITFLIPS)
805 tmp_aeb->scrub = 1;
806
807 tmp_aeb->ec = be64_to_cpu(ech->ec);
808 assign_aeb_to_av(ai, tmp_aeb, av);
809 }
810
811 kfree(ech);
812 } 797 }
813 798
814 ret = scan_pool(ubi, ai, fmpl1->pebs, pool_size, &max_sqnum, 799 ret = scan_pool(ubi, ai, fmpl1->pebs, pool_size, &max_sqnum, &free);
815 &eba_orphans, &free);
816 if (ret) 800 if (ret)
817 goto fail; 801 goto fail;
818 802
819 ret = scan_pool(ubi, ai, fmpl2->pebs, wl_pool_size, &max_sqnum, 803 ret = scan_pool(ubi, ai, fmpl2->pebs, wl_pool_size, &max_sqnum, &free);
820 &eba_orphans, &free);
821 if (ret) 804 if (ret)
822 goto fail; 805 goto fail;
823 806
@@ -827,8 +810,9 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
827 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list) 810 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list)
828 list_move_tail(&tmp_aeb->u.list, &ai->free); 811 list_move_tail(&tmp_aeb->u.list, &ai->free);
829 812
830 ubi_assert(list_empty(&used)); 813 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &used, u.list)
831 ubi_assert(list_empty(&eba_orphans)); 814 list_move_tail(&tmp_aeb->u.list, &ai->erase);
815
832 ubi_assert(list_empty(&free)); 816 ubi_assert(list_empty(&free));
833 817
834 /* 818 /*
@@ -850,10 +834,6 @@ fail:
850 list_del(&tmp_aeb->u.list); 834 list_del(&tmp_aeb->u.list);
851 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb); 835 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
852 } 836 }
853 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans, u.list) {
854 list_del(&tmp_aeb->u.list);
855 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
856 }
857 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list) { 837 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list) {
858 list_del(&tmp_aeb->u.list); 838 list_del(&tmp_aeb->u.list);
859 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb); 839 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
@@ -884,7 +864,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
884 __be32 crc, tmp_crc; 864 __be32 crc, tmp_crc;
885 unsigned long long sqnum = 0; 865 unsigned long long sqnum = 0;
886 866
887 mutex_lock(&ubi->fm_mutex); 867 down_write(&ubi->fm_protect);
888 memset(ubi->fm_buf, 0, ubi->fm_size); 868 memset(ubi->fm_buf, 0, ubi->fm_size);
889 869
890 fmsb = kmalloc(sizeof(*fmsb), GFP_KERNEL); 870 fmsb = kmalloc(sizeof(*fmsb), GFP_KERNEL);
@@ -1075,7 +1055,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
1075 ubi_free_vid_hdr(ubi, vh); 1055 ubi_free_vid_hdr(ubi, vh);
1076 kfree(ech); 1056 kfree(ech);
1077out: 1057out:
1078 mutex_unlock(&ubi->fm_mutex); 1058 up_write(&ubi->fm_protect);
1079 if (ret == UBI_BAD_FASTMAP) 1059 if (ret == UBI_BAD_FASTMAP)
1080 ubi_err(ubi, "Attach by fastmap failed, doing a full scan!"); 1060 ubi_err(ubi, "Attach by fastmap failed, doing a full scan!");
1081 return ret; 1061 return ret;
@@ -1107,13 +1087,14 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1107 struct ubi_fm_ec *fec; 1087 struct ubi_fm_ec *fec;
1108 struct ubi_fm_volhdr *fvh; 1088 struct ubi_fm_volhdr *fvh;
1109 struct ubi_fm_eba *feba; 1089 struct ubi_fm_eba *feba;
1110 struct rb_node *node;
1111 struct ubi_wl_entry *wl_e; 1090 struct ubi_wl_entry *wl_e;
1112 struct ubi_volume *vol; 1091 struct ubi_volume *vol;
1113 struct ubi_vid_hdr *avhdr, *dvhdr; 1092 struct ubi_vid_hdr *avhdr, *dvhdr;
1114 struct ubi_work *ubi_wrk; 1093 struct ubi_work *ubi_wrk;
1094 struct rb_node *tmp_rb;
1115 int ret, i, j, free_peb_count, used_peb_count, vol_count; 1095 int ret, i, j, free_peb_count, used_peb_count, vol_count;
1116 int scrub_peb_count, erase_peb_count; 1096 int scrub_peb_count, erase_peb_count;
1097 int *seen_pebs = NULL;
1117 1098
1118 fm_raw = ubi->fm_buf; 1099 fm_raw = ubi->fm_buf;
1119 memset(ubi->fm_buf, 0, ubi->fm_size); 1100 memset(ubi->fm_buf, 0, ubi->fm_size);
@@ -1130,6 +1111,12 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1130 goto out_kfree; 1111 goto out_kfree;
1131 } 1112 }
1132 1113
1114 seen_pebs = init_seen(ubi);
1115 if (IS_ERR(seen_pebs)) {
1116 ret = PTR_ERR(seen_pebs);
1117 goto out_kfree;
1118 }
1119
1133 spin_lock(&ubi->volumes_lock); 1120 spin_lock(&ubi->volumes_lock);
1134 spin_lock(&ubi->wl_lock); 1121 spin_lock(&ubi->wl_lock);
1135 1122
@@ -1160,8 +1147,10 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1160 fmpl1->size = cpu_to_be16(ubi->fm_pool.size); 1147 fmpl1->size = cpu_to_be16(ubi->fm_pool.size);
1161 fmpl1->max_size = cpu_to_be16(ubi->fm_pool.max_size); 1148 fmpl1->max_size = cpu_to_be16(ubi->fm_pool.max_size);
1162 1149
1163 for (i = 0; i < ubi->fm_pool.size; i++) 1150 for (i = 0; i < ubi->fm_pool.size; i++) {
1164 fmpl1->pebs[i] = cpu_to_be32(ubi->fm_pool.pebs[i]); 1151 fmpl1->pebs[i] = cpu_to_be32(ubi->fm_pool.pebs[i]);
1152 set_seen(ubi, ubi->fm_pool.pebs[i], seen_pebs);
1153 }
1165 1154
1166 fmpl2 = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos); 1155 fmpl2 = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
1167 fm_pos += sizeof(*fmpl2); 1156 fm_pos += sizeof(*fmpl2);
@@ -1169,14 +1158,16 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1169 fmpl2->size = cpu_to_be16(ubi->fm_wl_pool.size); 1158 fmpl2->size = cpu_to_be16(ubi->fm_wl_pool.size);
1170 fmpl2->max_size = cpu_to_be16(ubi->fm_wl_pool.max_size); 1159 fmpl2->max_size = cpu_to_be16(ubi->fm_wl_pool.max_size);
1171 1160
1172 for (i = 0; i < ubi->fm_wl_pool.size; i++) 1161 for (i = 0; i < ubi->fm_wl_pool.size; i++) {
1173 fmpl2->pebs[i] = cpu_to_be32(ubi->fm_wl_pool.pebs[i]); 1162 fmpl2->pebs[i] = cpu_to_be32(ubi->fm_wl_pool.pebs[i]);
1163 set_seen(ubi, ubi->fm_wl_pool.pebs[i], seen_pebs);
1164 }
1174 1165
1175 for (node = rb_first(&ubi->free); node; node = rb_next(node)) { 1166 ubi_for_each_free_peb(ubi, wl_e, tmp_rb) {
1176 wl_e = rb_entry(node, struct ubi_wl_entry, u.rb);
1177 fec = (struct ubi_fm_ec *)(fm_raw + fm_pos); 1167 fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
1178 1168
1179 fec->pnum = cpu_to_be32(wl_e->pnum); 1169 fec->pnum = cpu_to_be32(wl_e->pnum);
1170 set_seen(ubi, wl_e->pnum, seen_pebs);
1180 fec->ec = cpu_to_be32(wl_e->ec); 1171 fec->ec = cpu_to_be32(wl_e->ec);
1181 1172
1182 free_peb_count++; 1173 free_peb_count++;
@@ -1185,11 +1176,11 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1185 } 1176 }
1186 fmh->free_peb_count = cpu_to_be32(free_peb_count); 1177 fmh->free_peb_count = cpu_to_be32(free_peb_count);
1187 1178
1188 for (node = rb_first(&ubi->used); node; node = rb_next(node)) { 1179 ubi_for_each_used_peb(ubi, wl_e, tmp_rb) {
1189 wl_e = rb_entry(node, struct ubi_wl_entry, u.rb);
1190 fec = (struct ubi_fm_ec *)(fm_raw + fm_pos); 1180 fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
1191 1181
1192 fec->pnum = cpu_to_be32(wl_e->pnum); 1182 fec->pnum = cpu_to_be32(wl_e->pnum);
1183 set_seen(ubi, wl_e->pnum, seen_pebs);
1193 fec->ec = cpu_to_be32(wl_e->ec); 1184 fec->ec = cpu_to_be32(wl_e->ec);
1194 1185
1195 used_peb_count++; 1186 used_peb_count++;
@@ -1197,25 +1188,24 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1197 ubi_assert(fm_pos <= ubi->fm_size); 1188 ubi_assert(fm_pos <= ubi->fm_size);
1198 } 1189 }
1199 1190
1200 for (i = 0; i < UBI_PROT_QUEUE_LEN; i++) { 1191 ubi_for_each_protected_peb(ubi, i, wl_e) {
1201 list_for_each_entry(wl_e, &ubi->pq[i], u.list) { 1192 fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
1202 fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
1203 1193
1204 fec->pnum = cpu_to_be32(wl_e->pnum); 1194 fec->pnum = cpu_to_be32(wl_e->pnum);
1205 fec->ec = cpu_to_be32(wl_e->ec); 1195 set_seen(ubi, wl_e->pnum, seen_pebs);
1196 fec->ec = cpu_to_be32(wl_e->ec);
1206 1197
1207 used_peb_count++; 1198 used_peb_count++;
1208 fm_pos += sizeof(*fec); 1199 fm_pos += sizeof(*fec);
1209 ubi_assert(fm_pos <= ubi->fm_size); 1200 ubi_assert(fm_pos <= ubi->fm_size);
1210 }
1211 } 1201 }
1212 fmh->used_peb_count = cpu_to_be32(used_peb_count); 1202 fmh->used_peb_count = cpu_to_be32(used_peb_count);
1213 1203
1214 for (node = rb_first(&ubi->scrub); node; node = rb_next(node)) { 1204 ubi_for_each_scrub_peb(ubi, wl_e, tmp_rb) {
1215 wl_e = rb_entry(node, struct ubi_wl_entry, u.rb);
1216 fec = (struct ubi_fm_ec *)(fm_raw + fm_pos); 1205 fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
1217 1206
1218 fec->pnum = cpu_to_be32(wl_e->pnum); 1207 fec->pnum = cpu_to_be32(wl_e->pnum);
1208 set_seen(ubi, wl_e->pnum, seen_pebs);
1219 fec->ec = cpu_to_be32(wl_e->ec); 1209 fec->ec = cpu_to_be32(wl_e->ec);
1220 1210
1221 scrub_peb_count++; 1211 scrub_peb_count++;
@@ -1233,6 +1223,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1233 fec = (struct ubi_fm_ec *)(fm_raw + fm_pos); 1223 fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
1234 1224
1235 fec->pnum = cpu_to_be32(wl_e->pnum); 1225 fec->pnum = cpu_to_be32(wl_e->pnum);
1226 set_seen(ubi, wl_e->pnum, seen_pebs);
1236 fec->ec = cpu_to_be32(wl_e->ec); 1227 fec->ec = cpu_to_be32(wl_e->ec);
1237 1228
1238 erase_peb_count++; 1229 erase_peb_count++;
@@ -1292,6 +1283,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1292 1283
1293 for (i = 0; i < new_fm->used_blocks; i++) { 1284 for (i = 0; i < new_fm->used_blocks; i++) {
1294 fmsb->block_loc[i] = cpu_to_be32(new_fm->e[i]->pnum); 1285 fmsb->block_loc[i] = cpu_to_be32(new_fm->e[i]->pnum);
1286 set_seen(ubi, new_fm->e[i]->pnum, seen_pebs);
1295 fmsb->block_ec[i] = cpu_to_be32(new_fm->e[i]->ec); 1287 fmsb->block_ec[i] = cpu_to_be32(new_fm->e[i]->ec);
1296 } 1288 }
1297 1289
@@ -1325,11 +1317,13 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1325 ubi_assert(new_fm); 1317 ubi_assert(new_fm);
1326 ubi->fm = new_fm; 1318 ubi->fm = new_fm;
1327 1319
1320 ret = self_check_seen(ubi, seen_pebs);
1328 dbg_bld("fastmap written!"); 1321 dbg_bld("fastmap written!");
1329 1322
1330out_kfree: 1323out_kfree:
1331 ubi_free_vid_hdr(ubi, avhdr); 1324 ubi_free_vid_hdr(ubi, avhdr);
1332 ubi_free_vid_hdr(ubi, dvhdr); 1325 ubi_free_vid_hdr(ubi, dvhdr);
1326 free_seen(seen_pebs);
1333out: 1327out:
1334 return ret; 1328 return ret;
1335} 1329}
@@ -1384,31 +1378,87 @@ out:
1384/** 1378/**
1385 * invalidate_fastmap - destroys a fastmap. 1379 * invalidate_fastmap - destroys a fastmap.
1386 * @ubi: UBI device object 1380 * @ubi: UBI device object
1387 * @fm: the fastmap to be destroyed
1388 * 1381 *
1382 * This function ensures that upon next UBI attach a full scan
1383 * is issued. We need this if UBI is about to write a new fastmap
1384 * but is unable to do so. In this case we have two options:
1385 * a) Make sure that the current fastmap will not be usued upon
1386 * attach time and contine or b) fall back to RO mode to have the
1387 * current fastmap in a valid state.
1389 * Returns 0 on success, < 0 indicates an internal error. 1388 * Returns 0 on success, < 0 indicates an internal error.
1390 */ 1389 */
1391static int invalidate_fastmap(struct ubi_device *ubi, 1390static int invalidate_fastmap(struct ubi_device *ubi)
1392 struct ubi_fastmap_layout *fm)
1393{ 1391{
1394 int ret; 1392 int ret;
1395 struct ubi_vid_hdr *vh; 1393 struct ubi_fastmap_layout *fm;
1394 struct ubi_wl_entry *e;
1395 struct ubi_vid_hdr *vh = NULL;
1396 1396
1397 ret = erase_block(ubi, fm->e[0]->pnum); 1397 if (!ubi->fm)
1398 if (ret < 0) 1398 return 0;
1399 return ret; 1399
1400 ubi->fm = NULL;
1401
1402 ret = -ENOMEM;
1403 fm = kzalloc(sizeof(*fm), GFP_KERNEL);
1404 if (!fm)
1405 goto out;
1400 1406
1401 vh = new_fm_vhdr(ubi, UBI_FM_SB_VOLUME_ID); 1407 vh = new_fm_vhdr(ubi, UBI_FM_SB_VOLUME_ID);
1402 if (!vh) 1408 if (!vh)
1403 return -ENOMEM; 1409 goto out_free_fm;
1404 1410
1405 /* deleting the current fastmap SB is not enough, an old SB may exist, 1411 ret = -ENOSPC;
1406 * so create a (corrupted) SB such that fastmap will find it and fall 1412 e = ubi_wl_get_fm_peb(ubi, 1);
1407 * back to scanning mode in any case */ 1413 if (!e)
1414 goto out_free_fm;
1415
1416 /*
1417 * Create fake fastmap such that UBI will fall back
1418 * to scanning mode.
1419 */
1408 vh->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); 1420 vh->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
1409 ret = ubi_io_write_vid_hdr(ubi, fm->e[0]->pnum, vh); 1421 ret = ubi_io_write_vid_hdr(ubi, e->pnum, vh);
1422 if (ret < 0) {
1423 ubi_wl_put_fm_peb(ubi, e, 0, 0);
1424 goto out_free_fm;
1425 }
1426
1427 fm->used_blocks = 1;
1428 fm->e[0] = e;
1429
1430 ubi->fm = fm;
1410 1431
1432out:
1433 ubi_free_vid_hdr(ubi, vh);
1411 return ret; 1434 return ret;
1435
1436out_free_fm:
1437 kfree(fm);
1438 goto out;
1439}
1440
1441/**
1442 * return_fm_pebs - returns all PEBs used by a fastmap back to the
1443 * WL sub-system.
1444 * @ubi: UBI device object
1445 * @fm: fastmap layout object
1446 */
1447static void return_fm_pebs(struct ubi_device *ubi,
1448 struct ubi_fastmap_layout *fm)
1449{
1450 int i;
1451
1452 if (!fm)
1453 return;
1454
1455 for (i = 0; i < fm->used_blocks; i++) {
1456 if (fm->e[i]) {
1457 ubi_wl_put_fm_peb(ubi, fm->e[i], i,
1458 fm->to_be_tortured[i]);
1459 fm->e[i] = NULL;
1460 }
1461 }
1412} 1462}
1413 1463
1414/** 1464/**
@@ -1420,45 +1470,32 @@ static int invalidate_fastmap(struct ubi_device *ubi,
1420 */ 1470 */
1421int ubi_update_fastmap(struct ubi_device *ubi) 1471int ubi_update_fastmap(struct ubi_device *ubi)
1422{ 1472{
1423 int ret, i; 1473 int ret, i, j;
1424 struct ubi_fastmap_layout *new_fm, *old_fm; 1474 struct ubi_fastmap_layout *new_fm, *old_fm;
1425 struct ubi_wl_entry *tmp_e; 1475 struct ubi_wl_entry *tmp_e;
1426 1476
1427 mutex_lock(&ubi->fm_mutex); 1477 down_write(&ubi->fm_protect);
1428 1478
1429 ubi_refill_pools(ubi); 1479 ubi_refill_pools(ubi);
1430 1480
1431 if (ubi->ro_mode || ubi->fm_disabled) { 1481 if (ubi->ro_mode || ubi->fm_disabled) {
1432 mutex_unlock(&ubi->fm_mutex); 1482 up_write(&ubi->fm_protect);
1433 return 0; 1483 return 0;
1434 } 1484 }
1435 1485
1436 ret = ubi_ensure_anchor_pebs(ubi); 1486 ret = ubi_ensure_anchor_pebs(ubi);
1437 if (ret) { 1487 if (ret) {
1438 mutex_unlock(&ubi->fm_mutex); 1488 up_write(&ubi->fm_protect);
1439 return ret; 1489 return ret;
1440 } 1490 }
1441 1491
1442 new_fm = kzalloc(sizeof(*new_fm), GFP_KERNEL); 1492 new_fm = kzalloc(sizeof(*new_fm), GFP_KERNEL);
1443 if (!new_fm) { 1493 if (!new_fm) {
1444 mutex_unlock(&ubi->fm_mutex); 1494 up_write(&ubi->fm_protect);
1445 return -ENOMEM; 1495 return -ENOMEM;
1446 } 1496 }
1447 1497
1448 new_fm->used_blocks = ubi->fm_size / ubi->leb_size; 1498 new_fm->used_blocks = ubi->fm_size / ubi->leb_size;
1449
1450 for (i = 0; i < new_fm->used_blocks; i++) {
1451 new_fm->e[i] = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
1452 if (!new_fm->e[i]) {
1453 while (i--)
1454 kfree(new_fm->e[i]);
1455
1456 kfree(new_fm);
1457 mutex_unlock(&ubi->fm_mutex);
1458 return -ENOMEM;
1459 }
1460 }
1461
1462 old_fm = ubi->fm; 1499 old_fm = ubi->fm;
1463 ubi->fm = NULL; 1500 ubi->fm = NULL;
1464 1501
@@ -1473,37 +1510,49 @@ int ubi_update_fastmap(struct ubi_device *ubi)
1473 tmp_e = ubi_wl_get_fm_peb(ubi, 0); 1510 tmp_e = ubi_wl_get_fm_peb(ubi, 0);
1474 spin_unlock(&ubi->wl_lock); 1511 spin_unlock(&ubi->wl_lock);
1475 1512
1476 if (!tmp_e && !old_fm) { 1513 if (!tmp_e) {
1477 int j; 1514 if (old_fm && old_fm->e[i]) {
1478 ubi_err(ubi, "could not get any free erase block"); 1515 ret = erase_block(ubi, old_fm->e[i]->pnum);
1479 1516 if (ret < 0) {
1480 for (j = 1; j < i; j++) 1517 ubi_err(ubi, "could not erase old fastmap PEB");
1481 ubi_wl_put_fm_peb(ubi, new_fm->e[j], j, 0); 1518
1482 1519 for (j = 1; j < i; j++) {
1483 ret = -ENOSPC; 1520 ubi_wl_put_fm_peb(ubi, new_fm->e[j],
1484 goto err; 1521 j, 0);
1485 } else if (!tmp_e && old_fm) { 1522 new_fm->e[j] = NULL;
1486 ret = erase_block(ubi, old_fm->e[i]->pnum); 1523 }
1487 if (ret < 0) { 1524 goto err;
1488 int j; 1525 }
1489 1526 new_fm->e[i] = old_fm->e[i];
1490 for (j = 1; j < i; j++) 1527 old_fm->e[i] = NULL;
1491 ubi_wl_put_fm_peb(ubi, new_fm->e[j], 1528 } else {
1492 j, 0); 1529 ubi_err(ubi, "could not get any free erase block");
1530
1531 for (j = 1; j < i; j++) {
1532 ubi_wl_put_fm_peb(ubi, new_fm->e[j], j, 0);
1533 new_fm->e[j] = NULL;
1534 }
1493 1535
1494 ubi_err(ubi, "could not erase old fastmap PEB"); 1536 ret = -ENOSPC;
1495 goto err; 1537 goto err;
1496 } 1538 }
1497
1498 new_fm->e[i]->pnum = old_fm->e[i]->pnum;
1499 new_fm->e[i]->ec = old_fm->e[i]->ec;
1500 } else { 1539 } else {
1501 new_fm->e[i]->pnum = tmp_e->pnum; 1540 new_fm->e[i] = tmp_e;
1502 new_fm->e[i]->ec = tmp_e->ec;
1503 1541
1504 if (old_fm) 1542 if (old_fm && old_fm->e[i]) {
1505 ubi_wl_put_fm_peb(ubi, old_fm->e[i], i, 1543 ubi_wl_put_fm_peb(ubi, old_fm->e[i], i,
1506 old_fm->to_be_tortured[i]); 1544 old_fm->to_be_tortured[i]);
1545 old_fm->e[i] = NULL;
1546 }
1547 }
1548 }
1549
1550 /* Old fastmap is larger than the new one */
1551 if (old_fm && new_fm->used_blocks < old_fm->used_blocks) {
1552 for (i = new_fm->used_blocks; i < old_fm->used_blocks; i++) {
1553 ubi_wl_put_fm_peb(ubi, old_fm->e[i], i,
1554 old_fm->to_be_tortured[i]);
1555 old_fm->e[i] = NULL;
1507 } 1556 }
1508 } 1557 }
1509 1558
@@ -1516,67 +1565,67 @@ int ubi_update_fastmap(struct ubi_device *ubi)
1516 if (!tmp_e) { 1565 if (!tmp_e) {
1517 ret = erase_block(ubi, old_fm->e[0]->pnum); 1566 ret = erase_block(ubi, old_fm->e[0]->pnum);
1518 if (ret < 0) { 1567 if (ret < 0) {
1519 int i;
1520 ubi_err(ubi, "could not erase old anchor PEB"); 1568 ubi_err(ubi, "could not erase old anchor PEB");
1521 1569
1522 for (i = 1; i < new_fm->used_blocks; i++) 1570 for (i = 1; i < new_fm->used_blocks; i++) {
1523 ubi_wl_put_fm_peb(ubi, new_fm->e[i], 1571 ubi_wl_put_fm_peb(ubi, new_fm->e[i],
1524 i, 0); 1572 i, 0);
1573 new_fm->e[i] = NULL;
1574 }
1525 goto err; 1575 goto err;
1526 } 1576 }
1527 1577 new_fm->e[0] = old_fm->e[0];
1528 new_fm->e[0]->pnum = old_fm->e[0]->pnum;
1529 new_fm->e[0]->ec = ret; 1578 new_fm->e[0]->ec = ret;
1579 old_fm->e[0] = NULL;
1530 } else { 1580 } else {
1531 /* we've got a new anchor PEB, return the old one */ 1581 /* we've got a new anchor PEB, return the old one */
1532 ubi_wl_put_fm_peb(ubi, old_fm->e[0], 0, 1582 ubi_wl_put_fm_peb(ubi, old_fm->e[0], 0,
1533 old_fm->to_be_tortured[0]); 1583 old_fm->to_be_tortured[0]);
1534 1584 new_fm->e[0] = tmp_e;
1535 new_fm->e[0]->pnum = tmp_e->pnum; 1585 old_fm->e[0] = NULL;
1536 new_fm->e[0]->ec = tmp_e->ec;
1537 } 1586 }
1538 } else { 1587 } else {
1539 if (!tmp_e) { 1588 if (!tmp_e) {
1540 int i;
1541 ubi_err(ubi, "could not find any anchor PEB"); 1589 ubi_err(ubi, "could not find any anchor PEB");
1542 1590
1543 for (i = 1; i < new_fm->used_blocks; i++) 1591 for (i = 1; i < new_fm->used_blocks; i++) {
1544 ubi_wl_put_fm_peb(ubi, new_fm->e[i], i, 0); 1592 ubi_wl_put_fm_peb(ubi, new_fm->e[i], i, 0);
1593 new_fm->e[i] = NULL;
1594 }
1545 1595
1546 ret = -ENOSPC; 1596 ret = -ENOSPC;
1547 goto err; 1597 goto err;
1548 } 1598 }
1549 1599 new_fm->e[0] = tmp_e;
1550 new_fm->e[0]->pnum = tmp_e->pnum;
1551 new_fm->e[0]->ec = tmp_e->ec;
1552 } 1600 }
1553 1601
1554 down_write(&ubi->work_sem); 1602 down_write(&ubi->work_sem);
1555 down_write(&ubi->fm_sem); 1603 down_write(&ubi->fm_eba_sem);
1556 ret = ubi_write_fastmap(ubi, new_fm); 1604 ret = ubi_write_fastmap(ubi, new_fm);
1557 up_write(&ubi->fm_sem); 1605 up_write(&ubi->fm_eba_sem);
1558 up_write(&ubi->work_sem); 1606 up_write(&ubi->work_sem);
1559 1607
1560 if (ret) 1608 if (ret)
1561 goto err; 1609 goto err;
1562 1610
1563out_unlock: 1611out_unlock:
1564 mutex_unlock(&ubi->fm_mutex); 1612 up_write(&ubi->fm_protect);
1565 kfree(old_fm); 1613 kfree(old_fm);
1566 return ret; 1614 return ret;
1567 1615
1568err: 1616err:
1569 kfree(new_fm);
1570
1571 ubi_warn(ubi, "Unable to write new fastmap, err=%i", ret); 1617 ubi_warn(ubi, "Unable to write new fastmap, err=%i", ret);
1572 1618
1573 ret = 0; 1619 ret = invalidate_fastmap(ubi);
1574 if (old_fm) { 1620 if (ret < 0) {
1575 ret = invalidate_fastmap(ubi, old_fm); 1621 ubi_err(ubi, "Unable to invalidiate current fastmap!");
1576 if (ret < 0) 1622 ubi_ro_mode(ubi);
1577 ubi_err(ubi, "Unable to invalidiate current fastmap!"); 1623 } else {
1578 else if (ret) 1624 return_fm_pebs(ubi, old_fm);
1579 ret = 0; 1625 return_fm_pebs(ubi, new_fm);
1626 ret = 0;
1580 } 1627 }
1628
1629 kfree(new_fm);
1581 goto out_unlock; 1630 goto out_unlock;
1582} 1631}
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index ed0bcb35472f..5bbd1f094f4e 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -859,6 +859,9 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
859 if (err) 859 if (err)
860 return err; 860 return err;
861 861
862 if (ubi_dbg_power_cut(ubi, POWER_CUT_EC_WRITE))
863 return -EROFS;
864
862 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); 865 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize);
863 return err; 866 return err;
864} 867}
@@ -1106,6 +1109,9 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
1106 if (err) 1109 if (err)
1107 return err; 1110 return err;
1108 1111
1112 if (ubi_dbg_power_cut(ubi, POWER_CUT_VID_WRITE))
1113 return -EROFS;
1114
1109 p = (char *)vid_hdr - ubi->vid_hdr_shift; 1115 p = (char *)vid_hdr - ubi->vid_hdr_shift;
1110 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset, 1116 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
1111 ubi->vid_hdr_alsize); 1117 ubi->vid_hdr_alsize);
diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h
index ac2b24d1783d..d0d072e7ccd2 100644
--- a/drivers/mtd/ubi/ubi-media.h
+++ b/drivers/mtd/ubi/ubi-media.h
@@ -403,8 +403,6 @@ struct ubi_vtbl_record {
403#define UBI_FM_MIN_POOL_SIZE 8 403#define UBI_FM_MIN_POOL_SIZE 8
404#define UBI_FM_MAX_POOL_SIZE 256 404#define UBI_FM_MAX_POOL_SIZE 256
405 405
406#define UBI_FM_WL_POOL_SIZE 25
407
408/** 406/**
409 * struct ubi_fm_sb - UBI fastmap super block 407 * struct ubi_fm_sb - UBI fastmap super block
410 * @magic: fastmap super block magic number (%UBI_FM_SB_MAGIC) 408 * @magic: fastmap super block magic number (%UBI_FM_SB_MAGIC)
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index c5be82d9d345..c998212fc680 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -151,6 +151,17 @@ enum {
151 UBI_BAD_FASTMAP, 151 UBI_BAD_FASTMAP,
152}; 152};
153 153
154/*
155 * Flags for emulate_power_cut in ubi_debug_info
156 *
157 * POWER_CUT_EC_WRITE: Emulate a power cut when writing an EC header
158 * POWER_CUT_VID_WRITE: Emulate a power cut when writing a VID header
159 */
160enum {
161 POWER_CUT_EC_WRITE = 0x01,
162 POWER_CUT_VID_WRITE = 0x02,
163};
164
154/** 165/**
155 * struct ubi_wl_entry - wear-leveling entry. 166 * struct ubi_wl_entry - wear-leveling entry.
156 * @u.rb: link in the corresponding (free/used) RB-tree 167 * @u.rb: link in the corresponding (free/used) RB-tree
@@ -356,30 +367,48 @@ struct ubi_wl_entry;
356 * 367 *
357 * @chk_gen: if UBI general extra checks are enabled 368 * @chk_gen: if UBI general extra checks are enabled
358 * @chk_io: if UBI I/O extra checks are enabled 369 * @chk_io: if UBI I/O extra checks are enabled
370 * @chk_fastmap: if UBI fastmap extra checks are enabled
359 * @disable_bgt: disable the background task for testing purposes 371 * @disable_bgt: disable the background task for testing purposes
360 * @emulate_bitflips: emulate bit-flips for testing purposes 372 * @emulate_bitflips: emulate bit-flips for testing purposes
361 * @emulate_io_failures: emulate write/erase failures for testing purposes 373 * @emulate_io_failures: emulate write/erase failures for testing purposes
374 * @emulate_power_cut: emulate power cut for testing purposes
375 * @power_cut_counter: count down for writes left until emulated power cut
376 * @power_cut_min: minimum number of writes before emulating a power cut
377 * @power_cut_max: maximum number of writes until emulating a power cut
362 * @dfs_dir_name: name of debugfs directory containing files of this UBI device 378 * @dfs_dir_name: name of debugfs directory containing files of this UBI device
363 * @dfs_dir: direntry object of the UBI device debugfs directory 379 * @dfs_dir: direntry object of the UBI device debugfs directory
364 * @dfs_chk_gen: debugfs knob to enable UBI general extra checks 380 * @dfs_chk_gen: debugfs knob to enable UBI general extra checks
365 * @dfs_chk_io: debugfs knob to enable UBI I/O extra checks 381 * @dfs_chk_io: debugfs knob to enable UBI I/O extra checks
382 * @dfs_chk_fastmap: debugfs knob to enable UBI fastmap extra checks
366 * @dfs_disable_bgt: debugfs knob to disable the background task 383 * @dfs_disable_bgt: debugfs knob to disable the background task
367 * @dfs_emulate_bitflips: debugfs knob to emulate bit-flips 384 * @dfs_emulate_bitflips: debugfs knob to emulate bit-flips
368 * @dfs_emulate_io_failures: debugfs knob to emulate write/erase failures 385 * @dfs_emulate_io_failures: debugfs knob to emulate write/erase failures
386 * @dfs_emulate_power_cut: debugfs knob to emulate power cuts
387 * @dfs_power_cut_min: debugfs knob for minimum writes before power cut
388 * @dfs_power_cut_max: debugfs knob for maximum writes until power cut
369 */ 389 */
370struct ubi_debug_info { 390struct ubi_debug_info {
371 unsigned int chk_gen:1; 391 unsigned int chk_gen:1;
372 unsigned int chk_io:1; 392 unsigned int chk_io:1;
393 unsigned int chk_fastmap:1;
373 unsigned int disable_bgt:1; 394 unsigned int disable_bgt:1;
374 unsigned int emulate_bitflips:1; 395 unsigned int emulate_bitflips:1;
375 unsigned int emulate_io_failures:1; 396 unsigned int emulate_io_failures:1;
397 unsigned int emulate_power_cut:2;
398 unsigned int power_cut_counter;
399 unsigned int power_cut_min;
400 unsigned int power_cut_max;
376 char dfs_dir_name[UBI_DFS_DIR_LEN + 1]; 401 char dfs_dir_name[UBI_DFS_DIR_LEN + 1];
377 struct dentry *dfs_dir; 402 struct dentry *dfs_dir;
378 struct dentry *dfs_chk_gen; 403 struct dentry *dfs_chk_gen;
379 struct dentry *dfs_chk_io; 404 struct dentry *dfs_chk_io;
405 struct dentry *dfs_chk_fastmap;
380 struct dentry *dfs_disable_bgt; 406 struct dentry *dfs_disable_bgt;
381 struct dentry *dfs_emulate_bitflips; 407 struct dentry *dfs_emulate_bitflips;
382 struct dentry *dfs_emulate_io_failures; 408 struct dentry *dfs_emulate_io_failures;
409 struct dentry *dfs_emulate_power_cut;
410 struct dentry *dfs_power_cut_min;
411 struct dentry *dfs_power_cut_max;
383}; 412};
384 413
385/** 414/**
@@ -426,11 +455,13 @@ struct ubi_debug_info {
426 * @fm_pool: in-memory data structure of the fastmap pool 455 * @fm_pool: in-memory data structure of the fastmap pool
427 * @fm_wl_pool: in-memory data structure of the fastmap pool used by the WL 456 * @fm_wl_pool: in-memory data structure of the fastmap pool used by the WL
428 * sub-system 457 * sub-system
429 * @fm_mutex: serializes ubi_update_fastmap() and protects @fm_buf 458 * @fm_protect: serializes ubi_update_fastmap(), protects @fm_buf and makes sure
459 * that critical sections cannot be interrupted by ubi_update_fastmap()
430 * @fm_buf: vmalloc()'d buffer which holds the raw fastmap 460 * @fm_buf: vmalloc()'d buffer which holds the raw fastmap
431 * @fm_size: fastmap size in bytes 461 * @fm_size: fastmap size in bytes
432 * @fm_sem: allows ubi_update_fastmap() to block EBA table changes 462 * @fm_eba_sem: allows ubi_update_fastmap() to block EBA table changes
433 * @fm_work: fastmap work queue 463 * @fm_work: fastmap work queue
464 * @fm_work_scheduled: non-zero if fastmap work was scheduled
434 * 465 *
435 * @used: RB-tree of used physical eraseblocks 466 * @used: RB-tree of used physical eraseblocks
436 * @erroneous: RB-tree of erroneous used physical eraseblocks 467 * @erroneous: RB-tree of erroneous used physical eraseblocks
@@ -442,7 +473,8 @@ struct ubi_debug_info {
442 * @pq_head: protection queue head 473 * @pq_head: protection queue head
443 * @wl_lock: protects the @used, @free, @pq, @pq_head, @lookuptbl, @move_from, 474 * @wl_lock: protects the @used, @free, @pq, @pq_head, @lookuptbl, @move_from,
444 * @move_to, @move_to_put @erase_pending, @wl_scheduled, @works, 475 * @move_to, @move_to_put @erase_pending, @wl_scheduled, @works,
445 * @erroneous, and @erroneous_peb_count fields 476 * @erroneous, @erroneous_peb_count, @fm_work_scheduled, @fm_pool,
477 * and @fm_wl_pool fields
446 * @move_mutex: serializes eraseblock moves 478 * @move_mutex: serializes eraseblock moves
447 * @work_sem: used to wait for all the scheduled works to finish and prevent 479 * @work_sem: used to wait for all the scheduled works to finish and prevent
448 * new works from being submitted 480 * new works from being submitted
@@ -479,7 +511,7 @@ struct ubi_debug_info {
479 * @vid_hdr_offset: starting offset of the volume identifier header (might be 511 * @vid_hdr_offset: starting offset of the volume identifier header (might be
480 * unaligned) 512 * unaligned)
481 * @vid_hdr_aloffset: starting offset of the VID header aligned to 513 * @vid_hdr_aloffset: starting offset of the VID header aligned to
482 * @hdrs_min_io_size 514 * @hdrs_min_io_size
483 * @vid_hdr_shift: contains @vid_hdr_offset - @vid_hdr_aloffset 515 * @vid_hdr_shift: contains @vid_hdr_offset - @vid_hdr_aloffset
484 * @bad_allowed: whether the MTD device admits of bad physical eraseblocks or 516 * @bad_allowed: whether the MTD device admits of bad physical eraseblocks or
485 * not 517 * not
@@ -532,11 +564,12 @@ struct ubi_device {
532 struct ubi_fastmap_layout *fm; 564 struct ubi_fastmap_layout *fm;
533 struct ubi_fm_pool fm_pool; 565 struct ubi_fm_pool fm_pool;
534 struct ubi_fm_pool fm_wl_pool; 566 struct ubi_fm_pool fm_wl_pool;
535 struct rw_semaphore fm_sem; 567 struct rw_semaphore fm_eba_sem;
536 struct mutex fm_mutex; 568 struct rw_semaphore fm_protect;
537 void *fm_buf; 569 void *fm_buf;
538 size_t fm_size; 570 size_t fm_size;
539 struct work_struct fm_work; 571 struct work_struct fm_work;
572 int fm_work_scheduled;
540 573
541 /* Wear-leveling sub-system's stuff */ 574 /* Wear-leveling sub-system's stuff */
542 struct rb_root used; 575 struct rb_root used;
@@ -868,10 +901,14 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
868 int pnum, const struct ubi_vid_hdr *vid_hdr); 901 int pnum, const struct ubi_vid_hdr *vid_hdr);
869 902
870/* fastmap.c */ 903/* fastmap.c */
904#ifdef CONFIG_MTD_UBI_FASTMAP
871size_t ubi_calc_fm_size(struct ubi_device *ubi); 905size_t ubi_calc_fm_size(struct ubi_device *ubi);
872int ubi_update_fastmap(struct ubi_device *ubi); 906int ubi_update_fastmap(struct ubi_device *ubi);
873int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai, 907int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
874 int fm_anchor); 908 int fm_anchor);
909#else
910static inline int ubi_update_fastmap(struct ubi_device *ubi) { return 0; }
911#endif
875 912
876/* block.c */ 913/* block.c */
877#ifdef CONFIG_MTD_UBI_BLOCK 914#ifdef CONFIG_MTD_UBI_BLOCK
@@ -892,6 +929,42 @@ static inline int ubiblock_remove(struct ubi_volume_info *vi)
892} 929}
893#endif 930#endif
894 931
932/*
933 * ubi_for_each_free_peb - walk the UBI free RB tree.
934 * @ubi: UBI device description object
935 * @e: a pointer to a ubi_wl_entry to use as cursor
936 * @pos: a pointer to RB-tree entry type to use as a loop counter
937 */
938#define ubi_for_each_free_peb(ubi, e, tmp_rb) \
939 ubi_rb_for_each_entry((tmp_rb), (e), &(ubi)->free, u.rb)
940
941/*
942 * ubi_for_each_used_peb - walk the UBI used RB tree.
943 * @ubi: UBI device description object
944 * @e: a pointer to a ubi_wl_entry to use as cursor
945 * @pos: a pointer to RB-tree entry type to use as a loop counter
946 */
947#define ubi_for_each_used_peb(ubi, e, tmp_rb) \
948 ubi_rb_for_each_entry((tmp_rb), (e), &(ubi)->used, u.rb)
949
950/*
951 * ubi_for_each_scub_peb - walk the UBI scub RB tree.
952 * @ubi: UBI device description object
953 * @e: a pointer to a ubi_wl_entry to use as cursor
954 * @pos: a pointer to RB-tree entry type to use as a loop counter
955 */
956#define ubi_for_each_scrub_peb(ubi, e, tmp_rb) \
957 ubi_rb_for_each_entry((tmp_rb), (e), &(ubi)->scrub, u.rb)
958
959/*
960 * ubi_for_each_protected_peb - walk the UBI protection queue.
961 * @ubi: UBI device description object
962 * @i: a integer used as counter
963 * @e: a pointer to a ubi_wl_entry to use as cursor
964 */
965#define ubi_for_each_protected_peb(ubi, i, e) \
966 for ((i) = 0; (i) < UBI_PROT_QUEUE_LEN; (i)++) \
967 list_for_each_entry((e), &(ubi->pq[(i)]), u.list)
895 968
896/* 969/*
897 * ubi_rb_for_each_entry - walk an RB-tree. 970 * ubi_rb_for_each_entry - walk an RB-tree.
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 8f7bde6a85d6..16214d3d57a4 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -103,6 +103,7 @@
103#include <linux/freezer.h> 103#include <linux/freezer.h>
104#include <linux/kthread.h> 104#include <linux/kthread.h>
105#include "ubi.h" 105#include "ubi.h"
106#include "wl.h"
106 107
107/* Number of physical eraseblocks reserved for wear-leveling purposes */ 108/* Number of physical eraseblocks reserved for wear-leveling purposes */
108#define WL_RESERVED_PEBS 1 109#define WL_RESERVED_PEBS 1
@@ -140,42 +141,6 @@ static int self_check_in_wl_tree(const struct ubi_device *ubi,
140static int self_check_in_pq(const struct ubi_device *ubi, 141static int self_check_in_pq(const struct ubi_device *ubi,
141 struct ubi_wl_entry *e); 142 struct ubi_wl_entry *e);
142 143
143#ifdef CONFIG_MTD_UBI_FASTMAP
144/**
145 * update_fastmap_work_fn - calls ubi_update_fastmap from a work queue
146 * @wrk: the work description object
147 */
148static void update_fastmap_work_fn(struct work_struct *wrk)
149{
150 struct ubi_device *ubi = container_of(wrk, struct ubi_device, fm_work);
151 ubi_update_fastmap(ubi);
152}
153
154/**
155 * ubi_ubi_is_fm_block - returns 1 if a PEB is currently used in a fastmap.
156 * @ubi: UBI device description object
157 * @pnum: the to be checked PEB
158 */
159static int ubi_is_fm_block(struct ubi_device *ubi, int pnum)
160{
161 int i;
162
163 if (!ubi->fm)
164 return 0;
165
166 for (i = 0; i < ubi->fm->used_blocks; i++)
167 if (ubi->fm->e[i]->pnum == pnum)
168 return 1;
169
170 return 0;
171}
172#else
173static int ubi_is_fm_block(struct ubi_device *ubi, int pnum)
174{
175 return 0;
176}
177#endif
178
179/** 144/**
180 * wl_tree_add - add a wear-leveling entry to a WL RB-tree. 145 * wl_tree_add - add a wear-leveling entry to a WL RB-tree.
181 * @e: the wear-leveling entry to add 146 * @e: the wear-leveling entry to add
@@ -213,6 +178,20 @@ static void wl_tree_add(struct ubi_wl_entry *e, struct rb_root *root)
213} 178}
214 179
215/** 180/**
181 * wl_tree_destroy - destroy a wear-leveling entry.
182 * @ubi: UBI device description object
183 * @e: the wear-leveling entry to add
184 *
185 * This function destroys a wear leveling entry and removes
186 * the reference from the lookup table.
187 */
188static void wl_entry_destroy(struct ubi_device *ubi, struct ubi_wl_entry *e)
189{
190 ubi->lookuptbl[e->pnum] = NULL;
191 kmem_cache_free(ubi_wl_entry_slab, e);
192}
193
194/**
216 * do_work - do one pending work. 195 * do_work - do one pending work.
217 * @ubi: UBI device description object 196 * @ubi: UBI device description object
218 * 197 *
@@ -260,33 +239,6 @@ static int do_work(struct ubi_device *ubi)
260} 239}
261 240
262/** 241/**
263 * produce_free_peb - produce a free physical eraseblock.
264 * @ubi: UBI device description object
265 *
266 * This function tries to make a free PEB by means of synchronous execution of
267 * pending works. This may be needed if, for example the background thread is
268 * disabled. Returns zero in case of success and a negative error code in case
269 * of failure.
270 */
271static int produce_free_peb(struct ubi_device *ubi)
272{
273 int err;
274
275 while (!ubi->free.rb_node && ubi->works_count) {
276 spin_unlock(&ubi->wl_lock);
277
278 dbg_wl("do one work synchronously");
279 err = do_work(ubi);
280
281 spin_lock(&ubi->wl_lock);
282 if (err)
283 return err;
284 }
285
286 return 0;
287}
288
289/**
290 * in_wl_tree - check if wear-leveling entry is present in a WL RB-tree. 242 * in_wl_tree - check if wear-leveling entry is present in a WL RB-tree.
291 * @e: the wear-leveling entry to check 243 * @e: the wear-leveling entry to check
292 * @root: the root of the tree 244 * @root: the root of the tree
@@ -409,119 +361,32 @@ static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi,
409 if (last->ec - first->ec < WL_FREE_MAX_DIFF) { 361 if (last->ec - first->ec < WL_FREE_MAX_DIFF) {
410 e = rb_entry(root->rb_node, struct ubi_wl_entry, u.rb); 362 e = rb_entry(root->rb_node, struct ubi_wl_entry, u.rb);
411 363
412#ifdef CONFIG_MTD_UBI_FASTMAP
413 /* If no fastmap has been written and this WL entry can be used 364 /* If no fastmap has been written and this WL entry can be used
414 * as anchor PEB, hold it back and return the second best 365 * as anchor PEB, hold it back and return the second best
415 * WL entry such that fastmap can use the anchor PEB later. */ 366 * WL entry such that fastmap can use the anchor PEB later. */
416 if (e && !ubi->fm_disabled && !ubi->fm && 367 e = may_reserve_for_fm(ubi, e, root);
417 e->pnum < UBI_FM_MAX_START)
418 e = rb_entry(rb_next(root->rb_node),
419 struct ubi_wl_entry, u.rb);
420#endif
421 } else 368 } else
422 e = find_wl_entry(ubi, root, WL_FREE_MAX_DIFF/2); 369 e = find_wl_entry(ubi, root, WL_FREE_MAX_DIFF/2);
423 370
424 return e; 371 return e;
425} 372}
426 373
427#ifdef CONFIG_MTD_UBI_FASTMAP
428/**
429 * find_anchor_wl_entry - find wear-leveling entry to used as anchor PEB.
430 * @root: the RB-tree where to look for
431 */
432static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root)
433{
434 struct rb_node *p;
435 struct ubi_wl_entry *e, *victim = NULL;
436 int max_ec = UBI_MAX_ERASECOUNTER;
437
438 ubi_rb_for_each_entry(p, e, root, u.rb) {
439 if (e->pnum < UBI_FM_MAX_START && e->ec < max_ec) {
440 victim = e;
441 max_ec = e->ec;
442 }
443 }
444
445 return victim;
446}
447
448static int anchor_pebs_avalible(struct rb_root *root)
449{
450 struct rb_node *p;
451 struct ubi_wl_entry *e;
452
453 ubi_rb_for_each_entry(p, e, root, u.rb)
454 if (e->pnum < UBI_FM_MAX_START)
455 return 1;
456
457 return 0;
458}
459
460/** 374/**
461 * ubi_wl_get_fm_peb - find a physical erase block with a given maximal number. 375 * wl_get_wle - get a mean wl entry to be used by ubi_wl_get_peb() or
376 * refill_wl_user_pool().
462 * @ubi: UBI device description object 377 * @ubi: UBI device description object
463 * @anchor: This PEB will be used as anchor PEB by fastmap
464 * 378 *
465 * The function returns a physical erase block with a given maximal number 379 * This function returns a a wear leveling entry in case of success and
466 * and removes it from the wl subsystem. 380 * NULL in case of failure.
467 * Must be called with wl_lock held!
468 */ 381 */
469struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int anchor) 382static struct ubi_wl_entry *wl_get_wle(struct ubi_device *ubi)
470{ 383{
471 struct ubi_wl_entry *e = NULL;
472
473 if (!ubi->free.rb_node || (ubi->free_count - ubi->beb_rsvd_pebs < 1))
474 goto out;
475
476 if (anchor)
477 e = find_anchor_wl_entry(&ubi->free);
478 else
479 e = find_mean_wl_entry(ubi, &ubi->free);
480
481 if (!e)
482 goto out;
483
484 self_check_in_wl_tree(ubi, e, &ubi->free);
485
486 /* remove it from the free list,
487 * the wl subsystem does no longer know this erase block */
488 rb_erase(&e->u.rb, &ubi->free);
489 ubi->free_count--;
490out:
491 return e;
492}
493#endif
494
495/**
496 * __wl_get_peb - get a physical eraseblock.
497 * @ubi: UBI device description object
498 *
499 * This function returns a physical eraseblock in case of success and a
500 * negative error code in case of failure.
501 */
502static int __wl_get_peb(struct ubi_device *ubi)
503{
504 int err;
505 struct ubi_wl_entry *e; 384 struct ubi_wl_entry *e;
506 385
507retry:
508 if (!ubi->free.rb_node) {
509 if (ubi->works_count == 0) {
510 ubi_err(ubi, "no free eraseblocks");
511 ubi_assert(list_empty(&ubi->works));
512 return -ENOSPC;
513 }
514
515 err = produce_free_peb(ubi);
516 if (err < 0)
517 return err;
518 goto retry;
519 }
520
521 e = find_mean_wl_entry(ubi, &ubi->free); 386 e = find_mean_wl_entry(ubi, &ubi->free);
522 if (!e) { 387 if (!e) {
523 ubi_err(ubi, "no free eraseblocks"); 388 ubi_err(ubi, "no free eraseblocks");
524 return -ENOSPC; 389 return NULL;
525 } 390 }
526 391
527 self_check_in_wl_tree(ubi, e, &ubi->free); 392 self_check_in_wl_tree(ubi, e, &ubi->free);
@@ -533,174 +398,10 @@ retry:
533 rb_erase(&e->u.rb, &ubi->free); 398 rb_erase(&e->u.rb, &ubi->free);
534 ubi->free_count--; 399 ubi->free_count--;
535 dbg_wl("PEB %d EC %d", e->pnum, e->ec); 400 dbg_wl("PEB %d EC %d", e->pnum, e->ec);
536#ifndef CONFIG_MTD_UBI_FASTMAP
537 /* We have to enqueue e only if fastmap is disabled,
538 * is fastmap enabled prot_queue_add() will be called by
539 * ubi_wl_get_peb() after removing e from the pool. */
540 prot_queue_add(ubi, e);
541#endif
542 return e->pnum;
543}
544
545#ifdef CONFIG_MTD_UBI_FASTMAP
546/**
547 * return_unused_pool_pebs - returns unused PEB to the free tree.
548 * @ubi: UBI device description object
549 * @pool: fastmap pool description object
550 */
551static void return_unused_pool_pebs(struct ubi_device *ubi,
552 struct ubi_fm_pool *pool)
553{
554 int i;
555 struct ubi_wl_entry *e;
556
557 for (i = pool->used; i < pool->size; i++) {
558 e = ubi->lookuptbl[pool->pebs[i]];
559 wl_tree_add(e, &ubi->free);
560 ubi->free_count++;
561 }
562}
563
564/**
565 * refill_wl_pool - refills all the fastmap pool used by the
566 * WL sub-system.
567 * @ubi: UBI device description object
568 */
569static void refill_wl_pool(struct ubi_device *ubi)
570{
571 struct ubi_wl_entry *e;
572 struct ubi_fm_pool *pool = &ubi->fm_wl_pool;
573
574 return_unused_pool_pebs(ubi, pool);
575
576 for (pool->size = 0; pool->size < pool->max_size; pool->size++) {
577 if (!ubi->free.rb_node ||
578 (ubi->free_count - ubi->beb_rsvd_pebs < 5))
579 break;
580
581 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
582 self_check_in_wl_tree(ubi, e, &ubi->free);
583 rb_erase(&e->u.rb, &ubi->free);
584 ubi->free_count--;
585
586 pool->pebs[pool->size] = e->pnum;
587 }
588 pool->used = 0;
589}
590
591/**
592 * refill_wl_user_pool - refills all the fastmap pool used by ubi_wl_get_peb.
593 * @ubi: UBI device description object
594 */
595static void refill_wl_user_pool(struct ubi_device *ubi)
596{
597 struct ubi_fm_pool *pool = &ubi->fm_pool;
598
599 return_unused_pool_pebs(ubi, pool);
600
601 for (pool->size = 0; pool->size < pool->max_size; pool->size++) {
602 pool->pebs[pool->size] = __wl_get_peb(ubi);
603 if (pool->pebs[pool->size] < 0)
604 break;
605 }
606 pool->used = 0;
607}
608
609/**
610 * ubi_refill_pools - refills all fastmap PEB pools.
611 * @ubi: UBI device description object
612 */
613void ubi_refill_pools(struct ubi_device *ubi)
614{
615 spin_lock(&ubi->wl_lock);
616 refill_wl_pool(ubi);
617 refill_wl_user_pool(ubi);
618 spin_unlock(&ubi->wl_lock);
619}
620
621/* ubi_wl_get_peb - works exaclty like __wl_get_peb but keeps track of
622 * the fastmap pool.
623 */
624int ubi_wl_get_peb(struct ubi_device *ubi)
625{
626 int ret;
627 struct ubi_fm_pool *pool = &ubi->fm_pool;
628 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool;
629
630 if (!pool->size || !wl_pool->size || pool->used == pool->size ||
631 wl_pool->used == wl_pool->size)
632 ubi_update_fastmap(ubi);
633
634 /* we got not a single free PEB */
635 if (!pool->size)
636 ret = -ENOSPC;
637 else {
638 spin_lock(&ubi->wl_lock);
639 ret = pool->pebs[pool->used++];
640 prot_queue_add(ubi, ubi->lookuptbl[ret]);
641 spin_unlock(&ubi->wl_lock);
642 }
643
644 return ret;
645}
646
647/* get_peb_for_wl - returns a PEB to be used internally by the WL sub-system.
648 *
649 * @ubi: UBI device description object
650 */
651static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)
652{
653 struct ubi_fm_pool *pool = &ubi->fm_wl_pool;
654 int pnum;
655
656 if (pool->used == pool->size || !pool->size) {
657 /* We cannot update the fastmap here because this
658 * function is called in atomic context.
659 * Let's fail here and refill/update it as soon as possible. */
660 schedule_work(&ubi->fm_work);
661 return NULL;
662 } else {
663 pnum = pool->pebs[pool->used++];
664 return ubi->lookuptbl[pnum];
665 }
666}
667#else
668static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)
669{
670 struct ubi_wl_entry *e;
671
672 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
673 self_check_in_wl_tree(ubi, e, &ubi->free);
674 ubi->free_count--;
675 ubi_assert(ubi->free_count >= 0);
676 rb_erase(&e->u.rb, &ubi->free);
677 401
678 return e; 402 return e;
679} 403}
680 404
681int ubi_wl_get_peb(struct ubi_device *ubi)
682{
683 int peb, err;
684
685 spin_lock(&ubi->wl_lock);
686 peb = __wl_get_peb(ubi);
687 spin_unlock(&ubi->wl_lock);
688
689 if (peb < 0)
690 return peb;
691
692 err = ubi_self_check_all_ff(ubi, peb, ubi->vid_hdr_aloffset,
693 ubi->peb_size - ubi->vid_hdr_aloffset);
694 if (err) {
695 ubi_err(ubi, "new PEB %d does not contain all 0xFF bytes",
696 peb);
697 return err;
698 }
699
700 return peb;
701}
702#endif
703
704/** 405/**
705 * prot_queue_del - remove a physical eraseblock from the protection queue. 406 * prot_queue_del - remove a physical eraseblock from the protection queue.
706 * @ubi: UBI device description object 407 * @ubi: UBI device description object
@@ -867,17 +568,6 @@ static void schedule_ubi_work(struct ubi_device *ubi, struct ubi_work *wrk)
867static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk, 568static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
868 int shutdown); 569 int shutdown);
869 570
870#ifdef CONFIG_MTD_UBI_FASTMAP
871/**
872 * ubi_is_erase_work - checks whether a work is erase work.
873 * @wrk: The work object to be checked
874 */
875int ubi_is_erase_work(struct ubi_work *wrk)
876{
877 return wrk->func == erase_worker;
878}
879#endif
880
881/** 571/**
882 * schedule_erase - schedule an erase work. 572 * schedule_erase - schedule an erase work.
883 * @ubi: UBI device description object 573 * @ubi: UBI device description object
@@ -895,7 +585,6 @@ static int schedule_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
895 struct ubi_work *wl_wrk; 585 struct ubi_work *wl_wrk;
896 586
897 ubi_assert(e); 587 ubi_assert(e);
898 ubi_assert(!ubi_is_fm_block(ubi, e->pnum));
899 588
900 dbg_wl("schedule erasure of PEB %d, EC %d, torture %d", 589 dbg_wl("schedule erasure of PEB %d, EC %d, torture %d",
901 e->pnum, e->ec, torture); 590 e->pnum, e->ec, torture);
@@ -942,51 +631,6 @@ static int do_sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
942 return erase_worker(ubi, wl_wrk, 0); 631 return erase_worker(ubi, wl_wrk, 0);
943} 632}
944 633
945#ifdef CONFIG_MTD_UBI_FASTMAP
946/**
947 * ubi_wl_put_fm_peb - returns a PEB used in a fastmap to the wear-leveling
948 * sub-system.
949 * see: ubi_wl_put_peb()
950 *
951 * @ubi: UBI device description object
952 * @fm_e: physical eraseblock to return
953 * @lnum: the last used logical eraseblock number for the PEB
954 * @torture: if this physical eraseblock has to be tortured
955 */
956int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *fm_e,
957 int lnum, int torture)
958{
959 struct ubi_wl_entry *e;
960 int vol_id, pnum = fm_e->pnum;
961
962 dbg_wl("PEB %d", pnum);
963
964 ubi_assert(pnum >= 0);
965 ubi_assert(pnum < ubi->peb_count);
966
967 spin_lock(&ubi->wl_lock);
968 e = ubi->lookuptbl[pnum];
969
970 /* This can happen if we recovered from a fastmap the very
971 * first time and writing now a new one. In this case the wl system
972 * has never seen any PEB used by the original fastmap.
973 */
974 if (!e) {
975 e = fm_e;
976 ubi_assert(e->ec >= 0);
977 ubi->lookuptbl[pnum] = e;
978 } else {
979 e->ec = fm_e->ec;
980 kfree(fm_e);
981 }
982
983 spin_unlock(&ubi->wl_lock);
984
985 vol_id = lnum ? UBI_FM_DATA_VOLUME_ID : UBI_FM_SB_VOLUME_ID;
986 return schedule_erase(ubi, e, vol_id, lnum, torture);
987}
988#endif
989
990/** 634/**
991 * wear_leveling_worker - wear-leveling worker function. 635 * wear_leveling_worker - wear-leveling worker function.
992 * @ubi: UBI device description object 636 * @ubi: UBI device description object
@@ -1002,7 +646,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1002 int shutdown) 646 int shutdown)
1003{ 647{
1004 int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0; 648 int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0;
1005 int vol_id = -1, uninitialized_var(lnum); 649 int vol_id = -1, lnum = -1;
1006#ifdef CONFIG_MTD_UBI_FASTMAP 650#ifdef CONFIG_MTD_UBI_FASTMAP
1007 int anchor = wrk->anchor; 651 int anchor = wrk->anchor;
1008#endif 652#endif
@@ -1214,7 +858,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1214 err = do_sync_erase(ubi, e1, vol_id, lnum, 0); 858 err = do_sync_erase(ubi, e1, vol_id, lnum, 0);
1215 if (err) { 859 if (err) {
1216 if (e2) 860 if (e2)
1217 kmem_cache_free(ubi_wl_entry_slab, e2); 861 wl_entry_destroy(ubi, e2);
1218 goto out_ro; 862 goto out_ro;
1219 } 863 }
1220 864
@@ -1282,8 +926,8 @@ out_error:
1282 spin_unlock(&ubi->wl_lock); 926 spin_unlock(&ubi->wl_lock);
1283 927
1284 ubi_free_vid_hdr(ubi, vid_hdr); 928 ubi_free_vid_hdr(ubi, vid_hdr);
1285 kmem_cache_free(ubi_wl_entry_slab, e1); 929 wl_entry_destroy(ubi, e1);
1286 kmem_cache_free(ubi_wl_entry_slab, e2); 930 wl_entry_destroy(ubi, e2);
1287 931
1288out_ro: 932out_ro:
1289 ubi_ro_mode(ubi); 933 ubi_ro_mode(ubi);
@@ -1369,38 +1013,6 @@ out_unlock:
1369 return err; 1013 return err;
1370} 1014}
1371 1015
1372#ifdef CONFIG_MTD_UBI_FASTMAP
1373/**
1374 * ubi_ensure_anchor_pebs - schedule wear-leveling to produce an anchor PEB.
1375 * @ubi: UBI device description object
1376 */
1377int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
1378{
1379 struct ubi_work *wrk;
1380
1381 spin_lock(&ubi->wl_lock);
1382 if (ubi->wl_scheduled) {
1383 spin_unlock(&ubi->wl_lock);
1384 return 0;
1385 }
1386 ubi->wl_scheduled = 1;
1387 spin_unlock(&ubi->wl_lock);
1388
1389 wrk = kmalloc(sizeof(struct ubi_work), GFP_NOFS);
1390 if (!wrk) {
1391 spin_lock(&ubi->wl_lock);
1392 ubi->wl_scheduled = 0;
1393 spin_unlock(&ubi->wl_lock);
1394 return -ENOMEM;
1395 }
1396
1397 wrk->anchor = 1;
1398 wrk->func = &wear_leveling_worker;
1399 schedule_ubi_work(ubi, wrk);
1400 return 0;
1401}
1402#endif
1403
1404/** 1016/**
1405 * erase_worker - physical eraseblock erase worker function. 1017 * erase_worker - physical eraseblock erase worker function.
1406 * @ubi: UBI device description object 1018 * @ubi: UBI device description object
@@ -1425,15 +1037,13 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1425 if (shutdown) { 1037 if (shutdown) {
1426 dbg_wl("cancel erasure of PEB %d EC %d", pnum, e->ec); 1038 dbg_wl("cancel erasure of PEB %d EC %d", pnum, e->ec);
1427 kfree(wl_wrk); 1039 kfree(wl_wrk);
1428 kmem_cache_free(ubi_wl_entry_slab, e); 1040 wl_entry_destroy(ubi, e);
1429 return 0; 1041 return 0;
1430 } 1042 }
1431 1043
1432 dbg_wl("erase PEB %d EC %d LEB %d:%d", 1044 dbg_wl("erase PEB %d EC %d LEB %d:%d",
1433 pnum, e->ec, wl_wrk->vol_id, wl_wrk->lnum); 1045 pnum, e->ec, wl_wrk->vol_id, wl_wrk->lnum);
1434 1046
1435 ubi_assert(!ubi_is_fm_block(ubi, e->pnum));
1436
1437 err = sync_erase(ubi, e, wl_wrk->torture); 1047 err = sync_erase(ubi, e, wl_wrk->torture);
1438 if (!err) { 1048 if (!err) {
1439 /* Fine, we've erased it successfully */ 1049 /* Fine, we've erased it successfully */
@@ -1471,7 +1081,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1471 return err; 1081 return err;
1472 } 1082 }
1473 1083
1474 kmem_cache_free(ubi_wl_entry_slab, e); 1084 wl_entry_destroy(ubi, e);
1475 if (err != -EIO) 1085 if (err != -EIO)
1476 /* 1086 /*
1477 * If this is not %-EIO, we have no idea what to do. Scheduling 1087 * If this is not %-EIO, we have no idea what to do. Scheduling
@@ -1563,6 +1173,8 @@ int ubi_wl_put_peb(struct ubi_device *ubi, int vol_id, int lnum,
1563 ubi_assert(pnum >= 0); 1173 ubi_assert(pnum >= 0);
1564 ubi_assert(pnum < ubi->peb_count); 1174 ubi_assert(pnum < ubi->peb_count);
1565 1175
1176 down_read(&ubi->fm_protect);
1177
1566retry: 1178retry:
1567 spin_lock(&ubi->wl_lock); 1179 spin_lock(&ubi->wl_lock);
1568 e = ubi->lookuptbl[pnum]; 1180 e = ubi->lookuptbl[pnum];
@@ -1593,6 +1205,7 @@ retry:
1593 ubi_assert(!ubi->move_to_put); 1205 ubi_assert(!ubi->move_to_put);
1594 ubi->move_to_put = 1; 1206 ubi->move_to_put = 1;
1595 spin_unlock(&ubi->wl_lock); 1207 spin_unlock(&ubi->wl_lock);
1208 up_read(&ubi->fm_protect);
1596 return 0; 1209 return 0;
1597 } else { 1210 } else {
1598 if (in_wl_tree(e, &ubi->used)) { 1211 if (in_wl_tree(e, &ubi->used)) {
@@ -1614,6 +1227,7 @@ retry:
1614 ubi_err(ubi, "PEB %d not found", pnum); 1227 ubi_err(ubi, "PEB %d not found", pnum);
1615 ubi_ro_mode(ubi); 1228 ubi_ro_mode(ubi);
1616 spin_unlock(&ubi->wl_lock); 1229 spin_unlock(&ubi->wl_lock);
1230 up_read(&ubi->fm_protect);
1617 return err; 1231 return err;
1618 } 1232 }
1619 } 1233 }
@@ -1627,6 +1241,7 @@ retry:
1627 spin_unlock(&ubi->wl_lock); 1241 spin_unlock(&ubi->wl_lock);
1628 } 1242 }
1629 1243
1244 up_read(&ubi->fm_protect);
1630 return err; 1245 return err;
1631} 1246}
1632 1247
@@ -1758,9 +1373,10 @@ int ubi_wl_flush(struct ubi_device *ubi, int vol_id, int lnum)
1758 1373
1759/** 1374/**
1760 * tree_destroy - destroy an RB-tree. 1375 * tree_destroy - destroy an RB-tree.
1376 * @ubi: UBI device description object
1761 * @root: the root of the tree to destroy 1377 * @root: the root of the tree to destroy
1762 */ 1378 */
1763static void tree_destroy(struct rb_root *root) 1379static void tree_destroy(struct ubi_device *ubi, struct rb_root *root)
1764{ 1380{
1765 struct rb_node *rb; 1381 struct rb_node *rb;
1766 struct ubi_wl_entry *e; 1382 struct ubi_wl_entry *e;
@@ -1782,7 +1398,7 @@ static void tree_destroy(struct rb_root *root)
1782 rb->rb_right = NULL; 1398 rb->rb_right = NULL;
1783 } 1399 }
1784 1400
1785 kmem_cache_free(ubi_wl_entry_slab, e); 1401 wl_entry_destroy(ubi, e);
1786 } 1402 }
1787 } 1403 }
1788} 1404}
@@ -1850,6 +1466,9 @@ int ubi_thread(void *u)
1850 */ 1466 */
1851static void shutdown_work(struct ubi_device *ubi) 1467static void shutdown_work(struct ubi_device *ubi)
1852{ 1468{
1469#ifdef CONFIG_MTD_UBI_FASTMAP
1470 flush_work(&ubi->fm_work);
1471#endif
1853 while (!list_empty(&ubi->works)) { 1472 while (!list_empty(&ubi->works)) {
1854 struct ubi_work *wrk; 1473 struct ubi_work *wrk;
1855 1474
@@ -1883,9 +1502,6 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
1883 init_rwsem(&ubi->work_sem); 1502 init_rwsem(&ubi->work_sem);
1884 ubi->max_ec = ai->max_ec; 1503 ubi->max_ec = ai->max_ec;
1885 INIT_LIST_HEAD(&ubi->works); 1504 INIT_LIST_HEAD(&ubi->works);
1886#ifdef CONFIG_MTD_UBI_FASTMAP
1887 INIT_WORK(&ubi->fm_work, update_fastmap_work_fn);
1888#endif
1889 1505
1890 sprintf(ubi->bgt_name, UBI_BGT_NAME_PATTERN, ubi->ubi_num); 1506 sprintf(ubi->bgt_name, UBI_BGT_NAME_PATTERN, ubi->ubi_num);
1891 1507
@@ -1907,10 +1523,9 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
1907 1523
1908 e->pnum = aeb->pnum; 1524 e->pnum = aeb->pnum;
1909 e->ec = aeb->ec; 1525 e->ec = aeb->ec;
1910 ubi_assert(!ubi_is_fm_block(ubi, e->pnum));
1911 ubi->lookuptbl[e->pnum] = e; 1526 ubi->lookuptbl[e->pnum] = e;
1912 if (schedule_erase(ubi, e, aeb->vol_id, aeb->lnum, 0)) { 1527 if (schedule_erase(ubi, e, aeb->vol_id, aeb->lnum, 0)) {
1913 kmem_cache_free(ubi_wl_entry_slab, e); 1528 wl_entry_destroy(ubi, e);
1914 goto out_free; 1529 goto out_free;
1915 } 1530 }
1916 1531
@@ -1928,7 +1543,6 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
1928 e->pnum = aeb->pnum; 1543 e->pnum = aeb->pnum;
1929 e->ec = aeb->ec; 1544 e->ec = aeb->ec;
1930 ubi_assert(e->ec >= 0); 1545 ubi_assert(e->ec >= 0);
1931 ubi_assert(!ubi_is_fm_block(ubi, e->pnum));
1932 1546
1933 wl_tree_add(e, &ubi->free); 1547 wl_tree_add(e, &ubi->free);
1934 ubi->free_count++; 1548 ubi->free_count++;
@@ -1966,17 +1580,20 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
1966 1580
1967 dbg_wl("found %i PEBs", found_pebs); 1581 dbg_wl("found %i PEBs", found_pebs);
1968 1582
1969 if (ubi->fm) 1583 if (ubi->fm) {
1970 ubi_assert(ubi->good_peb_count == \ 1584 ubi_assert(ubi->good_peb_count == \
1971 found_pebs + ubi->fm->used_blocks); 1585 found_pebs + ubi->fm->used_blocks);
1586
1587 for (i = 0; i < ubi->fm->used_blocks; i++) {
1588 e = ubi->fm->e[i];
1589 ubi->lookuptbl[e->pnum] = e;
1590 }
1591 }
1972 else 1592 else
1973 ubi_assert(ubi->good_peb_count == found_pebs); 1593 ubi_assert(ubi->good_peb_count == found_pebs);
1974 1594
1975 reserved_pebs = WL_RESERVED_PEBS; 1595 reserved_pebs = WL_RESERVED_PEBS;
1976#ifdef CONFIG_MTD_UBI_FASTMAP 1596 ubi_fastmap_init(ubi, &reserved_pebs);
1977 /* Reserve enough LEBs to store two fastmaps. */
1978 reserved_pebs += (ubi->fm_size / ubi->leb_size) * 2;
1979#endif
1980 1597
1981 if (ubi->avail_pebs < reserved_pebs) { 1598 if (ubi->avail_pebs < reserved_pebs) {
1982 ubi_err(ubi, "no enough physical eraseblocks (%d, need %d)", 1599 ubi_err(ubi, "no enough physical eraseblocks (%d, need %d)",
@@ -1998,9 +1615,9 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
1998 1615
1999out_free: 1616out_free:
2000 shutdown_work(ubi); 1617 shutdown_work(ubi);
2001 tree_destroy(&ubi->used); 1618 tree_destroy(ubi, &ubi->used);
2002 tree_destroy(&ubi->free); 1619 tree_destroy(ubi, &ubi->free);
2003 tree_destroy(&ubi->scrub); 1620 tree_destroy(ubi, &ubi->scrub);
2004 kfree(ubi->lookuptbl); 1621 kfree(ubi->lookuptbl);
2005 return err; 1622 return err;
2006} 1623}
@@ -2017,7 +1634,7 @@ static void protection_queue_destroy(struct ubi_device *ubi)
2017 for (i = 0; i < UBI_PROT_QUEUE_LEN; ++i) { 1634 for (i = 0; i < UBI_PROT_QUEUE_LEN; ++i) {
2018 list_for_each_entry_safe(e, tmp, &ubi->pq[i], u.list) { 1635 list_for_each_entry_safe(e, tmp, &ubi->pq[i], u.list) {
2019 list_del(&e->u.list); 1636 list_del(&e->u.list);
2020 kmem_cache_free(ubi_wl_entry_slab, e); 1637 wl_entry_destroy(ubi, e);
2021 } 1638 }
2022 } 1639 }
2023} 1640}
@@ -2029,12 +1646,13 @@ static void protection_queue_destroy(struct ubi_device *ubi)
2029void ubi_wl_close(struct ubi_device *ubi) 1646void ubi_wl_close(struct ubi_device *ubi)
2030{ 1647{
2031 dbg_wl("close the WL sub-system"); 1648 dbg_wl("close the WL sub-system");
1649 ubi_fastmap_close(ubi);
2032 shutdown_work(ubi); 1650 shutdown_work(ubi);
2033 protection_queue_destroy(ubi); 1651 protection_queue_destroy(ubi);
2034 tree_destroy(&ubi->used); 1652 tree_destroy(ubi, &ubi->used);
2035 tree_destroy(&ubi->erroneous); 1653 tree_destroy(ubi, &ubi->erroneous);
2036 tree_destroy(&ubi->free); 1654 tree_destroy(ubi, &ubi->free);
2037 tree_destroy(&ubi->scrub); 1655 tree_destroy(ubi, &ubi->scrub);
2038 kfree(ubi->lookuptbl); 1656 kfree(ubi->lookuptbl);
2039} 1657}
2040 1658
@@ -2133,3 +1751,94 @@ static int self_check_in_pq(const struct ubi_device *ubi,
2133 dump_stack(); 1751 dump_stack();
2134 return -EINVAL; 1752 return -EINVAL;
2135} 1753}
1754#ifndef CONFIG_MTD_UBI_FASTMAP
1755static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)
1756{
1757 struct ubi_wl_entry *e;
1758
1759 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
1760 self_check_in_wl_tree(ubi, e, &ubi->free);
1761 ubi->free_count--;
1762 ubi_assert(ubi->free_count >= 0);
1763 rb_erase(&e->u.rb, &ubi->free);
1764
1765 return e;
1766}
1767
1768/**
1769 * produce_free_peb - produce a free physical eraseblock.
1770 * @ubi: UBI device description object
1771 *
1772 * This function tries to make a free PEB by means of synchronous execution of
1773 * pending works. This may be needed if, for example the background thread is
1774 * disabled. Returns zero in case of success and a negative error code in case
1775 * of failure.
1776 */
1777static int produce_free_peb(struct ubi_device *ubi)
1778{
1779 int err;
1780
1781 while (!ubi->free.rb_node && ubi->works_count) {
1782 spin_unlock(&ubi->wl_lock);
1783
1784 dbg_wl("do one work synchronously");
1785 err = do_work(ubi);
1786
1787 spin_lock(&ubi->wl_lock);
1788 if (err)
1789 return err;
1790 }
1791
1792 return 0;
1793}
1794
1795/**
1796 * ubi_wl_get_peb - get a physical eraseblock.
1797 * @ubi: UBI device description object
1798 *
1799 * This function returns a physical eraseblock in case of success and a
1800 * negative error code in case of failure.
1801 * Returns with ubi->fm_eba_sem held in read mode!
1802 */
1803int ubi_wl_get_peb(struct ubi_device *ubi)
1804{
1805 int err;
1806 struct ubi_wl_entry *e;
1807
1808retry:
1809 down_read(&ubi->fm_eba_sem);
1810 spin_lock(&ubi->wl_lock);
1811 if (!ubi->free.rb_node) {
1812 if (ubi->works_count == 0) {
1813 ubi_err(ubi, "no free eraseblocks");
1814 ubi_assert(list_empty(&ubi->works));
1815 spin_unlock(&ubi->wl_lock);
1816 return -ENOSPC;
1817 }
1818
1819 err = produce_free_peb(ubi);
1820 if (err < 0) {
1821 spin_unlock(&ubi->wl_lock);
1822 return err;
1823 }
1824 spin_unlock(&ubi->wl_lock);
1825 up_read(&ubi->fm_eba_sem);
1826 goto retry;
1827
1828 }
1829 e = wl_get_wle(ubi);
1830 prot_queue_add(ubi, e);
1831 spin_unlock(&ubi->wl_lock);
1832
1833 err = ubi_self_check_all_ff(ubi, e->pnum, ubi->vid_hdr_aloffset,
1834 ubi->peb_size - ubi->vid_hdr_aloffset);
1835 if (err) {
1836 ubi_err(ubi, "new PEB %d does not contain all 0xFF bytes", e->pnum);
1837 return err;
1838 }
1839
1840 return e->pnum;
1841}
1842#else
1843#include "fastmap-wl.c"
1844#endif
diff --git a/drivers/mtd/ubi/wl.h b/drivers/mtd/ubi/wl.h
new file mode 100644
index 000000000000..bd1f07e5ce9a
--- /dev/null
+++ b/drivers/mtd/ubi/wl.h
@@ -0,0 +1,28 @@
1#ifndef UBI_WL_H
2#define UBI_WL_H
3#ifdef CONFIG_MTD_UBI_FASTMAP
4static int anchor_pebs_avalible(struct rb_root *root);
5static void update_fastmap_work_fn(struct work_struct *wrk);
6static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root);
7static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi);
8static void ubi_fastmap_close(struct ubi_device *ubi);
9static inline void ubi_fastmap_init(struct ubi_device *ubi, int *count)
10{
11 /* Reserve enough LEBs to store two fastmaps. */
12 *count += (ubi->fm_size / ubi->leb_size) * 2;
13 INIT_WORK(&ubi->fm_work, update_fastmap_work_fn);
14}
15static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi,
16 struct ubi_wl_entry *e,
17 struct rb_root *root);
18#else /* !CONFIG_MTD_UBI_FASTMAP */
19static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi);
20static inline void ubi_fastmap_close(struct ubi_device *ubi) { }
21static inline void ubi_fastmap_init(struct ubi_device *ubi, int *count) { }
22static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi,
23 struct ubi_wl_entry *e,
24 struct rb_root *root) {
25 return e;
26}
27#endif /* CONFIG_MTD_UBI_FASTMAP */
28#endif /* UBI_WL_H */
diff --git a/fs/ubifs/budget.c b/fs/ubifs/budget.c
index eb997e9c4ab0..11a11b32a2a9 100644
--- a/fs/ubifs/budget.c
+++ b/fs/ubifs/budget.c
@@ -509,7 +509,7 @@ again:
509 c->bi.nospace_rp = 1; 509 c->bi.nospace_rp = 1;
510 smp_wmb(); 510 smp_wmb();
511 } else 511 } else
512 ubifs_err("cannot budget space, error %d", err); 512 ubifs_err(c, "cannot budget space, error %d", err);
513 return err; 513 return err;
514} 514}
515 515
diff --git a/fs/ubifs/commit.c b/fs/ubifs/commit.c
index 26b69b2d4a45..63f56619991d 100644
--- a/fs/ubifs/commit.c
+++ b/fs/ubifs/commit.c
@@ -225,7 +225,7 @@ out_cancel:
225out_up: 225out_up:
226 up_write(&c->commit_sem); 226 up_write(&c->commit_sem);
227out: 227out:
228 ubifs_err("commit failed, error %d", err); 228 ubifs_err(c, "commit failed, error %d", err);
229 spin_lock(&c->cs_lock); 229 spin_lock(&c->cs_lock);
230 c->cmt_state = COMMIT_BROKEN; 230 c->cmt_state = COMMIT_BROKEN;
231 wake_up(&c->cmt_wq); 231 wake_up(&c->cmt_wq);
@@ -289,7 +289,7 @@ int ubifs_bg_thread(void *info)
289 int err; 289 int err;
290 struct ubifs_info *c = info; 290 struct ubifs_info *c = info;
291 291
292 ubifs_msg("background thread \"%s\" started, PID %d", 292 ubifs_msg(c, "background thread \"%s\" started, PID %d",
293 c->bgt_name, current->pid); 293 c->bgt_name, current->pid);
294 set_freezable(); 294 set_freezable();
295 295
@@ -324,7 +324,7 @@ int ubifs_bg_thread(void *info)
324 cond_resched(); 324 cond_resched();
325 } 325 }
326 326
327 ubifs_msg("background thread \"%s\" stops", c->bgt_name); 327 ubifs_msg(c, "background thread \"%s\" stops", c->bgt_name);
328 return 0; 328 return 0;
329} 329}
330 330
@@ -712,13 +712,13 @@ out:
712 return 0; 712 return 0;
713 713
714out_dump: 714out_dump:
715 ubifs_err("dumping index node (iip=%d)", i->iip); 715 ubifs_err(c, "dumping index node (iip=%d)", i->iip);
716 ubifs_dump_node(c, idx); 716 ubifs_dump_node(c, idx);
717 list_del(&i->list); 717 list_del(&i->list);
718 kfree(i); 718 kfree(i);
719 if (!list_empty(&list)) { 719 if (!list_empty(&list)) {
720 i = list_entry(list.prev, struct idx_node, list); 720 i = list_entry(list.prev, struct idx_node, list);
721 ubifs_err("dumping parent index node"); 721 ubifs_err(c, "dumping parent index node");
722 ubifs_dump_node(c, &i->idx); 722 ubifs_dump_node(c, &i->idx);
723 } 723 }
724out_free: 724out_free:
@@ -727,7 +727,7 @@ out_free:
727 list_del(&i->list); 727 list_del(&i->list);
728 kfree(i); 728 kfree(i);
729 } 729 }
730 ubifs_err("failed, error %d", err); 730 ubifs_err(c, "failed, error %d", err);
731 if (err > 0) 731 if (err > 0)
732 err = -EINVAL; 732 err = -EINVAL;
733 return err; 733 return err;
diff --git a/fs/ubifs/compress.c b/fs/ubifs/compress.c
index 2bfa0953335d..565cb56d7225 100644
--- a/fs/ubifs/compress.c
+++ b/fs/ubifs/compress.c
@@ -92,8 +92,8 @@ struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
92 * Note, if the input buffer was not compressed, it is copied to the output 92 * Note, if the input buffer was not compressed, it is copied to the output
93 * buffer and %UBIFS_COMPR_NONE is returned in @compr_type. 93 * buffer and %UBIFS_COMPR_NONE is returned in @compr_type.
94 */ 94 */
95void ubifs_compress(const void *in_buf, int in_len, void *out_buf, int *out_len, 95void ubifs_compress(const struct ubifs_info *c, const void *in_buf,
96 int *compr_type) 96 int in_len, void *out_buf, int *out_len, int *compr_type)
97{ 97{
98 int err; 98 int err;
99 struct ubifs_compressor *compr = ubifs_compressors[*compr_type]; 99 struct ubifs_compressor *compr = ubifs_compressors[*compr_type];
@@ -112,9 +112,9 @@ void ubifs_compress(const void *in_buf, int in_len, void *out_buf, int *out_len,
112 if (compr->comp_mutex) 112 if (compr->comp_mutex)
113 mutex_unlock(compr->comp_mutex); 113 mutex_unlock(compr->comp_mutex);
114 if (unlikely(err)) { 114 if (unlikely(err)) {
115 ubifs_warn("cannot compress %d bytes, compressor %s, error %d, leave data uncompressed", 115 ubifs_warn(c, "cannot compress %d bytes, compressor %s, error %d, leave data uncompressed",
116 in_len, compr->name, err); 116 in_len, compr->name, err);
117 goto no_compr; 117 goto no_compr;
118 } 118 }
119 119
120 /* 120 /*
@@ -144,21 +144,21 @@ no_compr:
144 * The length of the uncompressed data is returned in @out_len. This functions 144 * The length of the uncompressed data is returned in @out_len. This functions
145 * returns %0 on success or a negative error code on failure. 145 * returns %0 on success or a negative error code on failure.
146 */ 146 */
147int ubifs_decompress(const void *in_buf, int in_len, void *out_buf, 147int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,
148 int *out_len, int compr_type) 148 int in_len, void *out_buf, int *out_len, int compr_type)
149{ 149{
150 int err; 150 int err;
151 struct ubifs_compressor *compr; 151 struct ubifs_compressor *compr;
152 152
153 if (unlikely(compr_type < 0 || compr_type >= UBIFS_COMPR_TYPES_CNT)) { 153 if (unlikely(compr_type < 0 || compr_type >= UBIFS_COMPR_TYPES_CNT)) {
154 ubifs_err("invalid compression type %d", compr_type); 154 ubifs_err(c, "invalid compression type %d", compr_type);
155 return -EINVAL; 155 return -EINVAL;
156 } 156 }
157 157
158 compr = ubifs_compressors[compr_type]; 158 compr = ubifs_compressors[compr_type];
159 159
160 if (unlikely(!compr->capi_name)) { 160 if (unlikely(!compr->capi_name)) {
161 ubifs_err("%s compression is not compiled in", compr->name); 161 ubifs_err(c, "%s compression is not compiled in", compr->name);
162 return -EINVAL; 162 return -EINVAL;
163 } 163 }
164 164
@@ -175,7 +175,7 @@ int ubifs_decompress(const void *in_buf, int in_len, void *out_buf,
175 if (compr->decomp_mutex) 175 if (compr->decomp_mutex)
176 mutex_unlock(compr->decomp_mutex); 176 mutex_unlock(compr->decomp_mutex);
177 if (err) 177 if (err)
178 ubifs_err("cannot decompress %d bytes, compressor %s, error %d", 178 ubifs_err(c, "cannot decompress %d bytes, compressor %s, error %d",
179 in_len, compr->name, err); 179 in_len, compr->name, err);
180 180
181 return err; 181 return err;
@@ -193,8 +193,8 @@ static int __init compr_init(struct ubifs_compressor *compr)
193 if (compr->capi_name) { 193 if (compr->capi_name) {
194 compr->cc = crypto_alloc_comp(compr->capi_name, 0, 0); 194 compr->cc = crypto_alloc_comp(compr->capi_name, 0, 0);
195 if (IS_ERR(compr->cc)) { 195 if (IS_ERR(compr->cc)) {
196 ubifs_err("cannot initialize compressor %s, error %ld", 196 pr_err("UBIFS error (pid %d): cannot initialize compressor %s, error %ld",
197 compr->name, PTR_ERR(compr->cc)); 197 current->pid, compr->name, PTR_ERR(compr->cc));
198 return PTR_ERR(compr->cc); 198 return PTR_ERR(compr->cc);
199 } 199 }
200 } 200 }
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index 4cfb3e82c56f..4c46a9865fa7 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -746,7 +746,7 @@ void ubifs_dump_lprops(struct ubifs_info *c)
746 for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) { 746 for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) {
747 err = ubifs_read_one_lp(c, lnum, &lp); 747 err = ubifs_read_one_lp(c, lnum, &lp);
748 if (err) { 748 if (err) {
749 ubifs_err("cannot read lprops for LEB %d", lnum); 749 ubifs_err(c, "cannot read lprops for LEB %d", lnum);
750 continue; 750 continue;
751 } 751 }
752 752
@@ -819,13 +819,13 @@ void ubifs_dump_leb(const struct ubifs_info *c, int lnum)
819 819
820 buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); 820 buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL);
821 if (!buf) { 821 if (!buf) {
822 ubifs_err("cannot allocate memory for dumping LEB %d", lnum); 822 ubifs_err(c, "cannot allocate memory for dumping LEB %d", lnum);
823 return; 823 return;
824 } 824 }
825 825
826 sleb = ubifs_scan(c, lnum, 0, buf, 0); 826 sleb = ubifs_scan(c, lnum, 0, buf, 0);
827 if (IS_ERR(sleb)) { 827 if (IS_ERR(sleb)) {
828 ubifs_err("scan error %d", (int)PTR_ERR(sleb)); 828 ubifs_err(c, "scan error %d", (int)PTR_ERR(sleb));
829 goto out; 829 goto out;
830 } 830 }
831 831
@@ -1032,7 +1032,7 @@ int dbg_check_space_info(struct ubifs_info *c)
1032 spin_unlock(&c->space_lock); 1032 spin_unlock(&c->space_lock);
1033 1033
1034 if (free != d->saved_free) { 1034 if (free != d->saved_free) {
1035 ubifs_err("free space changed from %lld to %lld", 1035 ubifs_err(c, "free space changed from %lld to %lld",
1036 d->saved_free, free); 1036 d->saved_free, free);
1037 goto out; 1037 goto out;
1038 } 1038 }
@@ -1040,15 +1040,15 @@ int dbg_check_space_info(struct ubifs_info *c)
1040 return 0; 1040 return 0;
1041 1041
1042out: 1042out:
1043 ubifs_msg("saved lprops statistics dump"); 1043 ubifs_msg(c, "saved lprops statistics dump");
1044 ubifs_dump_lstats(&d->saved_lst); 1044 ubifs_dump_lstats(&d->saved_lst);
1045 ubifs_msg("saved budgeting info dump"); 1045 ubifs_msg(c, "saved budgeting info dump");
1046 ubifs_dump_budg(c, &d->saved_bi); 1046 ubifs_dump_budg(c, &d->saved_bi);
1047 ubifs_msg("saved idx_gc_cnt %d", d->saved_idx_gc_cnt); 1047 ubifs_msg(c, "saved idx_gc_cnt %d", d->saved_idx_gc_cnt);
1048 ubifs_msg("current lprops statistics dump"); 1048 ubifs_msg(c, "current lprops statistics dump");
1049 ubifs_get_lp_stats(c, &lst); 1049 ubifs_get_lp_stats(c, &lst);
1050 ubifs_dump_lstats(&lst); 1050 ubifs_dump_lstats(&lst);
1051 ubifs_msg("current budgeting info dump"); 1051 ubifs_msg(c, "current budgeting info dump");
1052 ubifs_dump_budg(c, &c->bi); 1052 ubifs_dump_budg(c, &c->bi);
1053 dump_stack(); 1053 dump_stack();
1054 return -EINVAL; 1054 return -EINVAL;
@@ -1077,9 +1077,9 @@ int dbg_check_synced_i_size(const struct ubifs_info *c, struct inode *inode)
1077 mutex_lock(&ui->ui_mutex); 1077 mutex_lock(&ui->ui_mutex);
1078 spin_lock(&ui->ui_lock); 1078 spin_lock(&ui->ui_lock);
1079 if (ui->ui_size != ui->synced_i_size && !ui->dirty) { 1079 if (ui->ui_size != ui->synced_i_size && !ui->dirty) {
1080 ubifs_err("ui_size is %lld, synced_i_size is %lld, but inode is clean", 1080 ubifs_err(c, "ui_size is %lld, synced_i_size is %lld, but inode is clean",
1081 ui->ui_size, ui->synced_i_size); 1081 ui->ui_size, ui->synced_i_size);
1082 ubifs_err("i_ino %lu, i_mode %#x, i_size %lld", inode->i_ino, 1082 ubifs_err(c, "i_ino %lu, i_mode %#x, i_size %lld", inode->i_ino,
1083 inode->i_mode, i_size_read(inode)); 1083 inode->i_mode, i_size_read(inode));
1084 dump_stack(); 1084 dump_stack();
1085 err = -EINVAL; 1085 err = -EINVAL;
@@ -1140,7 +1140,7 @@ int dbg_check_dir(struct ubifs_info *c, const struct inode *dir)
1140 kfree(pdent); 1140 kfree(pdent);
1141 1141
1142 if (i_size_read(dir) != size) { 1142 if (i_size_read(dir) != size) {
1143 ubifs_err("directory inode %lu has size %llu, but calculated size is %llu", 1143 ubifs_err(c, "directory inode %lu has size %llu, but calculated size is %llu",
1144 dir->i_ino, (unsigned long long)i_size_read(dir), 1144 dir->i_ino, (unsigned long long)i_size_read(dir),
1145 (unsigned long long)size); 1145 (unsigned long long)size);
1146 ubifs_dump_inode(c, dir); 1146 ubifs_dump_inode(c, dir);
@@ -1148,7 +1148,7 @@ int dbg_check_dir(struct ubifs_info *c, const struct inode *dir)
1148 return -EINVAL; 1148 return -EINVAL;
1149 } 1149 }
1150 if (dir->i_nlink != nlink) { 1150 if (dir->i_nlink != nlink) {
1151 ubifs_err("directory inode %lu has nlink %u, but calculated nlink is %u", 1151 ubifs_err(c, "directory inode %lu has nlink %u, but calculated nlink is %u",
1152 dir->i_ino, dir->i_nlink, nlink); 1152 dir->i_ino, dir->i_nlink, nlink);
1153 ubifs_dump_inode(c, dir); 1153 ubifs_dump_inode(c, dir);
1154 dump_stack(); 1154 dump_stack();
@@ -1207,10 +1207,10 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1207 err = 1; 1207 err = 1;
1208 key_read(c, &dent1->key, &key); 1208 key_read(c, &dent1->key, &key);
1209 if (keys_cmp(c, &zbr1->key, &key)) { 1209 if (keys_cmp(c, &zbr1->key, &key)) {
1210 ubifs_err("1st entry at %d:%d has key %s", zbr1->lnum, 1210 ubifs_err(c, "1st entry at %d:%d has key %s", zbr1->lnum,
1211 zbr1->offs, dbg_snprintf_key(c, &key, key_buf, 1211 zbr1->offs, dbg_snprintf_key(c, &key, key_buf,
1212 DBG_KEY_BUF_LEN)); 1212 DBG_KEY_BUF_LEN));
1213 ubifs_err("but it should have key %s according to tnc", 1213 ubifs_err(c, "but it should have key %s according to tnc",
1214 dbg_snprintf_key(c, &zbr1->key, key_buf, 1214 dbg_snprintf_key(c, &zbr1->key, key_buf,
1215 DBG_KEY_BUF_LEN)); 1215 DBG_KEY_BUF_LEN));
1216 ubifs_dump_node(c, dent1); 1216 ubifs_dump_node(c, dent1);
@@ -1219,10 +1219,10 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1219 1219
1220 key_read(c, &dent2->key, &key); 1220 key_read(c, &dent2->key, &key);
1221 if (keys_cmp(c, &zbr2->key, &key)) { 1221 if (keys_cmp(c, &zbr2->key, &key)) {
1222 ubifs_err("2nd entry at %d:%d has key %s", zbr1->lnum, 1222 ubifs_err(c, "2nd entry at %d:%d has key %s", zbr1->lnum,
1223 zbr1->offs, dbg_snprintf_key(c, &key, key_buf, 1223 zbr1->offs, dbg_snprintf_key(c, &key, key_buf,
1224 DBG_KEY_BUF_LEN)); 1224 DBG_KEY_BUF_LEN));
1225 ubifs_err("but it should have key %s according to tnc", 1225 ubifs_err(c, "but it should have key %s according to tnc",
1226 dbg_snprintf_key(c, &zbr2->key, key_buf, 1226 dbg_snprintf_key(c, &zbr2->key, key_buf,
1227 DBG_KEY_BUF_LEN)); 1227 DBG_KEY_BUF_LEN));
1228 ubifs_dump_node(c, dent2); 1228 ubifs_dump_node(c, dent2);
@@ -1238,14 +1238,14 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1238 goto out_free; 1238 goto out_free;
1239 } 1239 }
1240 if (cmp == 0 && nlen1 == nlen2) 1240 if (cmp == 0 && nlen1 == nlen2)
1241 ubifs_err("2 xent/dent nodes with the same name"); 1241 ubifs_err(c, "2 xent/dent nodes with the same name");
1242 else 1242 else
1243 ubifs_err("bad order of colliding key %s", 1243 ubifs_err(c, "bad order of colliding key %s",
1244 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN)); 1244 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
1245 1245
1246 ubifs_msg("first node at %d:%d\n", zbr1->lnum, zbr1->offs); 1246 ubifs_msg(c, "first node at %d:%d\n", zbr1->lnum, zbr1->offs);
1247 ubifs_dump_node(c, dent1); 1247 ubifs_dump_node(c, dent1);
1248 ubifs_msg("second node at %d:%d\n", zbr2->lnum, zbr2->offs); 1248 ubifs_msg(c, "second node at %d:%d\n", zbr2->lnum, zbr2->offs);
1249 ubifs_dump_node(c, dent2); 1249 ubifs_dump_node(c, dent2);
1250 1250
1251out_free: 1251out_free:
@@ -1447,11 +1447,11 @@ static int dbg_check_znode(struct ubifs_info *c, struct ubifs_zbranch *zbr)
1447 return 0; 1447 return 0;
1448 1448
1449out: 1449out:
1450 ubifs_err("failed, error %d", err); 1450 ubifs_err(c, "failed, error %d", err);
1451 ubifs_msg("dump of the znode"); 1451 ubifs_msg(c, "dump of the znode");
1452 ubifs_dump_znode(c, znode); 1452 ubifs_dump_znode(c, znode);
1453 if (zp) { 1453 if (zp) {
1454 ubifs_msg("dump of the parent znode"); 1454 ubifs_msg(c, "dump of the parent znode");
1455 ubifs_dump_znode(c, zp); 1455 ubifs_dump_znode(c, zp);
1456 } 1456 }
1457 dump_stack(); 1457 dump_stack();
@@ -1518,9 +1518,9 @@ int dbg_check_tnc(struct ubifs_info *c, int extra)
1518 if (err < 0) 1518 if (err < 0)
1519 return err; 1519 return err;
1520 if (err) { 1520 if (err) {
1521 ubifs_msg("first znode"); 1521 ubifs_msg(c, "first znode");
1522 ubifs_dump_znode(c, prev); 1522 ubifs_dump_znode(c, prev);
1523 ubifs_msg("second znode"); 1523 ubifs_msg(c, "second znode");
1524 ubifs_dump_znode(c, znode); 1524 ubifs_dump_znode(c, znode);
1525 return -EINVAL; 1525 return -EINVAL;
1526 } 1526 }
@@ -1529,13 +1529,13 @@ int dbg_check_tnc(struct ubifs_info *c, int extra)
1529 1529
1530 if (extra) { 1530 if (extra) {
1531 if (clean_cnt != atomic_long_read(&c->clean_zn_cnt)) { 1531 if (clean_cnt != atomic_long_read(&c->clean_zn_cnt)) {
1532 ubifs_err("incorrect clean_zn_cnt %ld, calculated %ld", 1532 ubifs_err(c, "incorrect clean_zn_cnt %ld, calculated %ld",
1533 atomic_long_read(&c->clean_zn_cnt), 1533 atomic_long_read(&c->clean_zn_cnt),
1534 clean_cnt); 1534 clean_cnt);
1535 return -EINVAL; 1535 return -EINVAL;
1536 } 1536 }
1537 if (dirty_cnt != atomic_long_read(&c->dirty_zn_cnt)) { 1537 if (dirty_cnt != atomic_long_read(&c->dirty_zn_cnt)) {
1538 ubifs_err("incorrect dirty_zn_cnt %ld, calculated %ld", 1538 ubifs_err(c, "incorrect dirty_zn_cnt %ld, calculated %ld",
1539 atomic_long_read(&c->dirty_zn_cnt), 1539 atomic_long_read(&c->dirty_zn_cnt),
1540 dirty_cnt); 1540 dirty_cnt);
1541 return -EINVAL; 1541 return -EINVAL;
@@ -1608,7 +1608,7 @@ int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb,
1608 if (znode_cb) { 1608 if (znode_cb) {
1609 err = znode_cb(c, znode, priv); 1609 err = znode_cb(c, znode, priv);
1610 if (err) { 1610 if (err) {
1611 ubifs_err("znode checking function returned error %d", 1611 ubifs_err(c, "znode checking function returned error %d",
1612 err); 1612 err);
1613 ubifs_dump_znode(c, znode); 1613 ubifs_dump_znode(c, znode);
1614 goto out_dump; 1614 goto out_dump;
@@ -1619,7 +1619,7 @@ int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb,
1619 zbr = &znode->zbranch[idx]; 1619 zbr = &znode->zbranch[idx];
1620 err = leaf_cb(c, zbr, priv); 1620 err = leaf_cb(c, zbr, priv);
1621 if (err) { 1621 if (err) {
1622 ubifs_err("leaf checking function returned error %d, for leaf at LEB %d:%d", 1622 ubifs_err(c, "leaf checking function returned error %d, for leaf at LEB %d:%d",
1623 err, zbr->lnum, zbr->offs); 1623 err, zbr->lnum, zbr->offs);
1624 goto out_dump; 1624 goto out_dump;
1625 } 1625 }
@@ -1675,7 +1675,7 @@ out_dump:
1675 zbr = &znode->parent->zbranch[znode->iip]; 1675 zbr = &znode->parent->zbranch[znode->iip];
1676 else 1676 else
1677 zbr = &c->zroot; 1677 zbr = &c->zroot;
1678 ubifs_msg("dump of znode at LEB %d:%d", zbr->lnum, zbr->offs); 1678 ubifs_msg(c, "dump of znode at LEB %d:%d", zbr->lnum, zbr->offs);
1679 ubifs_dump_znode(c, znode); 1679 ubifs_dump_znode(c, znode);
1680out_unlock: 1680out_unlock:
1681 mutex_unlock(&c->tnc_mutex); 1681 mutex_unlock(&c->tnc_mutex);
@@ -1722,12 +1722,12 @@ int dbg_check_idx_size(struct ubifs_info *c, long long idx_size)
1722 1722
1723 err = dbg_walk_index(c, NULL, add_size, &calc); 1723 err = dbg_walk_index(c, NULL, add_size, &calc);
1724 if (err) { 1724 if (err) {
1725 ubifs_err("error %d while walking the index", err); 1725 ubifs_err(c, "error %d while walking the index", err);
1726 return err; 1726 return err;
1727 } 1727 }
1728 1728
1729 if (calc != idx_size) { 1729 if (calc != idx_size) {
1730 ubifs_err("index size check failed: calculated size is %lld, should be %lld", 1730 ubifs_err(c, "index size check failed: calculated size is %lld, should be %lld",
1731 calc, idx_size); 1731 calc, idx_size);
1732 dump_stack(); 1732 dump_stack();
1733 return -EINVAL; 1733 return -EINVAL;
@@ -1814,7 +1814,7 @@ static struct fsck_inode *add_inode(struct ubifs_info *c,
1814 } 1814 }
1815 1815
1816 if (inum > c->highest_inum) { 1816 if (inum > c->highest_inum) {
1817 ubifs_err("too high inode number, max. is %lu", 1817 ubifs_err(c, "too high inode number, max. is %lu",
1818 (unsigned long)c->highest_inum); 1818 (unsigned long)c->highest_inum);
1819 return ERR_PTR(-EINVAL); 1819 return ERR_PTR(-EINVAL);
1820 } 1820 }
@@ -1921,17 +1921,17 @@ static struct fsck_inode *read_add_inode(struct ubifs_info *c,
1921 ino_key_init(c, &key, inum); 1921 ino_key_init(c, &key, inum);
1922 err = ubifs_lookup_level0(c, &key, &znode, &n); 1922 err = ubifs_lookup_level0(c, &key, &znode, &n);
1923 if (!err) { 1923 if (!err) {
1924 ubifs_err("inode %lu not found in index", (unsigned long)inum); 1924 ubifs_err(c, "inode %lu not found in index", (unsigned long)inum);
1925 return ERR_PTR(-ENOENT); 1925 return ERR_PTR(-ENOENT);
1926 } else if (err < 0) { 1926 } else if (err < 0) {
1927 ubifs_err("error %d while looking up inode %lu", 1927 ubifs_err(c, "error %d while looking up inode %lu",
1928 err, (unsigned long)inum); 1928 err, (unsigned long)inum);
1929 return ERR_PTR(err); 1929 return ERR_PTR(err);
1930 } 1930 }
1931 1931
1932 zbr = &znode->zbranch[n]; 1932 zbr = &znode->zbranch[n];
1933 if (zbr->len < UBIFS_INO_NODE_SZ) { 1933 if (zbr->len < UBIFS_INO_NODE_SZ) {
1934 ubifs_err("bad node %lu node length %d", 1934 ubifs_err(c, "bad node %lu node length %d",
1935 (unsigned long)inum, zbr->len); 1935 (unsigned long)inum, zbr->len);
1936 return ERR_PTR(-EINVAL); 1936 return ERR_PTR(-EINVAL);
1937 } 1937 }
@@ -1942,7 +1942,7 @@ static struct fsck_inode *read_add_inode(struct ubifs_info *c,
1942 1942
1943 err = ubifs_tnc_read_node(c, zbr, ino); 1943 err = ubifs_tnc_read_node(c, zbr, ino);
1944 if (err) { 1944 if (err) {
1945 ubifs_err("cannot read inode node at LEB %d:%d, error %d", 1945 ubifs_err(c, "cannot read inode node at LEB %d:%d, error %d",
1946 zbr->lnum, zbr->offs, err); 1946 zbr->lnum, zbr->offs, err);
1947 kfree(ino); 1947 kfree(ino);
1948 return ERR_PTR(err); 1948 return ERR_PTR(err);
@@ -1951,7 +1951,7 @@ static struct fsck_inode *read_add_inode(struct ubifs_info *c,
1951 fscki = add_inode(c, fsckd, ino); 1951 fscki = add_inode(c, fsckd, ino);
1952 kfree(ino); 1952 kfree(ino);
1953 if (IS_ERR(fscki)) { 1953 if (IS_ERR(fscki)) {
1954 ubifs_err("error %ld while adding inode %lu node", 1954 ubifs_err(c, "error %ld while adding inode %lu node",
1955 PTR_ERR(fscki), (unsigned long)inum); 1955 PTR_ERR(fscki), (unsigned long)inum);
1956 return fscki; 1956 return fscki;
1957 } 1957 }
@@ -1985,7 +1985,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
1985 struct fsck_inode *fscki; 1985 struct fsck_inode *fscki;
1986 1986
1987 if (zbr->len < UBIFS_CH_SZ) { 1987 if (zbr->len < UBIFS_CH_SZ) {
1988 ubifs_err("bad leaf length %d (LEB %d:%d)", 1988 ubifs_err(c, "bad leaf length %d (LEB %d:%d)",
1989 zbr->len, zbr->lnum, zbr->offs); 1989 zbr->len, zbr->lnum, zbr->offs);
1990 return -EINVAL; 1990 return -EINVAL;
1991 } 1991 }
@@ -1996,7 +1996,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
1996 1996
1997 err = ubifs_tnc_read_node(c, zbr, node); 1997 err = ubifs_tnc_read_node(c, zbr, node);
1998 if (err) { 1998 if (err) {
1999 ubifs_err("cannot read leaf node at LEB %d:%d, error %d", 1999 ubifs_err(c, "cannot read leaf node at LEB %d:%d, error %d",
2000 zbr->lnum, zbr->offs, err); 2000 zbr->lnum, zbr->offs, err);
2001 goto out_free; 2001 goto out_free;
2002 } 2002 }
@@ -2006,7 +2006,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
2006 fscki = add_inode(c, priv, node); 2006 fscki = add_inode(c, priv, node);
2007 if (IS_ERR(fscki)) { 2007 if (IS_ERR(fscki)) {
2008 err = PTR_ERR(fscki); 2008 err = PTR_ERR(fscki);
2009 ubifs_err("error %d while adding inode node", err); 2009 ubifs_err(c, "error %d while adding inode node", err);
2010 goto out_dump; 2010 goto out_dump;
2011 } 2011 }
2012 goto out; 2012 goto out;
@@ -2014,7 +2014,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
2014 2014
2015 if (type != UBIFS_DENT_KEY && type != UBIFS_XENT_KEY && 2015 if (type != UBIFS_DENT_KEY && type != UBIFS_XENT_KEY &&
2016 type != UBIFS_DATA_KEY) { 2016 type != UBIFS_DATA_KEY) {
2017 ubifs_err("unexpected node type %d at LEB %d:%d", 2017 ubifs_err(c, "unexpected node type %d at LEB %d:%d",
2018 type, zbr->lnum, zbr->offs); 2018 type, zbr->lnum, zbr->offs);
2019 err = -EINVAL; 2019 err = -EINVAL;
2020 goto out_free; 2020 goto out_free;
@@ -2022,7 +2022,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
2022 2022
2023 ch = node; 2023 ch = node;
2024 if (le64_to_cpu(ch->sqnum) > c->max_sqnum) { 2024 if (le64_to_cpu(ch->sqnum) > c->max_sqnum) {
2025 ubifs_err("too high sequence number, max. is %llu", 2025 ubifs_err(c, "too high sequence number, max. is %llu",
2026 c->max_sqnum); 2026 c->max_sqnum);
2027 err = -EINVAL; 2027 err = -EINVAL;
2028 goto out_dump; 2028 goto out_dump;
@@ -2042,7 +2042,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
2042 fscki = read_add_inode(c, priv, inum); 2042 fscki = read_add_inode(c, priv, inum);
2043 if (IS_ERR(fscki)) { 2043 if (IS_ERR(fscki)) {
2044 err = PTR_ERR(fscki); 2044 err = PTR_ERR(fscki);
2045 ubifs_err("error %d while processing data node and trying to find inode node %lu", 2045 ubifs_err(c, "error %d while processing data node and trying to find inode node %lu",
2046 err, (unsigned long)inum); 2046 err, (unsigned long)inum);
2047 goto out_dump; 2047 goto out_dump;
2048 } 2048 }
@@ -2052,7 +2052,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
2052 blk_offs <<= UBIFS_BLOCK_SHIFT; 2052 blk_offs <<= UBIFS_BLOCK_SHIFT;
2053 blk_offs += le32_to_cpu(dn->size); 2053 blk_offs += le32_to_cpu(dn->size);
2054 if (blk_offs > fscki->size) { 2054 if (blk_offs > fscki->size) {
2055 ubifs_err("data node at LEB %d:%d is not within inode size %lld", 2055 ubifs_err(c, "data node at LEB %d:%d is not within inode size %lld",
2056 zbr->lnum, zbr->offs, fscki->size); 2056 zbr->lnum, zbr->offs, fscki->size);
2057 err = -EINVAL; 2057 err = -EINVAL;
2058 goto out_dump; 2058 goto out_dump;
@@ -2076,7 +2076,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
2076 fscki = read_add_inode(c, priv, inum); 2076 fscki = read_add_inode(c, priv, inum);
2077 if (IS_ERR(fscki)) { 2077 if (IS_ERR(fscki)) {
2078 err = PTR_ERR(fscki); 2078 err = PTR_ERR(fscki);
2079 ubifs_err("error %d while processing entry node and trying to find inode node %lu", 2079 ubifs_err(c, "error %d while processing entry node and trying to find inode node %lu",
2080 err, (unsigned long)inum); 2080 err, (unsigned long)inum);
2081 goto out_dump; 2081 goto out_dump;
2082 } 2082 }
@@ -2088,7 +2088,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
2088 fscki1 = read_add_inode(c, priv, inum); 2088 fscki1 = read_add_inode(c, priv, inum);
2089 if (IS_ERR(fscki1)) { 2089 if (IS_ERR(fscki1)) {
2090 err = PTR_ERR(fscki1); 2090 err = PTR_ERR(fscki1);
2091 ubifs_err("error %d while processing entry node and trying to find parent inode node %lu", 2091 ubifs_err(c, "error %d while processing entry node and trying to find parent inode node %lu",
2092 err, (unsigned long)inum); 2092 err, (unsigned long)inum);
2093 goto out_dump; 2093 goto out_dump;
2094 } 2094 }
@@ -2111,7 +2111,7 @@ out:
2111 return 0; 2111 return 0;
2112 2112
2113out_dump: 2113out_dump:
2114 ubifs_msg("dump of node at LEB %d:%d", zbr->lnum, zbr->offs); 2114 ubifs_msg(c, "dump of node at LEB %d:%d", zbr->lnum, zbr->offs);
2115 ubifs_dump_node(c, node); 2115 ubifs_dump_node(c, node);
2116out_free: 2116out_free:
2117 kfree(node); 2117 kfree(node);
@@ -2162,52 +2162,52 @@ static int check_inodes(struct ubifs_info *c, struct fsck_data *fsckd)
2162 */ 2162 */
2163 if (fscki->inum != UBIFS_ROOT_INO && 2163 if (fscki->inum != UBIFS_ROOT_INO &&
2164 fscki->references != 1) { 2164 fscki->references != 1) {
2165 ubifs_err("directory inode %lu has %d direntries which refer it, but should be 1", 2165 ubifs_err(c, "directory inode %lu has %d direntries which refer it, but should be 1",
2166 (unsigned long)fscki->inum, 2166 (unsigned long)fscki->inum,
2167 fscki->references); 2167 fscki->references);
2168 goto out_dump; 2168 goto out_dump;
2169 } 2169 }
2170 if (fscki->inum == UBIFS_ROOT_INO && 2170 if (fscki->inum == UBIFS_ROOT_INO &&
2171 fscki->references != 0) { 2171 fscki->references != 0) {
2172 ubifs_err("root inode %lu has non-zero (%d) direntries which refer it", 2172 ubifs_err(c, "root inode %lu has non-zero (%d) direntries which refer it",
2173 (unsigned long)fscki->inum, 2173 (unsigned long)fscki->inum,
2174 fscki->references); 2174 fscki->references);
2175 goto out_dump; 2175 goto out_dump;
2176 } 2176 }
2177 if (fscki->calc_sz != fscki->size) { 2177 if (fscki->calc_sz != fscki->size) {
2178 ubifs_err("directory inode %lu size is %lld, but calculated size is %lld", 2178 ubifs_err(c, "directory inode %lu size is %lld, but calculated size is %lld",
2179 (unsigned long)fscki->inum, 2179 (unsigned long)fscki->inum,
2180 fscki->size, fscki->calc_sz); 2180 fscki->size, fscki->calc_sz);
2181 goto out_dump; 2181 goto out_dump;
2182 } 2182 }
2183 if (fscki->calc_cnt != fscki->nlink) { 2183 if (fscki->calc_cnt != fscki->nlink) {
2184 ubifs_err("directory inode %lu nlink is %d, but calculated nlink is %d", 2184 ubifs_err(c, "directory inode %lu nlink is %d, but calculated nlink is %d",
2185 (unsigned long)fscki->inum, 2185 (unsigned long)fscki->inum,
2186 fscki->nlink, fscki->calc_cnt); 2186 fscki->nlink, fscki->calc_cnt);
2187 goto out_dump; 2187 goto out_dump;
2188 } 2188 }
2189 } else { 2189 } else {
2190 if (fscki->references != fscki->nlink) { 2190 if (fscki->references != fscki->nlink) {
2191 ubifs_err("inode %lu nlink is %d, but calculated nlink is %d", 2191 ubifs_err(c, "inode %lu nlink is %d, but calculated nlink is %d",
2192 (unsigned long)fscki->inum, 2192 (unsigned long)fscki->inum,
2193 fscki->nlink, fscki->references); 2193 fscki->nlink, fscki->references);
2194 goto out_dump; 2194 goto out_dump;
2195 } 2195 }
2196 } 2196 }
2197 if (fscki->xattr_sz != fscki->calc_xsz) { 2197 if (fscki->xattr_sz != fscki->calc_xsz) {
2198 ubifs_err("inode %lu has xattr size %u, but calculated size is %lld", 2198 ubifs_err(c, "inode %lu has xattr size %u, but calculated size is %lld",
2199 (unsigned long)fscki->inum, fscki->xattr_sz, 2199 (unsigned long)fscki->inum, fscki->xattr_sz,
2200 fscki->calc_xsz); 2200 fscki->calc_xsz);
2201 goto out_dump; 2201 goto out_dump;
2202 } 2202 }
2203 if (fscki->xattr_cnt != fscki->calc_xcnt) { 2203 if (fscki->xattr_cnt != fscki->calc_xcnt) {
2204 ubifs_err("inode %lu has %u xattrs, but calculated count is %lld", 2204 ubifs_err(c, "inode %lu has %u xattrs, but calculated count is %lld",
2205 (unsigned long)fscki->inum, 2205 (unsigned long)fscki->inum,
2206 fscki->xattr_cnt, fscki->calc_xcnt); 2206 fscki->xattr_cnt, fscki->calc_xcnt);
2207 goto out_dump; 2207 goto out_dump;
2208 } 2208 }
2209 if (fscki->xattr_nms != fscki->calc_xnms) { 2209 if (fscki->xattr_nms != fscki->calc_xnms) {
2210 ubifs_err("inode %lu has xattr names' size %u, but calculated names' size is %lld", 2210 ubifs_err(c, "inode %lu has xattr names' size %u, but calculated names' size is %lld",
2211 (unsigned long)fscki->inum, fscki->xattr_nms, 2211 (unsigned long)fscki->inum, fscki->xattr_nms,
2212 fscki->calc_xnms); 2212 fscki->calc_xnms);
2213 goto out_dump; 2213 goto out_dump;
@@ -2221,11 +2221,11 @@ out_dump:
2221 ino_key_init(c, &key, fscki->inum); 2221 ino_key_init(c, &key, fscki->inum);
2222 err = ubifs_lookup_level0(c, &key, &znode, &n); 2222 err = ubifs_lookup_level0(c, &key, &znode, &n);
2223 if (!err) { 2223 if (!err) {
2224 ubifs_err("inode %lu not found in index", 2224 ubifs_err(c, "inode %lu not found in index",
2225 (unsigned long)fscki->inum); 2225 (unsigned long)fscki->inum);
2226 return -ENOENT; 2226 return -ENOENT;
2227 } else if (err < 0) { 2227 } else if (err < 0) {
2228 ubifs_err("error %d while looking up inode %lu", 2228 ubifs_err(c, "error %d while looking up inode %lu",
2229 err, (unsigned long)fscki->inum); 2229 err, (unsigned long)fscki->inum);
2230 return err; 2230 return err;
2231 } 2231 }
@@ -2237,13 +2237,13 @@ out_dump:
2237 2237
2238 err = ubifs_tnc_read_node(c, zbr, ino); 2238 err = ubifs_tnc_read_node(c, zbr, ino);
2239 if (err) { 2239 if (err) {
2240 ubifs_err("cannot read inode node at LEB %d:%d, error %d", 2240 ubifs_err(c, "cannot read inode node at LEB %d:%d, error %d",
2241 zbr->lnum, zbr->offs, err); 2241 zbr->lnum, zbr->offs, err);
2242 kfree(ino); 2242 kfree(ino);
2243 return err; 2243 return err;
2244 } 2244 }
2245 2245
2246 ubifs_msg("dump of the inode %lu sitting in LEB %d:%d", 2246 ubifs_msg(c, "dump of the inode %lu sitting in LEB %d:%d",
2247 (unsigned long)fscki->inum, zbr->lnum, zbr->offs); 2247 (unsigned long)fscki->inum, zbr->lnum, zbr->offs);
2248 ubifs_dump_node(c, ino); 2248 ubifs_dump_node(c, ino);
2249 kfree(ino); 2249 kfree(ino);
@@ -2284,7 +2284,7 @@ int dbg_check_filesystem(struct ubifs_info *c)
2284 return 0; 2284 return 0;
2285 2285
2286out_free: 2286out_free:
2287 ubifs_err("file-system check failed with error %d", err); 2287 ubifs_err(c, "file-system check failed with error %d", err);
2288 dump_stack(); 2288 dump_stack();
2289 free_inodes(&fsckd); 2289 free_inodes(&fsckd);
2290 return err; 2290 return err;
@@ -2315,12 +2315,12 @@ int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head)
2315 sb = container_of(cur->next, struct ubifs_scan_node, list); 2315 sb = container_of(cur->next, struct ubifs_scan_node, list);
2316 2316
2317 if (sa->type != UBIFS_DATA_NODE) { 2317 if (sa->type != UBIFS_DATA_NODE) {
2318 ubifs_err("bad node type %d", sa->type); 2318 ubifs_err(c, "bad node type %d", sa->type);
2319 ubifs_dump_node(c, sa->node); 2319 ubifs_dump_node(c, sa->node);
2320 return -EINVAL; 2320 return -EINVAL;
2321 } 2321 }
2322 if (sb->type != UBIFS_DATA_NODE) { 2322 if (sb->type != UBIFS_DATA_NODE) {
2323 ubifs_err("bad node type %d", sb->type); 2323 ubifs_err(c, "bad node type %d", sb->type);
2324 ubifs_dump_node(c, sb->node); 2324 ubifs_dump_node(c, sb->node);
2325 return -EINVAL; 2325 return -EINVAL;
2326 } 2326 }
@@ -2331,7 +2331,7 @@ int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head)
2331 if (inuma < inumb) 2331 if (inuma < inumb)
2332 continue; 2332 continue;
2333 if (inuma > inumb) { 2333 if (inuma > inumb) {
2334 ubifs_err("larger inum %lu goes before inum %lu", 2334 ubifs_err(c, "larger inum %lu goes before inum %lu",
2335 (unsigned long)inuma, (unsigned long)inumb); 2335 (unsigned long)inuma, (unsigned long)inumb);
2336 goto error_dump; 2336 goto error_dump;
2337 } 2337 }
@@ -2340,11 +2340,11 @@ int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head)
2340 blkb = key_block(c, &sb->key); 2340 blkb = key_block(c, &sb->key);
2341 2341
2342 if (blka > blkb) { 2342 if (blka > blkb) {
2343 ubifs_err("larger block %u goes before %u", blka, blkb); 2343 ubifs_err(c, "larger block %u goes before %u", blka, blkb);
2344 goto error_dump; 2344 goto error_dump;
2345 } 2345 }
2346 if (blka == blkb) { 2346 if (blka == blkb) {
2347 ubifs_err("two data nodes for the same block"); 2347 ubifs_err(c, "two data nodes for the same block");
2348 goto error_dump; 2348 goto error_dump;
2349 } 2349 }
2350 } 2350 }
@@ -2383,19 +2383,19 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head)
2383 2383
2384 if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && 2384 if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE &&
2385 sa->type != UBIFS_XENT_NODE) { 2385 sa->type != UBIFS_XENT_NODE) {
2386 ubifs_err("bad node type %d", sa->type); 2386 ubifs_err(c, "bad node type %d", sa->type);
2387 ubifs_dump_node(c, sa->node); 2387 ubifs_dump_node(c, sa->node);
2388 return -EINVAL; 2388 return -EINVAL;
2389 } 2389 }
2390 if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && 2390 if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE &&
2391 sa->type != UBIFS_XENT_NODE) { 2391 sa->type != UBIFS_XENT_NODE) {
2392 ubifs_err("bad node type %d", sb->type); 2392 ubifs_err(c, "bad node type %d", sb->type);
2393 ubifs_dump_node(c, sb->node); 2393 ubifs_dump_node(c, sb->node);
2394 return -EINVAL; 2394 return -EINVAL;
2395 } 2395 }
2396 2396
2397 if (sa->type != UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) { 2397 if (sa->type != UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) {
2398 ubifs_err("non-inode node goes before inode node"); 2398 ubifs_err(c, "non-inode node goes before inode node");
2399 goto error_dump; 2399 goto error_dump;
2400 } 2400 }
2401 2401
@@ -2405,7 +2405,7 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head)
2405 if (sa->type == UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) { 2405 if (sa->type == UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) {
2406 /* Inode nodes are sorted in descending size order */ 2406 /* Inode nodes are sorted in descending size order */
2407 if (sa->len < sb->len) { 2407 if (sa->len < sb->len) {
2408 ubifs_err("smaller inode node goes first"); 2408 ubifs_err(c, "smaller inode node goes first");
2409 goto error_dump; 2409 goto error_dump;
2410 } 2410 }
2411 continue; 2411 continue;
@@ -2421,7 +2421,7 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head)
2421 if (inuma < inumb) 2421 if (inuma < inumb)
2422 continue; 2422 continue;
2423 if (inuma > inumb) { 2423 if (inuma > inumb) {
2424 ubifs_err("larger inum %lu goes before inum %lu", 2424 ubifs_err(c, "larger inum %lu goes before inum %lu",
2425 (unsigned long)inuma, (unsigned long)inumb); 2425 (unsigned long)inuma, (unsigned long)inumb);
2426 goto error_dump; 2426 goto error_dump;
2427 } 2427 }
@@ -2430,7 +2430,7 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head)
2430 hashb = key_block(c, &sb->key); 2430 hashb = key_block(c, &sb->key);
2431 2431
2432 if (hasha > hashb) { 2432 if (hasha > hashb) {
2433 ubifs_err("larger hash %u goes before %u", 2433 ubifs_err(c, "larger hash %u goes before %u",
2434 hasha, hashb); 2434 hasha, hashb);
2435 goto error_dump; 2435 goto error_dump;
2436 } 2436 }
@@ -2439,9 +2439,9 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head)
2439 return 0; 2439 return 0;
2440 2440
2441error_dump: 2441error_dump:
2442 ubifs_msg("dumping first node"); 2442 ubifs_msg(c, "dumping first node");
2443 ubifs_dump_node(c, sa->node); 2443 ubifs_dump_node(c, sa->node);
2444 ubifs_msg("dumping second node"); 2444 ubifs_msg(c, "dumping second node");
2445 ubifs_dump_node(c, sb->node); 2445 ubifs_dump_node(c, sb->node);
2446 return -EINVAL; 2446 return -EINVAL;
2447 return 0; 2447 return 0;
@@ -2470,13 +2470,13 @@ static int power_cut_emulated(struct ubifs_info *c, int lnum, int write)
2470 delay = prandom_u32() % 60000; 2470 delay = prandom_u32() % 60000;
2471 d->pc_timeout = jiffies; 2471 d->pc_timeout = jiffies;
2472 d->pc_timeout += msecs_to_jiffies(delay); 2472 d->pc_timeout += msecs_to_jiffies(delay);
2473 ubifs_warn("failing after %lums", delay); 2473 ubifs_warn(c, "failing after %lums", delay);
2474 } else { 2474 } else {
2475 d->pc_delay = 2; 2475 d->pc_delay = 2;
2476 delay = prandom_u32() % 10000; 2476 delay = prandom_u32() % 10000;
2477 /* Fail within 10000 operations */ 2477 /* Fail within 10000 operations */
2478 d->pc_cnt_max = delay; 2478 d->pc_cnt_max = delay;
2479 ubifs_warn("failing after %lu calls", delay); 2479 ubifs_warn(c, "failing after %lu calls", delay);
2480 } 2480 }
2481 } 2481 }
2482 2482
@@ -2494,55 +2494,55 @@ static int power_cut_emulated(struct ubifs_info *c, int lnum, int write)
2494 return 0; 2494 return 0;
2495 if (chance(19, 20)) 2495 if (chance(19, 20))
2496 return 0; 2496 return 0;
2497 ubifs_warn("failing in super block LEB %d", lnum); 2497 ubifs_warn(c, "failing in super block LEB %d", lnum);
2498 } else if (lnum == UBIFS_MST_LNUM || lnum == UBIFS_MST_LNUM + 1) { 2498 } else if (lnum == UBIFS_MST_LNUM || lnum == UBIFS_MST_LNUM + 1) {
2499 if (chance(19, 20)) 2499 if (chance(19, 20))
2500 return 0; 2500 return 0;
2501 ubifs_warn("failing in master LEB %d", lnum); 2501 ubifs_warn(c, "failing in master LEB %d", lnum);
2502 } else if (lnum >= UBIFS_LOG_LNUM && lnum <= c->log_last) { 2502 } else if (lnum >= UBIFS_LOG_LNUM && lnum <= c->log_last) {
2503 if (write && chance(99, 100)) 2503 if (write && chance(99, 100))
2504 return 0; 2504 return 0;
2505 if (chance(399, 400)) 2505 if (chance(399, 400))
2506 return 0; 2506 return 0;
2507 ubifs_warn("failing in log LEB %d", lnum); 2507 ubifs_warn(c, "failing in log LEB %d", lnum);
2508 } else if (lnum >= c->lpt_first && lnum <= c->lpt_last) { 2508 } else if (lnum >= c->lpt_first && lnum <= c->lpt_last) {
2509 if (write && chance(7, 8)) 2509 if (write && chance(7, 8))
2510 return 0; 2510 return 0;
2511 if (chance(19, 20)) 2511 if (chance(19, 20))
2512 return 0; 2512 return 0;
2513 ubifs_warn("failing in LPT LEB %d", lnum); 2513 ubifs_warn(c, "failing in LPT LEB %d", lnum);
2514 } else if (lnum >= c->orph_first && lnum <= c->orph_last) { 2514 } else if (lnum >= c->orph_first && lnum <= c->orph_last) {
2515 if (write && chance(1, 2)) 2515 if (write && chance(1, 2))
2516 return 0; 2516 return 0;
2517 if (chance(9, 10)) 2517 if (chance(9, 10))
2518 return 0; 2518 return 0;
2519 ubifs_warn("failing in orphan LEB %d", lnum); 2519 ubifs_warn(c, "failing in orphan LEB %d", lnum);
2520 } else if (lnum == c->ihead_lnum) { 2520 } else if (lnum == c->ihead_lnum) {
2521 if (chance(99, 100)) 2521 if (chance(99, 100))
2522 return 0; 2522 return 0;
2523 ubifs_warn("failing in index head LEB %d", lnum); 2523 ubifs_warn(c, "failing in index head LEB %d", lnum);
2524 } else if (c->jheads && lnum == c->jheads[GCHD].wbuf.lnum) { 2524 } else if (c->jheads && lnum == c->jheads[GCHD].wbuf.lnum) {
2525 if (chance(9, 10)) 2525 if (chance(9, 10))
2526 return 0; 2526 return 0;
2527 ubifs_warn("failing in GC head LEB %d", lnum); 2527 ubifs_warn(c, "failing in GC head LEB %d", lnum);
2528 } else if (write && !RB_EMPTY_ROOT(&c->buds) && 2528 } else if (write && !RB_EMPTY_ROOT(&c->buds) &&
2529 !ubifs_search_bud(c, lnum)) { 2529 !ubifs_search_bud(c, lnum)) {
2530 if (chance(19, 20)) 2530 if (chance(19, 20))
2531 return 0; 2531 return 0;
2532 ubifs_warn("failing in non-bud LEB %d", lnum); 2532 ubifs_warn(c, "failing in non-bud LEB %d", lnum);
2533 } else if (c->cmt_state == COMMIT_RUNNING_BACKGROUND || 2533 } else if (c->cmt_state == COMMIT_RUNNING_BACKGROUND ||
2534 c->cmt_state == COMMIT_RUNNING_REQUIRED) { 2534 c->cmt_state == COMMIT_RUNNING_REQUIRED) {
2535 if (chance(999, 1000)) 2535 if (chance(999, 1000))
2536 return 0; 2536 return 0;
2537 ubifs_warn("failing in bud LEB %d commit running", lnum); 2537 ubifs_warn(c, "failing in bud LEB %d commit running", lnum);
2538 } else { 2538 } else {
2539 if (chance(9999, 10000)) 2539 if (chance(9999, 10000))
2540 return 0; 2540 return 0;
2541 ubifs_warn("failing in bud LEB %d commit not running", lnum); 2541 ubifs_warn(c, "failing in bud LEB %d commit not running", lnum);
2542 } 2542 }
2543 2543
2544 d->pc_happened = 1; 2544 d->pc_happened = 1;
2545 ubifs_warn("========== Power cut emulated =========="); 2545 ubifs_warn(c, "========== Power cut emulated ==========");
2546 dump_stack(); 2546 dump_stack();
2547 return 1; 2547 return 1;
2548} 2548}
@@ -2557,7 +2557,7 @@ static int corrupt_data(const struct ubifs_info *c, const void *buf,
2557 /* Corruption span max to end of write unit */ 2557 /* Corruption span max to end of write unit */
2558 to = min(len, ALIGN(from + 1, c->max_write_size)); 2558 to = min(len, ALIGN(from + 1, c->max_write_size));
2559 2559
2560 ubifs_warn("filled bytes %u-%u with %s", from, to - 1, 2560 ubifs_warn(c, "filled bytes %u-%u with %s", from, to - 1,
2561 ffs ? "0xFFs" : "random data"); 2561 ffs ? "0xFFs" : "random data");
2562 2562
2563 if (ffs) 2563 if (ffs)
@@ -2579,7 +2579,7 @@ int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf,
2579 failing = power_cut_emulated(c, lnum, 1); 2579 failing = power_cut_emulated(c, lnum, 1);
2580 if (failing) { 2580 if (failing) {
2581 len = corrupt_data(c, buf, len); 2581 len = corrupt_data(c, buf, len);
2582 ubifs_warn("actually write %d bytes to LEB %d:%d (the buffer was corrupted)", 2582 ubifs_warn(c, "actually write %d bytes to LEB %d:%d (the buffer was corrupted)",
2583 len, lnum, offs); 2583 len, lnum, offs);
2584 } 2584 }
2585 err = ubi_leb_write(c->ubi, lnum, buf, offs, len); 2585 err = ubi_leb_write(c->ubi, lnum, buf, offs, len);
@@ -2909,7 +2909,7 @@ out_remove:
2909 debugfs_remove_recursive(d->dfs_dir); 2909 debugfs_remove_recursive(d->dfs_dir);
2910out: 2910out:
2911 err = dent ? PTR_ERR(dent) : -ENODEV; 2911 err = dent ? PTR_ERR(dent) : -ENODEV;
2912 ubifs_err("cannot create \"%s\" debugfs file or directory, error %d\n", 2912 ubifs_err(c, "cannot create \"%s\" debugfs file or directory, error %d\n",
2913 fname, err); 2913 fname, err);
2914 return err; 2914 return err;
2915} 2915}
@@ -3063,8 +3063,8 @@ out_remove:
3063 debugfs_remove_recursive(dfs_rootdir); 3063 debugfs_remove_recursive(dfs_rootdir);
3064out: 3064out:
3065 err = dent ? PTR_ERR(dent) : -ENODEV; 3065 err = dent ? PTR_ERR(dent) : -ENODEV;
3066 ubifs_err("cannot create \"%s\" debugfs file or directory, error %d\n", 3066 pr_err("UBIFS error (pid %d): cannot create \"%s\" debugfs file or directory, error %d\n",
3067 fname, err); 3067 current->pid, fname, err);
3068 return err; 3068 return err;
3069} 3069}
3070 3070
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 0fa6c803992e..02d1ee778df0 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -146,12 +146,12 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, const struct inode *dir,
146 if (c->highest_inum >= INUM_WARN_WATERMARK) { 146 if (c->highest_inum >= INUM_WARN_WATERMARK) {
147 if (c->highest_inum >= INUM_WATERMARK) { 147 if (c->highest_inum >= INUM_WATERMARK) {
148 spin_unlock(&c->cnt_lock); 148 spin_unlock(&c->cnt_lock);
149 ubifs_err("out of inode numbers"); 149 ubifs_err(c, "out of inode numbers");
150 make_bad_inode(inode); 150 make_bad_inode(inode);
151 iput(inode); 151 iput(inode);
152 return ERR_PTR(-EINVAL); 152 return ERR_PTR(-EINVAL);
153 } 153 }
154 ubifs_warn("running out of inode numbers (current %lu, max %d)", 154 ubifs_warn(c, "running out of inode numbers (current %lu, max %u)",
155 (unsigned long)c->highest_inum, INUM_WATERMARK); 155 (unsigned long)c->highest_inum, INUM_WATERMARK);
156 } 156 }
157 157
@@ -222,7 +222,7 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
222 * checking. 222 * checking.
223 */ 223 */
224 err = PTR_ERR(inode); 224 err = PTR_ERR(inode);
225 ubifs_err("dead directory entry '%pd', error %d", 225 ubifs_err(c, "dead directory entry '%pd', error %d",
226 dentry, err); 226 dentry, err);
227 ubifs_ro_mode(c, err); 227 ubifs_ro_mode(c, err);
228 goto out; 228 goto out;
@@ -272,7 +272,7 @@ static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
272 272
273 err = ubifs_init_security(dir, inode, &dentry->d_name); 273 err = ubifs_init_security(dir, inode, &dentry->d_name);
274 if (err) 274 if (err)
275 goto out_cancel; 275 goto out_inode;
276 276
277 mutex_lock(&dir_ui->ui_mutex); 277 mutex_lock(&dir_ui->ui_mutex);
278 dir->i_size += sz_change; 278 dir->i_size += sz_change;
@@ -292,11 +292,12 @@ out_cancel:
292 dir->i_size -= sz_change; 292 dir->i_size -= sz_change;
293 dir_ui->ui_size = dir->i_size; 293 dir_ui->ui_size = dir->i_size;
294 mutex_unlock(&dir_ui->ui_mutex); 294 mutex_unlock(&dir_ui->ui_mutex);
295out_inode:
295 make_bad_inode(inode); 296 make_bad_inode(inode);
296 iput(inode); 297 iput(inode);
297out_budg: 298out_budg:
298 ubifs_release_budget(c, &req); 299 ubifs_release_budget(c, &req);
299 ubifs_err("cannot create regular file, error %d", err); 300 ubifs_err(c, "cannot create regular file, error %d", err);
300 return err; 301 return err;
301} 302}
302 303
@@ -449,7 +450,7 @@ static int ubifs_readdir(struct file *file, struct dir_context *ctx)
449 450
450out: 451out:
451 if (err != -ENOENT) { 452 if (err != -ENOENT) {
452 ubifs_err("cannot find next direntry, error %d", err); 453 ubifs_err(c, "cannot find next direntry, error %d", err);
453 return err; 454 return err;
454 } 455 }
455 456
@@ -732,7 +733,7 @@ static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
732 733
733 err = ubifs_init_security(dir, inode, &dentry->d_name); 734 err = ubifs_init_security(dir, inode, &dentry->d_name);
734 if (err) 735 if (err)
735 goto out_cancel; 736 goto out_inode;
736 737
737 mutex_lock(&dir_ui->ui_mutex); 738 mutex_lock(&dir_ui->ui_mutex);
738 insert_inode_hash(inode); 739 insert_inode_hash(inode);
@@ -743,7 +744,7 @@ static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
743 dir->i_mtime = dir->i_ctime = inode->i_ctime; 744 dir->i_mtime = dir->i_ctime = inode->i_ctime;
744 err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0); 745 err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
745 if (err) { 746 if (err) {
746 ubifs_err("cannot create directory, error %d", err); 747 ubifs_err(c, "cannot create directory, error %d", err);
747 goto out_cancel; 748 goto out_cancel;
748 } 749 }
749 mutex_unlock(&dir_ui->ui_mutex); 750 mutex_unlock(&dir_ui->ui_mutex);
@@ -757,6 +758,7 @@ out_cancel:
757 dir_ui->ui_size = dir->i_size; 758 dir_ui->ui_size = dir->i_size;
758 drop_nlink(dir); 759 drop_nlink(dir);
759 mutex_unlock(&dir_ui->ui_mutex); 760 mutex_unlock(&dir_ui->ui_mutex);
761out_inode:
760 make_bad_inode(inode); 762 make_bad_inode(inode);
761 iput(inode); 763 iput(inode);
762out_budg: 764out_budg:
@@ -816,7 +818,7 @@ static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
816 818
817 err = ubifs_init_security(dir, inode, &dentry->d_name); 819 err = ubifs_init_security(dir, inode, &dentry->d_name);
818 if (err) 820 if (err)
819 goto out_cancel; 821 goto out_inode;
820 822
821 mutex_lock(&dir_ui->ui_mutex); 823 mutex_lock(&dir_ui->ui_mutex);
822 dir->i_size += sz_change; 824 dir->i_size += sz_change;
@@ -836,6 +838,7 @@ out_cancel:
836 dir->i_size -= sz_change; 838 dir->i_size -= sz_change;
837 dir_ui->ui_size = dir->i_size; 839 dir_ui->ui_size = dir->i_size;
838 mutex_unlock(&dir_ui->ui_mutex); 840 mutex_unlock(&dir_ui->ui_mutex);
841out_inode:
839 make_bad_inode(inode); 842 make_bad_inode(inode);
840 iput(inode); 843 iput(inode);
841out_budg: 844out_budg:
@@ -896,7 +899,7 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
896 899
897 err = ubifs_init_security(dir, inode, &dentry->d_name); 900 err = ubifs_init_security(dir, inode, &dentry->d_name);
898 if (err) 901 if (err)
899 goto out_cancel; 902 goto out_inode;
900 903
901 mutex_lock(&dir_ui->ui_mutex); 904 mutex_lock(&dir_ui->ui_mutex);
902 dir->i_size += sz_change; 905 dir->i_size += sz_change;
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index 475b15635f11..3ba3fef64e9e 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -79,7 +79,7 @@ static int read_block(struct inode *inode, void *addr, unsigned int block,
79 79
80 dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ; 80 dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
81 out_len = UBIFS_BLOCK_SIZE; 81 out_len = UBIFS_BLOCK_SIZE;
82 err = ubifs_decompress(&dn->data, dlen, addr, &out_len, 82 err = ubifs_decompress(c, &dn->data, dlen, addr, &out_len,
83 le16_to_cpu(dn->compr_type)); 83 le16_to_cpu(dn->compr_type));
84 if (err || len != out_len) 84 if (err || len != out_len)
85 goto dump; 85 goto dump;
@@ -95,7 +95,7 @@ static int read_block(struct inode *inode, void *addr, unsigned int block,
95 return 0; 95 return 0;
96 96
97dump: 97dump:
98 ubifs_err("bad data node (block %u, inode %lu)", 98 ubifs_err(c, "bad data node (block %u, inode %lu)",
99 block, inode->i_ino); 99 block, inode->i_ino);
100 ubifs_dump_node(c, dn); 100 ubifs_dump_node(c, dn);
101 return -EINVAL; 101 return -EINVAL;
@@ -160,13 +160,14 @@ static int do_readpage(struct page *page)
160 addr += UBIFS_BLOCK_SIZE; 160 addr += UBIFS_BLOCK_SIZE;
161 } 161 }
162 if (err) { 162 if (err) {
163 struct ubifs_info *c = inode->i_sb->s_fs_info;
163 if (err == -ENOENT) { 164 if (err == -ENOENT) {
164 /* Not found, so it must be a hole */ 165 /* Not found, so it must be a hole */
165 SetPageChecked(page); 166 SetPageChecked(page);
166 dbg_gen("hole"); 167 dbg_gen("hole");
167 goto out_free; 168 goto out_free;
168 } 169 }
169 ubifs_err("cannot read page %lu of inode %lu, error %d", 170 ubifs_err(c, "cannot read page %lu of inode %lu, error %d",
170 page->index, inode->i_ino, err); 171 page->index, inode->i_ino, err);
171 goto error; 172 goto error;
172 } 173 }
@@ -649,7 +650,7 @@ static int populate_page(struct ubifs_info *c, struct page *page,
649 650
650 dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ; 651 dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
651 out_len = UBIFS_BLOCK_SIZE; 652 out_len = UBIFS_BLOCK_SIZE;
652 err = ubifs_decompress(&dn->data, dlen, addr, &out_len, 653 err = ubifs_decompress(c, &dn->data, dlen, addr, &out_len,
653 le16_to_cpu(dn->compr_type)); 654 le16_to_cpu(dn->compr_type));
654 if (err || len != out_len) 655 if (err || len != out_len)
655 goto out_err; 656 goto out_err;
@@ -697,7 +698,7 @@ out_err:
697 SetPageError(page); 698 SetPageError(page);
698 flush_dcache_page(page); 699 flush_dcache_page(page);
699 kunmap(page); 700 kunmap(page);
700 ubifs_err("bad data node (block %u, inode %lu)", 701 ubifs_err(c, "bad data node (block %u, inode %lu)",
701 page_block, inode->i_ino); 702 page_block, inode->i_ino);
702 return -EINVAL; 703 return -EINVAL;
703} 704}
@@ -801,7 +802,7 @@ out_free:
801 return ret; 802 return ret;
802 803
803out_warn: 804out_warn:
804 ubifs_warn("ignoring error %d and skipping bulk-read", err); 805 ubifs_warn(c, "ignoring error %d and skipping bulk-read", err);
805 goto out_free; 806 goto out_free;
806 807
807out_bu_off: 808out_bu_off:
@@ -929,7 +930,7 @@ static int do_writepage(struct page *page, int len)
929 } 930 }
930 if (err) { 931 if (err) {
931 SetPageError(page); 932 SetPageError(page);
932 ubifs_err("cannot write page %lu of inode %lu, error %d", 933 ubifs_err(c, "cannot write page %lu of inode %lu, error %d",
933 page->index, inode->i_ino, err); 934 page->index, inode->i_ino, err);
934 ubifs_ro_mode(c, err); 935 ubifs_ro_mode(c, err);
935 } 936 }
@@ -1484,7 +1485,7 @@ static int ubifs_vm_page_mkwrite(struct vm_area_struct *vma,
1484 err = ubifs_budget_space(c, &req); 1485 err = ubifs_budget_space(c, &req);
1485 if (unlikely(err)) { 1486 if (unlikely(err)) {
1486 if (err == -ENOSPC) 1487 if (err == -ENOSPC)
1487 ubifs_warn("out of space for mmapped file (inode number %lu)", 1488 ubifs_warn(c, "out of space for mmapped file (inode number %lu)",
1488 inode->i_ino); 1489 inode->i_ino);
1489 return VM_FAULT_SIGBUS; 1490 return VM_FAULT_SIGBUS;
1490 } 1491 }
diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
index fb08b0c514b6..97be41215332 100644
--- a/fs/ubifs/io.c
+++ b/fs/ubifs/io.c
@@ -85,7 +85,7 @@ void ubifs_ro_mode(struct ubifs_info *c, int err)
85 c->ro_error = 1; 85 c->ro_error = 1;
86 c->no_chk_data_crc = 0; 86 c->no_chk_data_crc = 0;
87 c->vfs_sb->s_flags |= MS_RDONLY; 87 c->vfs_sb->s_flags |= MS_RDONLY;
88 ubifs_warn("switched to read-only mode, error %d", err); 88 ubifs_warn(c, "switched to read-only mode, error %d", err);
89 dump_stack(); 89 dump_stack();
90 } 90 }
91} 91}
@@ -107,7 +107,7 @@ int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs,
107 * @even_ebadmsg is true. 107 * @even_ebadmsg is true.
108 */ 108 */
109 if (err && (err != -EBADMSG || even_ebadmsg)) { 109 if (err && (err != -EBADMSG || even_ebadmsg)) {
110 ubifs_err("reading %d bytes from LEB %d:%d failed, error %d", 110 ubifs_err(c, "reading %d bytes from LEB %d:%d failed, error %d",
111 len, lnum, offs, err); 111 len, lnum, offs, err);
112 dump_stack(); 112 dump_stack();
113 } 113 }
@@ -127,7 +127,7 @@ int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
127 else 127 else
128 err = dbg_leb_write(c, lnum, buf, offs, len); 128 err = dbg_leb_write(c, lnum, buf, offs, len);
129 if (err) { 129 if (err) {
130 ubifs_err("writing %d bytes to LEB %d:%d failed, error %d", 130 ubifs_err(c, "writing %d bytes to LEB %d:%d failed, error %d",
131 len, lnum, offs, err); 131 len, lnum, offs, err);
132 ubifs_ro_mode(c, err); 132 ubifs_ro_mode(c, err);
133 dump_stack(); 133 dump_stack();
@@ -147,7 +147,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
147 else 147 else
148 err = dbg_leb_change(c, lnum, buf, len); 148 err = dbg_leb_change(c, lnum, buf, len);
149 if (err) { 149 if (err) {
150 ubifs_err("changing %d bytes in LEB %d failed, error %d", 150 ubifs_err(c, "changing %d bytes in LEB %d failed, error %d",
151 len, lnum, err); 151 len, lnum, err);
152 ubifs_ro_mode(c, err); 152 ubifs_ro_mode(c, err);
153 dump_stack(); 153 dump_stack();
@@ -167,7 +167,7 @@ int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
167 else 167 else
168 err = dbg_leb_unmap(c, lnum); 168 err = dbg_leb_unmap(c, lnum);
169 if (err) { 169 if (err) {
170 ubifs_err("unmap LEB %d failed, error %d", lnum, err); 170 ubifs_err(c, "unmap LEB %d failed, error %d", lnum, err);
171 ubifs_ro_mode(c, err); 171 ubifs_ro_mode(c, err);
172 dump_stack(); 172 dump_stack();
173 } 173 }
@@ -186,7 +186,7 @@ int ubifs_leb_map(struct ubifs_info *c, int lnum)
186 else 186 else
187 err = dbg_leb_map(c, lnum); 187 err = dbg_leb_map(c, lnum);
188 if (err) { 188 if (err) {
189 ubifs_err("mapping LEB %d failed, error %d", lnum, err); 189 ubifs_err(c, "mapping LEB %d failed, error %d", lnum, err);
190 ubifs_ro_mode(c, err); 190 ubifs_ro_mode(c, err);
191 dump_stack(); 191 dump_stack();
192 } 192 }
@@ -199,7 +199,7 @@ int ubifs_is_mapped(const struct ubifs_info *c, int lnum)
199 199
200 err = ubi_is_mapped(c->ubi, lnum); 200 err = ubi_is_mapped(c->ubi, lnum);
201 if (err < 0) { 201 if (err < 0) {
202 ubifs_err("ubi_is_mapped failed for LEB %d, error %d", 202 ubifs_err(c, "ubi_is_mapped failed for LEB %d, error %d",
203 lnum, err); 203 lnum, err);
204 dump_stack(); 204 dump_stack();
205 } 205 }
@@ -247,7 +247,7 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
247 magic = le32_to_cpu(ch->magic); 247 magic = le32_to_cpu(ch->magic);
248 if (magic != UBIFS_NODE_MAGIC) { 248 if (magic != UBIFS_NODE_MAGIC) {
249 if (!quiet) 249 if (!quiet)
250 ubifs_err("bad magic %#08x, expected %#08x", 250 ubifs_err(c, "bad magic %#08x, expected %#08x",
251 magic, UBIFS_NODE_MAGIC); 251 magic, UBIFS_NODE_MAGIC);
252 err = -EUCLEAN; 252 err = -EUCLEAN;
253 goto out; 253 goto out;
@@ -256,7 +256,7 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
256 type = ch->node_type; 256 type = ch->node_type;
257 if (type < 0 || type >= UBIFS_NODE_TYPES_CNT) { 257 if (type < 0 || type >= UBIFS_NODE_TYPES_CNT) {
258 if (!quiet) 258 if (!quiet)
259 ubifs_err("bad node type %d", type); 259 ubifs_err(c, "bad node type %d", type);
260 goto out; 260 goto out;
261 } 261 }
262 262
@@ -279,7 +279,7 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
279 node_crc = le32_to_cpu(ch->crc); 279 node_crc = le32_to_cpu(ch->crc);
280 if (crc != node_crc) { 280 if (crc != node_crc) {
281 if (!quiet) 281 if (!quiet)
282 ubifs_err("bad CRC: calculated %#08x, read %#08x", 282 ubifs_err(c, "bad CRC: calculated %#08x, read %#08x",
283 crc, node_crc); 283 crc, node_crc);
284 err = -EUCLEAN; 284 err = -EUCLEAN;
285 goto out; 285 goto out;
@@ -289,10 +289,10 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
289 289
290out_len: 290out_len:
291 if (!quiet) 291 if (!quiet)
292 ubifs_err("bad node length %d", node_len); 292 ubifs_err(c, "bad node length %d", node_len);
293out: 293out:
294 if (!quiet) { 294 if (!quiet) {
295 ubifs_err("bad node at LEB %d:%d", lnum, offs); 295 ubifs_err(c, "bad node at LEB %d:%d", lnum, offs);
296 ubifs_dump_node(c, buf); 296 ubifs_dump_node(c, buf);
297 dump_stack(); 297 dump_stack();
298 } 298 }
@@ -355,11 +355,11 @@ static unsigned long long next_sqnum(struct ubifs_info *c)
355 355
356 if (unlikely(sqnum >= SQNUM_WARN_WATERMARK)) { 356 if (unlikely(sqnum >= SQNUM_WARN_WATERMARK)) {
357 if (sqnum >= SQNUM_WATERMARK) { 357 if (sqnum >= SQNUM_WATERMARK) {
358 ubifs_err("sequence number overflow %llu, end of life", 358 ubifs_err(c, "sequence number overflow %llu, end of life",
359 sqnum); 359 sqnum);
360 ubifs_ro_mode(c, -EINVAL); 360 ubifs_ro_mode(c, -EINVAL);
361 } 361 }
362 ubifs_warn("running out of sequence numbers, end of life soon"); 362 ubifs_warn(c, "running out of sequence numbers, end of life soon");
363 } 363 }
364 364
365 return sqnum; 365 return sqnum;
@@ -636,7 +636,7 @@ int ubifs_bg_wbufs_sync(struct ubifs_info *c)
636 err = ubifs_wbuf_sync_nolock(wbuf); 636 err = ubifs_wbuf_sync_nolock(wbuf);
637 mutex_unlock(&wbuf->io_mutex); 637 mutex_unlock(&wbuf->io_mutex);
638 if (err) { 638 if (err) {
639 ubifs_err("cannot sync write-buffer, error %d", err); 639 ubifs_err(c, "cannot sync write-buffer, error %d", err);
640 ubifs_ro_mode(c, err); 640 ubifs_ro_mode(c, err);
641 goto out_timers; 641 goto out_timers;
642 } 642 }
@@ -833,7 +833,7 @@ exit:
833 return 0; 833 return 0;
834 834
835out: 835out:
836 ubifs_err("cannot write %d bytes to LEB %d:%d, error %d", 836 ubifs_err(c, "cannot write %d bytes to LEB %d:%d, error %d",
837 len, wbuf->lnum, wbuf->offs, err); 837 len, wbuf->lnum, wbuf->offs, err);
838 ubifs_dump_node(c, buf); 838 ubifs_dump_node(c, buf);
839 dump_stack(); 839 dump_stack();
@@ -932,27 +932,27 @@ int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len,
932 } 932 }
933 933
934 if (type != ch->node_type) { 934 if (type != ch->node_type) {
935 ubifs_err("bad node type (%d but expected %d)", 935 ubifs_err(c, "bad node type (%d but expected %d)",
936 ch->node_type, type); 936 ch->node_type, type);
937 goto out; 937 goto out;
938 } 938 }
939 939
940 err = ubifs_check_node(c, buf, lnum, offs, 0, 0); 940 err = ubifs_check_node(c, buf, lnum, offs, 0, 0);
941 if (err) { 941 if (err) {
942 ubifs_err("expected node type %d", type); 942 ubifs_err(c, "expected node type %d", type);
943 return err; 943 return err;
944 } 944 }
945 945
946 rlen = le32_to_cpu(ch->len); 946 rlen = le32_to_cpu(ch->len);
947 if (rlen != len) { 947 if (rlen != len) {
948 ubifs_err("bad node length %d, expected %d", rlen, len); 948 ubifs_err(c, "bad node length %d, expected %d", rlen, len);
949 goto out; 949 goto out;
950 } 950 }
951 951
952 return 0; 952 return 0;
953 953
954out: 954out:
955 ubifs_err("bad node at LEB %d:%d", lnum, offs); 955 ubifs_err(c, "bad node at LEB %d:%d", lnum, offs);
956 ubifs_dump_node(c, buf); 956 ubifs_dump_node(c, buf);
957 dump_stack(); 957 dump_stack();
958 return -EINVAL; 958 return -EINVAL;
diff --git a/fs/ubifs/ioctl.c b/fs/ubifs/ioctl.c
index 648b143606cc..3c7b29de0ca7 100644
--- a/fs/ubifs/ioctl.c
+++ b/fs/ubifs/ioctl.c
@@ -138,7 +138,7 @@ static int setflags(struct inode *inode, int flags)
138 return err; 138 return err;
139 139
140out_unlock: 140out_unlock:
141 ubifs_err("can't modify inode %lu attributes", inode->i_ino); 141 ubifs_err(c, "can't modify inode %lu attributes", inode->i_ino);
142 mutex_unlock(&ui->ui_mutex); 142 mutex_unlock(&ui->ui_mutex);
143 ubifs_release_budget(c, &req); 143 ubifs_release_budget(c, &req);
144 return err; 144 return err;
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
index f6ac3f29323c..90ae1a8439d9 100644
--- a/fs/ubifs/journal.c
+++ b/fs/ubifs/journal.c
@@ -363,11 +363,11 @@ again:
363 * This should not happen unless the journal size limitations 363 * This should not happen unless the journal size limitations
364 * are too tough. 364 * are too tough.
365 */ 365 */
366 ubifs_err("stuck in space allocation"); 366 ubifs_err(c, "stuck in space allocation");
367 err = -ENOSPC; 367 err = -ENOSPC;
368 goto out; 368 goto out;
369 } else if (cmt_retries > 32) 369 } else if (cmt_retries > 32)
370 ubifs_warn("too many space allocation re-tries (%d)", 370 ubifs_warn(c, "too many space allocation re-tries (%d)",
371 cmt_retries); 371 cmt_retries);
372 372
373 dbg_jnl("-EAGAIN, commit and retry (retried %d times)", 373 dbg_jnl("-EAGAIN, commit and retry (retried %d times)",
@@ -380,7 +380,7 @@ again:
380 goto again; 380 goto again;
381 381
382out: 382out:
383 ubifs_err("cannot reserve %d bytes in jhead %d, error %d", 383 ubifs_err(c, "cannot reserve %d bytes in jhead %d, error %d",
384 len, jhead, err); 384 len, jhead, err);
385 if (err == -ENOSPC) { 385 if (err == -ENOSPC) {
386 /* This are some budgeting problems, print useful information */ 386 /* This are some budgeting problems, print useful information */
@@ -731,7 +731,7 @@ int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
731 compr_type = ui->compr_type; 731 compr_type = ui->compr_type;
732 732
733 out_len = dlen - UBIFS_DATA_NODE_SZ; 733 out_len = dlen - UBIFS_DATA_NODE_SZ;
734 ubifs_compress(buf, len, &data->data, &out_len, &compr_type); 734 ubifs_compress(c, buf, len, &data->data, &out_len, &compr_type);
735 ubifs_assert(out_len <= UBIFS_BLOCK_SIZE); 735 ubifs_assert(out_len <= UBIFS_BLOCK_SIZE);
736 736
737 dlen = UBIFS_DATA_NODE_SZ + out_len; 737 dlen = UBIFS_DATA_NODE_SZ + out_len;
@@ -1100,7 +1100,8 @@ out_free:
1100 * This function is used when an inode is truncated and the last data node of 1100 * This function is used when an inode is truncated and the last data node of
1101 * the inode has to be re-compressed and re-written. 1101 * the inode has to be re-compressed and re-written.
1102 */ 1102 */
1103static int recomp_data_node(struct ubifs_data_node *dn, int *new_len) 1103static int recomp_data_node(const struct ubifs_info *c,
1104 struct ubifs_data_node *dn, int *new_len)
1104{ 1105{
1105 void *buf; 1106 void *buf;
1106 int err, len, compr_type, out_len; 1107 int err, len, compr_type, out_len;
@@ -1112,11 +1113,11 @@ static int recomp_data_node(struct ubifs_data_node *dn, int *new_len)
1112 1113
1113 len = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ; 1114 len = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
1114 compr_type = le16_to_cpu(dn->compr_type); 1115 compr_type = le16_to_cpu(dn->compr_type);
1115 err = ubifs_decompress(&dn->data, len, buf, &out_len, compr_type); 1116 err = ubifs_decompress(c, &dn->data, len, buf, &out_len, compr_type);
1116 if (err) 1117 if (err)
1117 goto out; 1118 goto out;
1118 1119
1119 ubifs_compress(buf, *new_len, &dn->data, &out_len, &compr_type); 1120 ubifs_compress(c, buf, *new_len, &dn->data, &out_len, &compr_type);
1120 ubifs_assert(out_len <= UBIFS_BLOCK_SIZE); 1121 ubifs_assert(out_len <= UBIFS_BLOCK_SIZE);
1121 dn->compr_type = cpu_to_le16(compr_type); 1122 dn->compr_type = cpu_to_le16(compr_type);
1122 dn->size = cpu_to_le32(*new_len); 1123 dn->size = cpu_to_le32(*new_len);
@@ -1191,7 +1192,7 @@ int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
1191 int compr_type = le16_to_cpu(dn->compr_type); 1192 int compr_type = le16_to_cpu(dn->compr_type);
1192 1193
1193 if (compr_type != UBIFS_COMPR_NONE) { 1194 if (compr_type != UBIFS_COMPR_NONE) {
1194 err = recomp_data_node(dn, &dlen); 1195 err = recomp_data_node(c, dn, &dlen);
1195 if (err) 1196 if (err)
1196 goto out_free; 1197 goto out_free;
1197 } else { 1198 } else {
diff --git a/fs/ubifs/log.c b/fs/ubifs/log.c
index c14628fbeee2..8c795e6392b1 100644
--- a/fs/ubifs/log.c
+++ b/fs/ubifs/log.c
@@ -696,7 +696,7 @@ int ubifs_consolidate_log(struct ubifs_info *c)
696 destroy_done_tree(&done_tree); 696 destroy_done_tree(&done_tree);
697 vfree(buf); 697 vfree(buf);
698 if (write_lnum == c->lhead_lnum) { 698 if (write_lnum == c->lhead_lnum) {
699 ubifs_err("log is too full"); 699 ubifs_err(c, "log is too full");
700 return -EINVAL; 700 return -EINVAL;
701 } 701 }
702 /* Unmap remaining LEBs */ 702 /* Unmap remaining LEBs */
@@ -743,7 +743,7 @@ static int dbg_check_bud_bytes(struct ubifs_info *c)
743 bud_bytes += c->leb_size - bud->start; 743 bud_bytes += c->leb_size - bud->start;
744 744
745 if (c->bud_bytes != bud_bytes) { 745 if (c->bud_bytes != bud_bytes) {
746 ubifs_err("bad bud_bytes %lld, calculated %lld", 746 ubifs_err(c, "bad bud_bytes %lld, calculated %lld",
747 c->bud_bytes, bud_bytes); 747 c->bud_bytes, bud_bytes);
748 err = -EINVAL; 748 err = -EINVAL;
749 } 749 }
diff --git a/fs/ubifs/lprops.c b/fs/ubifs/lprops.c
index 46190a7c42a6..a0011aa3a779 100644
--- a/fs/ubifs/lprops.c
+++ b/fs/ubifs/lprops.c
@@ -682,7 +682,7 @@ int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
682out: 682out:
683 ubifs_release_lprops(c); 683 ubifs_release_lprops(c);
684 if (err) 684 if (err)
685 ubifs_err("cannot change properties of LEB %d, error %d", 685 ubifs_err(c, "cannot change properties of LEB %d, error %d",
686 lnum, err); 686 lnum, err);
687 return err; 687 return err;
688} 688}
@@ -721,7 +721,7 @@ int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
721out: 721out:
722 ubifs_release_lprops(c); 722 ubifs_release_lprops(c);
723 if (err) 723 if (err)
724 ubifs_err("cannot update properties of LEB %d, error %d", 724 ubifs_err(c, "cannot update properties of LEB %d, error %d",
725 lnum, err); 725 lnum, err);
726 return err; 726 return err;
727} 727}
@@ -746,7 +746,7 @@ int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp)
746 lpp = ubifs_lpt_lookup(c, lnum); 746 lpp = ubifs_lpt_lookup(c, lnum);
747 if (IS_ERR(lpp)) { 747 if (IS_ERR(lpp)) {
748 err = PTR_ERR(lpp); 748 err = PTR_ERR(lpp);
749 ubifs_err("cannot read properties of LEB %d, error %d", 749 ubifs_err(c, "cannot read properties of LEB %d, error %d",
750 lnum, err); 750 lnum, err);
751 goto out; 751 goto out;
752 } 752 }
@@ -873,13 +873,13 @@ int dbg_check_cats(struct ubifs_info *c)
873 873
874 list_for_each_entry(lprops, &c->empty_list, list) { 874 list_for_each_entry(lprops, &c->empty_list, list) {
875 if (lprops->free != c->leb_size) { 875 if (lprops->free != c->leb_size) {
876 ubifs_err("non-empty LEB %d on empty list (free %d dirty %d flags %d)", 876 ubifs_err(c, "non-empty LEB %d on empty list (free %d dirty %d flags %d)",
877 lprops->lnum, lprops->free, lprops->dirty, 877 lprops->lnum, lprops->free, lprops->dirty,
878 lprops->flags); 878 lprops->flags);
879 return -EINVAL; 879 return -EINVAL;
880 } 880 }
881 if (lprops->flags & LPROPS_TAKEN) { 881 if (lprops->flags & LPROPS_TAKEN) {
882 ubifs_err("taken LEB %d on empty list (free %d dirty %d flags %d)", 882 ubifs_err(c, "taken LEB %d on empty list (free %d dirty %d flags %d)",
883 lprops->lnum, lprops->free, lprops->dirty, 883 lprops->lnum, lprops->free, lprops->dirty,
884 lprops->flags); 884 lprops->flags);
885 return -EINVAL; 885 return -EINVAL;
@@ -889,13 +889,13 @@ int dbg_check_cats(struct ubifs_info *c)
889 i = 0; 889 i = 0;
890 list_for_each_entry(lprops, &c->freeable_list, list) { 890 list_for_each_entry(lprops, &c->freeable_list, list) {
891 if (lprops->free + lprops->dirty != c->leb_size) { 891 if (lprops->free + lprops->dirty != c->leb_size) {
892 ubifs_err("non-freeable LEB %d on freeable list (free %d dirty %d flags %d)", 892 ubifs_err(c, "non-freeable LEB %d on freeable list (free %d dirty %d flags %d)",
893 lprops->lnum, lprops->free, lprops->dirty, 893 lprops->lnum, lprops->free, lprops->dirty,
894 lprops->flags); 894 lprops->flags);
895 return -EINVAL; 895 return -EINVAL;
896 } 896 }
897 if (lprops->flags & LPROPS_TAKEN) { 897 if (lprops->flags & LPROPS_TAKEN) {
898 ubifs_err("taken LEB %d on freeable list (free %d dirty %d flags %d)", 898 ubifs_err(c, "taken LEB %d on freeable list (free %d dirty %d flags %d)",
899 lprops->lnum, lprops->free, lprops->dirty, 899 lprops->lnum, lprops->free, lprops->dirty,
900 lprops->flags); 900 lprops->flags);
901 return -EINVAL; 901 return -EINVAL;
@@ -903,7 +903,7 @@ int dbg_check_cats(struct ubifs_info *c)
903 i += 1; 903 i += 1;
904 } 904 }
905 if (i != c->freeable_cnt) { 905 if (i != c->freeable_cnt) {
906 ubifs_err("freeable list count %d expected %d", i, 906 ubifs_err(c, "freeable list count %d expected %d", i,
907 c->freeable_cnt); 907 c->freeable_cnt);
908 return -EINVAL; 908 return -EINVAL;
909 } 909 }
@@ -912,26 +912,26 @@ int dbg_check_cats(struct ubifs_info *c)
912 list_for_each(pos, &c->idx_gc) 912 list_for_each(pos, &c->idx_gc)
913 i += 1; 913 i += 1;
914 if (i != c->idx_gc_cnt) { 914 if (i != c->idx_gc_cnt) {
915 ubifs_err("idx_gc list count %d expected %d", i, 915 ubifs_err(c, "idx_gc list count %d expected %d", i,
916 c->idx_gc_cnt); 916 c->idx_gc_cnt);
917 return -EINVAL; 917 return -EINVAL;
918 } 918 }
919 919
920 list_for_each_entry(lprops, &c->frdi_idx_list, list) { 920 list_for_each_entry(lprops, &c->frdi_idx_list, list) {
921 if (lprops->free + lprops->dirty != c->leb_size) { 921 if (lprops->free + lprops->dirty != c->leb_size) {
922 ubifs_err("non-freeable LEB %d on frdi_idx list (free %d dirty %d flags %d)", 922 ubifs_err(c, "non-freeable LEB %d on frdi_idx list (free %d dirty %d flags %d)",
923 lprops->lnum, lprops->free, lprops->dirty, 923 lprops->lnum, lprops->free, lprops->dirty,
924 lprops->flags); 924 lprops->flags);
925 return -EINVAL; 925 return -EINVAL;
926 } 926 }
927 if (lprops->flags & LPROPS_TAKEN) { 927 if (lprops->flags & LPROPS_TAKEN) {
928 ubifs_err("taken LEB %d on frdi_idx list (free %d dirty %d flags %d)", 928 ubifs_err(c, "taken LEB %d on frdi_idx list (free %d dirty %d flags %d)",
929 lprops->lnum, lprops->free, lprops->dirty, 929 lprops->lnum, lprops->free, lprops->dirty,
930 lprops->flags); 930 lprops->flags);
931 return -EINVAL; 931 return -EINVAL;
932 } 932 }
933 if (!(lprops->flags & LPROPS_INDEX)) { 933 if (!(lprops->flags & LPROPS_INDEX)) {
934 ubifs_err("non-index LEB %d on frdi_idx list (free %d dirty %d flags %d)", 934 ubifs_err(c, "non-index LEB %d on frdi_idx list (free %d dirty %d flags %d)",
935 lprops->lnum, lprops->free, lprops->dirty, 935 lprops->lnum, lprops->free, lprops->dirty,
936 lprops->flags); 936 lprops->flags);
937 return -EINVAL; 937 return -EINVAL;
@@ -944,15 +944,15 @@ int dbg_check_cats(struct ubifs_info *c)
944 for (i = 0; i < heap->cnt; i++) { 944 for (i = 0; i < heap->cnt; i++) {
945 lprops = heap->arr[i]; 945 lprops = heap->arr[i];
946 if (!lprops) { 946 if (!lprops) {
947 ubifs_err("null ptr in LPT heap cat %d", cat); 947 ubifs_err(c, "null ptr in LPT heap cat %d", cat);
948 return -EINVAL; 948 return -EINVAL;
949 } 949 }
950 if (lprops->hpos != i) { 950 if (lprops->hpos != i) {
951 ubifs_err("bad ptr in LPT heap cat %d", cat); 951 ubifs_err(c, "bad ptr in LPT heap cat %d", cat);
952 return -EINVAL; 952 return -EINVAL;
953 } 953 }
954 if (lprops->flags & LPROPS_TAKEN) { 954 if (lprops->flags & LPROPS_TAKEN) {
955 ubifs_err("taken LEB in LPT heap cat %d", cat); 955 ubifs_err(c, "taken LEB in LPT heap cat %d", cat);
956 return -EINVAL; 956 return -EINVAL;
957 } 957 }
958 } 958 }
@@ -988,7 +988,7 @@ void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat,
988 goto out; 988 goto out;
989 } 989 }
990 if (lprops != lp) { 990 if (lprops != lp) {
991 ubifs_err("lprops %zx lp %zx lprops->lnum %d lp->lnum %d", 991 ubifs_err(c, "lprops %zx lp %zx lprops->lnum %d lp->lnum %d",
992 (size_t)lprops, (size_t)lp, lprops->lnum, 992 (size_t)lprops, (size_t)lp, lprops->lnum,
993 lp->lnum); 993 lp->lnum);
994 err = 4; 994 err = 4;
@@ -1008,7 +1008,7 @@ void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat,
1008 } 1008 }
1009out: 1009out:
1010 if (err) { 1010 if (err) {
1011 ubifs_err("failed cat %d hpos %d err %d", cat, i, err); 1011 ubifs_err(c, "failed cat %d hpos %d err %d", cat, i, err);
1012 dump_stack(); 1012 dump_stack();
1013 ubifs_dump_heap(c, heap, cat); 1013 ubifs_dump_heap(c, heap, cat);
1014 } 1014 }
@@ -1039,7 +1039,7 @@ static int scan_check_cb(struct ubifs_info *c,
1039 if (cat != LPROPS_UNCAT) { 1039 if (cat != LPROPS_UNCAT) {
1040 cat = ubifs_categorize_lprops(c, lp); 1040 cat = ubifs_categorize_lprops(c, lp);
1041 if (cat != (lp->flags & LPROPS_CAT_MASK)) { 1041 if (cat != (lp->flags & LPROPS_CAT_MASK)) {
1042 ubifs_err("bad LEB category %d expected %d", 1042 ubifs_err(c, "bad LEB category %d expected %d",
1043 (lp->flags & LPROPS_CAT_MASK), cat); 1043 (lp->flags & LPROPS_CAT_MASK), cat);
1044 return -EINVAL; 1044 return -EINVAL;
1045 } 1045 }
@@ -1074,7 +1074,7 @@ static int scan_check_cb(struct ubifs_info *c,
1074 } 1074 }
1075 } 1075 }
1076 if (!found) { 1076 if (!found) {
1077 ubifs_err("bad LPT list (category %d)", cat); 1077 ubifs_err(c, "bad LPT list (category %d)", cat);
1078 return -EINVAL; 1078 return -EINVAL;
1079 } 1079 }
1080 } 1080 }
@@ -1086,7 +1086,7 @@ static int scan_check_cb(struct ubifs_info *c,
1086 1086
1087 if ((lp->hpos != -1 && heap->arr[lp->hpos]->lnum != lnum) || 1087 if ((lp->hpos != -1 && heap->arr[lp->hpos]->lnum != lnum) ||
1088 lp != heap->arr[lp->hpos]) { 1088 lp != heap->arr[lp->hpos]) {
1089 ubifs_err("bad LPT heap (category %d)", cat); 1089 ubifs_err(c, "bad LPT heap (category %d)", cat);
1090 return -EINVAL; 1090 return -EINVAL;
1091 } 1091 }
1092 } 1092 }
@@ -1133,7 +1133,7 @@ static int scan_check_cb(struct ubifs_info *c,
1133 is_idx = (snod->type == UBIFS_IDX_NODE) ? 1 : 0; 1133 is_idx = (snod->type == UBIFS_IDX_NODE) ? 1 : 0;
1134 1134
1135 if (is_idx && snod->type != UBIFS_IDX_NODE) { 1135 if (is_idx && snod->type != UBIFS_IDX_NODE) {
1136 ubifs_err("indexing node in data LEB %d:%d", 1136 ubifs_err(c, "indexing node in data LEB %d:%d",
1137 lnum, snod->offs); 1137 lnum, snod->offs);
1138 goto out_destroy; 1138 goto out_destroy;
1139 } 1139 }
@@ -1159,7 +1159,7 @@ static int scan_check_cb(struct ubifs_info *c,
1159 1159
1160 if (free > c->leb_size || free < 0 || dirty > c->leb_size || 1160 if (free > c->leb_size || free < 0 || dirty > c->leb_size ||
1161 dirty < 0) { 1161 dirty < 0) {
1162 ubifs_err("bad calculated accounting for LEB %d: free %d, dirty %d", 1162 ubifs_err(c, "bad calculated accounting for LEB %d: free %d, dirty %d",
1163 lnum, free, dirty); 1163 lnum, free, dirty);
1164 goto out_destroy; 1164 goto out_destroy;
1165 } 1165 }
@@ -1206,13 +1206,13 @@ static int scan_check_cb(struct ubifs_info *c,
1206 /* Free but not unmapped LEB, it's fine */ 1206 /* Free but not unmapped LEB, it's fine */
1207 is_idx = 0; 1207 is_idx = 0;
1208 else { 1208 else {
1209 ubifs_err("indexing node without indexing flag"); 1209 ubifs_err(c, "indexing node without indexing flag");
1210 goto out_print; 1210 goto out_print;
1211 } 1211 }
1212 } 1212 }
1213 1213
1214 if (!is_idx && (lp->flags & LPROPS_INDEX)) { 1214 if (!is_idx && (lp->flags & LPROPS_INDEX)) {
1215 ubifs_err("data node with indexing flag"); 1215 ubifs_err(c, "data node with indexing flag");
1216 goto out_print; 1216 goto out_print;
1217 } 1217 }
1218 1218
@@ -1241,7 +1241,7 @@ static int scan_check_cb(struct ubifs_info *c,
1241 return LPT_SCAN_CONTINUE; 1241 return LPT_SCAN_CONTINUE;
1242 1242
1243out_print: 1243out_print:
1244 ubifs_err("bad accounting of LEB %d: free %d, dirty %d flags %#x, should be free %d, dirty %d", 1244 ubifs_err(c, "bad accounting of LEB %d: free %d, dirty %d flags %#x, should be free %d, dirty %d",
1245 lnum, lp->free, lp->dirty, lp->flags, free, dirty); 1245 lnum, lp->free, lp->dirty, lp->flags, free, dirty);
1246 ubifs_dump_leb(c, lnum); 1246 ubifs_dump_leb(c, lnum);
1247out_destroy: 1247out_destroy:
@@ -1293,11 +1293,11 @@ int dbg_check_lprops(struct ubifs_info *c)
1293 lst.total_free != c->lst.total_free || 1293 lst.total_free != c->lst.total_free ||
1294 lst.total_dirty != c->lst.total_dirty || 1294 lst.total_dirty != c->lst.total_dirty ||
1295 lst.total_used != c->lst.total_used) { 1295 lst.total_used != c->lst.total_used) {
1296 ubifs_err("bad overall accounting"); 1296 ubifs_err(c, "bad overall accounting");
1297 ubifs_err("calculated: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, total_used %lld", 1297 ubifs_err(c, "calculated: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, total_used %lld",
1298 lst.empty_lebs, lst.idx_lebs, lst.total_free, 1298 lst.empty_lebs, lst.idx_lebs, lst.total_free,
1299 lst.total_dirty, lst.total_used); 1299 lst.total_dirty, lst.total_used);
1300 ubifs_err("read from lprops: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, total_used %lld", 1300 ubifs_err(c, "read from lprops: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, total_used %lld",
1301 c->lst.empty_lebs, c->lst.idx_lebs, c->lst.total_free, 1301 c->lst.empty_lebs, c->lst.idx_lebs, c->lst.total_free,
1302 c->lst.total_dirty, c->lst.total_used); 1302 c->lst.total_dirty, c->lst.total_used);
1303 err = -EINVAL; 1303 err = -EINVAL;
@@ -1306,10 +1306,10 @@ int dbg_check_lprops(struct ubifs_info *c)
1306 1306
1307 if (lst.total_dead != c->lst.total_dead || 1307 if (lst.total_dead != c->lst.total_dead ||
1308 lst.total_dark != c->lst.total_dark) { 1308 lst.total_dark != c->lst.total_dark) {
1309 ubifs_err("bad dead/dark space accounting"); 1309 ubifs_err(c, "bad dead/dark space accounting");
1310 ubifs_err("calculated: total_dead %lld, total_dark %lld", 1310 ubifs_err(c, "calculated: total_dead %lld, total_dark %lld",
1311 lst.total_dead, lst.total_dark); 1311 lst.total_dead, lst.total_dark);
1312 ubifs_err("read from lprops: total_dead %lld, total_dark %lld", 1312 ubifs_err(c, "read from lprops: total_dead %lld, total_dark %lld",
1313 c->lst.total_dead, c->lst.total_dark); 1313 c->lst.total_dead, c->lst.total_dark);
1314 err = -EINVAL; 1314 err = -EINVAL;
1315 goto out; 1315 goto out;
diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
index 421bd0a80424..dc9f27e9d61b 100644
--- a/fs/ubifs/lpt.c
+++ b/fs/ubifs/lpt.c
@@ -145,13 +145,13 @@ int ubifs_calc_lpt_geom(struct ubifs_info *c)
145 sz = c->lpt_sz * 2; /* Must have at least 2 times the size */ 145 sz = c->lpt_sz * 2; /* Must have at least 2 times the size */
146 lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size); 146 lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size);
147 if (lebs_needed > c->lpt_lebs) { 147 if (lebs_needed > c->lpt_lebs) {
148 ubifs_err("too few LPT LEBs"); 148 ubifs_err(c, "too few LPT LEBs");
149 return -EINVAL; 149 return -EINVAL;
150 } 150 }
151 151
152 /* Verify that ltab fits in a single LEB (since ltab is a single node */ 152 /* Verify that ltab fits in a single LEB (since ltab is a single node */
153 if (c->ltab_sz > c->leb_size) { 153 if (c->ltab_sz > c->leb_size) {
154 ubifs_err("LPT ltab too big"); 154 ubifs_err(c, "LPT ltab too big");
155 return -EINVAL; 155 return -EINVAL;
156 } 156 }
157 157
@@ -213,7 +213,7 @@ static int calc_dflt_lpt_geom(struct ubifs_info *c, int *main_lebs,
213 continue; 213 continue;
214 } 214 }
215 if (c->ltab_sz > c->leb_size) { 215 if (c->ltab_sz > c->leb_size) {
216 ubifs_err("LPT ltab too big"); 216 ubifs_err(c, "LPT ltab too big");
217 return -EINVAL; 217 return -EINVAL;
218 } 218 }
219 *main_lebs = c->main_lebs; 219 *main_lebs = c->main_lebs;
@@ -911,7 +911,7 @@ static void replace_cats(struct ubifs_info *c, struct ubifs_pnode *old_pnode,
911 * 911 *
912 * This function returns %0 on success and a negative error code on failure. 912 * This function returns %0 on success and a negative error code on failure.
913 */ 913 */
914static int check_lpt_crc(void *buf, int len) 914static int check_lpt_crc(const struct ubifs_info *c, void *buf, int len)
915{ 915{
916 int pos = 0; 916 int pos = 0;
917 uint8_t *addr = buf; 917 uint8_t *addr = buf;
@@ -921,8 +921,8 @@ static int check_lpt_crc(void *buf, int len)
921 calc_crc = crc16(-1, buf + UBIFS_LPT_CRC_BYTES, 921 calc_crc = crc16(-1, buf + UBIFS_LPT_CRC_BYTES,
922 len - UBIFS_LPT_CRC_BYTES); 922 len - UBIFS_LPT_CRC_BYTES);
923 if (crc != calc_crc) { 923 if (crc != calc_crc) {
924 ubifs_err("invalid crc in LPT node: crc %hx calc %hx", crc, 924 ubifs_err(c, "invalid crc in LPT node: crc %hx calc %hx",
925 calc_crc); 925 crc, calc_crc);
926 dump_stack(); 926 dump_stack();
927 return -EINVAL; 927 return -EINVAL;
928 } 928 }
@@ -938,14 +938,15 @@ static int check_lpt_crc(void *buf, int len)
938 * 938 *
939 * This function returns %0 on success and a negative error code on failure. 939 * This function returns %0 on success and a negative error code on failure.
940 */ 940 */
941static int check_lpt_type(uint8_t **addr, int *pos, int type) 941static int check_lpt_type(const struct ubifs_info *c, uint8_t **addr,
942 int *pos, int type)
942{ 943{
943 int node_type; 944 int node_type;
944 945
945 node_type = ubifs_unpack_bits(addr, pos, UBIFS_LPT_TYPE_BITS); 946 node_type = ubifs_unpack_bits(addr, pos, UBIFS_LPT_TYPE_BITS);
946 if (node_type != type) { 947 if (node_type != type) {
947 ubifs_err("invalid type (%d) in LPT node type %d", node_type, 948 ubifs_err(c, "invalid type (%d) in LPT node type %d",
948 type); 949 node_type, type);
949 dump_stack(); 950 dump_stack();
950 return -EINVAL; 951 return -EINVAL;
951 } 952 }
@@ -966,7 +967,7 @@ static int unpack_pnode(const struct ubifs_info *c, void *buf,
966 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 967 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
967 int i, pos = 0, err; 968 int i, pos = 0, err;
968 969
969 err = check_lpt_type(&addr, &pos, UBIFS_LPT_PNODE); 970 err = check_lpt_type(c, &addr, &pos, UBIFS_LPT_PNODE);
970 if (err) 971 if (err)
971 return err; 972 return err;
972 if (c->big_lpt) 973 if (c->big_lpt)
@@ -985,7 +986,7 @@ static int unpack_pnode(const struct ubifs_info *c, void *buf,
985 lprops->flags = 0; 986 lprops->flags = 0;
986 lprops->flags |= ubifs_categorize_lprops(c, lprops); 987 lprops->flags |= ubifs_categorize_lprops(c, lprops);
987 } 988 }
988 err = check_lpt_crc(buf, c->pnode_sz); 989 err = check_lpt_crc(c, buf, c->pnode_sz);
989 return err; 990 return err;
990} 991}
991 992
@@ -1003,7 +1004,7 @@ int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
1003 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1004 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1004 int i, pos = 0, err; 1005 int i, pos = 0, err;
1005 1006
1006 err = check_lpt_type(&addr, &pos, UBIFS_LPT_NNODE); 1007 err = check_lpt_type(c, &addr, &pos, UBIFS_LPT_NNODE);
1007 if (err) 1008 if (err)
1008 return err; 1009 return err;
1009 if (c->big_lpt) 1010 if (c->big_lpt)
@@ -1019,7 +1020,7 @@ int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
1019 nnode->nbranch[i].offs = ubifs_unpack_bits(&addr, &pos, 1020 nnode->nbranch[i].offs = ubifs_unpack_bits(&addr, &pos,
1020 c->lpt_offs_bits); 1021 c->lpt_offs_bits);
1021 } 1022 }
1022 err = check_lpt_crc(buf, c->nnode_sz); 1023 err = check_lpt_crc(c, buf, c->nnode_sz);
1023 return err; 1024 return err;
1024} 1025}
1025 1026
@@ -1035,7 +1036,7 @@ static int unpack_ltab(const struct ubifs_info *c, void *buf)
1035 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1036 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1036 int i, pos = 0, err; 1037 int i, pos = 0, err;
1037 1038
1038 err = check_lpt_type(&addr, &pos, UBIFS_LPT_LTAB); 1039 err = check_lpt_type(c, &addr, &pos, UBIFS_LPT_LTAB);
1039 if (err) 1040 if (err)
1040 return err; 1041 return err;
1041 for (i = 0; i < c->lpt_lebs; i++) { 1042 for (i = 0; i < c->lpt_lebs; i++) {
@@ -1051,7 +1052,7 @@ static int unpack_ltab(const struct ubifs_info *c, void *buf)
1051 c->ltab[i].tgc = 0; 1052 c->ltab[i].tgc = 0;
1052 c->ltab[i].cmt = 0; 1053 c->ltab[i].cmt = 0;
1053 } 1054 }
1054 err = check_lpt_crc(buf, c->ltab_sz); 1055 err = check_lpt_crc(c, buf, c->ltab_sz);
1055 return err; 1056 return err;
1056} 1057}
1057 1058
@@ -1067,7 +1068,7 @@ static int unpack_lsave(const struct ubifs_info *c, void *buf)
1067 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1068 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1068 int i, pos = 0, err; 1069 int i, pos = 0, err;
1069 1070
1070 err = check_lpt_type(&addr, &pos, UBIFS_LPT_LSAVE); 1071 err = check_lpt_type(c, &addr, &pos, UBIFS_LPT_LSAVE);
1071 if (err) 1072 if (err)
1072 return err; 1073 return err;
1073 for (i = 0; i < c->lsave_cnt; i++) { 1074 for (i = 0; i < c->lsave_cnt; i++) {
@@ -1077,7 +1078,7 @@ static int unpack_lsave(const struct ubifs_info *c, void *buf)
1077 return -EINVAL; 1078 return -EINVAL;
1078 c->lsave[i] = lnum; 1079 c->lsave[i] = lnum;
1079 } 1080 }
1080 err = check_lpt_crc(buf, c->lsave_sz); 1081 err = check_lpt_crc(c, buf, c->lsave_sz);
1081 return err; 1082 return err;
1082} 1083}
1083 1084
@@ -1243,7 +1244,7 @@ int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
1243 return 0; 1244 return 0;
1244 1245
1245out: 1246out:
1246 ubifs_err("error %d reading nnode at %d:%d", err, lnum, offs); 1247 ubifs_err(c, "error %d reading nnode at %d:%d", err, lnum, offs);
1247 dump_stack(); 1248 dump_stack();
1248 kfree(nnode); 1249 kfree(nnode);
1249 return err; 1250 return err;
@@ -1308,10 +1309,10 @@ static int read_pnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
1308 return 0; 1309 return 0;
1309 1310
1310out: 1311out:
1311 ubifs_err("error %d reading pnode at %d:%d", err, lnum, offs); 1312 ubifs_err(c, "error %d reading pnode at %d:%d", err, lnum, offs);
1312 ubifs_dump_pnode(c, pnode, parent, iip); 1313 ubifs_dump_pnode(c, pnode, parent, iip);
1313 dump_stack(); 1314 dump_stack();
1314 ubifs_err("calc num: %d", calc_pnode_num_from_parent(c, parent, iip)); 1315 ubifs_err(c, "calc num: %d", calc_pnode_num_from_parent(c, parent, iip));
1315 kfree(pnode); 1316 kfree(pnode);
1316 return err; 1317 return err;
1317} 1318}
@@ -2095,7 +2096,7 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2095 int i; 2096 int i;
2096 2097
2097 if (pnode->num != col) { 2098 if (pnode->num != col) {
2098 ubifs_err("pnode num %d expected %d parent num %d iip %d", 2099 ubifs_err(c, "pnode num %d expected %d parent num %d iip %d",
2099 pnode->num, col, pnode->parent->num, pnode->iip); 2100 pnode->num, col, pnode->parent->num, pnode->iip);
2100 return -EINVAL; 2101 return -EINVAL;
2101 } 2102 }
@@ -2110,13 +2111,13 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2110 if (lnum >= c->leb_cnt) 2111 if (lnum >= c->leb_cnt)
2111 continue; 2112 continue;
2112 if (lprops->lnum != lnum) { 2113 if (lprops->lnum != lnum) {
2113 ubifs_err("bad LEB number %d expected %d", 2114 ubifs_err(c, "bad LEB number %d expected %d",
2114 lprops->lnum, lnum); 2115 lprops->lnum, lnum);
2115 return -EINVAL; 2116 return -EINVAL;
2116 } 2117 }
2117 if (lprops->flags & LPROPS_TAKEN) { 2118 if (lprops->flags & LPROPS_TAKEN) {
2118 if (cat != LPROPS_UNCAT) { 2119 if (cat != LPROPS_UNCAT) {
2119 ubifs_err("LEB %d taken but not uncat %d", 2120 ubifs_err(c, "LEB %d taken but not uncat %d",
2120 lprops->lnum, cat); 2121 lprops->lnum, cat);
2121 return -EINVAL; 2122 return -EINVAL;
2122 } 2123 }
@@ -2129,7 +2130,7 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2129 case LPROPS_FRDI_IDX: 2130 case LPROPS_FRDI_IDX:
2130 break; 2131 break;
2131 default: 2132 default:
2132 ubifs_err("LEB %d index but cat %d", 2133 ubifs_err(c, "LEB %d index but cat %d",
2133 lprops->lnum, cat); 2134 lprops->lnum, cat);
2134 return -EINVAL; 2135 return -EINVAL;
2135 } 2136 }
@@ -2142,7 +2143,7 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2142 case LPROPS_FREEABLE: 2143 case LPROPS_FREEABLE:
2143 break; 2144 break;
2144 default: 2145 default:
2145 ubifs_err("LEB %d not index but cat %d", 2146 ubifs_err(c, "LEB %d not index but cat %d",
2146 lprops->lnum, cat); 2147 lprops->lnum, cat);
2147 return -EINVAL; 2148 return -EINVAL;
2148 } 2149 }
@@ -2183,14 +2184,14 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2183 break; 2184 break;
2184 } 2185 }
2185 if (!found) { 2186 if (!found) {
2186 ubifs_err("LEB %d cat %d not found in cat heap/list", 2187 ubifs_err(c, "LEB %d cat %d not found in cat heap/list",
2187 lprops->lnum, cat); 2188 lprops->lnum, cat);
2188 return -EINVAL; 2189 return -EINVAL;
2189 } 2190 }
2190 switch (cat) { 2191 switch (cat) {
2191 case LPROPS_EMPTY: 2192 case LPROPS_EMPTY:
2192 if (lprops->free != c->leb_size) { 2193 if (lprops->free != c->leb_size) {
2193 ubifs_err("LEB %d cat %d free %d dirty %d", 2194 ubifs_err(c, "LEB %d cat %d free %d dirty %d",
2194 lprops->lnum, cat, lprops->free, 2195 lprops->lnum, cat, lprops->free,
2195 lprops->dirty); 2196 lprops->dirty);
2196 return -EINVAL; 2197 return -EINVAL;
@@ -2199,7 +2200,7 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2199 case LPROPS_FREEABLE: 2200 case LPROPS_FREEABLE:
2200 case LPROPS_FRDI_IDX: 2201 case LPROPS_FRDI_IDX:
2201 if (lprops->free + lprops->dirty != c->leb_size) { 2202 if (lprops->free + lprops->dirty != c->leb_size) {
2202 ubifs_err("LEB %d cat %d free %d dirty %d", 2203 ubifs_err(c, "LEB %d cat %d free %d dirty %d",
2203 lprops->lnum, cat, lprops->free, 2204 lprops->lnum, cat, lprops->free,
2204 lprops->dirty); 2205 lprops->dirty);
2205 return -EINVAL; 2206 return -EINVAL;
@@ -2236,7 +2237,7 @@ int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode,
2236 /* cnode is a nnode */ 2237 /* cnode is a nnode */
2237 num = calc_nnode_num(row, col); 2238 num = calc_nnode_num(row, col);
2238 if (cnode->num != num) { 2239 if (cnode->num != num) {
2239 ubifs_err("nnode num %d expected %d parent num %d iip %d", 2240 ubifs_err(c, "nnode num %d expected %d parent num %d iip %d",
2240 cnode->num, num, 2241 cnode->num, num,
2241 (nnode ? nnode->num : 0), cnode->iip); 2242 (nnode ? nnode->num : 0), cnode->iip);
2242 return -EINVAL; 2243 return -EINVAL;
diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c
index d9c02928e992..ce89bdc3eb02 100644
--- a/fs/ubifs/lpt_commit.c
+++ b/fs/ubifs/lpt_commit.c
@@ -319,7 +319,7 @@ static int layout_cnodes(struct ubifs_info *c)
319 return 0; 319 return 0;
320 320
321no_space: 321no_space:
322 ubifs_err("LPT out of space at LEB %d:%d needing %d, done_ltab %d, done_lsave %d", 322 ubifs_err(c, "LPT out of space at LEB %d:%d needing %d, done_ltab %d, done_lsave %d",
323 lnum, offs, len, done_ltab, done_lsave); 323 lnum, offs, len, done_ltab, done_lsave);
324 ubifs_dump_lpt_info(c); 324 ubifs_dump_lpt_info(c);
325 ubifs_dump_lpt_lebs(c); 325 ubifs_dump_lpt_lebs(c);
@@ -543,7 +543,7 @@ static int write_cnodes(struct ubifs_info *c)
543 return 0; 543 return 0;
544 544
545no_space: 545no_space:
546 ubifs_err("LPT out of space mismatch at LEB %d:%d needing %d, done_ltab %d, done_lsave %d", 546 ubifs_err(c, "LPT out of space mismatch at LEB %d:%d needing %d, done_ltab %d, done_lsave %d",
547 lnum, offs, len, done_ltab, done_lsave); 547 lnum, offs, len, done_ltab, done_lsave);
548 ubifs_dump_lpt_info(c); 548 ubifs_dump_lpt_info(c);
549 ubifs_dump_lpt_lebs(c); 549 ubifs_dump_lpt_lebs(c);
@@ -1638,7 +1638,7 @@ static int dbg_check_ltab_lnum(struct ubifs_info *c, int lnum)
1638 1638
1639 buf = p = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); 1639 buf = p = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL);
1640 if (!buf) { 1640 if (!buf) {
1641 ubifs_err("cannot allocate memory for ltab checking"); 1641 ubifs_err(c, "cannot allocate memory for ltab checking");
1642 return 0; 1642 return 0;
1643 } 1643 }
1644 1644
@@ -1660,18 +1660,18 @@ static int dbg_check_ltab_lnum(struct ubifs_info *c, int lnum)
1660 continue; 1660 continue;
1661 } 1661 }
1662 if (!dbg_is_all_ff(p, len)) { 1662 if (!dbg_is_all_ff(p, len)) {
1663 ubifs_err("invalid empty space in LEB %d at %d", 1663 ubifs_err(c, "invalid empty space in LEB %d at %d",
1664 lnum, c->leb_size - len); 1664 lnum, c->leb_size - len);
1665 err = -EINVAL; 1665 err = -EINVAL;
1666 } 1666 }
1667 i = lnum - c->lpt_first; 1667 i = lnum - c->lpt_first;
1668 if (len != c->ltab[i].free) { 1668 if (len != c->ltab[i].free) {
1669 ubifs_err("invalid free space in LEB %d (free %d, expected %d)", 1669 ubifs_err(c, "invalid free space in LEB %d (free %d, expected %d)",
1670 lnum, len, c->ltab[i].free); 1670 lnum, len, c->ltab[i].free);
1671 err = -EINVAL; 1671 err = -EINVAL;
1672 } 1672 }
1673 if (dirty != c->ltab[i].dirty) { 1673 if (dirty != c->ltab[i].dirty) {
1674 ubifs_err("invalid dirty space in LEB %d (dirty %d, expected %d)", 1674 ubifs_err(c, "invalid dirty space in LEB %d (dirty %d, expected %d)",
1675 lnum, dirty, c->ltab[i].dirty); 1675 lnum, dirty, c->ltab[i].dirty);
1676 err = -EINVAL; 1676 err = -EINVAL;
1677 } 1677 }
@@ -1725,7 +1725,7 @@ int dbg_check_ltab(struct ubifs_info *c)
1725 for (lnum = c->lpt_first; lnum <= c->lpt_last; lnum++) { 1725 for (lnum = c->lpt_first; lnum <= c->lpt_last; lnum++) {
1726 err = dbg_check_ltab_lnum(c, lnum); 1726 err = dbg_check_ltab_lnum(c, lnum);
1727 if (err) { 1727 if (err) {
1728 ubifs_err("failed at LEB %d", lnum); 1728 ubifs_err(c, "failed at LEB %d", lnum);
1729 return err; 1729 return err;
1730 } 1730 }
1731 } 1731 }
@@ -1757,7 +1757,7 @@ int dbg_chk_lpt_free_spc(struct ubifs_info *c)
1757 free += c->leb_size; 1757 free += c->leb_size;
1758 } 1758 }
1759 if (free < c->lpt_sz) { 1759 if (free < c->lpt_sz) {
1760 ubifs_err("LPT space error: free %lld lpt_sz %lld", 1760 ubifs_err(c, "LPT space error: free %lld lpt_sz %lld",
1761 free, c->lpt_sz); 1761 free, c->lpt_sz);
1762 ubifs_dump_lpt_info(c); 1762 ubifs_dump_lpt_info(c);
1763 ubifs_dump_lpt_lebs(c); 1763 ubifs_dump_lpt_lebs(c);
@@ -1797,12 +1797,12 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)
1797 d->chk_lpt_lebs = 0; 1797 d->chk_lpt_lebs = 0;
1798 d->chk_lpt_wastage = 0; 1798 d->chk_lpt_wastage = 0;
1799 if (c->dirty_pn_cnt > c->pnode_cnt) { 1799 if (c->dirty_pn_cnt > c->pnode_cnt) {
1800 ubifs_err("dirty pnodes %d exceed max %d", 1800 ubifs_err(c, "dirty pnodes %d exceed max %d",
1801 c->dirty_pn_cnt, c->pnode_cnt); 1801 c->dirty_pn_cnt, c->pnode_cnt);
1802 err = -EINVAL; 1802 err = -EINVAL;
1803 } 1803 }
1804 if (c->dirty_nn_cnt > c->nnode_cnt) { 1804 if (c->dirty_nn_cnt > c->nnode_cnt) {
1805 ubifs_err("dirty nnodes %d exceed max %d", 1805 ubifs_err(c, "dirty nnodes %d exceed max %d",
1806 c->dirty_nn_cnt, c->nnode_cnt); 1806 c->dirty_nn_cnt, c->nnode_cnt);
1807 err = -EINVAL; 1807 err = -EINVAL;
1808 } 1808 }
@@ -1820,22 +1820,22 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)
1820 chk_lpt_sz *= d->chk_lpt_lebs; 1820 chk_lpt_sz *= d->chk_lpt_lebs;
1821 chk_lpt_sz += len - c->nhead_offs; 1821 chk_lpt_sz += len - c->nhead_offs;
1822 if (d->chk_lpt_sz != chk_lpt_sz) { 1822 if (d->chk_lpt_sz != chk_lpt_sz) {
1823 ubifs_err("LPT wrote %lld but space used was %lld", 1823 ubifs_err(c, "LPT wrote %lld but space used was %lld",
1824 d->chk_lpt_sz, chk_lpt_sz); 1824 d->chk_lpt_sz, chk_lpt_sz);
1825 err = -EINVAL; 1825 err = -EINVAL;
1826 } 1826 }
1827 if (d->chk_lpt_sz > c->lpt_sz) { 1827 if (d->chk_lpt_sz > c->lpt_sz) {
1828 ubifs_err("LPT wrote %lld but lpt_sz is %lld", 1828 ubifs_err(c, "LPT wrote %lld but lpt_sz is %lld",
1829 d->chk_lpt_sz, c->lpt_sz); 1829 d->chk_lpt_sz, c->lpt_sz);
1830 err = -EINVAL; 1830 err = -EINVAL;
1831 } 1831 }
1832 if (d->chk_lpt_sz2 && d->chk_lpt_sz != d->chk_lpt_sz2) { 1832 if (d->chk_lpt_sz2 && d->chk_lpt_sz != d->chk_lpt_sz2) {
1833 ubifs_err("LPT layout size %lld but wrote %lld", 1833 ubifs_err(c, "LPT layout size %lld but wrote %lld",
1834 d->chk_lpt_sz, d->chk_lpt_sz2); 1834 d->chk_lpt_sz, d->chk_lpt_sz2);
1835 err = -EINVAL; 1835 err = -EINVAL;
1836 } 1836 }
1837 if (d->chk_lpt_sz2 && d->new_nhead_offs != len) { 1837 if (d->chk_lpt_sz2 && d->new_nhead_offs != len) {
1838 ubifs_err("LPT new nhead offs: expected %d was %d", 1838 ubifs_err(c, "LPT new nhead offs: expected %d was %d",
1839 d->new_nhead_offs, len); 1839 d->new_nhead_offs, len);
1840 err = -EINVAL; 1840 err = -EINVAL;
1841 } 1841 }
@@ -1845,7 +1845,7 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)
1845 if (c->big_lpt) 1845 if (c->big_lpt)
1846 lpt_sz += c->lsave_sz; 1846 lpt_sz += c->lsave_sz;
1847 if (d->chk_lpt_sz - d->chk_lpt_wastage > lpt_sz) { 1847 if (d->chk_lpt_sz - d->chk_lpt_wastage > lpt_sz) {
1848 ubifs_err("LPT chk_lpt_sz %lld + waste %lld exceeds %lld", 1848 ubifs_err(c, "LPT chk_lpt_sz %lld + waste %lld exceeds %lld",
1849 d->chk_lpt_sz, d->chk_lpt_wastage, lpt_sz); 1849 d->chk_lpt_sz, d->chk_lpt_wastage, lpt_sz);
1850 err = -EINVAL; 1850 err = -EINVAL;
1851 } 1851 }
@@ -1887,7 +1887,7 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
1887 pr_err("(pid %d) start dumping LEB %d\n", current->pid, lnum); 1887 pr_err("(pid %d) start dumping LEB %d\n", current->pid, lnum);
1888 buf = p = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); 1888 buf = p = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL);
1889 if (!buf) { 1889 if (!buf) {
1890 ubifs_err("cannot allocate memory to dump LPT"); 1890 ubifs_err(c, "cannot allocate memory to dump LPT");
1891 return; 1891 return;
1892 } 1892 }
1893 1893
@@ -1962,7 +1962,7 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
1962 pr_err("LEB %d:%d, lsave len\n", lnum, offs); 1962 pr_err("LEB %d:%d, lsave len\n", lnum, offs);
1963 break; 1963 break;
1964 default: 1964 default:
1965 ubifs_err("LPT node type %d not recognized", node_type); 1965 ubifs_err(c, "LPT node type %d not recognized", node_type);
1966 goto out; 1966 goto out;
1967 } 1967 }
1968 1968
diff --git a/fs/ubifs/master.c b/fs/ubifs/master.c
index 1a4bb9e8b3b8..c6a5e39e2ba5 100644
--- a/fs/ubifs/master.c
+++ b/fs/ubifs/master.c
@@ -82,7 +82,7 @@ out:
82 return -EUCLEAN; 82 return -EUCLEAN;
83 83
84out_dump: 84out_dump:
85 ubifs_err("unexpected node type %d master LEB %d:%d", 85 ubifs_err(c, "unexpected node type %d master LEB %d:%d",
86 snod->type, lnum, snod->offs); 86 snod->type, lnum, snod->offs);
87 ubifs_scan_destroy(sleb); 87 ubifs_scan_destroy(sleb);
88 return -EINVAL; 88 return -EINVAL;
@@ -240,7 +240,7 @@ static int validate_master(const struct ubifs_info *c)
240 return 0; 240 return 0;
241 241
242out: 242out:
243 ubifs_err("bad master node at offset %d error %d", c->mst_offs, err); 243 ubifs_err(c, "bad master node at offset %d error %d", c->mst_offs, err);
244 ubifs_dump_node(c, c->mst_node); 244 ubifs_dump_node(c, c->mst_node);
245 return -EINVAL; 245 return -EINVAL;
246} 246}
@@ -316,7 +316,7 @@ int ubifs_read_master(struct ubifs_info *c)
316 316
317 if (c->leb_cnt < old_leb_cnt || 317 if (c->leb_cnt < old_leb_cnt ||
318 c->leb_cnt < UBIFS_MIN_LEB_CNT) { 318 c->leb_cnt < UBIFS_MIN_LEB_CNT) {
319 ubifs_err("bad leb_cnt on master node"); 319 ubifs_err(c, "bad leb_cnt on master node");
320 ubifs_dump_node(c, c->mst_node); 320 ubifs_dump_node(c, c->mst_node);
321 return -EINVAL; 321 return -EINVAL;
322 } 322 }
diff --git a/fs/ubifs/orphan.c b/fs/ubifs/orphan.c
index 4409f486ecef..caf2d123e9ee 100644
--- a/fs/ubifs/orphan.c
+++ b/fs/ubifs/orphan.c
@@ -88,7 +88,7 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
88 else if (inum > o->inum) 88 else if (inum > o->inum)
89 p = &(*p)->rb_right; 89 p = &(*p)->rb_right;
90 else { 90 else {
91 ubifs_err("orphaned twice"); 91 ubifs_err(c, "orphaned twice");
92 spin_unlock(&c->orphan_lock); 92 spin_unlock(&c->orphan_lock);
93 kfree(orphan); 93 kfree(orphan);
94 return 0; 94 return 0;
@@ -155,7 +155,7 @@ void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum)
155 } 155 }
156 } 156 }
157 spin_unlock(&c->orphan_lock); 157 spin_unlock(&c->orphan_lock);
158 ubifs_err("missing orphan ino %lu", (unsigned long)inum); 158 ubifs_err(c, "missing orphan ino %lu", (unsigned long)inum);
159 dump_stack(); 159 dump_stack();
160} 160}
161 161
@@ -287,7 +287,7 @@ static int write_orph_node(struct ubifs_info *c, int atomic)
287 * We limit the number of orphans so that this should 287 * We limit the number of orphans so that this should
288 * never happen. 288 * never happen.
289 */ 289 */
290 ubifs_err("out of space in orphan area"); 290 ubifs_err(c, "out of space in orphan area");
291 return -EINVAL; 291 return -EINVAL;
292 } 292 }
293 } 293 }
@@ -397,7 +397,7 @@ static int consolidate(struct ubifs_info *c)
397 * We limit the number of orphans so that this should 397 * We limit the number of orphans so that this should
398 * never happen. 398 * never happen.
399 */ 399 */
400 ubifs_err("out of space in orphan area"); 400 ubifs_err(c, "out of space in orphan area");
401 err = -EINVAL; 401 err = -EINVAL;
402 } 402 }
403 spin_unlock(&c->orphan_lock); 403 spin_unlock(&c->orphan_lock);
@@ -569,7 +569,7 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
569 569
570 list_for_each_entry(snod, &sleb->nodes, list) { 570 list_for_each_entry(snod, &sleb->nodes, list) {
571 if (snod->type != UBIFS_ORPH_NODE) { 571 if (snod->type != UBIFS_ORPH_NODE) {
572 ubifs_err("invalid node type %d in orphan area at %d:%d", 572 ubifs_err(c, "invalid node type %d in orphan area at %d:%d",
573 snod->type, sleb->lnum, snod->offs); 573 snod->type, sleb->lnum, snod->offs);
574 ubifs_dump_node(c, snod->node); 574 ubifs_dump_node(c, snod->node);
575 return -EINVAL; 575 return -EINVAL;
@@ -596,7 +596,7 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
596 * number. That makes this orphan node, out of date. 596 * number. That makes this orphan node, out of date.
597 */ 597 */
598 if (!first) { 598 if (!first) {
599 ubifs_err("out of order commit number %llu in orphan node at %d:%d", 599 ubifs_err(c, "out of order commit number %llu in orphan node at %d:%d",
600 cmt_no, sleb->lnum, snod->offs); 600 cmt_no, sleb->lnum, snod->offs);
601 ubifs_dump_node(c, snod->node); 601 ubifs_dump_node(c, snod->node);
602 return -EINVAL; 602 return -EINVAL;
@@ -831,20 +831,20 @@ static int dbg_orphan_check(struct ubifs_info *c, struct ubifs_zbranch *zbr,
831 if (inum != ci->last_ino) { 831 if (inum != ci->last_ino) {
832 /* Lowest node type is the inode node, so it comes first */ 832 /* Lowest node type is the inode node, so it comes first */
833 if (key_type(c, &zbr->key) != UBIFS_INO_KEY) 833 if (key_type(c, &zbr->key) != UBIFS_INO_KEY)
834 ubifs_err("found orphan node ino %lu, type %d", 834 ubifs_err(c, "found orphan node ino %lu, type %d",
835 (unsigned long)inum, key_type(c, &zbr->key)); 835 (unsigned long)inum, key_type(c, &zbr->key));
836 ci->last_ino = inum; 836 ci->last_ino = inum;
837 ci->tot_inos += 1; 837 ci->tot_inos += 1;
838 err = ubifs_tnc_read_node(c, zbr, ci->node); 838 err = ubifs_tnc_read_node(c, zbr, ci->node);
839 if (err) { 839 if (err) {
840 ubifs_err("node read failed, error %d", err); 840 ubifs_err(c, "node read failed, error %d", err);
841 return err; 841 return err;
842 } 842 }
843 if (ci->node->nlink == 0) 843 if (ci->node->nlink == 0)
844 /* Must be recorded as an orphan */ 844 /* Must be recorded as an orphan */
845 if (!dbg_find_check_orphan(&ci->root, inum) && 845 if (!dbg_find_check_orphan(&ci->root, inum) &&
846 !dbg_find_orphan(c, inum)) { 846 !dbg_find_orphan(c, inum)) {
847 ubifs_err("missing orphan, ino %lu", 847 ubifs_err(c, "missing orphan, ino %lu",
848 (unsigned long)inum); 848 (unsigned long)inum);
849 ci->missing += 1; 849 ci->missing += 1;
850 } 850 }
@@ -887,7 +887,7 @@ static int dbg_scan_orphans(struct ubifs_info *c, struct check_info *ci)
887 887
888 buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); 888 buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL);
889 if (!buf) { 889 if (!buf) {
890 ubifs_err("cannot allocate memory to check orphans"); 890 ubifs_err(c, "cannot allocate memory to check orphans");
891 return 0; 891 return 0;
892 } 892 }
893 893
@@ -925,7 +925,7 @@ static int dbg_check_orphans(struct ubifs_info *c)
925 ci.root = RB_ROOT; 925 ci.root = RB_ROOT;
926 ci.node = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS); 926 ci.node = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS);
927 if (!ci.node) { 927 if (!ci.node) {
928 ubifs_err("out of memory"); 928 ubifs_err(c, "out of memory");
929 return -ENOMEM; 929 return -ENOMEM;
930 } 930 }
931 931
@@ -935,12 +935,12 @@ static int dbg_check_orphans(struct ubifs_info *c)
935 935
936 err = dbg_walk_index(c, &dbg_orphan_check, NULL, &ci); 936 err = dbg_walk_index(c, &dbg_orphan_check, NULL, &ci);
937 if (err) { 937 if (err) {
938 ubifs_err("cannot scan TNC, error %d", err); 938 ubifs_err(c, "cannot scan TNC, error %d", err);
939 goto out; 939 goto out;
940 } 940 }
941 941
942 if (ci.missing) { 942 if (ci.missing) {
943 ubifs_err("%lu missing orphan(s)", ci.missing); 943 ubifs_err(c, "%lu missing orphan(s)", ci.missing);
944 err = -EINVAL; 944 err = -EINVAL;
945 goto out; 945 goto out;
946 } 946 }
diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c
index c640938f62f0..695fc71d5244 100644
--- a/fs/ubifs/recovery.c
+++ b/fs/ubifs/recovery.c
@@ -305,7 +305,7 @@ int ubifs_recover_master_node(struct ubifs_info *c)
305 mst = mst2; 305 mst = mst2;
306 } 306 }
307 307
308 ubifs_msg("recovered master node from LEB %d", 308 ubifs_msg(c, "recovered master node from LEB %d",
309 (mst == mst1 ? UBIFS_MST_LNUM : UBIFS_MST_LNUM + 1)); 309 (mst == mst1 ? UBIFS_MST_LNUM : UBIFS_MST_LNUM + 1));
310 310
311 memcpy(c->mst_node, mst, UBIFS_MST_NODE_SZ); 311 memcpy(c->mst_node, mst, UBIFS_MST_NODE_SZ);
@@ -360,13 +360,13 @@ int ubifs_recover_master_node(struct ubifs_info *c)
360out_err: 360out_err:
361 err = -EINVAL; 361 err = -EINVAL;
362out_free: 362out_free:
363 ubifs_err("failed to recover master node"); 363 ubifs_err(c, "failed to recover master node");
364 if (mst1) { 364 if (mst1) {
365 ubifs_err("dumping first master node"); 365 ubifs_err(c, "dumping first master node");
366 ubifs_dump_node(c, mst1); 366 ubifs_dump_node(c, mst1);
367 } 367 }
368 if (mst2) { 368 if (mst2) {
369 ubifs_err("dumping second master node"); 369 ubifs_err(c, "dumping second master node");
370 ubifs_dump_node(c, mst2); 370 ubifs_dump_node(c, mst2);
371 } 371 }
372 vfree(buf2); 372 vfree(buf2);
@@ -682,7 +682,7 @@ struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
682 ret, lnum, offs); 682 ret, lnum, offs);
683 break; 683 break;
684 } else { 684 } else {
685 ubifs_err("unexpected return value %d", ret); 685 ubifs_err(c, "unexpected return value %d", ret);
686 err = -EINVAL; 686 err = -EINVAL;
687 goto error; 687 goto error;
688 } 688 }
@@ -702,7 +702,7 @@ struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
702 * See header comment for this file for more 702 * See header comment for this file for more
703 * explanations about the reasons we have this check. 703 * explanations about the reasons we have this check.
704 */ 704 */
705 ubifs_err("corrupt empty space LEB %d:%d, corruption starts at %d", 705 ubifs_err(c, "corrupt empty space LEB %d:%d, corruption starts at %d",
706 lnum, offs, corruption); 706 lnum, offs, corruption);
707 /* Make sure we dump interesting non-0xFF data */ 707 /* Make sure we dump interesting non-0xFF data */
708 offs += corruption; 708 offs += corruption;
@@ -788,13 +788,13 @@ struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
788 788
789corrupted_rescan: 789corrupted_rescan:
790 /* Re-scan the corrupted data with verbose messages */ 790 /* Re-scan the corrupted data with verbose messages */
791 ubifs_err("corruption %d", ret); 791 ubifs_err(c, "corruption %d", ret);
792 ubifs_scan_a_node(c, buf, len, lnum, offs, 1); 792 ubifs_scan_a_node(c, buf, len, lnum, offs, 1);
793corrupted: 793corrupted:
794 ubifs_scanned_corruption(c, lnum, offs, buf); 794 ubifs_scanned_corruption(c, lnum, offs, buf);
795 err = -EUCLEAN; 795 err = -EUCLEAN;
796error: 796error:
797 ubifs_err("LEB %d scanning failed", lnum); 797 ubifs_err(c, "LEB %d scanning failed", lnum);
798 ubifs_scan_destroy(sleb); 798 ubifs_scan_destroy(sleb);
799 return ERR_PTR(err); 799 return ERR_PTR(err);
800} 800}
@@ -826,15 +826,15 @@ static int get_cs_sqnum(struct ubifs_info *c, int lnum, int offs,
826 goto out_free; 826 goto out_free;
827 ret = ubifs_scan_a_node(c, cs_node, UBIFS_CS_NODE_SZ, lnum, offs, 0); 827 ret = ubifs_scan_a_node(c, cs_node, UBIFS_CS_NODE_SZ, lnum, offs, 0);
828 if (ret != SCANNED_A_NODE) { 828 if (ret != SCANNED_A_NODE) {
829 ubifs_err("Not a valid node"); 829 ubifs_err(c, "Not a valid node");
830 goto out_err; 830 goto out_err;
831 } 831 }
832 if (cs_node->ch.node_type != UBIFS_CS_NODE) { 832 if (cs_node->ch.node_type != UBIFS_CS_NODE) {
833 ubifs_err("Node a CS node, type is %d", cs_node->ch.node_type); 833 ubifs_err(c, "Node a CS node, type is %d", cs_node->ch.node_type);
834 goto out_err; 834 goto out_err;
835 } 835 }
836 if (le64_to_cpu(cs_node->cmt_no) != c->cmt_no) { 836 if (le64_to_cpu(cs_node->cmt_no) != c->cmt_no) {
837 ubifs_err("CS node cmt_no %llu != current cmt_no %llu", 837 ubifs_err(c, "CS node cmt_no %llu != current cmt_no %llu",
838 (unsigned long long)le64_to_cpu(cs_node->cmt_no), 838 (unsigned long long)le64_to_cpu(cs_node->cmt_no),
839 c->cmt_no); 839 c->cmt_no);
840 goto out_err; 840 goto out_err;
@@ -847,7 +847,7 @@ static int get_cs_sqnum(struct ubifs_info *c, int lnum, int offs,
847out_err: 847out_err:
848 err = -EINVAL; 848 err = -EINVAL;
849out_free: 849out_free:
850 ubifs_err("failed to get CS sqnum"); 850 ubifs_err(c, "failed to get CS sqnum");
851 kfree(cs_node); 851 kfree(cs_node);
852 return err; 852 return err;
853} 853}
@@ -899,7 +899,7 @@ struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum,
899 } 899 }
900 } 900 }
901 if (snod->sqnum > cs_sqnum) { 901 if (snod->sqnum > cs_sqnum) {
902 ubifs_err("unrecoverable log corruption in LEB %d", 902 ubifs_err(c, "unrecoverable log corruption in LEB %d",
903 lnum); 903 lnum);
904 ubifs_scan_destroy(sleb); 904 ubifs_scan_destroy(sleb);
905 return ERR_PTR(-EUCLEAN); 905 return ERR_PTR(-EUCLEAN);
@@ -975,11 +975,8 @@ int ubifs_recover_inl_heads(struct ubifs_info *c, void *sbuf)
975 return err; 975 return err;
976 976
977 dbg_rcvry("checking LPT head at %d:%d", c->nhead_lnum, c->nhead_offs); 977 dbg_rcvry("checking LPT head at %d:%d", c->nhead_lnum, c->nhead_offs);
978 err = recover_head(c, c->nhead_lnum, c->nhead_offs, sbuf);
979 if (err)
980 return err;
981 978
982 return 0; 979 return recover_head(c, c->nhead_lnum, c->nhead_offs, sbuf);
983} 980}
984 981
985/** 982/**
@@ -1004,10 +1001,7 @@ static int clean_an_unclean_leb(struct ubifs_info *c,
1004 1001
1005 if (len == 0) { 1002 if (len == 0) {
1006 /* Nothing to read, just unmap it */ 1003 /* Nothing to read, just unmap it */
1007 err = ubifs_leb_unmap(c, lnum); 1004 return ubifs_leb_unmap(c, lnum);
1008 if (err)
1009 return err;
1010 return 0;
1011 } 1005 }
1012 1006
1013 err = ubifs_leb_read(c, lnum, buf, offs, len, 0); 1007 err = ubifs_leb_read(c, lnum, buf, offs, len, 0);
@@ -1043,7 +1037,7 @@ static int clean_an_unclean_leb(struct ubifs_info *c,
1043 } 1037 }
1044 1038
1045 if (ret == SCANNED_EMPTY_SPACE) { 1039 if (ret == SCANNED_EMPTY_SPACE) {
1046 ubifs_err("unexpected empty space at %d:%d", 1040 ubifs_err(c, "unexpected empty space at %d:%d",
1047 lnum, offs); 1041 lnum, offs);
1048 return -EUCLEAN; 1042 return -EUCLEAN;
1049 } 1043 }
@@ -1137,7 +1131,7 @@ static int grab_empty_leb(struct ubifs_info *c)
1137 */ 1131 */
1138 lnum = ubifs_find_free_leb_for_idx(c); 1132 lnum = ubifs_find_free_leb_for_idx(c);
1139 if (lnum < 0) { 1133 if (lnum < 0) {
1140 ubifs_err("could not find an empty LEB"); 1134 ubifs_err(c, "could not find an empty LEB");
1141 ubifs_dump_lprops(c); 1135 ubifs_dump_lprops(c);
1142 ubifs_dump_budg(c, &c->bi); 1136 ubifs_dump_budg(c, &c->bi);
1143 return lnum; 1137 return lnum;
@@ -1217,7 +1211,7 @@ int ubifs_rcvry_gc_commit(struct ubifs_info *c)
1217 } 1211 }
1218 mutex_unlock(&wbuf->io_mutex); 1212 mutex_unlock(&wbuf->io_mutex);
1219 if (err < 0) { 1213 if (err < 0) {
1220 ubifs_err("GC failed, error %d", err); 1214 ubifs_err(c, "GC failed, error %d", err);
1221 if (err == -EAGAIN) 1215 if (err == -EAGAIN)
1222 err = -EINVAL; 1216 err = -EINVAL;
1223 return err; 1217 return err;
@@ -1464,7 +1458,7 @@ static int fix_size_in_place(struct ubifs_info *c, struct size_entry *e)
1464 return 0; 1458 return 0;
1465 1459
1466out: 1460out:
1467 ubifs_warn("inode %lu failed to fix size %lld -> %lld error %d", 1461 ubifs_warn(c, "inode %lu failed to fix size %lld -> %lld error %d",
1468 (unsigned long)e->inum, e->i_size, e->d_size, err); 1462 (unsigned long)e->inum, e->i_size, e->d_size, err);
1469 return err; 1463 return err;
1470} 1464}
diff --git a/fs/ubifs/replay.c b/fs/ubifs/replay.c
index 9b40a1c5e160..3ca4540130b5 100644
--- a/fs/ubifs/replay.c
+++ b/fs/ubifs/replay.c
@@ -458,13 +458,13 @@ int ubifs_validate_entry(struct ubifs_info *c,
458 nlen > UBIFS_MAX_NLEN || dent->name[nlen] != 0 || 458 nlen > UBIFS_MAX_NLEN || dent->name[nlen] != 0 ||
459 strnlen(dent->name, nlen) != nlen || 459 strnlen(dent->name, nlen) != nlen ||
460 le64_to_cpu(dent->inum) > MAX_INUM) { 460 le64_to_cpu(dent->inum) > MAX_INUM) {
461 ubifs_err("bad %s node", key_type == UBIFS_DENT_KEY ? 461 ubifs_err(c, "bad %s node", key_type == UBIFS_DENT_KEY ?
462 "directory entry" : "extended attribute entry"); 462 "directory entry" : "extended attribute entry");
463 return -EINVAL; 463 return -EINVAL;
464 } 464 }
465 465
466 if (key_type != UBIFS_DENT_KEY && key_type != UBIFS_XENT_KEY) { 466 if (key_type != UBIFS_DENT_KEY && key_type != UBIFS_XENT_KEY) {
467 ubifs_err("bad key type %d", key_type); 467 ubifs_err(c, "bad key type %d", key_type);
468 return -EINVAL; 468 return -EINVAL;
469 } 469 }
470 470
@@ -589,7 +589,7 @@ static int replay_bud(struct ubifs_info *c, struct bud_entry *b)
589 cond_resched(); 589 cond_resched();
590 590
591 if (snod->sqnum >= SQNUM_WATERMARK) { 591 if (snod->sqnum >= SQNUM_WATERMARK) {
592 ubifs_err("file system's life ended"); 592 ubifs_err(c, "file system's life ended");
593 goto out_dump; 593 goto out_dump;
594 } 594 }
595 595
@@ -647,7 +647,7 @@ static int replay_bud(struct ubifs_info *c, struct bud_entry *b)
647 if (old_size < 0 || old_size > c->max_inode_sz || 647 if (old_size < 0 || old_size > c->max_inode_sz ||
648 new_size < 0 || new_size > c->max_inode_sz || 648 new_size < 0 || new_size > c->max_inode_sz ||
649 old_size <= new_size) { 649 old_size <= new_size) {
650 ubifs_err("bad truncation node"); 650 ubifs_err(c, "bad truncation node");
651 goto out_dump; 651 goto out_dump;
652 } 652 }
653 653
@@ -662,7 +662,7 @@ static int replay_bud(struct ubifs_info *c, struct bud_entry *b)
662 break; 662 break;
663 } 663 }
664 default: 664 default:
665 ubifs_err("unexpected node type %d in bud LEB %d:%d", 665 ubifs_err(c, "unexpected node type %d in bud LEB %d:%d",
666 snod->type, lnum, snod->offs); 666 snod->type, lnum, snod->offs);
667 err = -EINVAL; 667 err = -EINVAL;
668 goto out_dump; 668 goto out_dump;
@@ -685,7 +685,7 @@ out:
685 return err; 685 return err;
686 686
687out_dump: 687out_dump:
688 ubifs_err("bad node is at LEB %d:%d", lnum, snod->offs); 688 ubifs_err(c, "bad node is at LEB %d:%d", lnum, snod->offs);
689 ubifs_dump_node(c, snod->node); 689 ubifs_dump_node(c, snod->node);
690 ubifs_scan_destroy(sleb); 690 ubifs_scan_destroy(sleb);
691 return -EINVAL; 691 return -EINVAL;
@@ -805,7 +805,7 @@ static int validate_ref(struct ubifs_info *c, const struct ubifs_ref_node *ref)
805 if (bud) { 805 if (bud) {
806 if (bud->jhead == jhead && bud->start <= offs) 806 if (bud->jhead == jhead && bud->start <= offs)
807 return 1; 807 return 1;
808 ubifs_err("bud at LEB %d:%d was already referred", lnum, offs); 808 ubifs_err(c, "bud at LEB %d:%d was already referred", lnum, offs);
809 return -EINVAL; 809 return -EINVAL;
810 } 810 }
811 811
@@ -861,12 +861,12 @@ static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf)
861 * numbers. 861 * numbers.
862 */ 862 */
863 if (snod->type != UBIFS_CS_NODE) { 863 if (snod->type != UBIFS_CS_NODE) {
864 ubifs_err("first log node at LEB %d:%d is not CS node", 864 ubifs_err(c, "first log node at LEB %d:%d is not CS node",
865 lnum, offs); 865 lnum, offs);
866 goto out_dump; 866 goto out_dump;
867 } 867 }
868 if (le64_to_cpu(node->cmt_no) != c->cmt_no) { 868 if (le64_to_cpu(node->cmt_no) != c->cmt_no) {
869 ubifs_err("first CS node at LEB %d:%d has wrong commit number %llu expected %llu", 869 ubifs_err(c, "first CS node at LEB %d:%d has wrong commit number %llu expected %llu",
870 lnum, offs, 870 lnum, offs,
871 (unsigned long long)le64_to_cpu(node->cmt_no), 871 (unsigned long long)le64_to_cpu(node->cmt_no),
872 c->cmt_no); 872 c->cmt_no);
@@ -891,7 +891,7 @@ static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf)
891 891
892 /* Make sure the first node sits at offset zero of the LEB */ 892 /* Make sure the first node sits at offset zero of the LEB */
893 if (snod->offs != 0) { 893 if (snod->offs != 0) {
894 ubifs_err("first node is not at zero offset"); 894 ubifs_err(c, "first node is not at zero offset");
895 goto out_dump; 895 goto out_dump;
896 } 896 }
897 897
@@ -899,12 +899,12 @@ static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf)
899 cond_resched(); 899 cond_resched();
900 900
901 if (snod->sqnum >= SQNUM_WATERMARK) { 901 if (snod->sqnum >= SQNUM_WATERMARK) {
902 ubifs_err("file system's life ended"); 902 ubifs_err(c, "file system's life ended");
903 goto out_dump; 903 goto out_dump;
904 } 904 }
905 905
906 if (snod->sqnum < c->cs_sqnum) { 906 if (snod->sqnum < c->cs_sqnum) {
907 ubifs_err("bad sqnum %llu, commit sqnum %llu", 907 ubifs_err(c, "bad sqnum %llu, commit sqnum %llu",
908 snod->sqnum, c->cs_sqnum); 908 snod->sqnum, c->cs_sqnum);
909 goto out_dump; 909 goto out_dump;
910 } 910 }
@@ -934,12 +934,12 @@ static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf)
934 case UBIFS_CS_NODE: 934 case UBIFS_CS_NODE:
935 /* Make sure it sits at the beginning of LEB */ 935 /* Make sure it sits at the beginning of LEB */
936 if (snod->offs != 0) { 936 if (snod->offs != 0) {
937 ubifs_err("unexpected node in log"); 937 ubifs_err(c, "unexpected node in log");
938 goto out_dump; 938 goto out_dump;
939 } 939 }
940 break; 940 break;
941 default: 941 default:
942 ubifs_err("unexpected node in log"); 942 ubifs_err(c, "unexpected node in log");
943 goto out_dump; 943 goto out_dump;
944 } 944 }
945 } 945 }
@@ -955,7 +955,7 @@ out:
955 return err; 955 return err;
956 956
957out_dump: 957out_dump:
958 ubifs_err("log error detected while replaying the log at LEB %d:%d", 958 ubifs_err(c, "log error detected while replaying the log at LEB %d:%d",
959 lnum, offs + snod->offs); 959 lnum, offs + snod->offs);
960 ubifs_dump_node(c, snod->node); 960 ubifs_dump_node(c, snod->node);
961 ubifs_scan_destroy(sleb); 961 ubifs_scan_destroy(sleb);
@@ -1017,7 +1017,7 @@ int ubifs_replay_journal(struct ubifs_info *c)
1017 return free; /* Error code */ 1017 return free; /* Error code */
1018 1018
1019 if (c->ihead_offs != c->leb_size - free) { 1019 if (c->ihead_offs != c->leb_size - free) {
1020 ubifs_err("bad index head LEB %d:%d", c->ihead_lnum, 1020 ubifs_err(c, "bad index head LEB %d:%d", c->ihead_lnum,
1021 c->ihead_offs); 1021 c->ihead_offs);
1022 return -EINVAL; 1022 return -EINVAL;
1023 } 1023 }
@@ -1040,7 +1040,7 @@ int ubifs_replay_journal(struct ubifs_info *c)
1040 * someting went wrong and we cannot proceed mounting 1040 * someting went wrong and we cannot proceed mounting
1041 * the file-system. 1041 * the file-system.
1042 */ 1042 */
1043 ubifs_err("no UBIFS nodes found at the log head LEB %d:%d, possibly corrupted", 1043 ubifs_err(c, "no UBIFS nodes found at the log head LEB %d:%d, possibly corrupted",
1044 lnum, 0); 1044 lnum, 0);
1045 err = -EINVAL; 1045 err = -EINVAL;
1046 } 1046 }
diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c
index 79c6dbbc0e04..f4fbc7b6b794 100644
--- a/fs/ubifs/sb.c
+++ b/fs/ubifs/sb.c
@@ -335,7 +335,7 @@ static int create_default_filesystem(struct ubifs_info *c)
335 if (err) 335 if (err)
336 return err; 336 return err;
337 337
338 ubifs_msg("default file-system created"); 338 ubifs_msg(c, "default file-system created");
339 return 0; 339 return 0;
340} 340}
341 341
@@ -365,13 +365,13 @@ static int validate_sb(struct ubifs_info *c, struct ubifs_sb_node *sup)
365 } 365 }
366 366
367 if (le32_to_cpu(sup->min_io_size) != c->min_io_size) { 367 if (le32_to_cpu(sup->min_io_size) != c->min_io_size) {
368 ubifs_err("min. I/O unit mismatch: %d in superblock, %d real", 368 ubifs_err(c, "min. I/O unit mismatch: %d in superblock, %d real",
369 le32_to_cpu(sup->min_io_size), c->min_io_size); 369 le32_to_cpu(sup->min_io_size), c->min_io_size);
370 goto failed; 370 goto failed;
371 } 371 }
372 372
373 if (le32_to_cpu(sup->leb_size) != c->leb_size) { 373 if (le32_to_cpu(sup->leb_size) != c->leb_size) {
374 ubifs_err("LEB size mismatch: %d in superblock, %d real", 374 ubifs_err(c, "LEB size mismatch: %d in superblock, %d real",
375 le32_to_cpu(sup->leb_size), c->leb_size); 375 le32_to_cpu(sup->leb_size), c->leb_size);
376 goto failed; 376 goto failed;
377 } 377 }
@@ -393,33 +393,33 @@ static int validate_sb(struct ubifs_info *c, struct ubifs_sb_node *sup)
393 min_leb_cnt += c->lpt_lebs + c->orph_lebs + c->jhead_cnt + 6; 393 min_leb_cnt += c->lpt_lebs + c->orph_lebs + c->jhead_cnt + 6;
394 394
395 if (c->leb_cnt < min_leb_cnt || c->leb_cnt > c->vi.size) { 395 if (c->leb_cnt < min_leb_cnt || c->leb_cnt > c->vi.size) {
396 ubifs_err("bad LEB count: %d in superblock, %d on UBI volume, %d minimum required", 396 ubifs_err(c, "bad LEB count: %d in superblock, %d on UBI volume, %d minimum required",
397 c->leb_cnt, c->vi.size, min_leb_cnt); 397 c->leb_cnt, c->vi.size, min_leb_cnt);
398 goto failed; 398 goto failed;
399 } 399 }
400 400
401 if (c->max_leb_cnt < c->leb_cnt) { 401 if (c->max_leb_cnt < c->leb_cnt) {
402 ubifs_err("max. LEB count %d less than LEB count %d", 402 ubifs_err(c, "max. LEB count %d less than LEB count %d",
403 c->max_leb_cnt, c->leb_cnt); 403 c->max_leb_cnt, c->leb_cnt);
404 goto failed; 404 goto failed;
405 } 405 }
406 406
407 if (c->main_lebs < UBIFS_MIN_MAIN_LEBS) { 407 if (c->main_lebs < UBIFS_MIN_MAIN_LEBS) {
408 ubifs_err("too few main LEBs count %d, must be at least %d", 408 ubifs_err(c, "too few main LEBs count %d, must be at least %d",
409 c->main_lebs, UBIFS_MIN_MAIN_LEBS); 409 c->main_lebs, UBIFS_MIN_MAIN_LEBS);
410 goto failed; 410 goto failed;
411 } 411 }
412 412
413 max_bytes = (long long)c->leb_size * UBIFS_MIN_BUD_LEBS; 413 max_bytes = (long long)c->leb_size * UBIFS_MIN_BUD_LEBS;
414 if (c->max_bud_bytes < max_bytes) { 414 if (c->max_bud_bytes < max_bytes) {
415 ubifs_err("too small journal (%lld bytes), must be at least %lld bytes", 415 ubifs_err(c, "too small journal (%lld bytes), must be at least %lld bytes",
416 c->max_bud_bytes, max_bytes); 416 c->max_bud_bytes, max_bytes);
417 goto failed; 417 goto failed;
418 } 418 }
419 419
420 max_bytes = (long long)c->leb_size * c->main_lebs; 420 max_bytes = (long long)c->leb_size * c->main_lebs;
421 if (c->max_bud_bytes > max_bytes) { 421 if (c->max_bud_bytes > max_bytes) {
422 ubifs_err("too large journal size (%lld bytes), only %lld bytes available in the main area", 422 ubifs_err(c, "too large journal size (%lld bytes), only %lld bytes available in the main area",
423 c->max_bud_bytes, max_bytes); 423 c->max_bud_bytes, max_bytes);
424 goto failed; 424 goto failed;
425 } 425 }
@@ -468,7 +468,7 @@ static int validate_sb(struct ubifs_info *c, struct ubifs_sb_node *sup)
468 return 0; 468 return 0;
469 469
470failed: 470failed:
471 ubifs_err("bad superblock, error %d", err); 471 ubifs_err(c, "bad superblock, error %d", err);
472 ubifs_dump_node(c, sup); 472 ubifs_dump_node(c, sup);
473 return -EINVAL; 473 return -EINVAL;
474} 474}
@@ -549,12 +549,12 @@ int ubifs_read_superblock(struct ubifs_info *c)
549 ubifs_assert(!c->ro_media || c->ro_mount); 549 ubifs_assert(!c->ro_media || c->ro_mount);
550 if (!c->ro_mount || 550 if (!c->ro_mount ||
551 c->ro_compat_version > UBIFS_RO_COMPAT_VERSION) { 551 c->ro_compat_version > UBIFS_RO_COMPAT_VERSION) {
552 ubifs_err("on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d", 552 ubifs_err(c, "on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d",
553 c->fmt_version, c->ro_compat_version, 553 c->fmt_version, c->ro_compat_version,
554 UBIFS_FORMAT_VERSION, 554 UBIFS_FORMAT_VERSION,
555 UBIFS_RO_COMPAT_VERSION); 555 UBIFS_RO_COMPAT_VERSION);
556 if (c->ro_compat_version <= UBIFS_RO_COMPAT_VERSION) { 556 if (c->ro_compat_version <= UBIFS_RO_COMPAT_VERSION) {
557 ubifs_msg("only R/O mounting is possible"); 557 ubifs_msg(c, "only R/O mounting is possible");
558 err = -EROFS; 558 err = -EROFS;
559 } else 559 } else
560 err = -EINVAL; 560 err = -EINVAL;
@@ -570,7 +570,7 @@ int ubifs_read_superblock(struct ubifs_info *c)
570 } 570 }
571 571
572 if (c->fmt_version < 3) { 572 if (c->fmt_version < 3) {
573 ubifs_err("on-flash format version %d is not supported", 573 ubifs_err(c, "on-flash format version %d is not supported",
574 c->fmt_version); 574 c->fmt_version);
575 err = -EINVAL; 575 err = -EINVAL;
576 goto out; 576 goto out;
@@ -595,7 +595,7 @@ int ubifs_read_superblock(struct ubifs_info *c)
595 c->key_len = UBIFS_SK_LEN; 595 c->key_len = UBIFS_SK_LEN;
596 break; 596 break;
597 default: 597 default:
598 ubifs_err("unsupported key format"); 598 ubifs_err(c, "unsupported key format");
599 err = -EINVAL; 599 err = -EINVAL;
600 goto out; 600 goto out;
601 } 601 }
@@ -785,7 +785,7 @@ int ubifs_fixup_free_space(struct ubifs_info *c)
785 ubifs_assert(c->space_fixup); 785 ubifs_assert(c->space_fixup);
786 ubifs_assert(!c->ro_mount); 786 ubifs_assert(!c->ro_mount);
787 787
788 ubifs_msg("start fixing up free space"); 788 ubifs_msg(c, "start fixing up free space");
789 789
790 err = fixup_free_space(c); 790 err = fixup_free_space(c);
791 if (err) 791 if (err)
@@ -804,6 +804,6 @@ int ubifs_fixup_free_space(struct ubifs_info *c)
804 if (err) 804 if (err)
805 return err; 805 return err;
806 806
807 ubifs_msg("free space fixup complete"); 807 ubifs_msg(c, "free space fixup complete");
808 return err; 808 return err;
809} 809}
diff --git a/fs/ubifs/scan.c b/fs/ubifs/scan.c
index 89adbc4d08ac..aab87340d3de 100644
--- a/fs/ubifs/scan.c
+++ b/fs/ubifs/scan.c
@@ -100,7 +100,7 @@ int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
100 if (pad_len < 0 || 100 if (pad_len < 0 ||
101 offs + node_len + pad_len > c->leb_size) { 101 offs + node_len + pad_len > c->leb_size) {
102 if (!quiet) { 102 if (!quiet) {
103 ubifs_err("bad pad node at LEB %d:%d", 103 ubifs_err(c, "bad pad node at LEB %d:%d",
104 lnum, offs); 104 lnum, offs);
105 ubifs_dump_node(c, pad); 105 ubifs_dump_node(c, pad);
106 } 106 }
@@ -110,7 +110,7 @@ int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
110 /* Make the node pads to 8-byte boundary */ 110 /* Make the node pads to 8-byte boundary */
111 if ((node_len + pad_len) & 7) { 111 if ((node_len + pad_len) & 7) {
112 if (!quiet) 112 if (!quiet)
113 ubifs_err("bad padding length %d - %d", 113 ubifs_err(c, "bad padding length %d - %d",
114 offs, offs + node_len + pad_len); 114 offs, offs + node_len + pad_len);
115 return SCANNED_A_BAD_PAD_NODE; 115 return SCANNED_A_BAD_PAD_NODE;
116 } 116 }
@@ -152,7 +152,7 @@ struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
152 152
153 err = ubifs_leb_read(c, lnum, sbuf + offs, offs, c->leb_size - offs, 0); 153 err = ubifs_leb_read(c, lnum, sbuf + offs, offs, c->leb_size - offs, 0);
154 if (err && err != -EBADMSG) { 154 if (err && err != -EBADMSG) {
155 ubifs_err("cannot read %d bytes from LEB %d:%d, error %d", 155 ubifs_err(c, "cannot read %d bytes from LEB %d:%d, error %d",
156 c->leb_size - offs, lnum, offs, err); 156 c->leb_size - offs, lnum, offs, err);
157 kfree(sleb); 157 kfree(sleb);
158 return ERR_PTR(err); 158 return ERR_PTR(err);
@@ -240,11 +240,11 @@ void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
240{ 240{
241 int len; 241 int len;
242 242
243 ubifs_err("corruption at LEB %d:%d", lnum, offs); 243 ubifs_err(c, "corruption at LEB %d:%d", lnum, offs);
244 len = c->leb_size - offs; 244 len = c->leb_size - offs;
245 if (len > 8192) 245 if (len > 8192)
246 len = 8192; 246 len = 8192;
247 ubifs_err("first %d bytes from LEB %d:%d", len, lnum, offs); 247 ubifs_err(c, "first %d bytes from LEB %d:%d", len, lnum, offs);
248 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 4, buf, len, 1); 248 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 4, buf, len, 1);
249} 249}
250 250
@@ -299,16 +299,16 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
299 299
300 switch (ret) { 300 switch (ret) {
301 case SCANNED_GARBAGE: 301 case SCANNED_GARBAGE:
302 ubifs_err("garbage"); 302 ubifs_err(c, "garbage");
303 goto corrupted; 303 goto corrupted;
304 case SCANNED_A_NODE: 304 case SCANNED_A_NODE:
305 break; 305 break;
306 case SCANNED_A_CORRUPT_NODE: 306 case SCANNED_A_CORRUPT_NODE:
307 case SCANNED_A_BAD_PAD_NODE: 307 case SCANNED_A_BAD_PAD_NODE:
308 ubifs_err("bad node"); 308 ubifs_err(c, "bad node");
309 goto corrupted; 309 goto corrupted;
310 default: 310 default:
311 ubifs_err("unknown"); 311 ubifs_err(c, "unknown");
312 err = -EINVAL; 312 err = -EINVAL;
313 goto error; 313 goto error;
314 } 314 }
@@ -325,7 +325,7 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
325 325
326 if (offs % c->min_io_size) { 326 if (offs % c->min_io_size) {
327 if (!quiet) 327 if (!quiet)
328 ubifs_err("empty space starts at non-aligned offset %d", 328 ubifs_err(c, "empty space starts at non-aligned offset %d",
329 offs); 329 offs);
330 goto corrupted; 330 goto corrupted;
331 } 331 }
@@ -338,7 +338,7 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
338 for (; len; offs++, buf++, len--) 338 for (; len; offs++, buf++, len--)
339 if (*(uint8_t *)buf != 0xff) { 339 if (*(uint8_t *)buf != 0xff) {
340 if (!quiet) 340 if (!quiet)
341 ubifs_err("corrupt empty space at LEB %d:%d", 341 ubifs_err(c, "corrupt empty space at LEB %d:%d",
342 lnum, offs); 342 lnum, offs);
343 goto corrupted; 343 goto corrupted;
344 } 344 }
@@ -348,14 +348,14 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
348corrupted: 348corrupted:
349 if (!quiet) { 349 if (!quiet) {
350 ubifs_scanned_corruption(c, lnum, offs, buf); 350 ubifs_scanned_corruption(c, lnum, offs, buf);
351 ubifs_err("LEB %d scanning failed", lnum); 351 ubifs_err(c, "LEB %d scanning failed", lnum);
352 } 352 }
353 err = -EUCLEAN; 353 err = -EUCLEAN;
354 ubifs_scan_destroy(sleb); 354 ubifs_scan_destroy(sleb);
355 return ERR_PTR(err); 355 return ERR_PTR(err);
356 356
357error: 357error:
358 ubifs_err("LEB %d scanning failed, error %d", lnum, err); 358 ubifs_err(c, "LEB %d scanning failed, error %d", lnum, err);
359 ubifs_scan_destroy(sleb); 359 ubifs_scan_destroy(sleb);
360 return ERR_PTR(err); 360 return ERR_PTR(err);
361} 361}
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index 93e946561c5c..75e6f04bb795 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -70,13 +70,13 @@ static int validate_inode(struct ubifs_info *c, const struct inode *inode)
70 const struct ubifs_inode *ui = ubifs_inode(inode); 70 const struct ubifs_inode *ui = ubifs_inode(inode);
71 71
72 if (inode->i_size > c->max_inode_sz) { 72 if (inode->i_size > c->max_inode_sz) {
73 ubifs_err("inode is too large (%lld)", 73 ubifs_err(c, "inode is too large (%lld)",
74 (long long)inode->i_size); 74 (long long)inode->i_size);
75 return 1; 75 return 1;
76 } 76 }
77 77
78 if (ui->compr_type >= UBIFS_COMPR_TYPES_CNT) { 78 if (ui->compr_type >= UBIFS_COMPR_TYPES_CNT) {
79 ubifs_err("unknown compression type %d", ui->compr_type); 79 ubifs_err(c, "unknown compression type %d", ui->compr_type);
80 return 2; 80 return 2;
81 } 81 }
82 82
@@ -90,7 +90,7 @@ static int validate_inode(struct ubifs_info *c, const struct inode *inode)
90 return 5; 90 return 5;
91 91
92 if (!ubifs_compr_present(ui->compr_type)) { 92 if (!ubifs_compr_present(ui->compr_type)) {
93 ubifs_warn("inode %lu uses '%s' compression, but it was not compiled in", 93 ubifs_warn(c, "inode %lu uses '%s' compression, but it was not compiled in",
94 inode->i_ino, ubifs_compr_name(ui->compr_type)); 94 inode->i_ino, ubifs_compr_name(ui->compr_type));
95 } 95 }
96 96
@@ -242,14 +242,14 @@ struct inode *ubifs_iget(struct super_block *sb, unsigned long inum)
242 return inode; 242 return inode;
243 243
244out_invalid: 244out_invalid:
245 ubifs_err("inode %lu validation failed, error %d", inode->i_ino, err); 245 ubifs_err(c, "inode %lu validation failed, error %d", inode->i_ino, err);
246 ubifs_dump_node(c, ino); 246 ubifs_dump_node(c, ino);
247 ubifs_dump_inode(c, inode); 247 ubifs_dump_inode(c, inode);
248 err = -EINVAL; 248 err = -EINVAL;
249out_ino: 249out_ino:
250 kfree(ino); 250 kfree(ino);
251out: 251out:
252 ubifs_err("failed to read inode %lu, error %d", inode->i_ino, err); 252 ubifs_err(c, "failed to read inode %lu, error %d", inode->i_ino, err);
253 iget_failed(inode); 253 iget_failed(inode);
254 return ERR_PTR(err); 254 return ERR_PTR(err);
255} 255}
@@ -319,7 +319,7 @@ static int ubifs_write_inode(struct inode *inode, struct writeback_control *wbc)
319 if (inode->i_nlink) { 319 if (inode->i_nlink) {
320 err = ubifs_jnl_write_inode(c, inode); 320 err = ubifs_jnl_write_inode(c, inode);
321 if (err) 321 if (err)
322 ubifs_err("can't write inode %lu, error %d", 322 ubifs_err(c, "can't write inode %lu, error %d",
323 inode->i_ino, err); 323 inode->i_ino, err);
324 else 324 else
325 err = dbg_check_inode_size(c, inode, ui->ui_size); 325 err = dbg_check_inode_size(c, inode, ui->ui_size);
@@ -363,7 +363,7 @@ static void ubifs_evict_inode(struct inode *inode)
363 * Worst case we have a lost orphan inode wasting space, so a 363 * Worst case we have a lost orphan inode wasting space, so a
364 * simple error message is OK here. 364 * simple error message is OK here.
365 */ 365 */
366 ubifs_err("can't delete inode %lu, error %d", 366 ubifs_err(c, "can't delete inode %lu, error %d",
367 inode->i_ino, err); 367 inode->i_ino, err);
368 368
369out: 369out:
@@ -492,17 +492,17 @@ static int ubifs_sync_fs(struct super_block *sb, int wait)
492static int init_constants_early(struct ubifs_info *c) 492static int init_constants_early(struct ubifs_info *c)
493{ 493{
494 if (c->vi.corrupted) { 494 if (c->vi.corrupted) {
495 ubifs_warn("UBI volume is corrupted - read-only mode"); 495 ubifs_warn(c, "UBI volume is corrupted - read-only mode");
496 c->ro_media = 1; 496 c->ro_media = 1;
497 } 497 }
498 498
499 if (c->di.ro_mode) { 499 if (c->di.ro_mode) {
500 ubifs_msg("read-only UBI device"); 500 ubifs_msg(c, "read-only UBI device");
501 c->ro_media = 1; 501 c->ro_media = 1;
502 } 502 }
503 503
504 if (c->vi.vol_type == UBI_STATIC_VOLUME) { 504 if (c->vi.vol_type == UBI_STATIC_VOLUME) {
505 ubifs_msg("static UBI volume - read-only mode"); 505 ubifs_msg(c, "static UBI volume - read-only mode");
506 c->ro_media = 1; 506 c->ro_media = 1;
507 } 507 }
508 508
@@ -516,19 +516,19 @@ static int init_constants_early(struct ubifs_info *c)
516 c->max_write_shift = fls(c->max_write_size) - 1; 516 c->max_write_shift = fls(c->max_write_size) - 1;
517 517
518 if (c->leb_size < UBIFS_MIN_LEB_SZ) { 518 if (c->leb_size < UBIFS_MIN_LEB_SZ) {
519 ubifs_err("too small LEBs (%d bytes), min. is %d bytes", 519 ubifs_err(c, "too small LEBs (%d bytes), min. is %d bytes",
520 c->leb_size, UBIFS_MIN_LEB_SZ); 520 c->leb_size, UBIFS_MIN_LEB_SZ);
521 return -EINVAL; 521 return -EINVAL;
522 } 522 }
523 523
524 if (c->leb_cnt < UBIFS_MIN_LEB_CNT) { 524 if (c->leb_cnt < UBIFS_MIN_LEB_CNT) {
525 ubifs_err("too few LEBs (%d), min. is %d", 525 ubifs_err(c, "too few LEBs (%d), min. is %d",
526 c->leb_cnt, UBIFS_MIN_LEB_CNT); 526 c->leb_cnt, UBIFS_MIN_LEB_CNT);
527 return -EINVAL; 527 return -EINVAL;
528 } 528 }
529 529
530 if (!is_power_of_2(c->min_io_size)) { 530 if (!is_power_of_2(c->min_io_size)) {
531 ubifs_err("bad min. I/O size %d", c->min_io_size); 531 ubifs_err(c, "bad min. I/O size %d", c->min_io_size);
532 return -EINVAL; 532 return -EINVAL;
533 } 533 }
534 534
@@ -539,7 +539,7 @@ static int init_constants_early(struct ubifs_info *c)
539 if (c->max_write_size < c->min_io_size || 539 if (c->max_write_size < c->min_io_size ||
540 c->max_write_size % c->min_io_size || 540 c->max_write_size % c->min_io_size ||
541 !is_power_of_2(c->max_write_size)) { 541 !is_power_of_2(c->max_write_size)) {
542 ubifs_err("bad write buffer size %d for %d min. I/O unit", 542 ubifs_err(c, "bad write buffer size %d for %d min. I/O unit",
543 c->max_write_size, c->min_io_size); 543 c->max_write_size, c->min_io_size);
544 return -EINVAL; 544 return -EINVAL;
545 } 545 }
@@ -665,7 +665,7 @@ static int init_constants_sb(struct ubifs_info *c)
665 tmp = UBIFS_CS_NODE_SZ + UBIFS_REF_NODE_SZ * c->jhead_cnt; 665 tmp = UBIFS_CS_NODE_SZ + UBIFS_REF_NODE_SZ * c->jhead_cnt;
666 tmp = ALIGN(tmp, c->min_io_size); 666 tmp = ALIGN(tmp, c->min_io_size);
667 if (tmp > c->leb_size) { 667 if (tmp > c->leb_size) {
668 ubifs_err("too small LEB size %d, at least %d needed", 668 ubifs_err(c, "too small LEB size %d, at least %d needed",
669 c->leb_size, tmp); 669 c->leb_size, tmp);
670 return -EINVAL; 670 return -EINVAL;
671 } 671 }
@@ -680,7 +680,7 @@ static int init_constants_sb(struct ubifs_info *c)
680 tmp /= c->leb_size; 680 tmp /= c->leb_size;
681 tmp += 1; 681 tmp += 1;
682 if (c->log_lebs < tmp) { 682 if (c->log_lebs < tmp) {
683 ubifs_err("too small log %d LEBs, required min. %d LEBs", 683 ubifs_err(c, "too small log %d LEBs, required min. %d LEBs",
684 c->log_lebs, tmp); 684 c->log_lebs, tmp);
685 return -EINVAL; 685 return -EINVAL;
686 } 686 }
@@ -772,7 +772,7 @@ static int take_gc_lnum(struct ubifs_info *c)
772 int err; 772 int err;
773 773
774 if (c->gc_lnum == -1) { 774 if (c->gc_lnum == -1) {
775 ubifs_err("no LEB for GC"); 775 ubifs_err(c, "no LEB for GC");
776 return -EINVAL; 776 return -EINVAL;
777 } 777 }
778 778
@@ -857,7 +857,7 @@ static void free_orphans(struct ubifs_info *c)
857 orph = list_entry(c->orph_list.next, struct ubifs_orphan, list); 857 orph = list_entry(c->orph_list.next, struct ubifs_orphan, list);
858 list_del(&orph->list); 858 list_del(&orph->list);
859 kfree(orph); 859 kfree(orph);
860 ubifs_err("orphan list not empty at unmount"); 860 ubifs_err(c, "orphan list not empty at unmount");
861 } 861 }
862 862
863 vfree(c->orph_buf); 863 vfree(c->orph_buf);
@@ -954,7 +954,8 @@ static const match_table_t tokens = {
954 */ 954 */
955static int parse_standard_option(const char *option) 955static int parse_standard_option(const char *option)
956{ 956{
957 ubifs_msg("parse %s", option); 957
958 pr_notice("UBIFS: parse %s\n", option);
958 if (!strcmp(option, "sync")) 959 if (!strcmp(option, "sync"))
959 return MS_SYNCHRONOUS; 960 return MS_SYNCHRONOUS;
960 return 0; 961 return 0;
@@ -1026,7 +1027,7 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options,
1026 else if (!strcmp(name, "zlib")) 1027 else if (!strcmp(name, "zlib"))
1027 c->mount_opts.compr_type = UBIFS_COMPR_ZLIB; 1028 c->mount_opts.compr_type = UBIFS_COMPR_ZLIB;
1028 else { 1029 else {
1029 ubifs_err("unknown compressor \"%s\"", name); 1030 ubifs_err(c, "unknown compressor \"%s\"", name); //FIXME: is c ready?
1030 kfree(name); 1031 kfree(name);
1031 return -EINVAL; 1032 return -EINVAL;
1032 } 1033 }
@@ -1042,7 +1043,7 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options,
1042 1043
1043 flag = parse_standard_option(p); 1044 flag = parse_standard_option(p);
1044 if (!flag) { 1045 if (!flag) {
1045 ubifs_err("unrecognized mount option \"%s\" or missing value", 1046 ubifs_err(c, "unrecognized mount option \"%s\" or missing value",
1046 p); 1047 p);
1047 return -EINVAL; 1048 return -EINVAL;
1048 } 1049 }
@@ -1105,7 +1106,7 @@ again:
1105 } 1106 }
1106 1107
1107 /* Just disable bulk-read */ 1108 /* Just disable bulk-read */
1108 ubifs_warn("cannot allocate %d bytes of memory for bulk-read, disabling it", 1109 ubifs_warn(c, "cannot allocate %d bytes of memory for bulk-read, disabling it",
1109 c->max_bu_buf_len); 1110 c->max_bu_buf_len);
1110 c->mount_opts.bulk_read = 1; 1111 c->mount_opts.bulk_read = 1;
1111 c->bulk_read = 0; 1112 c->bulk_read = 0;
@@ -1124,7 +1125,7 @@ static int check_free_space(struct ubifs_info *c)
1124{ 1125{
1125 ubifs_assert(c->dark_wm > 0); 1126 ubifs_assert(c->dark_wm > 0);
1126 if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) { 1127 if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) {
1127 ubifs_err("insufficient free space to mount in R/W mode"); 1128 ubifs_err(c, "insufficient free space to mount in R/W mode");
1128 ubifs_dump_budg(c, &c->bi); 1129 ubifs_dump_budg(c, &c->bi);
1129 ubifs_dump_lprops(c); 1130 ubifs_dump_lprops(c);
1130 return -ENOSPC; 1131 return -ENOSPC;
@@ -1166,14 +1167,14 @@ static int mount_ubifs(struct ubifs_info *c)
1166 * This UBI volume is empty, and read-only, or the file system 1167 * This UBI volume is empty, and read-only, or the file system
1167 * is mounted read-only - we cannot format it. 1168 * is mounted read-only - we cannot format it.
1168 */ 1169 */
1169 ubifs_err("can't format empty UBI volume: read-only %s", 1170 ubifs_err(c, "can't format empty UBI volume: read-only %s",
1170 c->ro_media ? "UBI volume" : "mount"); 1171 c->ro_media ? "UBI volume" : "mount");
1171 err = -EROFS; 1172 err = -EROFS;
1172 goto out_free; 1173 goto out_free;
1173 } 1174 }
1174 1175
1175 if (c->ro_media && !c->ro_mount) { 1176 if (c->ro_media && !c->ro_mount) {
1176 ubifs_err("cannot mount read-write - read-only media"); 1177 ubifs_err(c, "cannot mount read-write - read-only media");
1177 err = -EROFS; 1178 err = -EROFS;
1178 goto out_free; 1179 goto out_free;
1179 } 1180 }
@@ -1221,7 +1222,7 @@ static int mount_ubifs(struct ubifs_info *c)
1221 * or overridden by mount options is actually compiled in. 1222 * or overridden by mount options is actually compiled in.
1222 */ 1223 */
1223 if (!ubifs_compr_present(c->default_compr)) { 1224 if (!ubifs_compr_present(c->default_compr)) {
1224 ubifs_err("'compressor \"%s\" is not compiled in", 1225 ubifs_err(c, "'compressor \"%s\" is not compiled in",
1225 ubifs_compr_name(c->default_compr)); 1226 ubifs_compr_name(c->default_compr));
1226 err = -ENOTSUPP; 1227 err = -ENOTSUPP;
1227 goto out_free; 1228 goto out_free;
@@ -1250,7 +1251,7 @@ static int mount_ubifs(struct ubifs_info *c)
1250 if (IS_ERR(c->bgt)) { 1251 if (IS_ERR(c->bgt)) {
1251 err = PTR_ERR(c->bgt); 1252 err = PTR_ERR(c->bgt);
1252 c->bgt = NULL; 1253 c->bgt = NULL;
1253 ubifs_err("cannot spawn \"%s\", error %d", 1254 ubifs_err(c, "cannot spawn \"%s\", error %d",
1254 c->bgt_name, err); 1255 c->bgt_name, err);
1255 goto out_wbufs; 1256 goto out_wbufs;
1256 } 1257 }
@@ -1264,7 +1265,7 @@ static int mount_ubifs(struct ubifs_info *c)
1264 init_constants_master(c); 1265 init_constants_master(c);
1265 1266
1266 if ((c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY)) != 0) { 1267 if ((c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY)) != 0) {
1267 ubifs_msg("recovery needed"); 1268 ubifs_msg(c, "recovery needed");
1268 c->need_recovery = 1; 1269 c->need_recovery = 1;
1269 } 1270 }
1270 1271
@@ -1284,7 +1285,7 @@ static int mount_ubifs(struct ubifs_info *c)
1284 goto out_lpt; 1285 goto out_lpt;
1285 } 1286 }
1286 1287
1287 if (!c->ro_mount) { 1288 if (!c->ro_mount && !c->need_recovery) {
1288 /* 1289 /*
1289 * Set the "dirty" flag so that if we reboot uncleanly we 1290 * Set the "dirty" flag so that if we reboot uncleanly we
1290 * will notice this immediately on the next mount. 1291 * will notice this immediately on the next mount.
@@ -1373,10 +1374,10 @@ static int mount_ubifs(struct ubifs_info *c)
1373 1374
1374 if (c->need_recovery) { 1375 if (c->need_recovery) {
1375 if (c->ro_mount) 1376 if (c->ro_mount)
1376 ubifs_msg("recovery deferred"); 1377 ubifs_msg(c, "recovery deferred");
1377 else { 1378 else {
1378 c->need_recovery = 0; 1379 c->need_recovery = 0;
1379 ubifs_msg("recovery completed"); 1380 ubifs_msg(c, "recovery completed");
1380 /* 1381 /*
1381 * GC LEB has to be empty and taken at this point. But 1382 * GC LEB has to be empty and taken at this point. But
1382 * the journal head LEBs may also be accounted as 1383 * the journal head LEBs may also be accounted as
@@ -1397,20 +1398,20 @@ static int mount_ubifs(struct ubifs_info *c)
1397 1398
1398 c->mounting = 0; 1399 c->mounting = 0;
1399 1400
1400 ubifs_msg("mounted UBI device %d, volume %d, name \"%s\"%s", 1401 ubifs_msg(c, "UBIFS: mounted UBI device %d, volume %d, name \"%s\"%s",
1401 c->vi.ubi_num, c->vi.vol_id, c->vi.name, 1402 c->vi.ubi_num, c->vi.vol_id, c->vi.name,
1402 c->ro_mount ? ", R/O mode" : ""); 1403 c->ro_mount ? ", R/O mode" : "");
1403 x = (long long)c->main_lebs * c->leb_size; 1404 x = (long long)c->main_lebs * c->leb_size;
1404 y = (long long)c->log_lebs * c->leb_size + c->max_bud_bytes; 1405 y = (long long)c->log_lebs * c->leb_size + c->max_bud_bytes;
1405 ubifs_msg("LEB size: %d bytes (%d KiB), min./max. I/O unit sizes: %d bytes/%d bytes", 1406 ubifs_msg(c, "LEB size: %d bytes (%d KiB), min./max. I/O unit sizes: %d bytes/%d bytes",
1406 c->leb_size, c->leb_size >> 10, c->min_io_size, 1407 c->leb_size, c->leb_size >> 10, c->min_io_size,
1407 c->max_write_size); 1408 c->max_write_size);
1408 ubifs_msg("FS size: %lld bytes (%lld MiB, %d LEBs), journal size %lld bytes (%lld MiB, %d LEBs)", 1409 ubifs_msg(c, "FS size: %lld bytes (%lld MiB, %d LEBs), journal size %lld bytes (%lld MiB, %d LEBs)",
1409 x, x >> 20, c->main_lebs, 1410 x, x >> 20, c->main_lebs,
1410 y, y >> 20, c->log_lebs + c->max_bud_cnt); 1411 y, y >> 20, c->log_lebs + c->max_bud_cnt);
1411 ubifs_msg("reserved for root: %llu bytes (%llu KiB)", 1412 ubifs_msg(c, "reserved for root: %llu bytes (%llu KiB)",
1412 c->report_rp_size, c->report_rp_size >> 10); 1413 c->report_rp_size, c->report_rp_size >> 10);
1413 ubifs_msg("media format: w%d/r%d (latest is w%d/r%d), UUID %pUB%s", 1414 ubifs_msg(c, "media format: w%d/r%d (latest is w%d/r%d), UUID %pUB%s",
1414 c->fmt_version, c->ro_compat_version, 1415 c->fmt_version, c->ro_compat_version,
1415 UBIFS_FORMAT_VERSION, UBIFS_RO_COMPAT_VERSION, c->uuid, 1416 UBIFS_FORMAT_VERSION, UBIFS_RO_COMPAT_VERSION, c->uuid,
1416 c->big_lpt ? ", big LPT model" : ", small LPT model"); 1417 c->big_lpt ? ", big LPT model" : ", small LPT model");
@@ -1543,8 +1544,8 @@ static int ubifs_remount_rw(struct ubifs_info *c)
1543 int err, lnum; 1544 int err, lnum;
1544 1545
1545 if (c->rw_incompat) { 1546 if (c->rw_incompat) {
1546 ubifs_err("the file-system is not R/W-compatible"); 1547 ubifs_err(c, "the file-system is not R/W-compatible");
1547 ubifs_msg("on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d", 1548 ubifs_msg(c, "on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d",
1548 c->fmt_version, c->ro_compat_version, 1549 c->fmt_version, c->ro_compat_version,
1549 UBIFS_FORMAT_VERSION, UBIFS_RO_COMPAT_VERSION); 1550 UBIFS_FORMAT_VERSION, UBIFS_RO_COMPAT_VERSION);
1550 return -EROFS; 1551 return -EROFS;
@@ -1581,7 +1582,7 @@ static int ubifs_remount_rw(struct ubifs_info *c)
1581 } 1582 }
1582 1583
1583 if (c->need_recovery) { 1584 if (c->need_recovery) {
1584 ubifs_msg("completing deferred recovery"); 1585 ubifs_msg(c, "completing deferred recovery");
1585 err = ubifs_write_rcvrd_mst_node(c); 1586 err = ubifs_write_rcvrd_mst_node(c);
1586 if (err) 1587 if (err)
1587 goto out; 1588 goto out;
@@ -1630,7 +1631,7 @@ static int ubifs_remount_rw(struct ubifs_info *c)
1630 if (IS_ERR(c->bgt)) { 1631 if (IS_ERR(c->bgt)) {
1631 err = PTR_ERR(c->bgt); 1632 err = PTR_ERR(c->bgt);
1632 c->bgt = NULL; 1633 c->bgt = NULL;
1633 ubifs_err("cannot spawn \"%s\", error %d", 1634 ubifs_err(c, "cannot spawn \"%s\", error %d",
1634 c->bgt_name, err); 1635 c->bgt_name, err);
1635 goto out; 1636 goto out;
1636 } 1637 }
@@ -1664,7 +1665,7 @@ static int ubifs_remount_rw(struct ubifs_info *c)
1664 1665
1665 if (c->need_recovery) { 1666 if (c->need_recovery) {
1666 c->need_recovery = 0; 1667 c->need_recovery = 0;
1667 ubifs_msg("deferred recovery completed"); 1668 ubifs_msg(c, "deferred recovery completed");
1668 } else { 1669 } else {
1669 /* 1670 /*
1670 * Do not run the debugging space check if the were doing 1671 * Do not run the debugging space check if the were doing
@@ -1752,8 +1753,7 @@ static void ubifs_put_super(struct super_block *sb)
1752 int i; 1753 int i;
1753 struct ubifs_info *c = sb->s_fs_info; 1754 struct ubifs_info *c = sb->s_fs_info;
1754 1755
1755 ubifs_msg("un-mount UBI device %d, volume %d", c->vi.ubi_num, 1756 ubifs_msg(c, "un-mount UBI device %d", c->vi.ubi_num);
1756 c->vi.vol_id);
1757 1757
1758 /* 1758 /*
1759 * The following asserts are only valid if there has not been a failure 1759 * The following asserts are only valid if there has not been a failure
@@ -1809,7 +1809,7 @@ static void ubifs_put_super(struct super_block *sb)
1809 * next mount, so we just print a message and 1809 * next mount, so we just print a message and
1810 * continue to unmount normally. 1810 * continue to unmount normally.
1811 */ 1811 */
1812 ubifs_err("failed to write master node, error %d", 1812 ubifs_err(c, "failed to write master node, error %d",
1813 err); 1813 err);
1814 } else { 1814 } else {
1815 for (i = 0; i < c->jhead_cnt; i++) 1815 for (i = 0; i < c->jhead_cnt; i++)
@@ -1834,17 +1834,17 @@ static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data)
1834 1834
1835 err = ubifs_parse_options(c, data, 1); 1835 err = ubifs_parse_options(c, data, 1);
1836 if (err) { 1836 if (err) {
1837 ubifs_err("invalid or unknown remount parameter"); 1837 ubifs_err(c, "invalid or unknown remount parameter");
1838 return err; 1838 return err;
1839 } 1839 }
1840 1840
1841 if (c->ro_mount && !(*flags & MS_RDONLY)) { 1841 if (c->ro_mount && !(*flags & MS_RDONLY)) {
1842 if (c->ro_error) { 1842 if (c->ro_error) {
1843 ubifs_msg("cannot re-mount R/W due to prior errors"); 1843 ubifs_msg(c, "cannot re-mount R/W due to prior errors");
1844 return -EROFS; 1844 return -EROFS;
1845 } 1845 }
1846 if (c->ro_media) { 1846 if (c->ro_media) {
1847 ubifs_msg("cannot re-mount R/W - UBI volume is R/O"); 1847 ubifs_msg(c, "cannot re-mount R/W - UBI volume is R/O");
1848 return -EROFS; 1848 return -EROFS;
1849 } 1849 }
1850 err = ubifs_remount_rw(c); 1850 err = ubifs_remount_rw(c);
@@ -1852,7 +1852,7 @@ static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data)
1852 return err; 1852 return err;
1853 } else if (!c->ro_mount && (*flags & MS_RDONLY)) { 1853 } else if (!c->ro_mount && (*flags & MS_RDONLY)) {
1854 if (c->ro_error) { 1854 if (c->ro_error) {
1855 ubifs_msg("cannot re-mount R/O due to prior errors"); 1855 ubifs_msg(c, "cannot re-mount R/O due to prior errors");
1856 return -EROFS; 1856 return -EROFS;
1857 } 1857 }
1858 ubifs_remount_ro(c); 1858 ubifs_remount_ro(c);
@@ -2104,8 +2104,8 @@ static struct dentry *ubifs_mount(struct file_system_type *fs_type, int flags,
2104 */ 2104 */
2105 ubi = open_ubi(name, UBI_READONLY); 2105 ubi = open_ubi(name, UBI_READONLY);
2106 if (IS_ERR(ubi)) { 2106 if (IS_ERR(ubi)) {
2107 ubifs_err("cannot open \"%s\", error %d", 2107 pr_err("UBIFS error (pid: %d): cannot open \"%s\", error %d",
2108 name, (int)PTR_ERR(ubi)); 2108 current->pid, name, (int)PTR_ERR(ubi));
2109 return ERR_CAST(ubi); 2109 return ERR_CAST(ubi);
2110 } 2110 }
2111 2111
@@ -2233,8 +2233,8 @@ static int __init ubifs_init(void)
2233 * UBIFS_BLOCK_SIZE. It is assumed that both are powers of 2. 2233 * UBIFS_BLOCK_SIZE. It is assumed that both are powers of 2.
2234 */ 2234 */
2235 if (PAGE_CACHE_SIZE < UBIFS_BLOCK_SIZE) { 2235 if (PAGE_CACHE_SIZE < UBIFS_BLOCK_SIZE) {
2236 ubifs_err("VFS page cache size is %u bytes, but UBIFS requires at least 4096 bytes", 2236 pr_err("UBIFS error (pid %d): VFS page cache size is %u bytes, but UBIFS requires at least 4096 bytes",
2237 (unsigned int)PAGE_CACHE_SIZE); 2237 current->pid, (unsigned int)PAGE_CACHE_SIZE);
2238 return -EINVAL; 2238 return -EINVAL;
2239 } 2239 }
2240 2240
@@ -2257,7 +2257,8 @@ static int __init ubifs_init(void)
2257 2257
2258 err = register_filesystem(&ubifs_fs_type); 2258 err = register_filesystem(&ubifs_fs_type);
2259 if (err) { 2259 if (err) {
2260 ubifs_err("cannot register file system, error %d", err); 2260 pr_err("UBIFS error (pid %d): cannot register file system, error %d",
2261 current->pid, err);
2261 goto out_dbg; 2262 goto out_dbg;
2262 } 2263 }
2263 return 0; 2264 return 0;
diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c
index 6793db0754f6..957f5757f374 100644
--- a/fs/ubifs/tnc.c
+++ b/fs/ubifs/tnc.c
@@ -98,7 +98,7 @@ static int insert_old_idx(struct ubifs_info *c, int lnum, int offs)
98 else if (offs > o->offs) 98 else if (offs > o->offs)
99 p = &(*p)->rb_right; 99 p = &(*p)->rb_right;
100 else { 100 else {
101 ubifs_err("old idx added twice!"); 101 ubifs_err(c, "old idx added twice!");
102 kfree(old_idx); 102 kfree(old_idx);
103 return 0; 103 return 0;
104 } 104 }
@@ -447,7 +447,7 @@ static int try_read_node(const struct ubifs_info *c, void *buf, int type,
447 447
448 err = ubifs_leb_read(c, lnum, buf, offs, len, 1); 448 err = ubifs_leb_read(c, lnum, buf, offs, len, 1);
449 if (err) { 449 if (err) {
450 ubifs_err("cannot read node type %d from LEB %d:%d, error %d", 450 ubifs_err(c, "cannot read node type %d from LEB %d:%d, error %d",
451 type, lnum, offs, err); 451 type, lnum, offs, err);
452 return err; 452 return err;
453 } 453 }
@@ -1684,27 +1684,27 @@ static int validate_data_node(struct ubifs_info *c, void *buf,
1684 int err, len; 1684 int err, len;
1685 1685
1686 if (ch->node_type != UBIFS_DATA_NODE) { 1686 if (ch->node_type != UBIFS_DATA_NODE) {
1687 ubifs_err("bad node type (%d but expected %d)", 1687 ubifs_err(c, "bad node type (%d but expected %d)",
1688 ch->node_type, UBIFS_DATA_NODE); 1688 ch->node_type, UBIFS_DATA_NODE);
1689 goto out_err; 1689 goto out_err;
1690 } 1690 }
1691 1691
1692 err = ubifs_check_node(c, buf, zbr->lnum, zbr->offs, 0, 0); 1692 err = ubifs_check_node(c, buf, zbr->lnum, zbr->offs, 0, 0);
1693 if (err) { 1693 if (err) {
1694 ubifs_err("expected node type %d", UBIFS_DATA_NODE); 1694 ubifs_err(c, "expected node type %d", UBIFS_DATA_NODE);
1695 goto out; 1695 goto out;
1696 } 1696 }
1697 1697
1698 len = le32_to_cpu(ch->len); 1698 len = le32_to_cpu(ch->len);
1699 if (len != zbr->len) { 1699 if (len != zbr->len) {
1700 ubifs_err("bad node length %d, expected %d", len, zbr->len); 1700 ubifs_err(c, "bad node length %d, expected %d", len, zbr->len);
1701 goto out_err; 1701 goto out_err;
1702 } 1702 }
1703 1703
1704 /* Make sure the key of the read node is correct */ 1704 /* Make sure the key of the read node is correct */
1705 key_read(c, buf + UBIFS_KEY_OFFSET, &key1); 1705 key_read(c, buf + UBIFS_KEY_OFFSET, &key1);
1706 if (!keys_eq(c, &zbr->key, &key1)) { 1706 if (!keys_eq(c, &zbr->key, &key1)) {
1707 ubifs_err("bad key in node at LEB %d:%d", 1707 ubifs_err(c, "bad key in node at LEB %d:%d",
1708 zbr->lnum, zbr->offs); 1708 zbr->lnum, zbr->offs);
1709 dbg_tnck(&zbr->key, "looked for key "); 1709 dbg_tnck(&zbr->key, "looked for key ");
1710 dbg_tnck(&key1, "found node's key "); 1710 dbg_tnck(&key1, "found node's key ");
@@ -1716,7 +1716,7 @@ static int validate_data_node(struct ubifs_info *c, void *buf,
1716out_err: 1716out_err:
1717 err = -EINVAL; 1717 err = -EINVAL;
1718out: 1718out:
1719 ubifs_err("bad node at LEB %d:%d", zbr->lnum, zbr->offs); 1719 ubifs_err(c, "bad node at LEB %d:%d", zbr->lnum, zbr->offs);
1720 ubifs_dump_node(c, buf); 1720 ubifs_dump_node(c, buf);
1721 dump_stack(); 1721 dump_stack();
1722 return err; 1722 return err;
@@ -1741,7 +1741,7 @@ int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu)
1741 len = bu->zbranch[bu->cnt - 1].offs; 1741 len = bu->zbranch[bu->cnt - 1].offs;
1742 len += bu->zbranch[bu->cnt - 1].len - offs; 1742 len += bu->zbranch[bu->cnt - 1].len - offs;
1743 if (len > bu->buf_len) { 1743 if (len > bu->buf_len) {
1744 ubifs_err("buffer too small %d vs %d", bu->buf_len, len); 1744 ubifs_err(c, "buffer too small %d vs %d", bu->buf_len, len);
1745 return -EINVAL; 1745 return -EINVAL;
1746 } 1746 }
1747 1747
@@ -1757,7 +1757,7 @@ int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu)
1757 return -EAGAIN; 1757 return -EAGAIN;
1758 1758
1759 if (err && err != -EBADMSG) { 1759 if (err && err != -EBADMSG) {
1760 ubifs_err("failed to read from LEB %d:%d, error %d", 1760 ubifs_err(c, "failed to read from LEB %d:%d, error %d",
1761 lnum, offs, err); 1761 lnum, offs, err);
1762 dump_stack(); 1762 dump_stack();
1763 dbg_tnck(&bu->key, "key "); 1763 dbg_tnck(&bu->key, "key ");
@@ -3313,7 +3313,7 @@ int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode,
3313 3313
3314out_dump: 3314out_dump:
3315 block = key_block(c, key); 3315 block = key_block(c, key);
3316 ubifs_err("inode %lu has size %lld, but there are data at offset %lld", 3316 ubifs_err(c, "inode %lu has size %lld, but there are data at offset %lld",
3317 (unsigned long)inode->i_ino, size, 3317 (unsigned long)inode->i_ino, size,
3318 ((loff_t)block) << UBIFS_BLOCK_SHIFT); 3318 ((loff_t)block) << UBIFS_BLOCK_SHIFT);
3319 mutex_unlock(&c->tnc_mutex); 3319 mutex_unlock(&c->tnc_mutex);
diff --git a/fs/ubifs/tnc_commit.c b/fs/ubifs/tnc_commit.c
index 7a205e046776..b45345d701e7 100644
--- a/fs/ubifs/tnc_commit.c
+++ b/fs/ubifs/tnc_commit.c
@@ -53,7 +53,7 @@ static int make_idx_node(struct ubifs_info *c, struct ubifs_idx_node *idx,
53 br->offs = cpu_to_le32(zbr->offs); 53 br->offs = cpu_to_le32(zbr->offs);
54 br->len = cpu_to_le32(zbr->len); 54 br->len = cpu_to_le32(zbr->len);
55 if (!zbr->lnum || !zbr->len) { 55 if (!zbr->lnum || !zbr->len) {
56 ubifs_err("bad ref in znode"); 56 ubifs_err(c, "bad ref in znode");
57 ubifs_dump_znode(c, znode); 57 ubifs_dump_znode(c, znode);
58 if (zbr->znode) 58 if (zbr->znode)
59 ubifs_dump_znode(c, zbr->znode); 59 ubifs_dump_znode(c, zbr->znode);
@@ -384,7 +384,7 @@ static int layout_in_gaps(struct ubifs_info *c, int cnt)
384 * Do not print scary warnings if the debugging 384 * Do not print scary warnings if the debugging
385 * option which forces in-the-gaps is enabled. 385 * option which forces in-the-gaps is enabled.
386 */ 386 */
387 ubifs_warn("out of space"); 387 ubifs_warn(c, "out of space");
388 ubifs_dump_budg(c, &c->bi); 388 ubifs_dump_budg(c, &c->bi);
389 ubifs_dump_lprops(c); 389 ubifs_dump_lprops(c);
390 } 390 }
@@ -441,7 +441,7 @@ static int layout_in_empty_space(struct ubifs_info *c)
441 /* Determine the index node position */ 441 /* Determine the index node position */
442 if (lnum == -1) { 442 if (lnum == -1) {
443 if (c->ileb_nxt >= c->ileb_cnt) { 443 if (c->ileb_nxt >= c->ileb_cnt) {
444 ubifs_err("out of space"); 444 ubifs_err(c, "out of space");
445 return -ENOSPC; 445 return -ENOSPC;
446 } 446 }
447 lnum = c->ilebs[c->ileb_nxt++]; 447 lnum = c->ilebs[c->ileb_nxt++];
@@ -855,7 +855,7 @@ static int write_index(struct ubifs_info *c)
855 br->offs = cpu_to_le32(zbr->offs); 855 br->offs = cpu_to_le32(zbr->offs);
856 br->len = cpu_to_le32(zbr->len); 856 br->len = cpu_to_le32(zbr->len);
857 if (!zbr->lnum || !zbr->len) { 857 if (!zbr->lnum || !zbr->len) {
858 ubifs_err("bad ref in znode"); 858 ubifs_err(c, "bad ref in znode");
859 ubifs_dump_znode(c, znode); 859 ubifs_dump_znode(c, znode);
860 if (zbr->znode) 860 if (zbr->znode)
861 ubifs_dump_znode(c, zbr->znode); 861 ubifs_dump_znode(c, zbr->znode);
@@ -875,7 +875,7 @@ static int write_index(struct ubifs_info *c)
875 875
876 if (lnum != znode->lnum || offs != znode->offs || 876 if (lnum != znode->lnum || offs != znode->offs ||
877 len != znode->len) { 877 len != znode->len) {
878 ubifs_err("inconsistent znode posn"); 878 ubifs_err(c, "inconsistent znode posn");
879 return -EINVAL; 879 return -EINVAL;
880 } 880 }
881 881
@@ -973,7 +973,7 @@ static int write_index(struct ubifs_info *c)
973 973
974 if (lnum != c->dbg->new_ihead_lnum || 974 if (lnum != c->dbg->new_ihead_lnum ||
975 buf_offs != c->dbg->new_ihead_offs) { 975 buf_offs != c->dbg->new_ihead_offs) {
976 ubifs_err("inconsistent ihead"); 976 ubifs_err(c, "inconsistent ihead");
977 return -EINVAL; 977 return -EINVAL;
978 } 978 }
979 979
diff --git a/fs/ubifs/tnc_misc.c b/fs/ubifs/tnc_misc.c
index f6bf8995c7b1..93f5b7859e6f 100644
--- a/fs/ubifs/tnc_misc.c
+++ b/fs/ubifs/tnc_misc.c
@@ -293,9 +293,9 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len,
293 lnum, offs, znode->level, znode->child_cnt); 293 lnum, offs, znode->level, znode->child_cnt);
294 294
295 if (znode->child_cnt > c->fanout || znode->level > UBIFS_MAX_LEVELS) { 295 if (znode->child_cnt > c->fanout || znode->level > UBIFS_MAX_LEVELS) {
296 ubifs_err("current fanout %d, branch count %d", 296 ubifs_err(c, "current fanout %d, branch count %d",
297 c->fanout, znode->child_cnt); 297 c->fanout, znode->child_cnt);
298 ubifs_err("max levels %d, znode level %d", 298 ubifs_err(c, "max levels %d, znode level %d",
299 UBIFS_MAX_LEVELS, znode->level); 299 UBIFS_MAX_LEVELS, znode->level);
300 err = 1; 300 err = 1;
301 goto out_dump; 301 goto out_dump;
@@ -316,7 +316,7 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len,
316 if (zbr->lnum < c->main_first || 316 if (zbr->lnum < c->main_first ||
317 zbr->lnum >= c->leb_cnt || zbr->offs < 0 || 317 zbr->lnum >= c->leb_cnt || zbr->offs < 0 ||
318 zbr->offs + zbr->len > c->leb_size || zbr->offs & 7) { 318 zbr->offs + zbr->len > c->leb_size || zbr->offs & 7) {
319 ubifs_err("bad branch %d", i); 319 ubifs_err(c, "bad branch %d", i);
320 err = 2; 320 err = 2;
321 goto out_dump; 321 goto out_dump;
322 } 322 }
@@ -328,7 +328,7 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len,
328 case UBIFS_XENT_KEY: 328 case UBIFS_XENT_KEY:
329 break; 329 break;
330 default: 330 default:
331 ubifs_err("bad key type at slot %d: %d", 331 ubifs_err(c, "bad key type at slot %d: %d",
332 i, key_type(c, &zbr->key)); 332 i, key_type(c, &zbr->key));
333 err = 3; 333 err = 3;
334 goto out_dump; 334 goto out_dump;
@@ -340,17 +340,17 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len,
340 type = key_type(c, &zbr->key); 340 type = key_type(c, &zbr->key);
341 if (c->ranges[type].max_len == 0) { 341 if (c->ranges[type].max_len == 0) {
342 if (zbr->len != c->ranges[type].len) { 342 if (zbr->len != c->ranges[type].len) {
343 ubifs_err("bad target node (type %d) length (%d)", 343 ubifs_err(c, "bad target node (type %d) length (%d)",
344 type, zbr->len); 344 type, zbr->len);
345 ubifs_err("have to be %d", c->ranges[type].len); 345 ubifs_err(c, "have to be %d", c->ranges[type].len);
346 err = 4; 346 err = 4;
347 goto out_dump; 347 goto out_dump;
348 } 348 }
349 } else if (zbr->len < c->ranges[type].min_len || 349 } else if (zbr->len < c->ranges[type].min_len ||
350 zbr->len > c->ranges[type].max_len) { 350 zbr->len > c->ranges[type].max_len) {
351 ubifs_err("bad target node (type %d) length (%d)", 351 ubifs_err(c, "bad target node (type %d) length (%d)",
352 type, zbr->len); 352 type, zbr->len);
353 ubifs_err("have to be in range of %d-%d", 353 ubifs_err(c, "have to be in range of %d-%d",
354 c->ranges[type].min_len, 354 c->ranges[type].min_len,
355 c->ranges[type].max_len); 355 c->ranges[type].max_len);
356 err = 5; 356 err = 5;
@@ -370,12 +370,12 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len,
370 370
371 cmp = keys_cmp(c, key1, key2); 371 cmp = keys_cmp(c, key1, key2);
372 if (cmp > 0) { 372 if (cmp > 0) {
373 ubifs_err("bad key order (keys %d and %d)", i, i + 1); 373 ubifs_err(c, "bad key order (keys %d and %d)", i, i + 1);
374 err = 6; 374 err = 6;
375 goto out_dump; 375 goto out_dump;
376 } else if (cmp == 0 && !is_hash_key(c, key1)) { 376 } else if (cmp == 0 && !is_hash_key(c, key1)) {
377 /* These can only be keys with colliding hash */ 377 /* These can only be keys with colliding hash */
378 ubifs_err("keys %d and %d are not hashed but equivalent", 378 ubifs_err(c, "keys %d and %d are not hashed but equivalent",
379 i, i + 1); 379 i, i + 1);
380 err = 7; 380 err = 7;
381 goto out_dump; 381 goto out_dump;
@@ -386,7 +386,7 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len,
386 return 0; 386 return 0;
387 387
388out_dump: 388out_dump:
389 ubifs_err("bad indexing node at LEB %d:%d, error %d", lnum, offs, err); 389 ubifs_err(c, "bad indexing node at LEB %d:%d, error %d", lnum, offs, err);
390 ubifs_dump_node(c, idx); 390 ubifs_dump_node(c, idx);
391 kfree(idx); 391 kfree(idx);
392 return -EINVAL; 392 return -EINVAL;
@@ -482,7 +482,7 @@ int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr,
482 /* Make sure the key of the read node is correct */ 482 /* Make sure the key of the read node is correct */
483 key_read(c, node + UBIFS_KEY_OFFSET, &key1); 483 key_read(c, node + UBIFS_KEY_OFFSET, &key1);
484 if (!keys_eq(c, key, &key1)) { 484 if (!keys_eq(c, key, &key1)) {
485 ubifs_err("bad key in node at LEB %d:%d", 485 ubifs_err(c, "bad key in node at LEB %d:%d",
486 zbr->lnum, zbr->offs); 486 zbr->lnum, zbr->offs);
487 dbg_tnck(key, "looked for key "); 487 dbg_tnck(key, "looked for key ");
488 dbg_tnck(&key1, "but found node's key "); 488 dbg_tnck(&key1, "but found node's key ");
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index bc04b9c69891..de759022f3d6 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -43,15 +43,19 @@
43#define UBIFS_VERSION 1 43#define UBIFS_VERSION 1
44 44
45/* Normal UBIFS messages */ 45/* Normal UBIFS messages */
46#define ubifs_msg(fmt, ...) pr_notice("UBIFS: " fmt "\n", ##__VA_ARGS__) 46#define ubifs_msg(c, fmt, ...) \
47 pr_notice("UBIFS (ubi%d:%d): " fmt "\n", \
48 (c)->vi.ubi_num, (c)->vi.vol_id, ##__VA_ARGS__)
47/* UBIFS error messages */ 49/* UBIFS error messages */
48#define ubifs_err(fmt, ...) \ 50#define ubifs_err(c, fmt, ...) \
49 pr_err("UBIFS error (pid %d): %s: " fmt "\n", current->pid, \ 51 pr_err("UBIFS error (ubi%d:%d pid %d): %s: " fmt "\n", \
52 (c)->vi.ubi_num, (c)->vi.vol_id, current->pid, \
50 __func__, ##__VA_ARGS__) 53 __func__, ##__VA_ARGS__)
51/* UBIFS warning messages */ 54/* UBIFS warning messages */
52#define ubifs_warn(fmt, ...) \ 55#define ubifs_warn(c, fmt, ...) \
53 pr_warn("UBIFS warning (pid %d): %s: " fmt "\n", \ 56 pr_warn("UBIFS warning (ubi%d:%d pid %d): %s: " fmt "\n", \
54 current->pid, __func__, ##__VA_ARGS__) 57 (c)->vi.ubi_num, (c)->vi.vol_id, current->pid, \
58 __func__, ##__VA_ARGS__)
55/* 59/*
56 * A variant of 'ubifs_err()' which takes the UBIFS file-sytem description 60 * A variant of 'ubifs_err()' which takes the UBIFS file-sytem description
57 * object as an argument. 61 * object as an argument.
@@ -59,7 +63,7 @@
59#define ubifs_errc(c, fmt, ...) \ 63#define ubifs_errc(c, fmt, ...) \
60 do { \ 64 do { \
61 if (!(c)->probing) \ 65 if (!(c)->probing) \
62 ubifs_err(fmt, ##__VA_ARGS__); \ 66 ubifs_err(c, fmt, ##__VA_ARGS__); \
63 } while (0) 67 } while (0)
64 68
65/* UBIFS file system VFS magic number */ 69/* UBIFS file system VFS magic number */
@@ -158,7 +162,7 @@
158#define WORST_COMPR_FACTOR 2 162#define WORST_COMPR_FACTOR 2
159 163
160/* 164/*
161 * How much memory is needed for a buffer where we comress a data node. 165 * How much memory is needed for a buffer where we compress a data node.
162 */ 166 */
163#define COMPRESSED_DATA_NODE_BUF_SZ \ 167#define COMPRESSED_DATA_NODE_BUF_SZ \
164 (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR) 168 (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR)
@@ -664,7 +668,7 @@ typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,
664 * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes 668 * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes
665 * fields 669 * fields
666 * @softlimit: soft write-buffer timeout interval 670 * @softlimit: soft write-buffer timeout interval
667 * @delta: hard and soft timeouts delta (the timer expire inteval is @softlimit 671 * @delta: hard and soft timeouts delta (the timer expire interval is @softlimit
668 * and @softlimit + @delta) 672 * and @softlimit + @delta)
669 * @timer: write-buffer timer 673 * @timer: write-buffer timer
670 * @no_timer: non-zero if this write-buffer does not have a timer 674 * @no_timer: non-zero if this write-buffer does not have a timer
@@ -930,9 +934,9 @@ struct ubifs_orphan {
930/** 934/**
931 * struct ubifs_mount_opts - UBIFS-specific mount options information. 935 * struct ubifs_mount_opts - UBIFS-specific mount options information.
932 * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast) 936 * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast)
933 * @bulk_read: enable/disable bulk-reads (%0 default, %1 disabe, %2 enable) 937 * @bulk_read: enable/disable bulk-reads (%0 default, %1 disable, %2 enable)
934 * @chk_data_crc: enable/disable CRC data checking when reading data nodes 938 * @chk_data_crc: enable/disable CRC data checking when reading data nodes
935 * (%0 default, %1 disabe, %2 enable) 939 * (%0 default, %1 disable, %2 enable)
936 * @override_compr: override default compressor (%0 - do not override and use 940 * @override_compr: override default compressor (%0 - do not override and use
937 * superblock compressor, %1 - override and use compressor 941 * superblock compressor, %1 - override and use compressor
938 * specified in @compr_type) 942 * specified in @compr_type)
@@ -962,9 +966,9 @@ struct ubifs_mount_opts {
962 * optimization) 966 * optimization)
963 * @nospace_rp: the same as @nospace, but additionally means that even reserved 967 * @nospace_rp: the same as @nospace, but additionally means that even reserved
964 * pool is full 968 * pool is full
965 * @page_budget: budget for a page (constant, nenver changed after mount) 969 * @page_budget: budget for a page (constant, never changed after mount)
966 * @inode_budget: budget for an inode (constant, nenver changed after mount) 970 * @inode_budget: budget for an inode (constant, never changed after mount)
967 * @dent_budget: budget for a directory entry (constant, nenver changed after 971 * @dent_budget: budget for a directory entry (constant, never changed after
968 * mount) 972 * mount)
969 */ 973 */
970struct ubifs_budg_info { 974struct ubifs_budg_info {
@@ -1787,10 +1791,10 @@ long ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1787/* compressor.c */ 1791/* compressor.c */
1788int __init ubifs_compressors_init(void); 1792int __init ubifs_compressors_init(void);
1789void ubifs_compressors_exit(void); 1793void ubifs_compressors_exit(void);
1790void ubifs_compress(const void *in_buf, int in_len, void *out_buf, int *out_len, 1794void ubifs_compress(const struct ubifs_info *c, const void *in_buf, int in_len,
1791 int *compr_type); 1795 void *out_buf, int *out_len, int *compr_type);
1792int ubifs_decompress(const void *buf, int len, void *out, int *out_len, 1796int ubifs_decompress(const struct ubifs_info *c, const void *buf, int len,
1793 int compr_type); 1797 void *out, int *out_len, int compr_type);
1794 1798
1795#include "debug.h" 1799#include "debug.h"
1796#include "misc.h" 1800#include "misc.h"
diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c
index a92be244a6fb..3659b1934500 100644
--- a/fs/ubifs/xattr.c
+++ b/fs/ubifs/xattr.c
@@ -108,7 +108,7 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
108 .dirtied_ino_d = ALIGN(host_ui->data_len, 8) }; 108 .dirtied_ino_d = ALIGN(host_ui->data_len, 8) };
109 109
110 if (host_ui->xattr_cnt >= MAX_XATTRS_PER_INODE) { 110 if (host_ui->xattr_cnt >= MAX_XATTRS_PER_INODE) {
111 ubifs_err("inode %lu already has too many xattrs (%d), cannot create more", 111 ubifs_err(c, "inode %lu already has too many xattrs (%d), cannot create more",
112 host->i_ino, host_ui->xattr_cnt); 112 host->i_ino, host_ui->xattr_cnt);
113 return -ENOSPC; 113 return -ENOSPC;
114 } 114 }
@@ -120,7 +120,7 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
120 */ 120 */
121 names_len = host_ui->xattr_names + host_ui->xattr_cnt + nm->len + 1; 121 names_len = host_ui->xattr_names + host_ui->xattr_cnt + nm->len + 1;
122 if (names_len > XATTR_LIST_MAX) { 122 if (names_len > XATTR_LIST_MAX) {
123 ubifs_err("cannot add one more xattr name to inode %lu, total names length would become %d, max. is %d", 123 ubifs_err(c, "cannot add one more xattr name to inode %lu, total names length would become %d, max. is %d",
124 host->i_ino, names_len, XATTR_LIST_MAX); 124 host->i_ino, names_len, XATTR_LIST_MAX);
125 return -ENOSPC; 125 return -ENOSPC;
126 } 126 }
@@ -288,13 +288,13 @@ static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum)
288 288
289 inode = ubifs_iget(c->vfs_sb, inum); 289 inode = ubifs_iget(c->vfs_sb, inum);
290 if (IS_ERR(inode)) { 290 if (IS_ERR(inode)) {
291 ubifs_err("dead extended attribute entry, error %d", 291 ubifs_err(c, "dead extended attribute entry, error %d",
292 (int)PTR_ERR(inode)); 292 (int)PTR_ERR(inode));
293 return inode; 293 return inode;
294 } 294 }
295 if (ubifs_inode(inode)->xattr) 295 if (ubifs_inode(inode)->xattr)
296 return inode; 296 return inode;
297 ubifs_err("corrupt extended attribute entry"); 297 ubifs_err(c, "corrupt extended attribute entry");
298 iput(inode); 298 iput(inode);
299 return ERR_PTR(-EINVAL); 299 return ERR_PTR(-EINVAL);
300} 300}
@@ -412,7 +412,7 @@ ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf,
412 if (buf) { 412 if (buf) {
413 /* If @buf is %NULL we are supposed to return the length */ 413 /* If @buf is %NULL we are supposed to return the length */
414 if (ui->data_len > size) { 414 if (ui->data_len > size) {
415 ubifs_err("buffer size %zd, xattr len %d", 415 ubifs_err(c, "buffer size %zd, xattr len %d",
416 size, ui->data_len); 416 size, ui->data_len);
417 err = -ERANGE; 417 err = -ERANGE;
418 goto out_iput; 418 goto out_iput;
@@ -485,7 +485,7 @@ ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size)
485 485
486 kfree(pxent); 486 kfree(pxent);
487 if (err != -ENOENT) { 487 if (err != -ENOENT) {
488 ubifs_err("cannot find next direntry, error %d", err); 488 ubifs_err(c, "cannot find next direntry, error %d", err);
489 return err; 489 return err;
490 } 490 }
491 491
@@ -657,8 +657,10 @@ int ubifs_init_security(struct inode *dentry, struct inode *inode,
657 &init_xattrs, 0); 657 &init_xattrs, 0);
658 mutex_unlock(&inode->i_mutex); 658 mutex_unlock(&inode->i_mutex);
659 659
660 if (err) 660 if (err) {
661 ubifs_err("cannot initialize security for inode %lu, error %d", 661 struct ubifs_info *c = dentry->i_sb->s_fs_info;
662 ubifs_err(c, "cannot initialize security for inode %lu, error %d",
662 inode->i_ino, err); 663 inode->i_ino, err);
664 }
663 return err; 665 return err;
664} 666}