diff --git a/src/cli_common.cpp b/src/cli_common.cpp index 71b465ac..d1915970 100644 --- a/src/cli_common.cpp +++ b/src/cli_common.cpp @@ -153,6 +153,7 @@ void cli_tool_t::loop_and_wait(std::function loop_cb, std: ringloop->unregister_consumer(&looper->consumer); looper->loop_cb = NULL; looper->complete_cb(looper->result); + ringloop->submit(); delete looper; return; } diff --git a/src/nfs_kv_setattr.cpp b/src/nfs_kv_setattr.cpp index e8223836..a1230649 100644 --- a/src/nfs_kv_setattr.cpp +++ b/src/nfs_kv_setattr.cpp @@ -25,6 +25,7 @@ struct nfs_kv_setattr_state static void nfs_kv_continue_setattr(nfs_kv_setattr_state *st, int state) { + // FIXME: NFS client does a lot of setattr calls, so maybe process them asynchronously if (state == 0) {} else if (state == 1) goto resume_1; else if (state == 2) goto resume_2; @@ -50,8 +51,7 @@ resume_1: cb(st->res); return; } - if (st->ientry["type"].string_value() == "link" || - st->ientry["type"].string_value() != "file" && + if (st->ientry["type"].string_value() != "file" && st->ientry["type"].string_value() != "" && !st->set_attrs["size"].is_null()) { diff --git a/src/nfs_kv_write.cpp b/src/nfs_kv_write.cpp index 61d51ad1..8a920f8c 100644 --- a/src/nfs_kv_write.cpp +++ b/src/nfs_kv_write.cpp @@ -151,9 +151,11 @@ static void nfs_do_write(uint64_t ino, uint64_t offset, uint64_t size, std::func static void nfs_do_unshare_write(nfs_kv_write_state *st, int state) { - nfs_do_write(st->ino, 0, st->aligned_size - sizeof(shared_file_header_t), [&](cluster_op_t *op) + uint64_t unshare_size = (st->ientry["size"].uint64_value() + st->self->parent->pool_alignment-1) + & ~(st->self->parent->pool_alignment-1); + nfs_do_write(st->ino, 0, unshare_size, [&](cluster_op_t *op) { - op->iov.push_back(st->aligned_buf + sizeof(shared_file_header_t), st->aligned_size - sizeof(shared_file_header_t)); + op->iov.push_back(st->aligned_buf + sizeof(shared_file_header_t), unshare_size); }, st, state); } @@ -292,6 +294,7 @@ static bool nfs_do_shared_readmodify(nfs_kv_write_state *st, int base_state, int ? sizeof(shared_file_header_t) + ((st->new_size + st->self->parent->pool_alignment-1) & ~(st->self->parent->pool_alignment-1)) : align_shared_size(st->self, st->new_size); st->aligned_buf = (uint8_t*)malloc_or_die(st->aligned_size); + // FIXME do not allocate zeroes if we only need zeroes memset(st->aligned_buf + sizeof(shared_file_header_t), 0, st->offset); memset(st->aligned_buf + sizeof(shared_file_header_t) + st->offset + st->size, 0, st->aligned_size - sizeof(shared_file_header_t) - st->offset - st->size); @@ -319,6 +322,7 @@ resume_0: return false; } } + // FIXME put shared_file_header_t after data to not break alignment *((shared_file_header_t*)st->aligned_buf) = { .magic = SHARED_FILE_MAGIC_V1, .inode = st->ino, @@ -679,7 +683,7 @@ resume_1: st->ientry["shared_alloc"].uint64_value() < sizeof(shared_file_header_t)+st->offset+st->size) { // Either empty, or shared and requires moving into a larger place (redirect-write) - allocate_shared_inode(st, 2, st->new_size); + allocate_shared_inode(st, 2, align_shared_size(st->self, st->new_size)); return; resume_2: if (st->res < 0) @@ -783,7 +787,12 @@ resume_10: nfs_do_unshare_write(st, 11); return; resume_11: - ; + if (st->res < 0) + { + auto cb = std::move(st->cb); + cb(st->res); + return; + } } st->self->parent->db->set(kv_inode_key(st->ino), new_unshared_ientry(st), [st](int res) {