Skip to content

Commit 4946784

Browse files
ubi: Make volume resize power cut aware
When the volume resize operation shrinks a volume, LEBs will be unmapped. Since unmapping will not erase these LEBs immediately we have to wait for that operation to finish. Otherwise in case of a power cut right after writing the new volume table the UBI attach process can find more LEBs than the volume table knows. This will render the UBI image unattachable. Fix this issue by waiting for erase to complete and write the new volume table afterward. Cc: <[email protected]> Reported-by: Boris Brezillon <[email protected]> Reviewed-by: Boris Brezillon <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent bc743f3 commit 4946784

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

drivers/mtd/ubi/vmt.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,6 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
488488
spin_unlock(&ubi->volumes_lock);
489489
}
490490

491-
/* Change volume table record */
492-
vtbl_rec = ubi->vtbl[vol_id];
493-
vtbl_rec.reserved_pebs = cpu_to_be32(reserved_pebs);
494-
err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
495-
if (err)
496-
goto out_acc;
497-
498491
if (pebs < 0) {
499492
for (i = 0; i < -pebs; i++) {
500493
err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i);
@@ -512,6 +505,24 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
512505
spin_unlock(&ubi->volumes_lock);
513506
}
514507

508+
/*
509+
* When we shrink a volume we have to flush all pending (erase) work.
510+
* Otherwise it can happen that upon next attach UBI finds a LEB with
511+
* lnum > highest_lnum and refuses to attach.
512+
*/
513+
if (pebs < 0) {
514+
err = ubi_wl_flush(ubi, vol_id, UBI_ALL);
515+
if (err)
516+
goto out_acc;
517+
}
518+
519+
/* Change volume table record */
520+
vtbl_rec = ubi->vtbl[vol_id];
521+
vtbl_rec.reserved_pebs = cpu_to_be32(reserved_pebs);
522+
err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
523+
if (err)
524+
goto out_acc;
525+
515526
vol->reserved_pebs = reserved_pebs;
516527
if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
517528
vol->used_ebs = reserved_pebs;

0 commit comments

Comments
 (0)