@@ -783,13 +783,16 @@ static int find_fallback(struct nbd_device *nbd, int index)
return new_index;
}
+ if (atomic_read(&config->live_connections) <= 0) {
+ dev_err_ratelimited(disk_to_dev(nbd->disk),
+ "Dead connection, failed to find a fallback\n");
+ goto out;
+ }
+
if (fallback >= 0 && fallback < config->num_connections &&
- !config->socks[fallback]->dead)
+ !config->socks[fallback]->dead) {
return fallback;
-
- if (nsock->fallback_index < 0 ||
- nsock->fallback_index >= config->num_connections ||
- config->socks[nsock->fallback_index]->dead) {
+ } else {
int i;
for (i = 0; i < config->num_connections; i++) {
if (i == index)
@@ -799,14 +802,10 @@ static int find_fallback(struct nbd_device *nbd, int index)
break;
}
}
- nsock->fallback_index = new_index;
- if (new_index < 0) {
- dev_err_ratelimited(disk_to_dev(nbd->disk),
- "Dead connection, failed to find a fallback\n");
- return new_index;
- }
}
- new_index = nsock->fallback_index;
+
+out:
+ nsock->fallback_index = new_index;
return new_index;
}