Commit 87968ddd authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Alasdair G Kergon

dm raid1: abstract get_valid_mirror function

Move the logic to get a valid mirror leg into a function for re-use
in a later patch.
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Reviewed-by: default avatarTakahiro Yasui <tyasui@redhat.com>
Tested-by: default avatarTakahiro Yasui <tyasui@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 0f398a84
...@@ -181,6 +181,17 @@ static void set_default_mirror(struct mirror *m) ...@@ -181,6 +181,17 @@ static void set_default_mirror(struct mirror *m)
atomic_set(&ms->default_mirror, m - m0); atomic_set(&ms->default_mirror, m - m0);
} }
static struct mirror *get_valid_mirror(struct mirror_set *ms)
{
struct mirror *m;
for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
if (!atomic_read(&m->error_count))
return m;
return NULL;
}
/* fail_mirror /* fail_mirror
* @m: mirror device to fail * @m: mirror device to fail
* @error_type: one of the enum's, DM_RAID1_*_ERROR * @error_type: one of the enum's, DM_RAID1_*_ERROR
...@@ -226,13 +237,10 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type) ...@@ -226,13 +237,10 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
goto out; goto out;
} }
for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++) new = get_valid_mirror(ms);
if (!atomic_read(&new->error_count)) { if (new)
set_default_mirror(new); set_default_mirror(new);
break; else
}
if (unlikely(new == ms->mirror + ms->nr_mirrors))
DMWARN("All sides of mirror have failed."); DMWARN("All sides of mirror have failed.");
out: out:
......
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