Skip to content

Commit

Permalink
CA-404370: enable NBD client only after completing handshake
Browse files Browse the repository at this point in the history
Previously the client was being enabled as part of
`tapdisk_nbdserver_newclient_fd_new_fixed` after calling
`tapdisk_nbdserver_new_protocol_handshake`. This erroneously assumed
that protocol handshake was complete by the time that function
returned, which is not the case as it simply adds the fd to an event
for the scheduler. Protocol handshake is only complete when we reach
the end of the `tapdisk_nbdserver_handshake_cb` callback and enabling
the client before this means we have two events registered for the
same fd.

This was causing quicktest to fail after blktap2 was removed and NBD
is used for all control domain access to the I/O datapath.

Signed-off-by: Mark Syms <[email protected]>
  • Loading branch information
MarkSymsCtx committed Jan 20, 2025
1 parent 58eee8d commit 6296684
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions drivers/tapdisk-nbdserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,14 +1029,16 @@ void
tapdisk_nbdserver_handshake_cb(event_id_t id, char mode, void *data)
{
uint32_t cflags = 0;
int tmp_fd;

td_nbdserver_client_t *client = (td_nbdserver_client_t*)data;
td_nbdserver_t *server = client->server;

int rc = recv_fully_or_fail(server->handshake_fd, &cflags, sizeof(cflags));
if(rc < 0) {
ERR("Could not receive client flags");
return;
close(server->handshake_fd);
goto out;
}

cflags = be32toh (cflags);
Expand All @@ -1048,6 +1050,15 @@ tapdisk_nbdserver_handshake_cb(event_id_t id, char mode, void *data)
close(server->handshake_fd);
}

INFO("About to enable client on fd %d", client->client_fd);
if (tapdisk_nbdserver_enable_client(client) < 0) {
ERR("Error enabling client");
tmp_fd = client->client_fd;
tapdisk_nbdserver_free_client(client);
close(tmp_fd);
}

out:
tapdisk_server_unregister_event(id);
}

Expand Down Expand Up @@ -1157,13 +1168,6 @@ tapdisk_nbdserver_newclient_fd_new_fixed(td_nbdserver_t *server, int new_fd)
close(new_fd);
return;
}

INFO("About to enable client on fd %d", client->client_fd);
if (tapdisk_nbdserver_enable_client(client) < 0) {
ERR("Error enabling client");
tapdisk_nbdserver_free_client(client);
close(new_fd);
}
}

static void
Expand Down Expand Up @@ -1402,7 +1406,7 @@ tapdisk_nbdserver_newclient_unix(event_id_t id, char mode, void *data)
return;
}

INFO("server: got connection\n");
INFO("server: got connection fd = %d\n", new_fd);

tapdisk_nbdserver_newclient_fd_new_fixed(server, new_fd);
}
Expand Down

0 comments on commit 6296684

Please sign in to comment.