Subject: Re: Writing to disk from the network stack (bottom half of the kernel)
To: Paul Sommerhein <firstname.lastname@example.org>
From: Jonathan Stone <jonathan@DSG.Stanford.EDU>
Date: 02/04/2003 09:31:48
>Ok, this might not be feasible, but what I want to do is to write
>a 64kB chunk of data to the end of a disk file from within the
>network stack in the bottom half of the kernel (incoming data
>path, no process context).
You should create a kernel thread and use it as a `write helper'
Create a queue of pending writes, synchronize with the queue
(from both sides) with a suitable bottohnetlf interrupt priority.
The helper will run a loop: tsleep() on the queue head waiting for
more data to arrive; then checking for a non-empty queue. If
non-empty, it removes the first element, writes it, and checks again.
The bottom-half enqueue does a wakeup on the queue address if it
attempts an insert whilst the queue is nonempty.
You really dont want to try scheduling writes from the bottom-half.
The file level I/O code assumes process context; if it works at all,
it works because you're putting some innocent victim process (curproc)
to sleep to wait for file I/O completion. Eventually your hardware
interrupt will fire with curproc == NULL, triggering a panic.