diff options
-rw-r--r-- | drivers/md/dm-raid1.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c index 0253130fa13a..d1a7f1a4789c 100644 --- a/drivers/md/dm-raid1.c +++ b/drivers/md/dm-raid1.c | |||
@@ -181,6 +181,17 @@ static void set_default_mirror(struct mirror *m) | |||
181 | atomic_set(&ms->default_mirror, m - m0); | 181 | atomic_set(&ms->default_mirror, m - m0); |
182 | } | 182 | } |
183 | 183 | ||
184 | static struct mirror *get_valid_mirror(struct mirror_set *ms) | ||
185 | { | ||
186 | struct mirror *m; | ||
187 | |||
188 | for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++) | ||
189 | if (!atomic_read(&m->error_count)) | ||
190 | return m; | ||
191 | |||
192 | return NULL; | ||
193 | } | ||
194 | |||
184 | /* fail_mirror | 195 | /* fail_mirror |
185 | * @m: mirror device to fail | 196 | * @m: mirror device to fail |
186 | * @error_type: one of the enum's, DM_RAID1_*_ERROR | 197 | * @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 | goto out; | 237 | goto out; |
227 | } | 238 | } |
228 | 239 | ||
229 | for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++) | 240 | new = get_valid_mirror(ms); |
230 | if (!atomic_read(&new->error_count)) { | 241 | if (new) |
231 | set_default_mirror(new); | 242 | set_default_mirror(new); |
232 | break; | 243 | else |
233 | } | ||
234 | |||
235 | if (unlikely(new == ms->mirror + ms->nr_mirrors)) | ||
236 | DMWARN("All sides of mirror have failed."); | 244 | DMWARN("All sides of mirror have failed."); |
237 | 245 | ||
238 | out: | 246 | out: |