[Nbd] [RFC]Probelem about nbd-client's negotiation
- To: nbd-general@lists.sourceforge.net
- Subject: [Nbd] [RFC]Probelem about nbd-client's negotiation
- From: harryxiyou <harryxiyou@...17...>
- Date: Wed, 15 Feb 2012 12:18:55 +0800
- Message-id: <CAD+1EGMf86vgOKQW=iTa7JhqA1hYs+EB61HEAQzPrb7OApfqHg@...18...>
nbd-client.c
...
void negotiate(int sock, u64 *rsize64, u32 *flags) {
u64 magic, size64;
char buf[256] = "\0\0\0\0\0\0\0\0\0";
printf("Negotiation: ");
if (read(sock, buf, 8) < 0)
err("Failed/1: %m");
if (strlen(buf)==0)
err("Server closed connection");
if (strcmp(buf, INIT_PASSWD))
err("INIT_PASSWD bad");
printf(".");
if (read(sock, &magic, sizeof(magic)) < 0)
err("Failed/2: %m");
magic = ntohll(magic);
if (magic != cliserv_magic)
err("Not enough cliserv_magic");
printf(".");
if (read(sock, &size64, sizeof(size64)) < 0)
err("Failed/3: %m\n");
size64 = ntohll(size64);
#ifdef NBD_SET_SIZE_BLOCKS
if ((size64>>10) > (~0UL >> 1)) {
printf("size = %luMB", (unsigned long)(size64>>20));
err("Exported device is too big for me. Get 64-bit machine :-(\n");
} else
printf("size = %luKB", (unsigned long)(size64>>10));
#else
if (size64 > (~0UL >> 1)) {
printf("size = %luKB", (unsigned long)(size64>>10));
err("Exported device is too big. Get 64-bit machine or newer kernel :-(\n");
} else
printf("size = %lu", (unsigned long)(size64));
#endif
if (read(sock, flags, sizeof(*flags)) < 0)
err("Failed/4: %m\n");
*flags = ntohl(*flags);
if (read(sock, &buf, 124) < 0)
err("Failed/5: %m\n");
printf("\n");
*rsize64 = size64;
}
...
In this function, we do the following things.
1, Read the INIT_PASSWD from nbd-server
2, Read the magic number from nbd-server.
3, Read the disk size from nbd-server.
4, Read the flag from nbd-server.
5, Read the buff from nbd-server.
Some questions confuse me a lot.
1, After get the size from nbd-server, we run following codes.
...
#ifdef NBD_SET_SIZE_BLOCKS
if ((size64>>10) > (~0UL >> 1)) {
printf("size = %luMB", (unsigned long)(size64>>20));
err("Exported device is too big for me. Get 64-bit machine :-(\n");
} else
printf("size = %luKB", (unsigned long)(size64>>10));
#else
if (size64 > (~0UL >> 1)) {
printf("size = %luKB", (unsigned long)(size64>>10));
err("Exported device is too big. Get 64-bit machine or newer kernel :-(\n");
} else
printf("size = %lu", (unsigned long)(size64));
#endif
...
I don't know the meanings of them. Cloud you please understand me, thanks.
2, We read the flag from the nbd-server, but what the flag is? How can
i understand
the flag's significances?
3, At last, we read buff like this.
...
if (read(sock, &buf, 124) < 0)
err("Failed/5: %m\n");
printf("\n");
...
What are the buffs? It really makes any senses, right?
--
Thanks
Harry Wei
Reply to: