This commit is contained in:
2025-11-09 16:20:50 +01:00
parent 8d56a32bd1
commit 3d1368938b
2 changed files with 24 additions and 20 deletions
+9 -5
View File
@@ -219,10 +219,10 @@ alloc_operation(TinyDFS *tdfs, OperationType type, int off, void *ptr, int len)
if (tdfs->num_operations == MAX_OPERATIONS) if (tdfs->num_operations == MAX_OPERATIONS)
return -1; return -1;
Operation *o = tdfs->operations; Operation *o = tdfs->operations;
while (o - tdfs->operations < MAX_OPERATIONS && o->type != OPERATION_TYPE_FREE) while (o->type != OPERATION_TYPE_FREE) {
o++; o++;
if (o - tdfs->operations >= MAX_OPERATIONS) assert(o < tdfs->operations + MAX_OPERATIONS);
return -1; }
o->type = type; o->type = type;
o->ptr = ptr; o->ptr = ptr;
o->off = off; o->off = off;
@@ -302,8 +302,10 @@ static int get_chunk_server(TinyDFS *tdfs, Address *addrs, int num_addrs, ByteQu
// Find free slot // Find free slot
found = 0; found = 0;
while (tdfs->chunk_servers[found].used) while (tdfs->chunk_servers[found].used) {
found++; found++;
assert(found < MAX_CHUNK_SERVERS);
}
if (tcp_connect(&tdfs->tcp, addrs[0], found, output) < 0) if (tcp_connect(&tdfs->tcp, addrs[0], found, output) < 0)
return -1; return -1;
@@ -1826,8 +1828,10 @@ int tinydfs_process_events(TinyDFS *tdfs, void **contexts, struct pollfd *polled
tdfs->chunk_servers[tag].current_addr_idx++; tdfs->chunk_servers[tag].current_addr_idx++;
} }
if (started) if (!started) {
reqs = &tdfs->chunk_servers[tag].reqs; reqs = &tdfs->chunk_servers[tag].reqs;
tdfs->chunk_servers[tag].used = false;
}
} }
} }
+15 -15
View File
@@ -75,52 +75,52 @@ int simulation_client_step(SimulationClient *client, void **contexts,
case TINYDFS_RESULT_CREATE_ERROR: case TINYDFS_RESULT_CREATE_ERROR:
assert(pending.type == PENDING_OPERATION_CREATE); assert(pending.type == PENDING_OPERATION_CREATE);
printf("[Client] create error\n"); //printf("[Client] create error\n");
break; break;
case TINYDFS_RESULT_CREATE_SUCCESS: case TINYDFS_RESULT_CREATE_SUCCESS:
assert(pending.type == PENDING_OPERATION_CREATE); assert(pending.type == PENDING_OPERATION_CREATE);
printf("[Client] create success\n"); //printf("[Client] create success\n");
break; break;
case TINYDFS_RESULT_DELETE_ERROR: case TINYDFS_RESULT_DELETE_ERROR:
assert(pending.type == PENDING_OPERATION_DELETE); assert(pending.type == PENDING_OPERATION_DELETE);
printf("[Client] delete error\n"); //printf("[Client] delete error\n");
break; break;
case TINYDFS_RESULT_DELETE_SUCCESS: case TINYDFS_RESULT_DELETE_SUCCESS:
assert(pending.type == PENDING_OPERATION_DELETE); assert(pending.type == PENDING_OPERATION_DELETE);
printf("[Client] delete success\n"); //printf("[Client] delete success\n");
break; break;
case TINYDFS_RESULT_LIST_ERROR: case TINYDFS_RESULT_LIST_ERROR:
assert(pending.type == PENDING_OPERATION_LIST); assert(pending.type == PENDING_OPERATION_LIST);
printf("[Client] list error\n"); //printf("[Client] list error\n");
break; break;
case TINYDFS_RESULT_LIST_SUCCESS: case TINYDFS_RESULT_LIST_SUCCESS:
assert(pending.type == PENDING_OPERATION_LIST); assert(pending.type == PENDING_OPERATION_LIST);
printf("[Client] list success\n"); //printf("[Client] list success\n");
break; break;
case TINYDFS_RESULT_READ_ERROR: case TINYDFS_RESULT_READ_ERROR:
assert(pending.type == PENDING_OPERATION_READ); assert(pending.type == PENDING_OPERATION_READ);
printf("[Client] read error\n"); //printf("[Client] read error\n");
break; break;
case TINYDFS_RESULT_READ_SUCCESS: case TINYDFS_RESULT_READ_SUCCESS:
assert(pending.type == PENDING_OPERATION_READ); assert(pending.type == PENDING_OPERATION_READ);
printf("[Client] read success\n"); //printf("[Client] read success\n");
break; break;
case TINYDFS_RESULT_WRITE_ERROR: case TINYDFS_RESULT_WRITE_ERROR:
assert(pending.type == PENDING_OPERATION_WRITE); assert(pending.type == PENDING_OPERATION_WRITE);
printf("[Client] write error\n"); //printf("[Client] write error\n");
break; break;
case TINYDFS_RESULT_WRITE_SUCCESS: case TINYDFS_RESULT_WRITE_SUCCESS:
assert(pending.type == PENDING_OPERATION_WRITE); assert(pending.type == PENDING_OPERATION_WRITE);
printf("[Client] write success\n"); //printf("[Client] write success\n");
break; break;
} }
free(pending.ptr); free(pending.ptr);
@@ -181,7 +181,7 @@ int simulation_client_step(SimulationClient *client, void **contexts,
entry.is_dir, entry.is_dir,
chunk_size chunk_size
); );
printf("[Client] submit create (path=%s, is_dir=%s, chunk_size=%d)\n", entry.path, entry.is_dir ? "true" : "false", chunk_size); //printf("[Client] submit create (path=%s, is_dir=%s, chunk_size=%d)\n", entry.path, entry.is_dir ? "true" : "false", chunk_size);
break; break;
case PENDING_OPERATION_DELETE: case PENDING_OPERATION_DELETE:
@@ -191,7 +191,7 @@ int simulation_client_step(SimulationClient *client, void **contexts,
entry.path, entry.path,
-1 -1
); );
printf("[Client] submit delete (path=%s)\n", entry.path); //printf("[Client] submit delete (path=%s)\n", entry.path);
break; break;
case PENDING_OPERATION_LIST: case PENDING_OPERATION_LIST:
@@ -201,7 +201,7 @@ int simulation_client_step(SimulationClient *client, void **contexts,
entry.path, entry.path,
-1 -1
); );
printf("[Client] submit list (path=%s)\n", entry.path); //printf("[Client] submit list (path=%s)\n", entry.path);
break; break;
case PENDING_OPERATION_READ: case PENDING_OPERATION_READ:
@@ -217,7 +217,7 @@ int simulation_client_step(SimulationClient *client, void **contexts,
ptr, ptr,
len len
); );
printf("[Client] submit read (path=%s, off=%d, len=%d)\n", entry.path, off, len); //printf("[Client] submit read (path=%s, off=%d, len=%d)\n", entry.path, off, len);
break; break;
case PENDING_OPERATION_WRITE: case PENDING_OPERATION_WRITE:
@@ -235,7 +235,7 @@ int simulation_client_step(SimulationClient *client, void **contexts,
ptr, ptr,
len len
); );
printf("[Client] submit write (path=%s, off=%d, len=%d)\n", entry.path, off, len); //printf("[Client] submit write (path=%s, off=%d, len=%d)\n", entry.path, off, len);
break; break;
} }
if (ret < 0) if (ret < 0)