[ENBD] stability issues, big red neon sign
Peter T. Breuer
enbd@lists.community.tummy.com
Wed, 27 Mar 2002 17:29:38 +0100 (MET)
"A month of sundays ago Peter T. Breuer wrote:"
> you the diff. Or let me know how I can reschedule the q->request_fn()
> for later if I see that I want to delay the kernel thread ... it _must_
> run.
OK .. this additional patch reschedules the kernel thread for later if
it tries to enter while the client thread is in the driver, and takes
the semaphore when it does enter, thus making the driver fully single
threaded on SMP.
For extra points, you get to add priorities so that no threads get
excluded unfairly often.
--- nbd-2.4.28/linux/drivers/block/nbd.c Mon Mar 25 00:22:52 2002
+++ nbd-2.4.29/linux/drivers/block/nbd.c Wed Mar 27 17:23:50 2002
@@ -2502,6 +2529,7 @@
while (!NBD_QUEUE_EMPTY) {
struct nbd_device *lo = NULL;
+ int release_semaphore = 0;
req = CURRENT;
@@ -2523,6 +2551,15 @@
}
lo = &nbd_dev[nbd];
+ if (down_trylock(&lo->sem) != 0) {
+ // PTB temporarily couldn't get the DEBUG smp lock. Try again later
+ q->plugged = 1;
+ NBD_ERROR ("delaying NBD request fn at jiffies %lu\n", jiffies);
+ queue_task(&q->plug_tq, & tq_disk);
+ return;
+ }
+ release_semaphore = 1;
+
atomic_inc (&lo->kthreads); /* PTB - one kernel thread enters */
if (atomic_read (&lo->kthreads) > atomic_read (&lo->kmax))
atomic_set (&lo->kmax, atomic_read (&lo->kthreads));
@@ -2631,6 +2668,8 @@
accounting:
atomic_dec (&lo->kthreads);
NBD_DEBUG (3, "DEBUG 5\n");
+ if (release_semaphore)
+ up(&lo->sem);
continue; // PTB next request
error_out:
@@ -2645,6 +2684,8 @@
atomic_add (req_blks, &lo->requests_err);
atomic_dec (&lo->kthreads);
}
+ if (release_semaphore)
+ up(&lo->sem);
NBD_DEBUG (3, "DEBUG 7\n");
}