Commit b234c6d7 authored by Dmitry Fomichev's avatar Dmitry Fomichev Committed by Mike Snitzer

dm zoned: improve error handling in reclaim

There are several places in reclaim code where errors are not
propagated to the main function, dmz_reclaim(). This function
is responsible for unlocking zones that might be still locked
at the end of any failed reclaim iterations. As the result,
some device zones may be left permanently locked for reclaim,
degrading target's capability to reclaim zones.

This patch fixes these issues as follows -

Make sure that dmz_reclaim_buf(), dmz_reclaim_seq_data() and
dmz_reclaim_rnd_data() return error codes to the caller.

dmz_reclaim() function is renamed to dmz_do_reclaim() to avoid
clashing with "struct dmz_reclaim" and is modified to return the
error to the caller.

dmz_get_zone_for_reclaim() now returns an error instead of NULL
pointer and reclaim code checks for that error.

Error logging/debug messages are added where necessary.

Fixes: 3b1a94c8 ("dm zoned: drive-managed zoned block device target")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarDmitry Fomichev <dmitry.fomichev@wdc.com>
Reviewed-by: default avatarDamien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent d1fef414
...@@ -1542,7 +1542,7 @@ static struct dm_zone *dmz_get_rnd_zone_for_reclaim(struct dmz_metadata *zmd) ...@@ -1542,7 +1542,7 @@ static struct dm_zone *dmz_get_rnd_zone_for_reclaim(struct dmz_metadata *zmd)
struct dm_zone *zone; struct dm_zone *zone;
if (list_empty(&zmd->map_rnd_list)) if (list_empty(&zmd->map_rnd_list))
return NULL; return ERR_PTR(-EBUSY);
list_for_each_entry(zone, &zmd->map_rnd_list, link) { list_for_each_entry(zone, &zmd->map_rnd_list, link) {
if (dmz_is_buf(zone)) if (dmz_is_buf(zone))
...@@ -1553,7 +1553,7 @@ static struct dm_zone *dmz_get_rnd_zone_for_reclaim(struct dmz_metadata *zmd) ...@@ -1553,7 +1553,7 @@ static struct dm_zone *dmz_get_rnd_zone_for_reclaim(struct dmz_metadata *zmd)
return dzone; return dzone;
} }
return NULL; return ERR_PTR(-EBUSY);
} }
/* /*
......
...@@ -215,7 +215,7 @@ static int dmz_reclaim_buf(struct dmz_reclaim *zrc, struct dm_zone *dzone) ...@@ -215,7 +215,7 @@ static int dmz_reclaim_buf(struct dmz_reclaim *zrc, struct dm_zone *dzone)
dmz_unlock_flush(zmd); dmz_unlock_flush(zmd);
return 0; return ret;
} }
/* /*
...@@ -259,7 +259,7 @@ static int dmz_reclaim_seq_data(struct dmz_reclaim *zrc, struct dm_zone *dzone) ...@@ -259,7 +259,7 @@ static int dmz_reclaim_seq_data(struct dmz_reclaim *zrc, struct dm_zone *dzone)
dmz_unlock_flush(zmd); dmz_unlock_flush(zmd);
return 0; return ret;
} }
/* /*
...@@ -312,7 +312,7 @@ static int dmz_reclaim_rnd_data(struct dmz_reclaim *zrc, struct dm_zone *dzone) ...@@ -312,7 +312,7 @@ static int dmz_reclaim_rnd_data(struct dmz_reclaim *zrc, struct dm_zone *dzone)
dmz_unlock_flush(zmd); dmz_unlock_flush(zmd);
return 0; return ret;
} }
/* /*
...@@ -334,7 +334,7 @@ static void dmz_reclaim_empty(struct dmz_reclaim *zrc, struct dm_zone *dzone) ...@@ -334,7 +334,7 @@ static void dmz_reclaim_empty(struct dmz_reclaim *zrc, struct dm_zone *dzone)
/* /*
* Find a candidate zone for reclaim and process it. * Find a candidate zone for reclaim and process it.
*/ */
static void dmz_reclaim(struct dmz_reclaim *zrc) static int dmz_do_reclaim(struct dmz_reclaim *zrc)
{ {
struct dmz_metadata *zmd = zrc->metadata; struct dmz_metadata *zmd = zrc->metadata;
struct dm_zone *dzone; struct dm_zone *dzone;
...@@ -344,8 +344,8 @@ static void dmz_reclaim(struct dmz_reclaim *zrc) ...@@ -344,8 +344,8 @@ static void dmz_reclaim(struct dmz_reclaim *zrc)
/* Get a data zone */ /* Get a data zone */
dzone = dmz_get_zone_for_reclaim(zmd); dzone = dmz_get_zone_for_reclaim(zmd);
if (!dzone) if (IS_ERR(dzone))
return; return PTR_ERR(dzone);
start = jiffies; start = jiffies;
...@@ -391,13 +391,20 @@ static void dmz_reclaim(struct dmz_reclaim *zrc) ...@@ -391,13 +391,20 @@ static void dmz_reclaim(struct dmz_reclaim *zrc)
out: out:
if (ret) { if (ret) {
dmz_unlock_zone_reclaim(dzone); dmz_unlock_zone_reclaim(dzone);
return; return ret;
} }
(void) dmz_flush_metadata(zrc->metadata); ret = dmz_flush_metadata(zrc->metadata);
if (ret) {
dmz_dev_debug(zrc->dev,
"Metadata flush for zone %u failed, err %d\n",
dmz_id(zmd, rzone), ret);
return ret;
}
dmz_dev_debug(zrc->dev, "Reclaimed zone %u in %u ms", dmz_dev_debug(zrc->dev, "Reclaimed zone %u in %u ms",
dmz_id(zmd, rzone), jiffies_to_msecs(jiffies - start)); dmz_id(zmd, rzone), jiffies_to_msecs(jiffies - start));
return 0;
} }
/* /*
...@@ -442,6 +449,7 @@ static void dmz_reclaim_work(struct work_struct *work) ...@@ -442,6 +449,7 @@ static void dmz_reclaim_work(struct work_struct *work)
struct dmz_metadata *zmd = zrc->metadata; struct dmz_metadata *zmd = zrc->metadata;
unsigned int nr_rnd, nr_unmap_rnd; unsigned int nr_rnd, nr_unmap_rnd;
unsigned int p_unmap_rnd; unsigned int p_unmap_rnd;
int ret;
if (!dmz_should_reclaim(zrc)) { if (!dmz_should_reclaim(zrc)) {
mod_delayed_work(zrc->wq, &zrc->work, DMZ_IDLE_PERIOD); mod_delayed_work(zrc->wq, &zrc->work, DMZ_IDLE_PERIOD);
...@@ -471,7 +479,9 @@ static void dmz_reclaim_work(struct work_struct *work) ...@@ -471,7 +479,9 @@ static void dmz_reclaim_work(struct work_struct *work)
(dmz_target_idle(zrc) ? "Idle" : "Busy"), (dmz_target_idle(zrc) ? "Idle" : "Busy"),
p_unmap_rnd, nr_unmap_rnd, nr_rnd); p_unmap_rnd, nr_unmap_rnd, nr_rnd);
dmz_reclaim(zrc); ret = dmz_do_reclaim(zrc);
if (ret)
dmz_dev_debug(zrc->dev, "Reclaim error %d\n", ret);
dmz_schedule_reclaim(zrc); dmz_schedule_reclaim(zrc);
} }
......
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