aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-03-20 06:57:04 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-20 16:16:24 -0400
commitb182aa6e967e8272a3ba718a89697f661915be7a (patch)
tree459bde7fdc30914ee8f0df99b7fc03bb0331a1fc /lib
parentfa3773211eb61f2a08ffc399a98af53594ba1509 (diff)
test_rhashtable: Use inlined rhashtable interface
This patch converts test_rhashtable to the inlined rhashtable interface. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/test_rhashtable.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c
index 2bc403d8f9ee..a2ba6adb60a2 100644
--- a/lib/test_rhashtable.c
+++ b/lib/test_rhashtable.c
@@ -38,6 +38,16 @@ struct test_obj {
38 struct rhash_head node; 38 struct rhash_head node;
39}; 39};
40 40
41static const struct rhashtable_params test_rht_params = {
42 .nelem_hint = TEST_HT_SIZE,
43 .head_offset = offsetof(struct test_obj, node),
44 .key_offset = offsetof(struct test_obj, value),
45 .key_len = sizeof(int),
46 .hashfn = jhash,
47 .max_size = 2, /* we expand/shrink manually here */
48 .nulls_base = (3U << RHT_BASE_SHIFT),
49};
50
41static int __init test_rht_lookup(struct rhashtable *ht) 51static int __init test_rht_lookup(struct rhashtable *ht)
42{ 52{
43 unsigned int i; 53 unsigned int i;
@@ -47,7 +57,7 @@ static int __init test_rht_lookup(struct rhashtable *ht)
47 bool expected = !(i % 2); 57 bool expected = !(i % 2);
48 u32 key = i; 58 u32 key = i;
49 59
50 obj = rhashtable_lookup(ht, &key); 60 obj = rhashtable_lookup_fast(ht, &key, test_rht_params);
51 61
52 if (expected && !obj) { 62 if (expected && !obj) {
53 pr_warn("Test failed: Could not find key %u\n", key); 63 pr_warn("Test failed: Could not find key %u\n", key);
@@ -133,7 +143,11 @@ static int __init test_rhashtable(struct rhashtable *ht)
133 obj->ptr = TEST_PTR; 143 obj->ptr = TEST_PTR;
134 obj->value = i * 2; 144 obj->value = i * 2;
135 145
136 rhashtable_insert(ht, &obj->node); 146 err = rhashtable_insert_fast(ht, &obj->node, test_rht_params);
147 if (err) {
148 kfree(obj);
149 goto error;
150 }
137 } 151 }
138 152
139 rcu_read_lock(); 153 rcu_read_lock();
@@ -173,10 +187,10 @@ static int __init test_rhashtable(struct rhashtable *ht)
173 for (i = 0; i < TEST_ENTRIES; i++) { 187 for (i = 0; i < TEST_ENTRIES; i++) {
174 u32 key = i * 2; 188 u32 key = i * 2;
175 189
176 obj = rhashtable_lookup(ht, &key); 190 obj = rhashtable_lookup_fast(ht, &key, test_rht_params);
177 BUG_ON(!obj); 191 BUG_ON(!obj);
178 192
179 rhashtable_remove(ht, &obj->node); 193 rhashtable_remove_fast(ht, &obj->node, test_rht_params);
180 kfree(obj); 194 kfree(obj);
181 } 195 }
182 196
@@ -195,20 +209,11 @@ static struct rhashtable ht;
195 209
196static int __init test_rht_init(void) 210static int __init test_rht_init(void)
197{ 211{
198 struct rhashtable_params params = {
199 .nelem_hint = TEST_HT_SIZE,
200 .head_offset = offsetof(struct test_obj, node),
201 .key_offset = offsetof(struct test_obj, value),
202 .key_len = sizeof(int),
203 .hashfn = jhash,
204 .max_size = 2, /* we expand/shrink manually here */
205 .nulls_base = (3U << RHT_BASE_SHIFT),
206 };
207 int err; 212 int err;
208 213
209 pr_info("Running resizable hashtable tests...\n"); 214 pr_info("Running resizable hashtable tests...\n");
210 215
211 err = rhashtable_init(&ht, &params); 216 err = rhashtable_init(&ht, &test_rht_params);
212 if (err < 0) { 217 if (err < 0) {
213 pr_warn("Test failed: Unable to initialize hashtable: %d\n", 218 pr_warn("Test failed: Unable to initialize hashtable: %d\n",
214 err); 219 err);