mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 22:14:03 +02:00
nbd: simplify find_fallback() by removing redundant logic
The second conditional checking nsock->fallback_index validity is the logical inverse of the first, so drop it and let execution fall through naturally. Consolidate the two identical dev_err_ratelimited() + return paths into a single no_fallback label to reduce duplication. Reviewed-by: Yu Kuai <yukuai@fygo.io> Signed-off-by: Long Li <leo.lilong@huawei.com> Link: https://patch.msgid.link/20260805122930.57647-2-yangerkun@huawei.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
1207dbb91c
commit
fe247030f1
|
|
@ -1061,40 +1061,31 @@ static int find_fallback(struct nbd_device *nbd, int index)
|
|||
int new_index = -1;
|
||||
struct nbd_sock *nsock = config->socks[index];
|
||||
int fallback = nsock->fallback_index;
|
||||
int i;
|
||||
|
||||
if (test_bit(NBD_RT_DISCONNECTED, &config->runtime_flags))
|
||||
return new_index;
|
||||
|
||||
if (config->num_connections <= 1) {
|
||||
dev_err_ratelimited(disk_to_dev(nbd->disk),
|
||||
"Dead connection, failed to find a fallback\n");
|
||||
return new_index;
|
||||
}
|
||||
if (config->num_connections <= 1)
|
||||
goto no_fallback;
|
||||
|
||||
if (fallback >= 0 && fallback < config->num_connections &&
|
||||
!config->socks[fallback]->dead)
|
||||
return fallback;
|
||||
|
||||
if (nsock->fallback_index < 0 ||
|
||||
nsock->fallback_index >= config->num_connections ||
|
||||
config->socks[nsock->fallback_index]->dead) {
|
||||
int i;
|
||||
for (i = 0; i < config->num_connections; i++) {
|
||||
if (i == index)
|
||||
continue;
|
||||
if (!config->socks[i]->dead) {
|
||||
new_index = i;
|
||||
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;
|
||||
for (i = 0; i < config->num_connections; i++) {
|
||||
if (i != index && !config->socks[i]->dead) {
|
||||
new_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
new_index = nsock->fallback_index;
|
||||
nsock->fallback_index = new_index;
|
||||
if (new_index >= 0)
|
||||
return new_index;
|
||||
|
||||
no_fallback:
|
||||
dev_err_ratelimited(disk_to_dev(nbd->disk),
|
||||
"Dead connection, failed to find a fallback\n");
|
||||
return new_index;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user