wl.c (16217dc79dbc599b110dda26d0421df47904bba4) wl.c (3291b52f9ff0acc80a8ee3f92a960db937dccecb)
1/*
2 * Copyright (c) International Business Machines Corp., 2006
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *

--- 635 unchanged lines hidden (view full) ---

644 int shutdown)
645{
646 int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0;
647 int vol_id = -1, lnum = -1;
648#ifdef CONFIG_MTD_UBI_FASTMAP
649 int anchor = wrk->anchor;
650#endif
651 struct ubi_wl_entry *e1, *e2;
1/*
2 * Copyright (c) International Business Machines Corp., 2006
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *

--- 635 unchanged lines hidden (view full) ---

644 int shutdown)
645{
646 int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0;
647 int vol_id = -1, lnum = -1;
648#ifdef CONFIG_MTD_UBI_FASTMAP
649 int anchor = wrk->anchor;
650#endif
651 struct ubi_wl_entry *e1, *e2;
652 struct ubi_vid_io_buf *vidb;
652 struct ubi_vid_hdr *vid_hdr;
653 int dst_leb_clean = 0;
654
655 kfree(wrk);
656 if (shutdown)
657 return 0;
658
653 struct ubi_vid_hdr *vid_hdr;
654 int dst_leb_clean = 0;
655
656 kfree(wrk);
657 if (shutdown)
658 return 0;
659
659 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
660 if (!vid_hdr)
660 vidb = ubi_alloc_vid_buf(ubi, GFP_NOFS);
661 if (!vidb)
661 return -ENOMEM;
662
662 return -ENOMEM;
663
664 vid_hdr = ubi_get_vid_hdr(vidb);
665
663 mutex_lock(&ubi->move_mutex);
664 spin_lock(&ubi->wl_lock);
665 ubi_assert(!ubi->move_from && !ubi->move_to);
666 ubi_assert(!ubi->move_to_put);
667
668 if (!ubi->free.rb_node ||
669 (!ubi->used.rb_node && !ubi->scrub.rb_node)) {
670 /*

--- 77 unchanged lines hidden (view full) ---

748 * eraseblock (@e1) belongs to. We have to read the volume identifier
749 * header first.
750 *
751 * Note, we are protected from this PEB being unmapped and erased. The
752 * 'ubi_wl_put_peb()' would wait for moving to be finished if the PEB
753 * which is being moved was unmapped.
754 */
755
666 mutex_lock(&ubi->move_mutex);
667 spin_lock(&ubi->wl_lock);
668 ubi_assert(!ubi->move_from && !ubi->move_to);
669 ubi_assert(!ubi->move_to_put);
670
671 if (!ubi->free.rb_node ||
672 (!ubi->used.rb_node && !ubi->scrub.rb_node)) {
673 /*

--- 77 unchanged lines hidden (view full) ---

751 * eraseblock (@e1) belongs to. We have to read the volume identifier
752 * header first.
753 *
754 * Note, we are protected from this PEB being unmapped and erased. The
755 * 'ubi_wl_put_peb()' would wait for moving to be finished if the PEB
756 * which is being moved was unmapped.
757 */
758
756 err = ubi_io_read_vid_hdr(ubi, e1->pnum, vid_hdr, 0);
759 err = ubi_io_read_vid_hdr(ubi, e1->pnum, vidb, 0);
757 if (err && err != UBI_IO_BITFLIPS) {
758 dst_leb_clean = 1;
759 if (err == UBI_IO_FF) {
760 /*
761 * We are trying to move PEB without a VID header. UBI
762 * always write VID headers shortly after the PEB was
763 * given, so we have a situation when it has not yet
764 * had a chance to write it, because it was preempted.

--- 20 unchanged lines hidden (view full) ---

785 ubi_err(ubi, "error %d while reading VID header from PEB %d",
786 err, e1->pnum);
787 goto out_error;
788 }
789
790 vol_id = be32_to_cpu(vid_hdr->vol_id);
791 lnum = be32_to_cpu(vid_hdr->lnum);
792
760 if (err && err != UBI_IO_BITFLIPS) {
761 dst_leb_clean = 1;
762 if (err == UBI_IO_FF) {
763 /*
764 * We are trying to move PEB without a VID header. UBI
765 * always write VID headers shortly after the PEB was
766 * given, so we have a situation when it has not yet
767 * had a chance to write it, because it was preempted.

--- 20 unchanged lines hidden (view full) ---

788 ubi_err(ubi, "error %d while reading VID header from PEB %d",
789 err, e1->pnum);
790 goto out_error;
791 }
792
793 vol_id = be32_to_cpu(vid_hdr->vol_id);
794 lnum = be32_to_cpu(vid_hdr->lnum);
795
793 err = ubi_eba_copy_leb(ubi, e1->pnum, e2->pnum, vid_hdr);
796 err = ubi_eba_copy_leb(ubi, e1->pnum, e2->pnum, vidb);
794 if (err) {
795 if (err == MOVE_CANCEL_RACE) {
796 /*
797 * The LEB has not been moved because the volume is
798 * being deleted or the PEB has been put meanwhile. We
799 * should prevent this PEB from being selected for
800 * wear-leveling movement again, so put it to the
801 * protection queue.

--- 40 unchanged lines hidden (view full) ---

842
843 ubi_assert(0);
844 }
845
846 /* The PEB has been successfully moved */
847 if (scrubbing)
848 ubi_msg(ubi, "scrubbed PEB %d (LEB %d:%d), data moved to PEB %d",
849 e1->pnum, vol_id, lnum, e2->pnum);
797 if (err) {
798 if (err == MOVE_CANCEL_RACE) {
799 /*
800 * The LEB has not been moved because the volume is
801 * being deleted or the PEB has been put meanwhile. We
802 * should prevent this PEB from being selected for
803 * wear-leveling movement again, so put it to the
804 * protection queue.

--- 40 unchanged lines hidden (view full) ---

845
846 ubi_assert(0);
847 }
848
849 /* The PEB has been successfully moved */
850 if (scrubbing)
851 ubi_msg(ubi, "scrubbed PEB %d (LEB %d:%d), data moved to PEB %d",
852 e1->pnum, vol_id, lnum, e2->pnum);
850 ubi_free_vid_hdr(ubi, vid_hdr);
853 ubi_free_vid_buf(vidb);
851
852 spin_lock(&ubi->wl_lock);
853 if (!ubi->move_to_put) {
854 wl_tree_add(e2, &ubi->used);
855 e2 = NULL;
856 }
857 ubi->move_from = ubi->move_to = NULL;
858 ubi->move_to_put = ubi->wl_scheduled = 0;

--- 49 unchanged lines hidden (view full) ---

908 ubi->free_count++;
909 }
910
911 ubi_assert(!ubi->move_to_put);
912 ubi->move_from = ubi->move_to = NULL;
913 ubi->wl_scheduled = 0;
914 spin_unlock(&ubi->wl_lock);
915
854
855 spin_lock(&ubi->wl_lock);
856 if (!ubi->move_to_put) {
857 wl_tree_add(e2, &ubi->used);
858 e2 = NULL;
859 }
860 ubi->move_from = ubi->move_to = NULL;
861 ubi->move_to_put = ubi->wl_scheduled = 0;

--- 49 unchanged lines hidden (view full) ---

911 ubi->free_count++;
912 }
913
914 ubi_assert(!ubi->move_to_put);
915 ubi->move_from = ubi->move_to = NULL;
916 ubi->wl_scheduled = 0;
917 spin_unlock(&ubi->wl_lock);
918
916 ubi_free_vid_hdr(ubi, vid_hdr);
919 ubi_free_vid_buf(vidb);
917 if (dst_leb_clean) {
918 ensure_wear_leveling(ubi, 1);
919 } else {
920 err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
921 if (err)
922 goto out_ro;
923 }
924

--- 7 unchanged lines hidden (view full) ---

932 else
933 ubi_err(ubi, "error %d while moving PEB %d (LEB %d:%d) to PEB %d",
934 err, e1->pnum, vol_id, lnum, e2->pnum);
935 spin_lock(&ubi->wl_lock);
936 ubi->move_from = ubi->move_to = NULL;
937 ubi->move_to_put = ubi->wl_scheduled = 0;
938 spin_unlock(&ubi->wl_lock);
939
920 if (dst_leb_clean) {
921 ensure_wear_leveling(ubi, 1);
922 } else {
923 err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
924 if (err)
925 goto out_ro;
926 }
927

--- 7 unchanged lines hidden (view full) ---

935 else
936 ubi_err(ubi, "error %d while moving PEB %d (LEB %d:%d) to PEB %d",
937 err, e1->pnum, vol_id, lnum, e2->pnum);
938 spin_lock(&ubi->wl_lock);
939 ubi->move_from = ubi->move_to = NULL;
940 ubi->move_to_put = ubi->wl_scheduled = 0;
941 spin_unlock(&ubi->wl_lock);
942
940 ubi_free_vid_hdr(ubi, vid_hdr);
943 ubi_free_vid_buf(vidb);
941 wl_entry_destroy(ubi, e1);
942 wl_entry_destroy(ubi, e2);
943
944out_ro:
945 ubi_ro_mode(ubi);
946 mutex_unlock(&ubi->move_mutex);
947 ubi_assert(err != 0);
948 return err < 0 ? err : -EIO;
949
950out_cancel:
951 ubi->wl_scheduled = 0;
952 spin_unlock(&ubi->wl_lock);
953 mutex_unlock(&ubi->move_mutex);
944 wl_entry_destroy(ubi, e1);
945 wl_entry_destroy(ubi, e2);
946
947out_ro:
948 ubi_ro_mode(ubi);
949 mutex_unlock(&ubi->move_mutex);
950 ubi_assert(err != 0);
951 return err < 0 ? err : -EIO;
952
953out_cancel:
954 ubi->wl_scheduled = 0;
955 spin_unlock(&ubi->wl_lock);
956 mutex_unlock(&ubi->move_mutex);
954 ubi_free_vid_hdr(ubi, vid_hdr);
957 ubi_free_vid_buf(vidb);
955 return 0;
956}
957
958/**
959 * ensure_wear_leveling - schedule wear-leveling if it is needed.
960 * @ubi: UBI device description object
961 * @nested: set to non-zero if this function is called from UBI worker
962 *

--- 928 unchanged lines hidden ---
958 return 0;
959}
960
961/**
962 * ensure_wear_leveling - schedule wear-leveling if it is needed.
963 * @ubi: UBI device description object
964 * @nested: set to non-zero if this function is called from UBI worker
965 *

--- 928 unchanged lines hidden ---