Skip to content

Commit

Permalink
rhashtable: Change rhashtable_walk_start to return void
Browse files Browse the repository at this point in the history
Most callers of rhashtable_walk_start don't care about a resize event
which is indicated by a return value of -EAGAIN. So calls to
rhashtable_walk_start are wrapped wih code to ignore -EAGAIN. Something
like this is common:

       ret = rhashtable_walk_start(rhiter);
       if (ret && ret != -EAGAIN)
               goto out;

Since zero and -EAGAIN are the only possible return values from the
function this check is pointless. The condition never evaluates to true.

This patch changes rhashtable_walk_start to return void. This simplifies
code for the callers that ignore -EAGAIN. For the few cases where the
caller cares about the resize event, particularly where the table can be
walked in mulitple parts for netlink or seq file dump, the function
rhashtable_walk_start_check has been added that returns -EAGAIN on a
resize event.

Signed-off-by: Tom Herbert <[email protected]>
Acked-by: Herbert Xu <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Tom Herbert authored and davem330 committed Dec 11, 2017
1 parent a0b586f commit 97a6ec4
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 94 deletions.
6 changes: 1 addition & 5 deletions drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1412,11 +1412,7 @@ bnxt_tc_flow_stats_batch_prep(struct bnxt *bp,
void *flow_node;
int rc, i;

rc = rhashtable_walk_start(iter);
if (rc && rc != -EAGAIN) {
i = 0;
goto done;
}
rhashtable_walk_start(iter);

rc = 0;
for (i = 0; i < BNXT_FLOW_STATS_BATCH_MAX; i++) {
Expand Down
7 changes: 3 additions & 4 deletions drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,7 @@ static void ch_flower_stats_handler(struct work_struct *work)

rhashtable_walk_enter(&adap->flower_tbl, &iter);
do {
flower_entry = ERR_PTR(rhashtable_walk_start(&iter));
if (IS_ERR(flower_entry))
goto walk_stop;
rhashtable_walk_start(&iter);

while ((flower_entry = rhashtable_walk_next(&iter)) &&
!IS_ERR(flower_entry)) {
Expand All @@ -784,8 +782,9 @@ static void ch_flower_stats_handler(struct work_struct *work)
spin_unlock(&flower_entry->lock);
}
}
walk_stop:

rhashtable_walk_stop(&iter);

} while (flower_entry == ERR_PTR(-EAGAIN));
rhashtable_walk_exit(&iter);
mod_timer(&adap->flower_stats_timer, jiffies + STATS_CHECK_PERIOD);
Expand Down
7 changes: 2 additions & 5 deletions fs/gfs2/glock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1549,16 +1549,13 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
rhashtable_walk_enter(&gl_hash_table, &iter);

do {
gl = ERR_PTR(rhashtable_walk_start(&iter));
if (IS_ERR(gl))
goto walk_stop;
rhashtable_walk_start(&iter);

while ((gl = rhashtable_walk_next(&iter)) && !IS_ERR(gl))
if (gl->gl_name.ln_sbd == sdp &&
lockref_get_not_dead(&gl->gl_lockref))
examiner(gl);

walk_stop:
rhashtable_walk_stop(&iter);
} while (cond_resched(), gl == ERR_PTR(-EAGAIN));

Expand Down Expand Up @@ -1947,7 +1944,7 @@ static void *gfs2_glock_seq_start(struct seq_file *seq, loff_t *pos)
loff_t n = *pos;

rhashtable_walk_enter(&gl_hash_table, &gi->hti);
if (rhashtable_walk_start(&gi->hti) != 0)
if (rhashtable_walk_start_check(&gi->hti) != 0)
return NULL;

do {
Expand Down
8 changes: 7 additions & 1 deletion include/linux/rhashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,13 @@ void *rhashtable_insert_slow(struct rhashtable *ht, const void *key,
void rhashtable_walk_enter(struct rhashtable *ht,
struct rhashtable_iter *iter);
void rhashtable_walk_exit(struct rhashtable_iter *iter);
int rhashtable_walk_start(struct rhashtable_iter *iter) __acquires(RCU);
int rhashtable_walk_start_check(struct rhashtable_iter *iter) __acquires(RCU);

static inline void rhashtable_walk_start(struct rhashtable_iter *iter)
{
(void)rhashtable_walk_start_check(iter);
}

void *rhashtable_walk_next(struct rhashtable_iter *iter);
void rhashtable_walk_stop(struct rhashtable_iter *iter) __releases(RCU);

Expand Down
2 changes: 1 addition & 1 deletion include/net/sctp/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ extern struct percpu_counter sctp_sockets_allocated;
int sctp_asconf_mgmt(struct sctp_sock *, struct sctp_sockaddr_entry *);
struct sk_buff *sctp_skb_recv_datagram(struct sock *, int, int, int *);

int sctp_transport_walk_start(struct rhashtable_iter *iter);
void sctp_transport_walk_start(struct rhashtable_iter *iter);
void sctp_transport_walk_stop(struct rhashtable_iter *iter);
struct sctp_transport *sctp_transport_get_next(struct net *net,
struct rhashtable_iter *iter);
Expand Down
10 changes: 7 additions & 3 deletions lib/rhashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ void rhashtable_walk_exit(struct rhashtable_iter *iter)
EXPORT_SYMBOL_GPL(rhashtable_walk_exit);

/**
* rhashtable_walk_start - Start a hash table walk
* rhashtable_walk_start_check - Start a hash table walk
* @iter: Hash table iterator
*
* Start a hash table walk at the current iterator position. Note that we take
Expand All @@ -744,8 +744,12 @@ EXPORT_SYMBOL_GPL(rhashtable_walk_exit);
* Returns -EAGAIN if resize event occured. Note that the iterator
* will rewind back to the beginning and you may use it immediately
* by calling rhashtable_walk_next.
*
* rhashtable_walk_start is defined as an inline variant that returns
* void. This is preferred in cases where the caller would ignore
* resize events and always continue.
*/
int rhashtable_walk_start(struct rhashtable_iter *iter)
int rhashtable_walk_start_check(struct rhashtable_iter *iter)
__acquires(RCU)
{
struct rhashtable *ht = iter->ht;
Expand All @@ -764,7 +768,7 @@ int rhashtable_walk_start(struct rhashtable_iter *iter)

return 0;
}
EXPORT_SYMBOL_GPL(rhashtable_walk_start);
EXPORT_SYMBOL_GPL(rhashtable_walk_start_check);

/**
* rhashtable_walk_next - Return the next object and advance the iterator
Expand Down
6 changes: 1 addition & 5 deletions lib/test_rhashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,7 @@ static void test_bucket_stats(struct rhashtable *ht, unsigned int entries)
return;
}

err = rhashtable_walk_start(&hti);
if (err && err != -EAGAIN) {
pr_warn("Test failed: iterator failed: %d\n", err);
return;
}
rhashtable_walk_start(&hti);

while ((pos = rhashtable_walk_next(&hti))) {
if (PTR_ERR(pos) == -EAGAIN) {
Expand Down
4 changes: 1 addition & 3 deletions net/ipv6/ila/ila_xlat.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,7 @@ static int ila_nl_dump(struct sk_buff *skb, struct netlink_callback *cb)
struct ila_map *ila;
int ret;

ret = rhashtable_walk_start(rhiter);
if (ret && ret != -EAGAIN)
goto done;
rhashtable_walk_start(rhiter);

for (;;) {
ila = rhashtable_walk_next(rhiter);
Expand Down
4 changes: 1 addition & 3 deletions net/ipv6/seg6.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,7 @@ static int seg6_genl_dumphmac(struct sk_buff *skb, struct netlink_callback *cb)
struct seg6_hmac_info *hinfo;
int ret;

ret = rhashtable_walk_start(iter);
if (ret && ret != -EAGAIN)
goto done;
rhashtable_walk_start(iter);

for (;;) {
hinfo = rhashtable_walk_next(iter);
Expand Down
34 changes: 10 additions & 24 deletions net/mac80211/mesh_pathtbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ __mesh_path_lookup_by_idx(struct mesh_table *tbl, int idx)
if (ret)
return NULL;

ret = rhashtable_walk_start(&iter);
if (ret && ret != -EAGAIN)
goto err;
rhashtable_walk_start(&iter);

while ((mpath = rhashtable_walk_next(&iter))) {
if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN)
Expand All @@ -269,7 +267,6 @@ __mesh_path_lookup_by_idx(struct mesh_table *tbl, int idx)
if (i++ == idx)
break;
}
err:
rhashtable_walk_stop(&iter);
rhashtable_walk_exit(&iter);

Expand Down Expand Up @@ -513,9 +510,7 @@ void mesh_plink_broken(struct sta_info *sta)
if (ret)
return;

ret = rhashtable_walk_start(&iter);
if (ret && ret != -EAGAIN)
goto out;
rhashtable_walk_start(&iter);

while ((mpath = rhashtable_walk_next(&iter))) {
if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN)
Expand All @@ -535,7 +530,6 @@ void mesh_plink_broken(struct sta_info *sta)
WLAN_REASON_MESH_PATH_DEST_UNREACHABLE, bcast);
}
}
out:
rhashtable_walk_stop(&iter);
rhashtable_walk_exit(&iter);
}
Expand Down Expand Up @@ -584,9 +578,7 @@ void mesh_path_flush_by_nexthop(struct sta_info *sta)
if (ret)
return;

ret = rhashtable_walk_start(&iter);
if (ret && ret != -EAGAIN)
goto out;
rhashtable_walk_start(&iter);

while ((mpath = rhashtable_walk_next(&iter))) {
if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN)
Expand All @@ -597,7 +589,7 @@ void mesh_path_flush_by_nexthop(struct sta_info *sta)
if (rcu_access_pointer(mpath->next_hop) == sta)
__mesh_path_del(tbl, mpath);
}
out:

rhashtable_walk_stop(&iter);
rhashtable_walk_exit(&iter);
}
Expand All @@ -614,9 +606,7 @@ static void mpp_flush_by_proxy(struct ieee80211_sub_if_data *sdata,
if (ret)
return;

ret = rhashtable_walk_start(&iter);
if (ret && ret != -EAGAIN)
goto out;
rhashtable_walk_start(&iter);

while ((mpath = rhashtable_walk_next(&iter))) {
if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN)
Expand All @@ -627,7 +617,7 @@ static void mpp_flush_by_proxy(struct ieee80211_sub_if_data *sdata,
if (ether_addr_equal(mpath->mpp, proxy))
__mesh_path_del(tbl, mpath);
}
out:

rhashtable_walk_stop(&iter);
rhashtable_walk_exit(&iter);
}
Expand All @@ -642,9 +632,7 @@ static void table_flush_by_iface(struct mesh_table *tbl)
if (ret)
return;

ret = rhashtable_walk_start(&iter);
if (ret && ret != -EAGAIN)
goto out;
rhashtable_walk_start(&iter);

while ((mpath = rhashtable_walk_next(&iter))) {
if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN)
Expand All @@ -653,7 +641,7 @@ static void table_flush_by_iface(struct mesh_table *tbl)
break;
__mesh_path_del(tbl, mpath);
}
out:

rhashtable_walk_stop(&iter);
rhashtable_walk_exit(&iter);
}
Expand Down Expand Up @@ -873,9 +861,7 @@ void mesh_path_tbl_expire(struct ieee80211_sub_if_data *sdata,
if (ret)
return;

ret = rhashtable_walk_start(&iter);
if (ret && ret != -EAGAIN)
goto out;
rhashtable_walk_start(&iter);

while ((mpath = rhashtable_walk_next(&iter))) {
if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN)
Expand All @@ -887,7 +873,7 @@ void mesh_path_tbl_expire(struct ieee80211_sub_if_data *sdata,
time_after(jiffies, mpath->exp_time + MESH_PATH_EXPIRE))
__mesh_path_del(tbl, mpath);
}
out:

rhashtable_walk_stop(&iter);
rhashtable_walk_exit(&iter);
}
Expand Down
10 changes: 2 additions & 8 deletions net/netfilter/nft_set_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,7 @@ static void nft_rhash_walk(const struct nft_ctx *ctx, struct nft_set *set,
if (err)
return;

err = rhashtable_walk_start(&hti);
if (err && err != -EAGAIN) {
iter->err = err;
goto out;
}
rhashtable_walk_start(&hti);

while ((he = rhashtable_walk_next(&hti))) {
if (IS_ERR(he)) {
Expand Down Expand Up @@ -306,9 +302,7 @@ static void nft_rhash_gc(struct work_struct *work)
if (err)
goto schedule;

err = rhashtable_walk_start(&hti);
if (err && err != -EAGAIN)
goto out;
rhashtable_walk_start(&hti);

while ((he = rhashtable_walk_next(&hti))) {
if (IS_ERR(he)) {
Expand Down
5 changes: 3 additions & 2 deletions net/netlink/af_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2478,8 +2478,9 @@ static int netlink_walk_start(struct nl_seq_iter *iter)
return err;
}

err = rhashtable_walk_start(&iter->hti);
return err == -EAGAIN ? 0 : err;
rhashtable_walk_start(&iter->hti);

return 0;
}

static void netlink_walk_stop(struct nl_seq_iter *iter)
Expand Down
8 changes: 2 additions & 6 deletions net/netlink/diag.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@ static int __netlink_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
if (!s_num)
rhashtable_walk_enter(&tbl->hash, hti);

ret = rhashtable_walk_start(hti);
if (ret == -EAGAIN)
ret = 0;
if (ret)
goto stop;
rhashtable_walk_start(hti);

while ((nlsk = rhashtable_walk_next(hti))) {
if (IS_ERR(nlsk)) {
Expand All @@ -146,8 +142,8 @@ static int __netlink_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
}
}

stop:
rhashtable_walk_stop(hti);

if (ret)
goto done;

Expand Down
6 changes: 1 addition & 5 deletions net/sctp/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,8 @@ struct sctp_ht_iter {
static void *sctp_transport_seq_start(struct seq_file *seq, loff_t *pos)
{
struct sctp_ht_iter *iter = seq->private;
int err = sctp_transport_walk_start(&iter->hti);

if (err) {
iter->start_fail = 1;
return ERR_PTR(err);
}
sctp_transport_walk_start(&iter->hti);

iter->start_fail = 0;
return sctp_transport_get_idx(seq_file_net(seq), &iter->hti, *pos);
Expand Down
19 changes: 4 additions & 15 deletions net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -4676,20 +4676,11 @@ int sctp_get_sctp_info(struct sock *sk, struct sctp_association *asoc,
EXPORT_SYMBOL_GPL(sctp_get_sctp_info);

/* use callback to avoid exporting the core structure */
int sctp_transport_walk_start(struct rhashtable_iter *iter)
void sctp_transport_walk_start(struct rhashtable_iter *iter)
{
int err;

rhltable_walk_enter(&sctp_transport_hashtable, iter);

err = rhashtable_walk_start(iter);
if (err && err != -EAGAIN) {
rhashtable_walk_stop(iter);
rhashtable_walk_exit(iter);
return err;
}

return 0;
rhashtable_walk_start(iter);
}

void sctp_transport_walk_stop(struct rhashtable_iter *iter)
Expand Down Expand Up @@ -4780,12 +4771,10 @@ int sctp_for_each_transport(int (*cb)(struct sctp_transport *, void *),
struct net *net, int *pos, void *p) {
struct rhashtable_iter hti;
struct sctp_transport *tsp;
int ret;
int ret = 0;

again:
ret = sctp_transport_walk_start(&hti);
if (ret)
return ret;
sctp_transport_walk_start(&hti);

tsp = sctp_transport_get_idx(net, &hti, *pos + 1);
for (; !IS_ERR_OR_NULL(tsp); tsp = sctp_transport_get_next(net, &hti)) {
Expand Down
Loading

0 comments on commit 97a6ec4

Please sign in to comment.