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)
return -1;
Operation *o = tdfs->operations;
while (o - tdfs->operations < MAX_OPERATIONS && o->type != OPERATION_TYPE_FREE)
while (o->type != OPERATION_TYPE_FREE) {
o++;
if (o - tdfs->operations >= MAX_OPERATIONS)
return -1;
assert(o < tdfs->operations + MAX_OPERATIONS);
}
o->type = type;
o->ptr = ptr;
o->off = off;
@@ -302,8 +302,10 @@ static int get_chunk_server(TinyDFS *tdfs, Address *addrs, int num_addrs, ByteQu
// Find free slot
found = 0;
while (tdfs->chunk_servers[found].used)
while (tdfs->chunk_servers[found].used) {
found++;
assert(found < MAX_CHUNK_SERVERS);
}
if (tcp_connect(&tdfs->tcp, addrs[0], found, output) < 0)
return -1;
@@ -1826,8 +1828,10 @@ int tinydfs_process_events(TinyDFS *tdfs, void **contexts, struct pollfd *polled
tdfs->chunk_servers[tag].current_addr_idx++;
}
if (started)
if (!started) {
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:
assert(pending.type == PENDING_OPERATION_CREATE);
printf("[Client] create error\n");
//printf("[Client] create error\n");
break;
case TINYDFS_RESULT_CREATE_SUCCESS:
assert(pending.type == PENDING_OPERATION_CREATE);
printf("[Client] create success\n");
//printf("[Client] create success\n");
break;
case TINYDFS_RESULT_DELETE_ERROR:
assert(pending.type == PENDING_OPERATION_DELETE);
printf("[Client] delete error\n");
//printf("[Client] delete error\n");
break;
case TINYDFS_RESULT_DELETE_SUCCESS:
assert(pending.type == PENDING_OPERATION_DELETE);
printf("[Client] delete success\n");
//printf("[Client] delete success\n");
break;
case TINYDFS_RESULT_LIST_ERROR:
assert(pending.type == PENDING_OPERATION_LIST);
printf("[Client] list error\n");
//printf("[Client] list error\n");
break;
case TINYDFS_RESULT_LIST_SUCCESS:
assert(pending.type == PENDING_OPERATION_LIST);
printf("[Client] list success\n");
//printf("[Client] list success\n");
break;
case TINYDFS_RESULT_READ_ERROR:
assert(pending.type == PENDING_OPERATION_READ);
printf("[Client] read error\n");
//printf("[Client] read error\n");
break;
case TINYDFS_RESULT_READ_SUCCESS:
assert(pending.type == PENDING_OPERATION_READ);
printf("[Client] read success\n");
//printf("[Client] read success\n");
break;
case TINYDFS_RESULT_WRITE_ERROR:
assert(pending.type == PENDING_OPERATION_WRITE);
printf("[Client] write error\n");
//printf("[Client] write error\n");
break;
case TINYDFS_RESULT_WRITE_SUCCESS:
assert(pending.type == PENDING_OPERATION_WRITE);
printf("[Client] write success\n");
//printf("[Client] write success\n");
break;
}
free(pending.ptr);
@@ -181,7 +181,7 @@ int simulation_client_step(SimulationClient *client, void **contexts,
entry.is_dir,
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;
case PENDING_OPERATION_DELETE:
@@ -191,7 +191,7 @@ int simulation_client_step(SimulationClient *client, void **contexts,
entry.path,
-1
);
printf("[Client] submit delete (path=%s)\n", entry.path);
//printf("[Client] submit delete (path=%s)\n", entry.path);
break;
case PENDING_OPERATION_LIST:
@@ -201,7 +201,7 @@ int simulation_client_step(SimulationClient *client, void **contexts,
entry.path,
-1
);
printf("[Client] submit list (path=%s)\n", entry.path);
//printf("[Client] submit list (path=%s)\n", entry.path);
break;
case PENDING_OPERATION_READ:
@@ -217,7 +217,7 @@ int simulation_client_step(SimulationClient *client, void **contexts,
ptr,
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;
case PENDING_OPERATION_WRITE:
@@ -235,7 +235,7 @@ int simulation_client_step(SimulationClient *client, void **contexts,
ptr,
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;
}
if (ret < 0)