diff options
author | Mikulas Patocka <mpatocka@redhat.com> | 2009-12-10 18:52:04 -0500 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2009-12-10 18:52:04 -0500 |
commit | 87968ddd2f3be1c21b932cac30157a83a1c4f935 (patch) | |
tree | f4d4caa4ec52f697ed5745a88322d3620cf7ee0a /drivers/md | |
parent | 0f398a8403e31c737b429fddc3850093d0bf58d0 (diff) |
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: Mikulas Patocka <mpatocka@redhat.com>
Reviewed-by: Takahiro Yasui <tyasui@redhat.com>
Tested-by: Takahiro Yasui <tyasui@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md')
-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: |