Alter struct types to reflect reality, avoiding mixing "host" and "raw" structs
This commit is contained in:
1
debian/changelog
vendored
1
debian/changelog
vendored
@@ -14,6 +14,7 @@ flexnbd (0.2.0) UNRELEASED; urgency=medium
|
||||
filesystem, and EINVAL to unknown commands. (#36, !40)
|
||||
* Proxy passes all NBD protocol errors through to the client instead of
|
||||
disconnecting and retrying (#36, !40)
|
||||
* Fix struct types in readwrite.c (#35, !41)
|
||||
|
||||
-- James Carter <james.carter@bytemark.co.uk> Thu, 11 Jan 2018 10:05:35 +0000
|
||||
|
||||
|
@@ -106,14 +106,14 @@ int socket_nbd_write_hello( int fd, off64_t out_size, uint32_t out_flags )
|
||||
return 1;
|
||||
}
|
||||
|
||||
void fill_request(struct nbd_request *request, uint16_t type, uint16_t flags, uint64_t from, uint32_t len)
|
||||
void fill_request(struct nbd_request_raw *request_raw, uint16_t type, uint16_t flags, uint64_t from, uint32_t len)
|
||||
{
|
||||
request->magic = htobe32(REQUEST_MAGIC);
|
||||
request->type = htobe16(type);
|
||||
request->flags = htobe16(flags);
|
||||
request->handle.w = (((uint64_t)rand()) << 32) | ((uint64_t)rand());
|
||||
request->from = htobe64(from);
|
||||
request->len = htobe32(len);
|
||||
request_raw->magic = htobe32(REQUEST_MAGIC);
|
||||
request_raw->type = htobe16(type);
|
||||
request_raw->flags = htobe16(flags);
|
||||
request_raw->handle.w = (((uint64_t)rand()) << 32) | ((uint64_t)rand());
|
||||
request_raw->from = htobe64(from);
|
||||
request_raw->len = htobe32(len);
|
||||
}
|
||||
|
||||
void read_reply(int fd, struct nbd_request *request, struct nbd_reply *reply)
|
||||
@@ -156,14 +156,17 @@ void wait_for_data( int fd, int timeout_secs )
|
||||
|
||||
void socket_nbd_read(int fd, uint64_t from, uint32_t len, int out_fd, void* out_buf, int timeout_secs)
|
||||
{
|
||||
struct nbd_request request;
|
||||
struct nbd_reply reply;
|
||||
struct nbd_request_raw request_raw;
|
||||
struct nbd_request request;
|
||||
struct nbd_reply reply;
|
||||
|
||||
fill_request(&request, REQUEST_READ, 0, from, len);
|
||||
FATAL_IF_NEGATIVE(writeloop(fd, &request, sizeof(request)),
|
||||
fill_request(&request_raw, REQUEST_READ, 0, from, len);
|
||||
FATAL_IF_NEGATIVE(writeloop(fd, &request_raw, sizeof(request)),
|
||||
"Couldn't write request");
|
||||
|
||||
|
||||
wait_for_data( fd, timeout_secs );
|
||||
nbd_r2h_request( &request_raw, &request );
|
||||
read_reply(fd, &request, &reply);
|
||||
|
||||
if (out_buf) {
|
||||
@@ -180,11 +183,12 @@ void socket_nbd_read(int fd, uint64_t from, uint32_t len, int out_fd, void* out_
|
||||
|
||||
void socket_nbd_write(int fd, uint64_t from, uint32_t len, int in_fd, void* in_buf, int timeout_secs)
|
||||
{
|
||||
struct nbd_request request;
|
||||
struct nbd_reply reply;
|
||||
struct nbd_request_raw request_raw;
|
||||
struct nbd_request request;
|
||||
struct nbd_reply reply;
|
||||
|
||||
fill_request(&request, REQUEST_WRITE, 0, from, len);
|
||||
ERROR_IF_NEGATIVE(writeloop(fd, &request, sizeof(request)),
|
||||
fill_request(&request_raw, REQUEST_WRITE, 0, from, len);
|
||||
ERROR_IF_NEGATIVE(writeloop(fd, &request_raw, sizeof(request_raw)),
|
||||
"Couldn't write request");
|
||||
|
||||
if (in_buf) {
|
||||
@@ -199,6 +203,7 @@ void socket_nbd_write(int fd, uint64_t from, uint32_t len, int in_fd, void* in_b
|
||||
}
|
||||
|
||||
wait_for_data( fd, timeout_secs );
|
||||
nbd_r2h_request( &request_raw, &request );
|
||||
read_reply(fd, &request, &reply);
|
||||
}
|
||||
|
||||
@@ -206,13 +211,13 @@ void socket_nbd_write(int fd, uint64_t from, uint32_t len, int in_fd, void* in_b
|
||||
int socket_nbd_disconnect( int fd )
|
||||
{
|
||||
int success = 1;
|
||||
struct nbd_request request;
|
||||
struct nbd_request_raw request_raw;
|
||||
|
||||
fill_request( &request, REQUEST_DISCONNECT, 0, 0, 0 );
|
||||
fill_request( &request_raw, REQUEST_DISCONNECT, 0, 0, 0 );
|
||||
/* FIXME: This shouldn't be a FATAL error. We should just drop
|
||||
* the mirror without affecting the main server.
|
||||
*/
|
||||
FATAL_IF_NEGATIVE( writeloop( fd, &request, sizeof( request ) ),
|
||||
FATAL_IF_NEGATIVE( writeloop( fd, &request_raw, sizeof( request_raw ) ),
|
||||
"Failed to write the disconnect request." );
|
||||
return success;
|
||||
}
|
||||
|
Reference in New Issue
Block a user