Compare commits

...

2 Commits

Author SHA1 Message Date
Vitaliy Filippov 3b23cad061 WIP store parent dir for subdirs in inode
Test / test_snapshot_ec (push) Has been skipped Details
Test / test_minsize_1 (push) Has been skipped Details
Test / test_move_reappear (push) Has been skipped Details
Test / test_rm (push) Has been skipped Details
Test / test_snapshot_chain (push) Has been skipped Details
Test / test_snapshot_chain_ec (push) Has been skipped Details
Test / test_snapshot_down (push) Has been skipped Details
Test / test_snapshot_down_ec (push) Has been skipped Details
Test / test_splitbrain (push) Has been skipped Details
Test / test_rebalance_verify (push) Has been skipped Details
Test / test_rebalance_verify_imm (push) Has been skipped Details
Test / test_rebalance_verify_ec (push) Has been skipped Details
Test / test_rebalance_verify_ec_imm (push) Has been skipped Details
Test / test_write (push) Has been skipped Details
Test / test_write_xor (push) Has been skipped Details
Test / test_write_no_same (push) Has been skipped Details
Test / test_heal_pg_size_2 (push) Has been skipped Details
Test / test_heal_ec (push) Has been skipped Details
Test / test_heal_csum_32k_dmj (push) Has been skipped Details
Test / test_heal_csum_32k_dj (push) Has been skipped Details
Test / test_heal_csum_32k (push) Has been skipped Details
Test / test_heal_csum_4k_dmj (push) Has been skipped Details
Test / test_heal_csum_4k_dj (push) Has been skipped Details
Test / test_heal_csum_4k (push) Has been skipped Details
Test / test_scrub (push) Has been skipped Details
Test / test_scrub_zero_osd_2 (push) Has been skipped Details
Test / test_scrub_xor (push) Has been skipped Details
Test / test_scrub_pg_size_3 (push) Has been skipped Details
Test / test_scrub_pg_size_6_pg_minsize_4_osd_count_6_ec (push) Has been skipped Details
Test / test_scrub_ec (push) Has been skipped Details
2024-01-09 02:47:25 +03:00
Vitaliy Filippov e0c16c9aa0 WIP FS readdir
Test / test_snapshot_ec (push) Has been skipped Details
Test / test_minsize_1 (push) Has been skipped Details
Test / test_move_reappear (push) Has been skipped Details
Test / test_rm (push) Has been skipped Details
Test / test_snapshot_chain (push) Has been skipped Details
Test / test_snapshot_chain_ec (push) Has been skipped Details
Test / test_snapshot_down (push) Has been skipped Details
Test / test_snapshot_down_ec (push) Has been skipped Details
Test / test_splitbrain (push) Has been skipped Details
Test / test_rebalance_verify (push) Has been skipped Details
Test / test_rebalance_verify_imm (push) Has been skipped Details
Test / test_rebalance_verify_ec (push) Has been skipped Details
Test / test_rebalance_verify_ec_imm (push) Has been skipped Details
Test / test_write (push) Has been skipped Details
Test / test_write_xor (push) Has been skipped Details
Test / test_write_no_same (push) Has been skipped Details
Test / test_heal_pg_size_2 (push) Has been skipped Details
Test / test_heal_ec (push) Has been skipped Details
Test / test_heal_csum_32k_dmj (push) Has been skipped Details
Test / test_heal_csum_32k_dj (push) Has been skipped Details
Test / test_heal_csum_32k (push) Has been skipped Details
Test / test_heal_csum_4k_dmj (push) Has been skipped Details
Test / test_heal_csum_4k_dj (push) Has been skipped Details
Test / test_heal_csum_4k (push) Has been skipped Details
Test / test_scrub (push) Has been skipped Details
Test / test_scrub_zero_osd_2 (push) Has been skipped Details
Test / test_scrub_xor (push) Has been skipped Details
Test / test_scrub_pg_size_3 (push) Has been skipped Details
Test / test_scrub_pg_size_6_pg_minsize_4_osd_count_6_ec (push) Has been skipped Details
Test / test_scrub_ec (push) Has been skipped Details
2024-01-08 01:42:49 +03:00
1 changed files with 191 additions and 63 deletions

View File

@ -389,7 +389,7 @@ static int nfs3_lookup_proc(void *opaque, rpc_op_t *rop)
auto direntry = json11::Json::parse(value, err);
if (err != "")
{
fprintf(stderr, "Invalid direntry %s: %s\n", kv_direntry_key(dir_ino, filename).c_str(), err.c_str());
fprintf(stderr, "Invalid JSON in direntry %s = %s: %s\n", kv_direntry_key(dir_ino, filename).c_str(), value.c_str(), err.c_str());
*reply = (LOOKUP3res){ .status = NFS3ERR_IO };
rpc_queue_reply(rop);
return;
@ -832,9 +832,13 @@ static void kv_do_create(kv_create_state *st)
return;
}
st->new_id = new_id;
json11::Json direntry = json11::Json::object{ { "ino", st->new_id } };
auto direntry = json11::Json::object{ { "ino", st->new_id } };
if (st->attrobj["type"].uint64_value() == NF3DIR)
{
direntry["type"] = (uint64_t)NF3DIR;
}
st->attrs = std::move(st->attrobj);
st->direntry_text = direntry.dump().c_str();
st->direntry_text = json11::Json(direntry).dump().c_str();
// Set direntry
st->self->parent->db->set(kv_direntry_key(st->dir_ino, st->filename), st->direntry_text, [st](int res)
{
@ -898,8 +902,8 @@ static void kv_do_create(kv_create_state *st)
auto direntry = json11::Json::parse(value, err);
if (err != "")
{
fprintf(stderr, "direntry %s contains invalid JSON: %s, overwriting\n",
kv_direntry_key(st->dir_ino, st->filename).c_str(), value.c_str());
fprintf(stderr, "Invalid JSON in direntry %s = %s: %s, overwriting\n",
kv_direntry_key(st->dir_ino, st->filename).c_str(), value.c_str(), err.c_str());
return true;
}
if (st->exclusive && direntry["verf"].uint64_value() == st->verf)
@ -990,6 +994,7 @@ static int nfs3_mkdir_proc(void *opaque, rpc_op_t *rop)
st->dir_ino = kv_fh_inode(args->where.dir);
st->filename = args->where.name;
st->attrobj["type"] = NF3DIR;
st->attrobj["parent_ino"] = st->dir_ino;
kv_create_setattr(st->attrobj, args->attributes);
st->cb = [st](int res) { kv_create_reply<MKDIR3RES>(st, res); };
kv_do_create(st);
@ -1091,8 +1096,8 @@ resume_1:
st->direntry = json11::Json::parse(st->direntry_text, err);
if (err != "")
{
fprintf(stderr, "direntry %s contains invalid JSON: %s, deleting\n",
kv_direntry_key(st->dir_ino, st->filename).c_str(), st->direntry_text.c_str());
fprintf(stderr, "Invalid JSON in direntry %s = %s: %s, deleting\n",
kv_direntry_key(st->dir_ino, st->filename).c_str(), st->direntry_text.c_str(), err.c_str());
// Just delete direntry and skip inode
}
else
@ -1119,8 +1124,8 @@ resume_2:
st->ientry = json11::Json::parse(st->ientry_text, err);
if (err != "")
{
fprintf(stderr, "inode %s contains invalid JSON: %s, treating as a regular file\n",
kv_inode_key(st->ino).c_str(), st->ientry_text.c_str());
fprintf(stderr, "Invalid JSON in inode %s = %s: %s, treating as a regular file\n",
kv_inode_key(st->ino).c_str(), st->ientry_text.c_str(), err.c_str());
}
// (1-2) Check type
st->type = st->ientry["type"].uint64_value();
@ -1346,6 +1351,8 @@ static void nfs_kv_continue_rename(nfs_kv_rename_state *st, int state)
else if (state == 2) goto resume_2;
else if (state == 3) goto resume_3;
else if (state == 4) goto resume_4;
else if (state == 5) goto resume_5;
else if (state == 6) goto resume_6;
else
{
fprintf("BUG: invalid state in nfs_kv_continue_delete()");
@ -1380,19 +1387,71 @@ resume_2:
if (st->res < 0)
{
auto cb = std::move(st->cb);
cb(res);
cb(st->res);
return;
}
{
std::string err;
st->direntry = json11::Json::parse(st->old_direntry_text, err);
if (err != "")
{
fprintf(stderr, "Invalid JSON in direntry %s = %s: %s\n",
kv_direntry_key(st->old_dir_ino, st->old_name).c_str(),
st->old_direntry_text.c_str(), err.c_str());
}
}
if (st->direntry["type"].uint64_value() == NF3DIR &&
st->direntry["ino"].uint64_value() != 0 &&
st->new_dir_ino != st->old_dir_ino)
{
// Read & check inode
kv_read_inode(st->self, st->direntry["ino"].uint64_value(), [st](int res, uint64_t ino, const std::string & value, json11::Json ientry)
{
st->res = res;
st->ientry_text = value;
st->ientry = ientry;
nfs_kv_continue_rename(3);
});
return;
resume_3:
if (st->res < 0)
{
auto cb = std::move(st->cb);
cb(st->res);
return;
}
// Change parent reference
{
auto ientry_new = st->ientry.object_items();
ientry_new["parent_ino"] = st->new_dir_ino;
st->self->parent->db->set(kv_inode_key(st->direntry["ino"].uint64_value()), json11::Json(ientry_new).dump(), [st](int res)
{
st->res = res;
nfs_kv_continue_rename(st, 4);
}, [st](int res, const std::string & old_value)
{
return old_value == st->ientry_text;
});
}
return;
resume_4:
if (st->res < 0)
{
auto cb = std::move(st->cb);
cb(st->res);
return;
}
}
st->self->parent->db->set(kv_direntry_key(st->new_dir_ino, st->new_name), [st](int res)
{
st->res = res;
nfs_kv_continue_rename(st, 3);
nfs_kv_continue_rename(st, 5);
}, [st](int res, const std::string & old_value)
{
return res == -ENOENT;
});
return;
resume_3:
resume_5:
if (st->res < 0)
{
if (st->res == -EAGAIN)
@ -1401,13 +1460,13 @@ resume_3:
st->self->parent->db->set(kv_direntry_key(st->old_dir_ino, st->old_name), st->old_direntry_text, [st](int res)
{
st->res = res;
nfs_kv_continue_rename(st, 4);
nfs_kv_continue_rename(st, 6);
}, [st](int res, const std::string & old_value)
{
return res == -ENOENT;
});
return;
resume_4:
resume_6:
if (st->res < 0)
{
if (st->res == -EAGAIN)
@ -1427,6 +1486,7 @@ static int nfs3_rename_proc(void *opaque, rpc_op_t *rop)
{
auto st = new nfs_kv_rename_state;
st->self = (nfs_client_t*)opaque;
st->rop = rop;
RENAME3args *args = (RENAME3args*)rop->request;
st->old_dir_ino = kv_fh_inode(args->from.dir);
st->new_dir_ino = kv_fh_inode(args->to.dir);
@ -1462,6 +1522,11 @@ static int nfs3_rename_proc(void *opaque, rpc_op_t *rop)
static int nfs3_link_proc(void *opaque, rpc_op_t *rop)
{
// 1) Find the source file
// 2) If it's a directory - fail with -EISDIR
// 3) Update the inode entry with refcount++
// 5) Create the new direntry with the same inode reference
// Fail and rollback refcount if it already exists
//nfs_client_t *self = (nfs_client_t*)opaque;
//LINK3args *args = (LINK3args*)rop->request;
LINK3res *reply = (LINK3res*)rop->reply;
@ -1471,54 +1536,129 @@ static int nfs3_link_proc(void *opaque, rpc_op_t *rop)
return 0;
}
static void fill_dir_entry(nfs_client_t *self, rpc_op_t *rop,
std::map<std::string, nfs_dir_t>::iterator dir_id_it, struct entryplus3 *entry, bool is_plus)
struct nfs_kv_readdir_state
{
if (dir_id_it == self->parent->dir_info.end())
{
return;
}
entry->fileid = dir_id_it->second.id;
if (is_plus)
{
entry->name_attributes = (post_op_attr){
.attributes_follow = 1,
.attributes = get_dir_attributes(self, dir_id_it->first),
};
entry->name_handle = (post_op_fh3){
.handle_follows = 1,
.handle = xdr_copy_string(rop->xdrs, "S"+base64_encode(sha256(dir_id_it->first))),
};
}
}
nfs_client_t *self = NULL;
rpc_op_t *rop = NULL;
bool is_plus = false;
READDIRPLUS3args args;
uint64_t dir_ino = 0;
std::string prefix;
void *list_handle;
bool eof = false;
int reply_size = 0;
std::vector<entryplus3> entries;
};
static void nfs3_readdir_common(void *opaque, rpc_op_t *rop, bool is_plus)
{
nfs_client_t *self = (nfs_client_t*)opaque;
READDIRPLUS3args plus_args;
READDIRPLUS3args *args = NULL;
auto st = new nfs_kv_rename_state;
st->self = (nfs_client_t*)opaque;
st->rop = rop;
if (is_plus)
args = ((READDIRPLUS3args*)rop->request);
st->args = *((READDIRPLUS3args*)rop->request);
else
{
args = &plus_args;
READDIR3args *in_args = ((READDIR3args*)rop->request);
args->dir = in_args->dir;
args->cookie = in_args->cookie;
*((uint64_t*)args->cookieverf) = *((uint64_t*)in_args->cookieverf);
args->dircount = 512;
args->maxcount = in_args->count;
st->args.dir = in_args->dir;
st->args.cookie = in_args->cookie;
*((uint64_t*)st->args.cookieverf) = *((uint64_t*)in_args->cookieverf);
st->args.dircount = 512;
st->args.maxcount = in_args->count;
}
std::string dirhash = args->dir;
std::string dir;
if (dirhash != "roothandle")
st->dir_ino = kv_fh_inode(st->args.dir);
st->prefix = kv_direntry_key(dir_ino, "");
st->list_handle = self->parent->db->list_start(prefix);
st->eof = true;
// Limit results based on maximum reply size
// Sadly we have to calculate reply size by hand
// reply without entries is 4+4+(dir_attributes ? sizeof(fattr3) : 0)+8+4 bytes
st->reply_size = 20;
if (st->reply_size > st->args.maxcount)
{
auto dir_it = self->parent->dir_by_hash.find(dirhash);
if (dir_it != self->parent->dir_by_hash.end())
dir = dir_it->second;
// Error, too small max reply size
if (is_plus)
{
READDIRPLUS3res *reply = (READDIRPLUS3res*)rop->reply;
*reply = (READDIRPLUS3res){ .status = NFS3ERR_TOOSMALL };
rpc_queue_reply(rop);
}
std::string prefix = dir.size() ? dir+"/" : self->parent->name_prefix;
std::map<std::string, struct entryplus3> entries;
else
{
READDIR3res *reply = (READDIR3res*)rop->reply;
*reply = (READDIR3res){ .status = NFS3ERR_TOOSMALL };
rpc_queue_reply(rop);
}
return;
}
// Add . and ..
if (st->args.cookie == 0)
{
kv_read_inode(st->self, kv_fh_inode(st->args.dir), [st](int res, const std::string & value, json11::Json ientry)
{
});
auto dir_id_it = self->parent->dir_info.find(dir);
fill_dir_entry(self, rop, dir_id_it, &entries["."], is_plus);
auto sl = dir.rfind("/");
if (sl != std::string::npos)
{
auto dir_id_it = self->parent->dir_info.find(dir.substr(0, sl));
fill_dir_entry(self, rop, dir_id_it, &entries[".."], is_plus);
}
}
st->self->parent->db->list_next(st->list_handle, [=](int res, const std::string & key, const std::string & value)
{
if (res == -ENOENT || key.size() > prefix.size() || key.substr(0, prefix.size()) != prefix)
{
self->parent->db->list_close(list_handle);
return;
}
auto direntry = json11::Json::parse(value, err);
if (err != "")
{
fprintf(stderr, "readdir: direntry %s contains invalid JSON: %s, skipping\n",
key.c_str(), value.c_str());
self->parent->db->list_next(list_handle);
return;
}
auto ino = direntry["ino"].uint64_value();
auto name = kv_direntry_filename(key);
auto fh = kv_fh(ino);
// 1 entry3 is (8+4+(filename_len+3)/4*4+8) bytes
// 1 entryplus3 is (8+4+(filename_len+3)/4*4+8
// + 4+(name_attributes ? (sizeof(fattr3) = 84) : 0)
// + 4+(name_handle ? 4+(handle_len+3)/4*4 : 0)) bytes
auto entry_size = 20 + len_pad4(name) + (is_plus ? 8 + 88 + len_pad4(fh.size()) : 0);
if (st->reply_size + entry_size > st->args.maxcount)
{
st->eof = false;
self->parent->db->list_close(list_handle);
return;
}
auto idx = st->entries.size();
st->entries.push_back((entryplus3){});
auto entry = &st->entries[idx];
entry->name = xdr_copy_string(rop->xdrs, name);
entry->fileid = ino;
if (is_plus)
{
st->getattr_queue.push_back(idx);
if (st->getattr_running < self->parent->readdir_getattr_parallel)
{
kv_readdir_getattr_next(st);
}
entry->name_handle = (post_op_fh3){
.handle_follows = 1,
.handle = xdr_copy_string(fh),
};
}
self->parent->db->list_next(list_handle);
});
for (auto & ic: self->parent->cli->st_cli.inode_config)
{
auto & inode_cfg = ic.second;
@ -1540,18 +1680,6 @@ static void nfs3_readdir_common(void *opaque, rpc_op_t *rop, bool is_plus)
// fileid will change when the user creates snapshots
// however, we hope that clients tolerate it well
// Linux does, even though it complains about "fileid changed" in dmesg
entries[subname].fileid = ic.first;
if (is_plus)
{
entries[subname].name_attributes = (post_op_attr){
.attributes_follow = 1,
.attributes = get_file_attributes(self, ic.first),
};
entries[subname].name_handle = (post_op_fh3){
.handle_follows = 1,
.handle = xdr_copy_string(rop->xdrs, "S"+base64_encode(sha256(inode_cfg.name))),
};
}
}
else
{