This commit is contained in:
2025-11-09 20:36:08 +01:00
parent d13ad3ae6c
commit bab8558511
7 changed files with 25 additions and 18 deletions
+1 -1
View File
@@ -644,7 +644,7 @@ process_client_create_chunk(ChunkServer *state, int conn_idx, ByteView msg)
if (mem == NULL) if (mem == NULL)
return send_error(&state->tcp, conn_idx, false, MESSAGE_TYPE_CREATE_CHUNK_ERROR, S("Out of memory")); return send_error(&state->tcp, conn_idx, false, MESSAGE_TYPE_CREATE_CHUNK_ERROR, S("Out of memory"));
assert(data.len <= chunk_size); assert((uint32_t) data.len <= chunk_size);
assert(target_off + data.len <= chunk_size); assert(target_off + data.len <= chunk_size);
memset(mem, 0, chunk_size); memset(mem, 0, chunk_size);
+10 -8
View File
@@ -1211,11 +1211,11 @@ static void process_event_for_write(TinyDFS *tdfs,
char *src = full_ptr + relative_off; char *src = full_ptr + relative_off;
int off = 0; uint32_t off = 0;
if (i == 0) if (i == 0)
off = full_off % chunk_size; off = full_off % chunk_size;
int len = full_len - relative_off; uint32_t len = full_len - relative_off;
if (len > chunk_size - off) if (len > chunk_size - off)
len = chunk_size - off; len = chunk_size - off;
@@ -1355,15 +1355,15 @@ static void process_event_for_write(TinyDFS *tdfs,
#endif #endif
int old_relative_off = relative_off; int old_relative_off = relative_off;
for (int w = 0; w < num_new_hashes; w++) { for (uint32_t w = 0; w < num_new_hashes; w++) {
char *src = full_ptr + relative_off; char *src = full_ptr + relative_off;
int off = 0; uint32_t off = 0;
if (num_hashes == 0 && w == 0) if (num_hashes == 0 && w == 0)
off = full_off % chunk_size; off = full_off % chunk_size;
int len = full_len - relative_off; uint32_t len = full_len - relative_off;
if (len > chunk_size - off) if (len > chunk_size - off)
len = chunk_size - off; len = chunk_size - off;
@@ -1422,13 +1422,13 @@ static void process_event_for_write(TinyDFS *tdfs,
#endif #endif
int old_relative_off = relative_off; int old_relative_off = relative_off;
for (int w = 0; w < num_new_hashes; w++) { for (uint32_t w = 0; w < num_new_hashes; w++) {
int off = 0; uint32_t off = 0;
if (num_hashes == 0 && w == 0) if (num_hashes == 0 && w == 0)
off = full_off % chunk_size; off = full_off % chunk_size;
int len = full_len - relative_off; uint32_t len = full_len - relative_off;
if (len > chunk_size - off) if (len > chunk_size - off)
len = chunk_size - off; len = chunk_size - off;
@@ -1917,6 +1917,8 @@ int tinydfs_process_events(TinyDFS *tdfs, void **contexts, struct pollfd *polled
void tinydfs_wait(TinyDFS *tdfs, int opidx, TinyDFS_Result *result, int timeout) void tinydfs_wait(TinyDFS *tdfs, int opidx, TinyDFS_Result *result, int timeout)
{ {
// TODO: use the timeout parameter
void *contexts[MAX_CONNS+1]; void *contexts[MAX_CONNS+1];
struct pollfd polled[MAX_CONNS+1]; struct pollfd polled[MAX_CONNS+1];
int num_polled; int num_polled;
+1 -1
View File
@@ -15,7 +15,7 @@ int main(int argc, char **argv)
// TODO: set simulation_should_stop=true on ctrl+C // TODO: set simulation_should_stop=true on ctrl+C
startup_simulation(3); startup_simulation(2);
// Spawn metadata server (leader) // Spawn metadata server (leader)
spawn_simulated_process("--addr 127.0.0.1 --port 8080 --leader"); spawn_simulated_process("--addr 127.0.0.1 --port 8080 --leader");
+5 -5
View File
@@ -155,7 +155,7 @@ void message_dump(FILE *stream, ByteView msg)
} }
fprintf(stream, " path_len: %d\n", path_len); fprintf(stream, " path_len: %d\n", path_len);
char *path = reader.src + reader.cur; char *path = (char*) reader.src + reader.cur;
if (!binary_read(&reader, NULL, path_len)) { if (!binary_read(&reader, NULL, path_len)) {
fprintf(stream, " (incomplete)\n"); fprintf(stream, " (incomplete)\n");
return; return;
@@ -189,7 +189,7 @@ void message_dump(FILE *stream, ByteView msg)
} }
fprintf(stream, " path_len: %d\n", path_len); fprintf(stream, " path_len: %d\n", path_len);
char *path = reader.src + reader.cur; char *path = (char*) reader.src + reader.cur;
if (!binary_read(&reader, NULL, path_len)) { if (!binary_read(&reader, NULL, path_len)) {
fprintf(stream, " (incomplete)\n"); fprintf(stream, " (incomplete)\n");
return; return;
@@ -207,7 +207,7 @@ void message_dump(FILE *stream, ByteView msg)
} }
fprintf(stream, " path_len: %d\n", path_len); fprintf(stream, " path_len: %d\n", path_len);
char *path = reader.src + reader.cur; char *path = (char*) reader.src + reader.cur;
if (!binary_read(&reader, NULL, path_len)) { if (!binary_read(&reader, NULL, path_len)) {
fprintf(stream, " (incomplete)\n"); fprintf(stream, " (incomplete)\n");
return; return;
@@ -225,7 +225,7 @@ void message_dump(FILE *stream, ByteView msg)
} }
fprintf(stream, " path_len: %d\n", path_len); fprintf(stream, " path_len: %d\n", path_len);
char *path = reader.src + reader.cur; char *path = (char*) reader.src + reader.cur;
if (!binary_read(&reader, NULL, path_len)) { if (!binary_read(&reader, NULL, path_len)) {
fprintf(stream, " (incomplete)\n"); fprintf(stream, " (incomplete)\n");
return; return;
@@ -257,7 +257,7 @@ void message_dump(FILE *stream, ByteView msg)
} }
fprintf(stream, " path_len: %d\n", path_len); fprintf(stream, " path_len: %d\n", path_len);
char *path = reader.src + reader.cur; char *path = (char*) reader.src + reader.cur;
if (!binary_read(&reader, NULL, path_len)) { if (!binary_read(&reader, NULL, path_len)) {
fprintf(stream, " (incomplete)\n"); fprintf(stream, " (incomplete)\n");
return; return;
+4 -1
View File
@@ -573,6 +573,9 @@ process_client_write(MetadataServer *state, int conn_idx, ByteView msg)
ChunkWriteResult results[MAX_CHUNKS_PER_WRITE]; ChunkWriteResult results[MAX_CHUNKS_PER_WRITE];
if (num_chunks > MAX_CHUNKS_PER_WRITE)
return -1; // TODO
for (uint32_t i = 0; i < num_chunks; i++) { for (uint32_t i = 0; i < num_chunks; i++) {
SHA256 old_hash; SHA256 old_hash;
@@ -626,7 +629,7 @@ process_client_write(MetadataServer *state, int conn_idx, ByteView msg)
SHA256 old_hashes[MAX_CHUNKS_PER_WRITE]; SHA256 old_hashes[MAX_CHUNKS_PER_WRITE];
SHA256 new_hashes[MAX_CHUNKS_PER_WRITE]; SHA256 new_hashes[MAX_CHUNKS_PER_WRITE];
for (int i = 0; i < num_chunks; i++) { for (uint32_t i = 0; i < num_chunks; i++) {
old_hashes[i] = results[i].old_hash; old_hashes[i] = results[i].old_hash;
new_hashes[i] = results[i].new_hash; new_hashes[i] = results[i].new_hash;
} }
-2
View File
@@ -55,8 +55,6 @@ static int random_in_range(int min, int max)
int simulation_client_step(SimulationClient *client, void **contexts, int simulation_client_step(SimulationClient *client, void **contexts,
struct pollfd *polled, int num_polled, int *timeout) struct pollfd *polled, int num_polled, int *timeout)
{ {
TinyDFS_Result result;
// Process any pending events from the network and get new poll descriptors // Process any pending events from the network and get new poll descriptors
num_polled = tinydfs_process_events(client->tdfs, contexts, polled, num_polled); num_polled = tinydfs_process_events(client->tdfs, contexts, polled, num_polled);
+4
View File
@@ -982,6 +982,10 @@ int mock_getsockopt(SOCKET fd, int level, int optname, void *optval, socklen_t *
int val; int val;
switch (desc->type) { switch (desc->type) {
case DESC_EMPTY:
assert(0);
break;
case DESC_FILE: case DESC_FILE:
SET_SOCKET_ERROR(SOCKET_ERROR_NOTSOCK); SET_SOCKET_ERROR(SOCKET_ERROR_NOTSOCK);
return -1; return -1;