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

Re: [Nbd] [NBD]Some confusions when i read the nbd codes



On Tue, Aug 09, 2011 at 12:22:21PM +0800, harryxiyou wrote:
> On Tue, Aug 9, 2011 at 11:56 AM, harryxiyou <harryxiyou@...17...> wrote:
> > Hi all,
> >
> > NOTE: my nbd source code's version is nbd-2.9.15.tar.bz2.

That's fairly old...

> > 1, Why do we handle the
> >
> Sorry for sending the mail unfinished just now, okay, see following
> for the rest.
> 
> 1, Why do we handle the 'serve->port == 0' in nbd-server.c
> particularly? I don't know
> the differences for 'port == 0'.
> 1889         if(serve) {
> 1890                 serve->socket_family = AF_UNSPEC;
> 1891
> 1892                 append_serve(serve, servers);
> 1893
> 1894                 if (!(serve->port)) {
> 1895                         CLIENT *client;
> 1896 #ifndef ISSERVER
> 1897                         /* You really should define ISSERVER if
> you're going to use
> 1898                          * inetd mode, but if you don't, closing
> stdout and stderr
> 1899                          * (which inetd had connected to the
> client socket) will let it
> 1900                          * work. */
> 1901                         close(1);

If the specified port number is zero, we're running in inetd mode. This
means that nbd-server communicates over stdin and stdout, and inetd will
do the socket handling.

See 'man inetd' for a description of what inetd is.

> 2, Can you just describe the relationships among nbd.c in kernel as a module
>  and nbd-client.c && nbd-server.c in our nbd package ?

The nbd.c in the kernel does the actual work on the client side;
nbd-client only sets up the connection and then hands off the socket
that it negotiated with the nbd-server to the in-kernel module.

> 3, Okay, now i have a nbd client and a nbd server. I just know nbd client can
> get disk space from nbd server but how server can get the exact datas which
> entered by user from nbd client?

Two options: either you use a loop-mount, or you set up an nbd-client
connection to localhost.

> 4, We have three functions in nbd-server.c like following.
> rawexpwrite(...)
> rawexpwrite_fully(...)
> expwrite(...)
> I am not sure if these functions write datas to client device or server?
> I just see datas in client but server.

'write' here means 'write to a file handle'. Depending on which file
handle we're talking about, this can be the client (if the socket) or
the server's backend store (if the file).

> 5, i have a nbd client and server. Now they have establish the
> nbd connections. Client just use /dev/nbd0. And format /dev/nbd0
> to ext3 FS. Then i mount it to /mnt/nbd0. I copy /root to /mnt/nbd0.
> Now how can i get the /root directory from the nbd server?

disconnect the client, connect it on the server, mount it there, tada.

-- 
The volume of a pizza of thickness a and radius z can be described by
the following formula:

pi zz a



Reply to: