mirror of
https://github.com/versity/scoutfs.git
synced 2026-01-09 05:13:18 +00:00
scoutfs: remove struct scoutfs_log_trees_val
The log_trees structs store the data that is used by client commits. The primary struct is communicated over the wire so it includes the rid and nr that identify the log. The _val struct was stored in btree item values and was missing the rid and nr because those were stored in the item's key. It's madness to duplicate the entire struct just to shave off those two fields. We can remove the _val struct and store the main struct in item values, including the rid and nr. Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
@@ -1122,7 +1122,7 @@ int scoutfs_alloc_foreach(struct super_block *sb,
|
||||
struct scoutfs_btree_ref refs[2] = {{0,}};
|
||||
struct scoutfs_super_block *super = NULL;
|
||||
struct scoutfs_srch_compact *sc;
|
||||
struct scoutfs_log_trees_val ltv;
|
||||
struct scoutfs_log_trees lt;
|
||||
SCOUTFS_BTREE_ITEM_REF(iref);
|
||||
struct scoutfs_key key;
|
||||
int ret;
|
||||
@@ -1169,9 +1169,9 @@ retry:
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
if (iref.val_len == sizeof(ltv)) {
|
||||
if (iref.val_len == sizeof(lt)) {
|
||||
key = *iref.key;
|
||||
memcpy(<v, iref.val, sizeof(ltv));
|
||||
memcpy(<, iref.val, sizeof(lt));
|
||||
} else {
|
||||
ret = -EIO;
|
||||
}
|
||||
@@ -1181,16 +1181,16 @@ retry:
|
||||
|
||||
ret = cb(sb, arg, SCOUTFS_ALLOC_OWNER_MOUNT,
|
||||
le64_to_cpu(key.sklt_rid), true, true,
|
||||
le64_to_cpu(ltv.meta_avail.total_nr)) ?:
|
||||
le64_to_cpu(lt.meta_avail.total_nr)) ?:
|
||||
cb(sb, arg, SCOUTFS_ALLOC_OWNER_MOUNT,
|
||||
le64_to_cpu(key.sklt_rid), true, false,
|
||||
le64_to_cpu(ltv.meta_freed.total_nr)) ?:
|
||||
le64_to_cpu(lt.meta_freed.total_nr)) ?:
|
||||
cb(sb, arg, SCOUTFS_ALLOC_OWNER_MOUNT,
|
||||
le64_to_cpu(key.sklt_rid), false, true,
|
||||
le64_to_cpu(ltv.data_avail.total_len)) ?:
|
||||
le64_to_cpu(lt.data_avail.total_len)) ?:
|
||||
cb(sb, arg, SCOUTFS_ALLOC_OWNER_MOUNT,
|
||||
le64_to_cpu(key.sklt_rid), false, false,
|
||||
le64_to_cpu(ltv.data_freed.total_len));
|
||||
le64_to_cpu(lt.data_freed.total_len));
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ int scoutfs_forest_next_hint(struct super_block *sb, struct scoutfs_key *key,
|
||||
DECLARE_STALE_TRACKING_SUPER_REFS(prev_refs, refs);
|
||||
struct scoutfs_net_roots roots;
|
||||
struct scoutfs_btree_root item_root;
|
||||
struct scoutfs_log_trees_val *ltv;
|
||||
struct scoutfs_log_trees *lt;
|
||||
SCOUTFS_BTREE_ITEM_REF(iref);
|
||||
struct scoutfs_key found;
|
||||
struct scoutfs_key ltk;
|
||||
@@ -175,11 +175,11 @@ retry:
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
if (iref.val_len == sizeof(*ltv)) {
|
||||
if (iref.val_len == sizeof(*lt)) {
|
||||
ltk = *iref.key;
|
||||
scoutfs_key_inc(<k);
|
||||
ltv = iref.val;
|
||||
item_root = ltv->item_root;
|
||||
lt = iref.val;
|
||||
item_root = lt->item_root;
|
||||
} else {
|
||||
ret = -EIO;
|
||||
}
|
||||
@@ -267,7 +267,7 @@ int scoutfs_forest_read_items(struct super_block *sb,
|
||||
.cb = cb,
|
||||
.cb_arg = arg,
|
||||
};
|
||||
struct scoutfs_log_trees_val ltv;
|
||||
struct scoutfs_log_trees lt;
|
||||
struct scoutfs_net_roots roots;
|
||||
struct scoutfs_bloom_block *bb;
|
||||
struct forest_bloom_nrs bloom;
|
||||
@@ -305,9 +305,9 @@ retry:
|
||||
for (;; scoutfs_key_inc(<k)) {
|
||||
ret = scoutfs_btree_next(sb, &roots.logs_root, <k, &iref);
|
||||
if (ret == 0) {
|
||||
if (iref.val_len == sizeof(ltv)) {
|
||||
if (iref.val_len == sizeof(lt)) {
|
||||
ltk = *iref.key;
|
||||
memcpy(<v, iref.val, sizeof(ltv));
|
||||
memcpy(<, iref.val, sizeof(lt));
|
||||
} else {
|
||||
ret = -EIO;
|
||||
}
|
||||
@@ -319,10 +319,10 @@ retry:
|
||||
goto out; /* including stale */
|
||||
}
|
||||
|
||||
if (ltv.bloom_ref.blkno == 0)
|
||||
if (lt.bloom_ref.blkno == 0)
|
||||
continue;
|
||||
|
||||
bl = read_bloom_ref(sb, <v.bloom_ref);
|
||||
bl = read_bloom_ref(sb, <.bloom_ref);
|
||||
if (IS_ERR(bl)) {
|
||||
ret = PTR_ERR(bl);
|
||||
goto out;
|
||||
@@ -344,7 +344,7 @@ retry:
|
||||
|
||||
scoutfs_inc_counter(sb, forest_bloom_pass);
|
||||
|
||||
ret = scoutfs_btree_read_items(sb, <v.item_root, key, start,
|
||||
ret = scoutfs_btree_read_items(sb, <.item_root, key, start,
|
||||
end, forest_read_items, &rid);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
@@ -430,16 +430,6 @@ struct scoutfs_log_trees {
|
||||
__le64 nr;
|
||||
};
|
||||
|
||||
struct scoutfs_log_trees_val {
|
||||
struct scoutfs_alloc_list_head meta_avail;
|
||||
struct scoutfs_alloc_list_head meta_freed;
|
||||
struct scoutfs_btree_root item_root;
|
||||
struct scoutfs_btree_ref bloom_ref;
|
||||
struct scoutfs_alloc_root data_avail;
|
||||
struct scoutfs_alloc_root data_freed;
|
||||
struct scoutfs_srch_file srch_file;
|
||||
};
|
||||
|
||||
struct scoutfs_log_item_value {
|
||||
__le64 vers;
|
||||
__u8 flags;
|
||||
|
||||
@@ -397,7 +397,6 @@ static int server_get_log_trees(struct super_block *sb,
|
||||
u64 rid = scoutfs_net_client_rid(conn);
|
||||
DECLARE_SERVER_INFO(sb, server);
|
||||
SCOUTFS_BTREE_ITEM_REF(iref);
|
||||
struct scoutfs_log_trees_val ltv;
|
||||
struct scoutfs_log_trees lt;
|
||||
struct scoutfs_key key;
|
||||
int ret;
|
||||
@@ -419,9 +418,9 @@ static int server_get_log_trees(struct super_block *sb,
|
||||
if (ret < 0 && ret != -ENOENT)
|
||||
goto unlock;
|
||||
if (ret == 0) {
|
||||
if (iref.val_len == sizeof(struct scoutfs_log_trees_val)) {
|
||||
if (iref.val_len == sizeof(struct scoutfs_log_trees)) {
|
||||
key = *iref.key;
|
||||
memcpy(<v, iref.val, iref.val_len);
|
||||
memcpy(<, iref.val, iref.val_len);
|
||||
if (le64_to_cpu(key.sklt_rid) != rid)
|
||||
ret = -ENOENT;
|
||||
} else {
|
||||
@@ -436,20 +435,22 @@ static int server_get_log_trees(struct super_block *sb,
|
||||
if (ret == -ENOENT) {
|
||||
key.sklt_rid = cpu_to_le64(rid);
|
||||
key.sklt_nr = cpu_to_le64(1);
|
||||
memset(<v, 0, sizeof(ltv));
|
||||
memset(<, 0, sizeof(lt));
|
||||
lt.rid = key.sklt_rid;
|
||||
lt.nr = key.sklt_nr;
|
||||
}
|
||||
|
||||
/* return freed to server for emptying, refill avail */
|
||||
mutex_lock(&server->alloc_mutex);
|
||||
ret = scoutfs_alloc_splice_list(sb, &server->alloc, &server->wri,
|
||||
server->other_freed,
|
||||
<v.meta_freed) ?:
|
||||
alloc_move_empty(sb, &super->data_alloc, <v.data_freed) ?:
|
||||
<.meta_freed) ?:
|
||||
alloc_move_empty(sb, &super->data_alloc, <.data_freed) ?:
|
||||
scoutfs_alloc_fill_list(sb, &server->alloc, &server->wri,
|
||||
<v.meta_avail, server->meta_avail,
|
||||
<.meta_avail, server->meta_avail,
|
||||
SCOUTFS_SERVER_META_FILL_LO,
|
||||
SCOUTFS_SERVER_META_FILL_TARGET) ?:
|
||||
alloc_move_refill(sb, <v.data_avail, &super->data_alloc,
|
||||
alloc_move_refill(sb, <.data_avail, &super->data_alloc,
|
||||
SCOUTFS_SERVER_DATA_FILL_LO,
|
||||
SCOUTFS_SERVER_DATA_FILL_TARGET);
|
||||
mutex_unlock(&server->alloc_mutex);
|
||||
@@ -458,23 +459,11 @@ static int server_get_log_trees(struct super_block *sb,
|
||||
|
||||
/* update client's log tree's item */
|
||||
ret = scoutfs_btree_force(sb, &server->alloc, &server->wri,
|
||||
&super->logs_root, &key, <v, sizeof(ltv));
|
||||
&super->logs_root, &key, <, sizeof(lt));
|
||||
unlock:
|
||||
mutex_unlock(&server->logs_mutex);
|
||||
|
||||
ret = scoutfs_server_apply_commit(sb, ret);
|
||||
if (ret == 0) {
|
||||
lt.meta_avail = ltv.meta_avail;
|
||||
lt.meta_freed = ltv.meta_freed;
|
||||
lt.item_root = ltv.item_root;
|
||||
lt.bloom_ref = ltv.bloom_ref;
|
||||
lt.data_avail = ltv.data_avail;
|
||||
lt.data_freed = ltv.data_freed;
|
||||
lt.srch_file = ltv.srch_file;
|
||||
lt.rid = key.sklt_rid;
|
||||
lt.nr = key.sklt_nr;
|
||||
}
|
||||
|
||||
out:
|
||||
WARN_ON_ONCE(ret < 0);
|
||||
return scoutfs_net_response(sb, conn, cmd, id, ret, <, sizeof(lt));
|
||||
@@ -493,8 +482,7 @@ static int server_commit_log_trees(struct super_block *sb,
|
||||
struct scoutfs_super_block *super = &SCOUTFS_SB(sb)->super;
|
||||
DECLARE_SERVER_INFO(sb, server);
|
||||
SCOUTFS_BTREE_ITEM_REF(iref);
|
||||
struct scoutfs_log_trees_val ltv;
|
||||
struct scoutfs_log_trees *lt;
|
||||
struct scoutfs_log_trees lt;
|
||||
struct scoutfs_key key;
|
||||
int ret;
|
||||
|
||||
@@ -502,7 +490,9 @@ static int server_commit_log_trees(struct super_block *sb,
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
lt = arg;
|
||||
|
||||
/* don't modify the caller's log_trees */
|
||||
memcpy(<, arg, sizeof(struct scoutfs_log_trees));
|
||||
|
||||
ret = scoutfs_server_hold_commit(sb);
|
||||
if (ret < 0) {
|
||||
@@ -513,46 +503,28 @@ static int server_commit_log_trees(struct super_block *sb,
|
||||
mutex_lock(&server->logs_mutex);
|
||||
|
||||
/* find the client's existing item */
|
||||
scoutfs_key_init_log_trees(&key, le64_to_cpu(lt->rid),
|
||||
le64_to_cpu(lt->nr));
|
||||
scoutfs_key_init_log_trees(&key, le64_to_cpu(lt.rid),
|
||||
le64_to_cpu(lt.nr));
|
||||
ret = scoutfs_btree_lookup(sb, &super->logs_root, &key, &iref);
|
||||
if (ret < 0 && ret != -ENOENT) {
|
||||
if (ret < 0) {
|
||||
scoutfs_err(sb, "server error finding client logs: %d", ret);
|
||||
goto unlock;
|
||||
}
|
||||
if (ret == 0) {
|
||||
if (iref.val_len == sizeof(struct scoutfs_log_trees_val)) {
|
||||
memcpy(<v, iref.val, iref.val_len);
|
||||
} else {
|
||||
ret = -EIO;
|
||||
scoutfs_err(sb, "server error, invalid log item: %d",
|
||||
ret);
|
||||
}
|
||||
if (ret == 0)
|
||||
scoutfs_btree_put_iref(&iref);
|
||||
if (ret < 0)
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
/* try to rotate the srch log when big enough */
|
||||
mutex_lock(&server->srch_mutex);
|
||||
ret = scoutfs_srch_rotate_log(sb, &server->alloc, &server->wri,
|
||||
&super->srch_root, <->srch_file);
|
||||
&super->srch_root, <.srch_file);
|
||||
mutex_unlock(&server->srch_mutex);
|
||||
if (ret < 0) {
|
||||
scoutfs_err(sb, "server error, rotating srch log: %d", ret);
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
ltv.meta_avail = lt->meta_avail;
|
||||
ltv.meta_freed = lt->meta_freed;
|
||||
ltv.data_avail = lt->data_avail;
|
||||
ltv.data_freed = lt->data_freed;
|
||||
ltv.item_root = lt->item_root;
|
||||
ltv.bloom_ref = lt->bloom_ref;
|
||||
ltv.srch_file = lt->srch_file;
|
||||
|
||||
ret = scoutfs_btree_update(sb, &server->alloc, &server->wri,
|
||||
&super->logs_root, &key, <v, sizeof(ltv));
|
||||
&super->logs_root, &key, <, sizeof(lt));
|
||||
if (ret < 0)
|
||||
scoutfs_err(sb, "server error updating client logs: %d", ret);
|
||||
|
||||
@@ -613,7 +585,7 @@ static int reclaim_log_trees(struct super_block *sb, u64 rid)
|
||||
struct scoutfs_super_block *super = &SCOUTFS_SB(sb)->super;
|
||||
DECLARE_SERVER_INFO(sb, server);
|
||||
SCOUTFS_BTREE_ITEM_REF(iref);
|
||||
struct scoutfs_log_trees_val ltv;
|
||||
struct scoutfs_log_trees lt;
|
||||
struct scoutfs_key key;
|
||||
int ret;
|
||||
int err;
|
||||
@@ -624,9 +596,9 @@ static int reclaim_log_trees(struct super_block *sb, u64 rid)
|
||||
scoutfs_key_init_log_trees(&key, rid, 0);
|
||||
ret = scoutfs_btree_next(sb, &super->logs_root, &key, &iref);
|
||||
if (ret == 0) {
|
||||
if (iref.val_len == sizeof(struct scoutfs_log_trees_val)) {
|
||||
if (iref.val_len == sizeof(struct scoutfs_log_trees)) {
|
||||
key = *iref.key;
|
||||
memcpy(<v, iref.val, iref.val_len);
|
||||
memcpy(<, iref.val, iref.val_len);
|
||||
if (le64_to_cpu(key.sklt_rid) != rid)
|
||||
ret = -ENOENT;
|
||||
} else {
|
||||
@@ -648,16 +620,16 @@ static int reclaim_log_trees(struct super_block *sb, u64 rid)
|
||||
mutex_lock(&server->alloc_mutex);
|
||||
ret = scoutfs_alloc_splice_list(sb, &server->alloc, &server->wri,
|
||||
server->other_freed,
|
||||
<v.meta_freed) ?:
|
||||
<.meta_freed) ?:
|
||||
scoutfs_alloc_splice_list(sb, &server->alloc, &server->wri,
|
||||
server->other_freed,
|
||||
<v.meta_avail) ?:
|
||||
alloc_move_empty(sb, &super->data_alloc, <v.data_avail) ?:
|
||||
alloc_move_empty(sb, &super->data_alloc, <v.data_freed);
|
||||
<.meta_avail) ?:
|
||||
alloc_move_empty(sb, &super->data_alloc, <.data_avail) ?:
|
||||
alloc_move_empty(sb, &super->data_alloc, <.data_freed);
|
||||
mutex_unlock(&server->alloc_mutex);
|
||||
|
||||
err = scoutfs_btree_update(sb, &server->alloc, &server->wri,
|
||||
&super->logs_root, &key, <v, sizeof(ltv));
|
||||
&super->logs_root, &key, <, sizeof(lt));
|
||||
BUG_ON(err != 0); /* alloc and log item roots out of sync */
|
||||
|
||||
out:
|
||||
|
||||
@@ -920,7 +920,7 @@ int scoutfs_srch_search_xattrs(struct super_block *sb,
|
||||
struct scoutfs_srch_entry start;
|
||||
struct scoutfs_srch_entry end;
|
||||
struct scoutfs_srch_entry final;
|
||||
struct scoutfs_log_trees_val ltv;
|
||||
struct scoutfs_log_trees lt;
|
||||
struct scoutfs_srch_file sfl;
|
||||
SCOUTFS_BTREE_ITEM_REF(iref);
|
||||
struct scoutfs_key key;
|
||||
@@ -992,10 +992,10 @@ retry:
|
||||
if (ret == -ENOENT)
|
||||
break;
|
||||
if (ret == 0) {
|
||||
if (iref.val_len == sizeof(ltv)) {
|
||||
if (iref.val_len == sizeof(lt)) {
|
||||
key = *iref.key;
|
||||
scoutfs_key_inc(&key);
|
||||
memcpy(<v, iref.val, iref.val_len);
|
||||
memcpy(<, iref.val, iref.val_len);
|
||||
} else {
|
||||
ret = -EIO;
|
||||
}
|
||||
@@ -1004,7 +1004,7 @@ retry:
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
ret = search_file(sb, SCOUTFS_SRCH_LOG_TYPE, <v.srch_file,
|
||||
ret = search_file(sb, SCOUTFS_SRCH_LOG_TYPE, <.srch_file,
|
||||
sroot, &start, &end, limit);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
Reference in New Issue
Block a user