Please review and comment... This is the sixth patch to the NBD driver and it fixes a variety of outstanding locking issues with the ioctl user interface. This patch modifies both drivers/block/nbd.c and include/linux/nbd.h. It's intended to be applied incrementally (on top of the fifth patch). Of major note is that since the linux 2.5 change in the block layer code, the distributions of the nbd-client user tool that I am familiar with (including the one in my anbd distribution up through release 0.4) will already be unable to correctly set the size of the served block device. This happens because nbd-client opens the nbd, calls the set size ioctl on its descriptor and eventually calls the do_it ioctl with that same still opened descriptor. The set size ioctl essentially just calls set_capacity() on the relevant gendisk structure. In the new block layer code however, the nbd descriptor has to be released after the set size ioctl call and then re-opened in order for the correct size to be registered by other openers. This could also be worked around in the driver but it has not been done (yet). That said, this seems like an opportunistic time to further break compatibility with the existing nbd-client user tool and do away with the problematic components of the ioctl user interface. This patch deprecates two ioctl's (NBD_SET_SOCK and NBD_CLEAR_SOCK) and changes the usage of the NBD_DO_IT ioctl to take the socket descriptor as its argument. As such, NBD_DO_IT rolls all the functionality of the three ioctls into just one. It simplifies the user interface and makes resource locking much easier. Consequently, several race conditions can be cleaned up in the driver itself (rather than via work arounds in nbd-client). There are other ways of course... the new NBD_DO_IT style interface could be introduced instead as another ioctl completely and these 3 ioctls could be maintained for backward compatibility for a while longer. That seems contradictory though to the idea of keeping the newest code the cleanest but at least it doesn't break existing nbd-client tools. So look at the patch if you're interested and let me know what you think. Please don't make it part of the kernel distro though, at least not yet. I'll be "disconnected" from Thursday through Sunday so I won't be able to do any fixes should this introduce more problems than it fixes till next week.