[PATCH 6/9] block/pktdvd: switch congestion waiting to ___wait_var_event()
From: NeilBrown
Date: Mon Aug 19 2024 - 01:38:49 EST
Rather than having an open-coded wait event loop, use
__var_wait_event().
This fixes a bug as the existing loop doesn't call finish_wait().
Also add missing memory barrier before wake_up_var().
Signed-off-by: NeilBrown <neilb@xxxxxxx>
---
drivers/block/pktcdvd.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 7cece5884b9c..273fbe05d80f 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -1210,6 +1210,7 @@ static int pkt_handle_queue(struct pktcdvd_device *pd)
if (pd->congested &&
pd->bio_queue_size <= pd->write_congestion_off) {
pd->congested = false;
+ smp_mb();
wake_up_var(&pd->congested);
}
spin_unlock(&pd->lock);
@@ -2383,20 +2384,16 @@ static void pkt_make_request_write(struct bio *bio)
spin_lock(&pd->lock);
if (pd->write_congestion_on > 0
&& pd->bio_queue_size >= pd->write_congestion_on) {
- struct wait_bit_queue_entry wqe;
- init_wait_var_entry(&wqe, &pd->congested, 0);
- for (;;) {
- prepare_to_wait_event(__var_waitqueue(&pd->congested),
- &wqe.wq_entry,
- TASK_UNINTERRUPTIBLE);
- if (pd->bio_queue_size <= pd->write_congestion_off)
- break;
- pd->congested = true;
- spin_unlock(&pd->lock);
- schedule();
- spin_lock(&pd->lock);
- }
+ ___wait_var_event(&pd->congested,
+ pd->bio_queue_size <= pd->write_congestion_off,
+ TASK_UNINTERRUPTIBLE, 0, 0,
+ ({ pd->congested = true;
+ spin_unlock(&pd->lock);
+ schedule();
+ spin_lock(&pd->lock);
+ })
+ );
}
spin_unlock(&pd->lock);
--
2.44.0