[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Nbd] For help, about kernel NBD driver



On Thu, May 20, 2010 at 05:31:29PM +0800, edelweiss_zf3842 wrote:
> Hello!
> 
> I'm a Chinese student, doing my graduation project at Tsinghua University.
> I really want to know the mechanism of NBD at kernel-level, such as:
> 
> 1. How does the client get data from server (in detail) in order to use the
> remote block device?

The client is actually implemented in kernel space; all the nbd-client
program really does is perform a protocol handshake with the server, and
then hand the socket to the kernel so that it can use it. From then on,
the entire client side of NBD is implemented in kernel space.

So when a userspace program tries to read from or write to an NBD
device, the kernel will create an NBD request packet (with the data of
the write() call, if that's what was done), and write it to the socket.
This causes that data to be sent to the server, which then responds by,
depending on the type of request, either reading from or writing to the
device or the file it has open, and to then send the result of that read
or write operation back to the client.

That's all.

> 2. What should I do if I want to make client get data from localhost
> instead of remote server when client has already gotten those data
> from server and saved them on local disk?

The client never writes to the local disk. An NBD device is a completely
virtual device; everything is emulated by sending requests that the
client wants to make to the server. So you can't do that.

That doesn't mean that whatever you're trying to do is impossible,
however; you would just have to do it in a different way. Could you
explain what you're trying to accomplish?

-- 
The biometric identification system at the gates of the CIA headquarters
works because there's a guard with a large gun making sure no one is
trying to fool the system.
  http://www.schneier.com/blog/archives/2009/01/biometrics.html



Reply to: