3

I'm writing a kernel module, that uses a module-wide hashmap to store connections. I want to release all these connections, when the module is unloaded, delete them from the hashmap and then delete the whole map.

I defined the hashmap:

#define CONNECTIONS_HASH_BITS 10
static DEFINE_HASHTABLE(connection_hashtable, CONNECTIONS_HASH_BITS);

add entries with

hash_add_rcu(connection_hashtable, &con->t_hash,
    oat_hash(&con->key, sizeof(struct hash_key)));

and finally want to delete all entries:

struct connection *result = NULL;
struct hlist_node *node;
unsigned int i;

    hash_for_each_rcu(connection_hashtable, i, node, result, t_hash)
    {
        hash_del_rcu(node);
    }

My questions:

  • Can I delete in the for loop hash_for_each_rcu?
  • How do I make this threadsafe?
  • Do I need to call something like free_hash for hashmap? (My guess here is no as it is an array and no kalloc was called, but I'm not that good with c)
  • Bonus: Do you have a good/easy tutorial on RCU in the Linux Kernel?

Thank you

kaidowei
  • 105
  • 1
  • 9

0 Answers0