Previously the proxy would just disconnect when it saw an NBD protocol
error, and retry the operation it was in the middle of.
Additionally, the server needs to return the correct error types when
this happens.
I changed the request struct to break the 32 bits reserved for the
request type into two. The first part of this is used for the flags
(such as FUA), and the second part for the command type. Previously
we'd masked the top two bytes, thus ignoring any flags.
```
In file included from src/server/bitset.h:4:0,
from src/server/mirror.h:8,
from src/server/flexnbd.h:5,
from src/server/serve.h:8,
from src/server/serve.c:1:
src/server/serve.c: In function 'tryjoin_client_thread':
src/server/serve.c:258:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
(uint64_t)status);
^
```
Simplified NBD handle comparisons
8 bytes, therefore a uing64_t to compare to, no need for memcmp()
Signed-off-by: Michel Pollet <buserror@gmail.com>
See merge request !5
This will prevent the bind() wrapper to loop forever in some cases. I
could nor reproduc the issue, but this removes the only infinite loop I
could find.
Signed-off-by: Michel Pollet <buserror@gmail.com>
This was listed as a bug, and was immediatelly picked the static
analyzer anyway, this is very likely the cause for the
migration-cancel-crash bug.
Signed-off-by: Michel Pollet <buserror@gmail.com>
We were calculating the wrong number of words per byte in the first
place, and then passing the number of *words* to malloc, which expects
the number of *bytes*.
Fix both errors
Now that we're using NODELAY, we should definitely use cork around
writes to the upstream server. This prevents each partial write()
from being its own packet, which would be terrible if it actually
happened with any regularity (we'd mostly see it when the kernel
is stressed, and write() is progressing a few bytes at a time as
a result)
Nagle doesn't actually affect us too badly here, as we don't write
the header and then the data in two separate calls under normal
circumstances, which is the pathological case, but we should have
NODELAY on, regardless