]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dlm: fix creating multiple node structures
authorAlexander Aring <aahringo@redhat.com>
Tue, 10 Oct 2023 22:04:44 +0000 (18:04 -0400)
committerDavid Teigland <teigland@redhat.com>
Thu, 12 Oct 2023 20:20:28 +0000 (15:20 -0500)
This patch will lookup existing nodes instead of always creating them
when dlm_midcomms_addr() is called. The idea is here to create midcomms
nodes when user space getting informed that nodes joins the cluster. This
is the case when dlm_midcomms_addr() is called, however it can be called
multiple times by user space to add several address configurations to one
node e.g. when using SCTP. Those multiple times need to be filtered out
and we doing that by looking up if the node exists before. Due configfs
entry it is safe that this function gets only called once at a time.

Fixes: 63e711b08160 ("fs: dlm: create midcomms nodes when configure")
Signed-off-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: David Teigland <teigland@redhat.com>
fs/dlm/midcomms.c

index f641b36a36db0c12a9260766c7c7b4a66012c3fb..455265c6ba53d2e649138a9f04c522720fa7cb35 100644 (file)
@@ -337,13 +337,21 @@ static struct midcomms_node *nodeid2node(int nodeid)
 
 int dlm_midcomms_addr(int nodeid, struct sockaddr_storage *addr, int len)
 {
-       int ret, r = nodeid_hash(nodeid);
+       int ret, idx, r = nodeid_hash(nodeid);
        struct midcomms_node *node;
 
        ret = dlm_lowcomms_addr(nodeid, addr, len);
        if (ret)
                return ret;
 
+       idx = srcu_read_lock(&nodes_srcu);
+       node = __find_node(nodeid, r);
+       if (node) {
+               srcu_read_unlock(&nodes_srcu, idx);
+               return 0;
+       }
+       srcu_read_unlock(&nodes_srcu, idx);
+
        node = kmalloc(sizeof(*node), GFP_NOFS);
        if (!node)
                return -ENOMEM;