nbd: clear waiting_queue on shutdown
commit fded4e090c upstream.
Fix a serious but uncommon bug in nbd which occurs when there is heavy
I/O going to the nbd device while, at the same time, a failure (server,
network) or manual disconnect of the nbd connection occurs.
There is a small window between the time that the nbd_thread is stopped
and the socket is shutdown where requests can continue to be queued to
nbd's internal waiting_queue. When this happens, those requests are
never completed or freed.
The fix is to clear the waiting_queue on shutdown of the nbd device, in
the same way that the nbd request queue (queue_head) is already being
cleared.
Signed-off-by: Paul Clements <paul.clements@steeleye.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[bwh: Backported to 3.2: local nbd_device pointers are called 'lo' not 'nbd']
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
This commit is contained in:
committed by
Ben Hutchings
parent
4fa89f936f
commit
b641778814
@ -445,6 +445,14 @@ static void nbd_clear_que(struct nbd_device *lo)
|
||||
req->errors++;
|
||||
nbd_end_request(req);
|
||||
}
|
||||
|
||||
while (!list_empty(&lo->waiting_queue)) {
|
||||
req = list_entry(lo->waiting_queue.next, struct request,
|
||||
queuelist);
|
||||
list_del_init(&req->queuelist);
|
||||
req->errors++;
|
||||
nbd_end_request(req);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -594,6 +602,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
|
||||
lo->file = NULL;
|
||||
nbd_clear_que(lo);
|
||||
BUG_ON(!list_empty(&lo->queue_head));
|
||||
BUG_ON(!list_empty(&lo->waiting_queue));
|
||||
if (file)
|
||||
fput(file);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user