[ENBD] ENBD on 2.4.x

Peter T. Breuer ptb@it.uc3m.es
Mon, 19 Mar 2001 01:10:14 +0100 (MET)


"A month of sundays ago jona@orac.ensor.org wrote:"
> Could somebody sanity check me here?  I'm still looking at issues

Actually, I've been looking too, and both our sanities are at stake.

> with 2.4.x and ENBD and wanted to see how the Kernel module
> makes sure it doesn't merge requests to the point that it would
> overrun the client's buffer during a 'get_req' call (I suspect that
> I'm getting a SEGV in the ioctl(fd, MY_NBD_GET_REQ, 1000) call).
> 
> I see that the Kernel module tries to keep that from happening
> by looking at 'buf_sectors', but something still seems to be
> going wrong.

I can find no way that it can go wrong. The code does a check
on the size of the request multiple times (I'm going to put them in
PARANOIA brackets!). The crucial point was that the module substitutes
the kernels merge_request functions, and the replacements check the
resulting request size before letting the kernel make the bigger
request. And if you load with merge_requests=0, then the replacement
functions always say no anyway.

As I suggested earlier, if you disable plugging (by substituting a
no-op plugging function for nbd into the kernel), then the kernel won't
ever get to try and merge requests. That's because it only merges
rewuests when they're on the request queue. If the queue isn't plugged,
then the kernel calls the device request function (us) after every new
request, so they don't accumulate, and can't be merged.

I have now noticed a third safety mechanism that can be applies. I seem
to have missed it for several years! There is a
max_sectors[major][minor] array in the kernel. Filling
max_sectors[major] at mod init time with the address of a 256 integer
array of  small numbers (e.g. 64) will stop the kernel from making
requests of size more that 32K for us, ever.

I've added this measure into 2.4.23.

> Mar 15 18:40:04 jarney kernel: NBD #3481[0]: init_module registered device at major 43
> Mar 15 18:40:18 jarney kernel: NBD #1892[0]: nbd_set_sock device nda not signed yet!
> Mar 15 18:40:27 jarney kernel: NBD #1469[0]: nbd_get_req Warning!  Want to write something larger than my buffer 131072

That was REALLY REAAAAALLY REALLY mysterious. I am adding a max request
display to the printout too.

I'll try kernel 2.4.2 this week.

Peter