diff --git a/kmod/src/alloc.c b/kmod/src/alloc.c index a36387b7..8b5ac274 100644 --- a/kmod/src/alloc.c +++ b/kmod/src/alloc.c @@ -1572,12 +1572,10 @@ out: * call the caller's callback. This assumes that the super it's reading * could be stale and will retry if it encounters stale blocks. */ -int scoutfs_alloc_foreach(struct super_block *sb, - scoutfs_alloc_foreach_cb_t cb, void *arg) +int scoutfs_alloc_foreach(struct super_block *sb, scoutfs_alloc_foreach_cb_t cb, void *arg) { struct scoutfs_super_block *super = NULL; - struct scoutfs_block_ref stale_refs[2] = {{0,}}; - struct scoutfs_block_ref refs[2] = {{0,}}; + DECLARE_SAVED_REFS(saved); int ret; super = kmalloc(sizeof(struct scoutfs_super_block), GFP_NOFS); @@ -1586,26 +1584,18 @@ int scoutfs_alloc_foreach(struct super_block *sb, goto out; } -retry: - ret = scoutfs_read_super(sb, super); - if (ret < 0) - goto out; + do { + ret = scoutfs_read_super(sb, super); + if (ret < 0) + goto out; - refs[0] = super->logs_root.ref; - refs[1] = super->srch_root.ref; + ret = scoutfs_alloc_foreach_super(sb, super, cb, arg); + + ret = scoutfs_block_check_stale(sb, ret, &saved, &super->logs_root.ref, + &super->srch_root.ref); + } while (ret == -ESTALE); - ret = scoutfs_alloc_foreach_super(sb, super, cb, arg); out: - if (ret == -ESTALE) { - if (memcmp(&stale_refs, &refs, sizeof(refs)) == 0) { - ret = -EIO; - } else { - BUILD_BUG_ON(sizeof(stale_refs) != sizeof(refs)); - memcpy(stale_refs, refs, sizeof(stale_refs)); - goto retry; - } - } - kfree(super); return ret; } diff --git a/kmod/src/counters.h b/kmod/src/counters.h index f4111feb..378fcdc1 100644 --- a/kmod/src/counters.h +++ b/kmod/src/counters.h @@ -187,8 +187,6 @@ EXPAND_COUNTER(srch_search_retry_empty) \ EXPAND_COUNTER(srch_search_sorted) \ EXPAND_COUNTER(srch_search_sorted_block) \ - EXPAND_COUNTER(srch_search_stale_eio) \ - EXPAND_COUNTER(srch_search_stale_retry) \ EXPAND_COUNTER(srch_search_xattrs) \ EXPAND_COUNTER(srch_read_stale) \ EXPAND_COUNTER(statfs) \ diff --git a/kmod/src/forest.c b/kmod/src/forest.c index 37705c62..062d3713 100644 --- a/kmod/src/forest.c +++ b/kmod/src/forest.c @@ -78,11 +78,6 @@ struct forest_refs { struct scoutfs_block_ref logs_ref; }; -/* initialize some refs that initially aren't equal */ -#define DECLARE_STALE_TRACKING_SUPER_REFS(a, b) \ - struct forest_refs a = {{cpu_to_le64(0),}}; \ - struct forest_refs b = {{cpu_to_le64(1),}} - struct forest_bloom_nrs { unsigned int nrs[SCOUTFS_FOREST_BLOOM_NRS]; }; @@ -136,11 +131,11 @@ static struct scoutfs_block *read_bloom_ref(struct super_block *sb, struct scout int scoutfs_forest_next_hint(struct super_block *sb, struct scoutfs_key *key, struct scoutfs_key *next) { - DECLARE_STALE_TRACKING_SUPER_REFS(prev_refs, refs); struct scoutfs_net_roots roots; struct scoutfs_btree_root item_root; struct scoutfs_log_trees *lt; SCOUTFS_BTREE_ITEM_REF(iref); + DECLARE_SAVED_REFS(saved); struct scoutfs_key found; struct scoutfs_key ltk; bool checked_fs; @@ -155,8 +150,6 @@ retry: goto out; trace_scoutfs_forest_using_roots(sb, &roots.fs_root, &roots.logs_root); - refs.fs_ref = roots.fs_root.ref; - refs.logs_ref = roots.logs_root.ref; scoutfs_key_init_log_trees(<k, 0, 0); checked_fs = false; @@ -212,14 +205,10 @@ retry: } } - if (ret == -ESTALE) { - if (memcmp(&prev_refs, &refs, sizeof(refs)) == 0) - return -EIO; - prev_refs = refs; + ret = scoutfs_block_check_stale(sb, ret, &saved, &roots.fs_root.ref, &roots.logs_root.ref); + if (ret == -ESTALE) goto retry; - } out: - return ret; } diff --git a/kmod/src/srch.c b/kmod/src/srch.c index b23fc6c2..2cb99b4c 100644 --- a/kmod/src/srch.c +++ b/kmod/src/srch.c @@ -861,7 +861,6 @@ int scoutfs_srch_search_xattrs(struct super_block *sb, struct scoutfs_srch_rb_root *sroot, u64 hash, u64 ino, u64 last_ino, bool *done) { - struct scoutfs_net_roots prev_roots; struct scoutfs_net_roots roots; struct scoutfs_srch_entry start; struct scoutfs_srch_entry end; @@ -869,6 +868,7 @@ int scoutfs_srch_search_xattrs(struct super_block *sb, struct scoutfs_log_trees lt; struct scoutfs_srch_file sfl; SCOUTFS_BTREE_ITEM_REF(iref); + DECLARE_SAVED_REFS(saved); struct scoutfs_key key; unsigned long limit = SRCH_LIMIT; int ret; @@ -877,7 +877,6 @@ int scoutfs_srch_search_xattrs(struct super_block *sb, *done = false; srch_init_rb_root(sroot); - memset(&prev_roots, 0, sizeof(prev_roots)); start.hash = cpu_to_le64(hash); start.ino = cpu_to_le64(ino); @@ -892,7 +891,6 @@ retry: ret = scoutfs_client_get_roots(sb, &roots); if (ret) goto out; - memset(&roots.fs_root, 0, sizeof(roots.fs_root)); end = final; @@ -968,16 +966,10 @@ retry: *done = sre_cmp(&end, &final) == 0; ret = 0; out: - if (ret == -ESTALE) { - if (memcmp(&prev_roots, &roots, sizeof(roots)) == 0) { - scoutfs_inc_counter(sb, srch_search_stale_eio); - ret = -EIO; - } else { - scoutfs_inc_counter(sb, srch_search_stale_retry); - prev_roots = roots; - goto retry; - } - } + ret = scoutfs_block_check_stale(sb, ret, &saved, &roots.srch_root.ref, + &roots.logs_root.ref); + if (ret == -ESTALE) + goto retry; return ret; }