Commit 90bf0265 authored by Artem Bityutskiy's avatar Artem Bityutskiy

UBI: introduce new constants

This patch is a clean-up and a preparation for the following
patches. It introduece constants for the return values of the
'ubi_eba_copy_leb()' function.
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent ddbd3b61
...@@ -950,12 +950,7 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, ...@@ -950,12 +950,7 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
* physical eraseblock @to. The @vid_hdr buffer may be changed by this * physical eraseblock @to. The @vid_hdr buffer may be changed by this
* function. Returns: * function. Returns:
* o %0 in case of success; * o %0 in case of success;
* o %1 if the operation was canceled because the volume is being deleted * o %MOVE_CANCEL_RACE, %MOVE_TARGET_WR_ERR, or %MOVE_CANCEL_BITFLIPS;
* or because the PEB was put meanwhile;
* o %2 if the operation was canceled because there was a write error to the
* target PEB;
* o %-EAGAIN if the operation was canceled because a bit-flip was detected
* in the target PEB;
* o a negative error code in case of failure. * o a negative error code in case of failure.
*/ */
int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
...@@ -986,13 +981,12 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, ...@@ -986,13 +981,12 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
* be locked in 'ubi_wl_put_peb()' and wait for the WL worker to finish. * be locked in 'ubi_wl_put_peb()' and wait for the WL worker to finish.
*/ */
vol = ubi->volumes[idx]; vol = ubi->volumes[idx];
spin_unlock(&ubi->volumes_lock);
if (!vol) { if (!vol) {
/* No need to do further work, cancel */ /* No need to do further work, cancel */
dbg_eba("volume %d is being removed, cancel", vol_id); dbg_eba("volume %d is being removed, cancel", vol_id);
spin_unlock(&ubi->volumes_lock); return MOVE_CANCEL_RACE;
return 1;
} }
spin_unlock(&ubi->volumes_lock);
/* /*
* We do not want anybody to write to this logical eraseblock while we * We do not want anybody to write to this logical eraseblock while we
...@@ -1004,12 +998,13 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, ...@@ -1004,12 +998,13 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
* (@from). This task locks the LEB and goes sleep in the * (@from). This task locks the LEB and goes sleep in the
* 'ubi_wl_put_peb()' function on the @ubi->move_mutex. In turn, we are * 'ubi_wl_put_peb()' function on the @ubi->move_mutex. In turn, we are
* holding @ubi->move_mutex and go sleep on the LEB lock. So, if the * holding @ubi->move_mutex and go sleep on the LEB lock. So, if the
* LEB is already locked, we just do not move it and return %1. * LEB is already locked, we just do not move it and return
* %MOVE_CANCEL_RACE, which means that UBI will re-try, but later.
*/ */
err = leb_write_trylock(ubi, vol_id, lnum); err = leb_write_trylock(ubi, vol_id, lnum);
if (err) { if (err) {
dbg_eba("contention on LEB %d:%d, cancel", vol_id, lnum); dbg_eba("contention on LEB %d:%d, cancel", vol_id, lnum);
return err; return MOVE_CANCEL_RACE;
} }
/* /*
...@@ -1021,14 +1016,14 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, ...@@ -1021,14 +1016,14 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
dbg_eba("LEB %d:%d is no longer mapped to PEB %d, mapped to " dbg_eba("LEB %d:%d is no longer mapped to PEB %d, mapped to "
"PEB %d, cancel", vol_id, lnum, from, "PEB %d, cancel", vol_id, lnum, from,
vol->eba_tbl[lnum]); vol->eba_tbl[lnum]);
err = 1; err = MOVE_CANCEL_RACE;
goto out_unlock_leb; goto out_unlock_leb;
} }
/* /*
* OK, now the LEB is locked and we can safely start moving it. Since * OK, now the LEB is locked and we can safely start moving it. Since
* this function utilizes the @ubi->peb1_buf buffer which is shared * this function utilizes the @ubi->peb_buf1 buffer which is shared
* with some other functions, so lock the buffer by taking the * with some other functions - we lock the buffer by taking the
* @ubi->buf_mutex. * @ubi->buf_mutex.
*/ */
mutex_lock(&ubi->buf_mutex); mutex_lock(&ubi->buf_mutex);
...@@ -1059,7 +1054,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, ...@@ -1059,7 +1054,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
cond_resched(); cond_resched();
/* /*
* It may turn out to me that the whole @from physical eraseblock * It may turn out to be that the whole @from physical eraseblock
* contains only 0xFF bytes. Then we have to only write the VID header * contains only 0xFF bytes. Then we have to only write the VID header
* and do not write any data. This also means we should not set * and do not write any data. This also means we should not set
* @vid_hdr->copy_flag, @vid_hdr->data_size, and @vid_hdr->data_crc. * @vid_hdr->copy_flag, @vid_hdr->data_size, and @vid_hdr->data_crc.
...@@ -1074,7 +1069,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, ...@@ -1074,7 +1069,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
err = ubi_io_write_vid_hdr(ubi, to, vid_hdr); err = ubi_io_write_vid_hdr(ubi, to, vid_hdr);
if (err) { if (err) {
if (err == -EIO) if (err == -EIO)
err = 2; err = MOVE_TARGET_WR_ERR;
goto out_unlock_buf; goto out_unlock_buf;
} }
...@@ -1086,7 +1081,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, ...@@ -1086,7 +1081,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
if (err != UBI_IO_BITFLIPS) if (err != UBI_IO_BITFLIPS)
ubi_warn("cannot read VID header back from PEB %d", to); ubi_warn("cannot read VID header back from PEB %d", to);
else else
err = -EAGAIN; err = MOVE_CANCEL_BITFLIPS;
goto out_unlock_buf; goto out_unlock_buf;
} }
...@@ -1094,7 +1089,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, ...@@ -1094,7 +1089,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
err = ubi_io_write_data(ubi, ubi->peb_buf1, to, 0, aldata_size); err = ubi_io_write_data(ubi, ubi->peb_buf1, to, 0, aldata_size);
if (err) { if (err) {
if (err == -EIO) if (err == -EIO)
err = 2; err = MOVE_TARGET_WR_ERR;
goto out_unlock_buf; goto out_unlock_buf;
} }
...@@ -1111,7 +1106,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, ...@@ -1111,7 +1106,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
ubi_warn("cannot read data back from PEB %d", ubi_warn("cannot read data back from PEB %d",
to); to);
else else
err = -EAGAIN; err = MOVE_CANCEL_BITFLIPS;
goto out_unlock_buf; goto out_unlock_buf;
} }
......
...@@ -100,6 +100,22 @@ enum { ...@@ -100,6 +100,22 @@ enum {
UBI_IO_BITFLIPS UBI_IO_BITFLIPS
}; };
/*
* Return codes of the 'ubi_eba_copy_leb()' function.
*
* MOVE_CANCEL_RACE: canceled because the volume is being deleted, the source
* PEB was put meanwhile, or there is I/O on the source PEB
* MOVE_TARGET_WR_ERR: canceled because there was a write error to the target
* PEB
* MOVE_CANCEL_BITFLIPS: canceled because a bit-flip was detected in the
* target PEB
*/
enum {
MOVE_CANCEL_RACE = 1,
MOVE_TARGET_WR_ERR,
MOVE_CANCEL_BITFLIPS,
};
/** /**
* struct ubi_wl_entry - wear-leveling entry. * struct ubi_wl_entry - wear-leveling entry.
* @u.rb: link in the corresponding (free/used) RB-tree * @u.rb: link in the corresponding (free/used) RB-tree
......
...@@ -756,15 +756,14 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, ...@@ -756,15 +756,14 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
err = ubi_eba_copy_leb(ubi, e1->pnum, e2->pnum, vid_hdr); err = ubi_eba_copy_leb(ubi, e1->pnum, e2->pnum, vid_hdr);
if (err) { if (err) {
if (err == -EAGAIN) if (err == MOVE_CANCEL_BITFLIPS ||
goto out_not_moved; err == MOVE_TARGET_WR_ERR) {
if (err < 0) /* Target PEB bit-flips or write error, torture it */
goto out_error;
if (err == 2) {
/* Target PEB write error, torture it */
torture = 1; torture = 1;
goto out_not_moved; goto out_not_moved;
} }
if (err < 0)
goto out_error;
/* /*
* The LEB has not been moved because the volume is being * The LEB has not been moved because the volume is being
...@@ -774,7 +773,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, ...@@ -774,7 +773,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
*/ */
dbg_wl("canceled moving PEB %d", e1->pnum); dbg_wl("canceled moving PEB %d", e1->pnum);
ubi_assert(err == 1); ubi_assert(err == MOVE_CANCEL_RACE);
ubi_free_vid_hdr(ubi, vid_hdr); ubi_free_vid_hdr(ubi, vid_hdr);
vid_hdr = NULL; vid_hdr = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment