Skip to content

Commit 62f3845

Browse files
Joel Reardondedekind
authored andcommitted
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>
1 parent 05a3cb7 commit 62f3845

7 files changed

Lines changed: 70 additions & 31 deletions

File tree

‎drivers/mtd/ubi/cdev.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
514514
if (err)
515515
break;
516516

517-
err = ubi_wl_flush(ubi);
517+
err = ubi_wl_flush(ubi, UBI_ALL, UBI_ALL);
518518
break;
519519
}
520520

‎drivers/mtd/ubi/kapi.c‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum)
551551
if (err)
552552
return err;
553553

554-
return ubi_wl_flush(ubi);
554+
return ubi_wl_flush(ubi, vol->vol_id, lnum);
555555
}
556556
EXPORT_SYMBOL_GPL(ubi_leb_erase);
557557

@@ -704,6 +704,33 @@ int ubi_sync(int ubi_num)
704704
}
705705
EXPORT_SYMBOL_GPL(ubi_sync);
706706

707+
/**
708+
* ubi_flush - flush UBI work queue.
709+
* @ubi_num: UBI device to flush work queue
710+
* @vol_id: volume id to flush for
711+
* @lnum: logical eraseblock number to flush for
712+
*
713+
* This function executes all pending works for a particular volume id / logical
714+
* eraseblock number pair. If either value is set to %UBI_ALL, then it acts as
715+
* a wildcard for all of the corresponding volume numbers or logical
716+
* eraseblock numbers. It returns zero in case of success and a negative error
717+
* code in case of failure.
718+
*/
719+
int ubi_flush(int ubi_num, int vol_id, int lnum)
720+
{
721+
struct ubi_device *ubi;
722+
int err = 0;
723+
724+
ubi = ubi_get_device(ubi_num);
725+
if (!ubi)
726+
return -ENODEV;
727+
728+
err = ubi_wl_flush(ubi, vol_id, lnum);
729+
ubi_put_device(ubi);
730+
return err;
731+
}
732+
EXPORT_SYMBOL_GPL(ubi_flush);
733+
707734
BLOCKING_NOTIFIER_HEAD(ubi_notifiers);
708735

709736
/**

‎drivers/mtd/ubi/ubi.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ int ubi_eba_init(struct ubi_device *ubi, struct ubi_attach_info *ai);
669669
int ubi_wl_get_peb(struct ubi_device *ubi);
670670
int ubi_wl_put_peb(struct ubi_device *ubi, int vol_id, int lnum,
671671
int pnum, int torture);
672-
int ubi_wl_flush(struct ubi_device *ubi);
672+
int ubi_wl_flush(struct ubi_device *ubi, int vol_id, int lnum);
673673
int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum);
674674
int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai);
675675
void ubi_wl_close(struct ubi_device *ubi);

‎drivers/mtd/ubi/upd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
147147
}
148148

149149
if (bytes == 0) {
150-
err = ubi_wl_flush(ubi);
150+
err = ubi_wl_flush(ubi, UBI_ALL, UBI_ALL);
151151
if (err)
152152
return err;
153153

@@ -361,7 +361,7 @@ int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol,
361361

362362
ubi_assert(vol->upd_received <= vol->upd_bytes);
363363
if (vol->upd_received == vol->upd_bytes) {
364-
err = ubi_wl_flush(ubi);
364+
err = ubi_wl_flush(ubi, UBI_ALL, UBI_ALL);
365365
if (err)
366366
return err;
367367
/* The update is finished, clear the update marker */

‎drivers/mtd/ubi/vmt.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
280280
* Finish all pending erases because there may be some LEBs belonging
281281
* to the same volume ID.
282282
*/
283-
err = ubi_wl_flush(ubi);
283+
err = ubi_wl_flush(ubi, vol_id, UBI_ALL);
284284
if (err)
285285
goto out_acc;
286286

‎drivers/mtd/ubi/wl.c‎

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,44 +1241,55 @@ int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum)
12411241
/**
12421242
* ubi_wl_flush - flush all pending works.
12431243
* @ubi: UBI device description object
1244+
* @vol_id: the volume id to flush for
1245+
* @lnum: the logical eraseblock number to flush for
12441246
*
1245-
* This function returns zero in case of success and a negative error code in
1246-
* case of failure.
1247+
* This function executes all pending works for a particular volume id /
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.
12471252
*/
1248-
int ubi_wl_flush(struct ubi_device *ubi)
1253+
int ubi_wl_flush(struct ubi_device *ubi, int vol_id, int lnum)
12491254
{
1250-
int err;
1255+
int err = 0;
1256+
int found = 1;
12511257

12521258
/*
12531259
* Erase while the pending works queue is not empty, but not more than
12541260
* the number of currently pending works.
12551261
*/
1256-
dbg_wl("flush (%d pending works)", ubi->works_count);
1257-
while (ubi->works_count) {
1258-
err = do_work(ubi);
1259-
if (err)
1260-
return err;
1261-
}
1262+
dbg_wl("flush pending work for LEB %d:%d (%d pending works)",
1263+
vol_id, lnum, ubi->works_count);
12621264

1263-
/*
1264-
* Make sure all the works which have been done in parallel are
1265-
* finished.
1266-
*/
12671265
down_write(&ubi->work_sem);
1268-
up_write(&ubi->work_sem);
1266+
while (found) {
1267+
struct ubi_work *wrk;
1268+
found = 0;
12691269

1270-
/*
1271-
* And in case last was the WL worker and it canceled the LEB
1272-
* movement, flush again.
1273-
*/
1274-
while (ubi->works_count) {
1275-
dbg_wl("flush more (%d pending works)", ubi->works_count);
1276-
err = do_work(ubi);
1277-
if (err)
1278-
return err;
1270+
spin_lock(&ubi->wl_lock);
1271+
list_for_each_entry(wrk, &ubi->works, list) {
1272+
if ((vol_id == UBI_ALL || wrk->vol_id == vol_id) &&
1273+
(lnum == UBI_ALL || wrk->lnum == lnum)) {
1274+
list_del(&wrk->list);
1275+
ubi->works_count -= 1;
1276+
ubi_assert(ubi->works_count >= 0);
1277+
spin_unlock(&ubi->wl_lock);
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);
12791288
}
12801289

1281-
return 0;
1290+
out:
1291+
up_write(&ubi->work_sem);
1292+
return err;
12821293
}
12831294

12841295
/**

‎include/linux/mtd/ubi.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum);
219219
int ubi_leb_map(struct ubi_volume_desc *desc, int lnum);
220220
int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum);
221221
int ubi_sync(int ubi_num);
222+
int ubi_flush(int ubi_num, int vol_id, int lnum);
222223

223224
/*
224225
* This function is the same as the 'ubi_leb_read()' function, but it does not

0 commit comments

Comments
 (0)