Progress
This commit is contained in:
@@ -1659,12 +1659,14 @@ static void process_event_for_write(TinyDFS *tdfs,
|
||||
uint16_t path_len = path.len;
|
||||
|
||||
uint32_t num_chunks = num_upload_results;
|
||||
uint32_t chunk_size = tdfs->operations[opidx].chunk_size;
|
||||
|
||||
message_write(&writer, &path_len, sizeof(path_len));
|
||||
message_write(&writer, path.ptr, path.len);
|
||||
message_write(&writer, &offset, sizeof(offset));
|
||||
message_write(&writer, &length, sizeof(length));
|
||||
message_write(&writer, &num_chunks, sizeof(num_chunks));
|
||||
message_write(&writer, &chunk_size, sizeof(chunk_size));
|
||||
|
||||
for (int i = 0; i < num_upload_results; i++) {
|
||||
|
||||
|
||||
+7
-3
@@ -319,8 +319,9 @@ int file_tree_delete_entity(FileTree *ft, string path)
|
||||
|
||||
int file_tree_write(FileTree *ft, string path,
|
||||
uint64_t off, uint64_t len, uint32_t num_chunks,
|
||||
SHA256 *prev_hashes, SHA256 *hashes,
|
||||
SHA256 *removed_hashes, int *num_removed)
|
||||
uint32_t chunk_size, SHA256 *prev_hashes,
|
||||
SHA256 *hashes, SHA256 *removed_hashes,
|
||||
int *num_removed)
|
||||
{
|
||||
int num_comps;
|
||||
string comps[MAX_COMPS];
|
||||
@@ -339,6 +340,9 @@ int file_tree_write(FileTree *ft, string path,
|
||||
|
||||
File *f = &e->f;
|
||||
|
||||
if (f->chunk_size != chunk_size)
|
||||
return -1; // TODO: error code
|
||||
|
||||
uint64_t first_chunk_index = off / f->chunk_size;
|
||||
uint64_t last_chunk_index = first_chunk_index + (len - 1) / f->chunk_size;
|
||||
|
||||
@@ -363,7 +367,7 @@ int file_tree_write(FileTree *ft, string path,
|
||||
// Verify prev_hashes match
|
||||
for (uint64_t i = first_chunk_index; i <= last_chunk_index; i++)
|
||||
if (memcmp(&f->chunks[i], &prev_hashes[i - first_chunk_index], sizeof(SHA256)))
|
||||
return -1;
|
||||
return -1; // TODO: error code
|
||||
|
||||
// Update chunks
|
||||
for (uint64_t i = first_chunk_index; i <= last_chunk_index; i++)
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ bool file_tree_uses_hash(FileTree *ft, SHA256 hash);
|
||||
int file_tree_list(FileTree *ft, string path, ListItem *items, int max_items);
|
||||
int file_tree_create_entity(FileTree *ft, string path, bool is_dir, uint64_t chunk_size);
|
||||
int file_tree_delete_entity(FileTree *ft, string path);
|
||||
int file_tree_write(FileTree *ft, string path, uint64_t off, uint64_t len, uint32_t num_chunks, SHA256 *prev_hashes, SHA256 *hashes, SHA256 *removed_hashes, int *num_removed);
|
||||
int file_tree_write(FileTree *ft, string path, uint64_t off, uint64_t len, uint32_t num_chunks, uint32_t chunk_size, SHA256 *prev_hashes, SHA256 *hashes, SHA256 *removed_hashes, int *num_removed);
|
||||
int file_tree_read(FileTree *ft, string path, uint64_t off, uint64_t len, uint64_t *chunk_size, SHA256 *hashes, int max_hashes);
|
||||
string file_tree_strerror(int code);
|
||||
|
||||
|
||||
@@ -558,6 +558,10 @@ process_client_write(MetadataServer *state, int conn_idx, ByteView msg)
|
||||
if (!binary_read(&reader, &num_chunks, sizeof(num_chunks)))
|
||||
return -1;
|
||||
|
||||
uint32_t chunk_size;
|
||||
if (!binary_read(&reader, &chunk_size, sizeof(chunk_size)))
|
||||
return -1;
|
||||
|
||||
#define MAX_CHUNKS_PER_WRITE 32
|
||||
|
||||
typedef struct {
|
||||
@@ -628,7 +632,7 @@ process_client_write(MetadataServer *state, int conn_idx, ByteView msg)
|
||||
}
|
||||
|
||||
int ret = file_tree_write(&state->file_tree, path, offset, length,
|
||||
num_chunks, old_hashes, new_hashes, removed_hashes, &num_removed);
|
||||
num_chunks, chunk_size, old_hashes, new_hashes, removed_hashes, &num_removed);
|
||||
|
||||
if (ret < 0) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user