NetworkBlockDevice / nbd

Network Block Device
GNU General Public License v2.0
459 stars 119 forks source link

nbd-client: Support a pre-initialized connection #105

Closed joshtriplett closed 4 years ago

joshtriplett commented 4 years ago

For debugging purposes, sometimes I'd find it helpful if nbd-client could skip the handshake, and just send the socket directly to the kernel after connecting. Would it be possible to add an option to skip the handshake negotiation?

joshtriplett commented 4 years ago

(This would require providing the size of the device on the command line.)

yoe commented 4 years ago

I'm sure we can do this if necessary, but I don't see how this helps with debugging... Can you clarify that?

I'm reluctant to add a feature if I don't understand how it works, as in my experience that results in suboptimal implementations...

joshtriplett commented 4 years ago

@yoe I've worked with various applications that process an NBD protocol stream (typically only read or only read and write messages), hand a UNIX socket or some other pre-arranged connection to the kernel, and use that to implement a block device. Many of those applications don't bother with the handshake protocol, because the kernel doesn't need it, and it's more complex to implement than read or read/write. For debugging and testing, I'd like to be able to take a socket like that, already connected and ready to speak NBD protocol, and use nbd-client to hand it to the kernel along with a size, block size, and flags.

For local purposes, I did some simple testing by modifying the code of nbd-client to drop the call to handshake and manually initializing size64 and flags at that point.

yoe commented 4 years ago

If you already have a patch, could you perhaps send it to the mailinglist? That makes discussing it a bit easier...

joshtriplett commented 4 years ago

@yoe I don't, but I can write one.

joshtriplett commented 4 years ago

The attached commits add support for this.

The first commit adds an option (-R) to force the NBD device to be read-only, even if the server would allow it to be read-write; this is useful in general, and in particular it allows specifying the read-only option for a preinitialized connection.

The second commit adds options to use a preinitialized connection, and to specify the device size.

joshtriplett commented 4 years ago

I sent both patches to the mailing list as well.

yoe commented 4 years ago

Sorry, they dropped off my radar. I've merged the versions from the mailinglist now.

joshtriplett commented 4 years ago

Thank you, I really appreciate this!