aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/wl.c
diff options
context:
space:
mode:
authorJoel Reardon <joel@clambassador.com>2012-05-20 15:27:11 -0400
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-05-21 04:34:41 -0400
commit62f384552b6756cf1ea71f8762d1e97dc77dbd90 (patch)
tree6ebd89f4f18eca1724e8a50b8fc6cdefc29de18a /drivers/mtd/ubi/wl.c
parent05a3cb7dcec5a15ed9b18a5317ba2075355c7547 (diff)
UBI: modify ubi_wl_flush function to clear work queue for a lnum
This patch modifies ubi_wl_flush to force the erasure of particular volume id / logical eraseblock number pairs. Previous functionality is preserved when passing UBI_ALL for both values. The locations where ubi_wl_flush were called are appropriately changed: ubi_leb_erase only flushes for the erased LEB, and ubi_create_volume forces only flushing for its volume id. External code can call this new feature via the new function ubi_flush() added to kapi.c, which simply passes through to ubi_wl_flush(). This was tested by disabling the call to do_work in ubi thread, which results in the work queue remaining unless explicitly called to remove. UBIFS was changed to call ubifs_leb_change 50 times for four different LEBs. Then the new function was called to clear the queue: passing wrong volume ids / lnum, correct ones, and finally UBI_ALL for both to ensure it was finally all cleard. The work queue was dumped each time and the selective removal of the particular LEB numbers was observed. Extra checks were enabled and ubifs's integck was also run. Finally, the drive was repeatedly filled and emptied to ensure that the queue was cleared normally. Artem: amended the patch. Signed-off-by: Joel Reardon <reardonj@inf.ethz.ch> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'drivers/mtd/ubi/wl.c')
-rw-r--r--drivers/mtd/ubi/wl.c61
1 files changed, 36 insertions, 25 deletions
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 70ebfa7bc384..9df100a4ec38 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1241,44 +1241,55 @@ retry:
1241/** 1241/**
1242 * ubi_wl_flush - flush all pending works. 1242 * ubi_wl_flush - flush all pending works.
1243 * @ubi: UBI device description object 1243 * @ubi: UBI device description object
1244 * @vol_id: the volume id to flush for
1245 * @lnum: the logical eraseblock number to flush for
1244 * 1246 *
1245 * This function returns zero in case of success and a negative error code in 1247 * This function executes all pending works for a particular volume id /
1246 * case of failure. 1248 * logical eraseblock number pair. If either value is set to %UBI_ALL, then it
1249 * acts as a wildcard for all of the corresponding volume numbers or logical
1250 * eraseblock numbers. It returns zero in case of success and a negative error
1251 * code in case of failure.
1247 */ 1252 */
1248int ubi_wl_flush(struct ubi_device *ubi) 1253int ubi_wl_flush(struct ubi_device *ubi, int vol_id, int lnum)
1249{ 1254{
1250 int err; 1255 int err = 0;
1256 int found = 1;
1251 1257
1252 /* 1258 /*
1253 * Erase while the pending works queue is not empty, but not more than 1259 * Erase while the pending works queue is not empty, but not more than
1254 * the number of currently pending works. 1260 * the number of currently pending works.
1255 */ 1261 */
1256 dbg_wl("flush (%d pending works)", ubi->works_count); 1262 dbg_wl("flush pending work for LEB %d:%d (%d pending works)",
1257 while (ubi->works_count) { 1263 vol_id, lnum, ubi->works_count);
1258 err = do_work(ubi);
1259 if (err)
1260 return err;
1261 }
1262 1264
1263 /*
1264 * Make sure all the works which have been done in parallel are
1265 * finished.
1266 */
1267 down_write(&ubi->work_sem); 1265 down_write(&ubi->work_sem);
1268 up_write(&ubi->work_sem); 1266 while (found) {
1267 struct ubi_work *wrk;
1268 found = 0;
1269 1269
1270 /* 1270 spin_lock(&ubi->wl_lock);
1271 * And in case last was the WL worker and it canceled the LEB 1271 list_for_each_entry(wrk, &ubi->works, list) {
1272 * movement, flush again. 1272 if ((vol_id == UBI_ALL || wrk->vol_id == vol_id) &&
1273 */ 1273 (lnum == UBI_ALL || wrk->lnum == lnum)) {
1274 while (ubi->works_count) { 1274 list_del(&wrk->list);
1275 dbg_wl("flush more (%d pending works)", ubi->works_count); 1275 ubi->works_count -= 1;
1276 err = do_work(ubi); 1276 ubi_assert(ubi->works_count >= 0);
1277 if (err) 1277 spin_unlock(&ubi->wl_lock);
1278 return err; 1278
1279 err = wrk->func(ubi, wrk, 0);
1280 if (err)
1281 goto out;
1282 spin_lock(&ubi->wl_lock);
1283 found = 1;
1284 break;
1285 }
1286 }
1287 spin_unlock(&ubi->wl_lock);
1279 } 1288 }
1280 1289
1281 return 0; 1290out:
1291 up_write(&ubi->work_sem);
1292 return err;
1282} 1293}
1283 1294
1284/** 1295/**