Skip to content

Commit 7138c79

Browse files
Alexander Aringteigland
authored andcommitted
dlm: disallow different configs nodeid storages
The DLM configfs path has usually a nodeid in it's directory path and again a file to store the nodeid again in a separate storage. It is forced that the user space will set both (the directory name and nodeid file) storage to the same value if it doesn't do that we run in some kind of broken state. This patch will simply represent the file storage to it's upper directory nodeid name. It will force the user now to use a valid unsigned int as nodeid directory name and will ignore all nodeid writes in the nodeid file storage as this will now always represent the upper nodeid directory name. Signed-off-by: Alexander Aring <aahringo@redhat.com> Signed-off-by: David Teigland <teigland@redhat.com>
1 parent b98333c commit 7138c79

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed

fs/dlm/config.c

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
#include "lowcomms.h"
2525

2626
/*
27-
* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid
27+
* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid (refers to <node>)
2828
* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/weight
29-
* /config/dlm/<cluster>/comms/<comm>/nodeid
29+
* /config/dlm/<cluster>/comms/<comm>/nodeid (refers to <comm>)
3030
* /config/dlm/<cluster>/comms/<comm>/local
3131
* /config/dlm/<cluster>/comms/<comm>/addr (write only)
3232
* /config/dlm/<cluster>/comms/<comm>/addr_list (read only)
@@ -517,6 +517,12 @@ static void release_space(struct config_item *i)
517517
static struct config_item *make_comm(struct config_group *g, const char *name)
518518
{
519519
struct dlm_comm *cm;
520+
unsigned int nodeid;
521+
int rv;
522+
523+
rv = kstrtouint(name, 0, &nodeid);
524+
if (rv)
525+
return ERR_PTR(rv);
520526

521527
cm = kzalloc(sizeof(struct dlm_comm), GFP_NOFS);
522528
if (!cm)
@@ -528,7 +534,7 @@ static struct config_item *make_comm(struct config_group *g, const char *name)
528534
if (!cm->seq)
529535
cm->seq = dlm_comm_count++;
530536

531-
cm->nodeid = -1;
537+
cm->nodeid = nodeid;
532538
cm->local = 0;
533539
cm->addr_count = 0;
534540
cm->mark = 0;
@@ -555,16 +561,25 @@ static void release_comm(struct config_item *i)
555561
static struct config_item *make_node(struct config_group *g, const char *name)
556562
{
557563
struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent);
564+
unsigned int nodeid;
558565
struct dlm_node *nd;
566+
uint32_t seq = 0;
567+
int rv;
568+
569+
rv = kstrtouint(name, 0, &nodeid);
570+
if (rv)
571+
return ERR_PTR(rv);
559572

560573
nd = kzalloc(sizeof(struct dlm_node), GFP_NOFS);
561574
if (!nd)
562575
return ERR_PTR(-ENOMEM);
563576

564577
config_item_init_type_name(&nd->item, name, &node_type);
565-
nd->nodeid = -1;
578+
nd->nodeid = nodeid;
566579
nd->weight = 1; /* default weight of 1 if none is set */
567580
nd->new = 1; /* set to 0 once it's been read by dlm_nodeid_list() */
581+
dlm_comm_seq(nodeid, &seq, true);
582+
nd->comm_seq = seq;
568583

569584
mutex_lock(&sp->members_lock);
570585
list_add(&nd->list, &sp->members);
@@ -622,16 +637,19 @@ void dlm_config_exit(void)
622637

623638
static ssize_t comm_nodeid_show(struct config_item *item, char *buf)
624639
{
625-
return sprintf(buf, "%d\n", config_item_to_comm(item)->nodeid);
640+
unsigned int nodeid;
641+
int rv;
642+
643+
rv = kstrtouint(config_item_name(item), 0, &nodeid);
644+
if (WARN_ON(rv))
645+
return rv;
646+
647+
return sprintf(buf, "%u\n", nodeid);
626648
}
627649

628650
static ssize_t comm_nodeid_store(struct config_item *item, const char *buf,
629651
size_t len)
630652
{
631-
int rc = kstrtoint(buf, 0, &config_item_to_comm(item)->nodeid);
632-
633-
if (rc)
634-
return rc;
635653
return len;
636654
}
637655

@@ -772,20 +790,19 @@ static struct configfs_attribute *comm_attrs[] = {
772790

773791
static ssize_t node_nodeid_show(struct config_item *item, char *buf)
774792
{
775-
return sprintf(buf, "%d\n", config_item_to_node(item)->nodeid);
793+
unsigned int nodeid;
794+
int rv;
795+
796+
rv = kstrtouint(config_item_name(item), 0, &nodeid);
797+
if (WARN_ON(rv))
798+
return rv;
799+
800+
return sprintf(buf, "%u\n", nodeid);
776801
}
777802

778803
static ssize_t node_nodeid_store(struct config_item *item, const char *buf,
779804
size_t len)
780805
{
781-
struct dlm_node *nd = config_item_to_node(item);
782-
uint32_t seq = 0;
783-
int rc = kstrtoint(buf, 0, &nd->nodeid);
784-
785-
if (rc)
786-
return rc;
787-
dlm_comm_seq(nd->nodeid, &seq);
788-
nd->comm_seq = seq;
789806
return len;
790807
}
791808

@@ -845,7 +862,7 @@ static struct dlm_comm *get_comm(int nodeid)
845862
if (!comm_list)
846863
return NULL;
847864

848-
mutex_lock(&clusters_root.subsys.su_mutex);
865+
WARN_ON_ONCE(!mutex_is_locked(&clusters_root.subsys.su_mutex));
849866

850867
list_for_each_entry(i, &comm_list->cg_children, ci_entry) {
851868
cm = config_item_to_comm(i);
@@ -856,7 +873,6 @@ static struct dlm_comm *get_comm(int nodeid)
856873
config_item_get(i);
857874
break;
858875
}
859-
mutex_unlock(&clusters_root.subsys.su_mutex);
860876

861877
if (!found)
862878
cm = NULL;
@@ -916,11 +932,20 @@ int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out,
916932
return rv;
917933
}
918934

919-
int dlm_comm_seq(int nodeid, uint32_t *seq)
935+
int dlm_comm_seq(int nodeid, uint32_t *seq, bool locked)
920936
{
921-
struct dlm_comm *cm = get_comm(nodeid);
937+
struct dlm_comm *cm;
938+
939+
if (locked) {
940+
cm = get_comm(nodeid);
941+
} else {
942+
mutex_lock(&clusters_root.subsys.su_mutex);
943+
cm = get_comm(nodeid);
944+
mutex_unlock(&clusters_root.subsys.su_mutex);
945+
}
922946
if (!cm)
923947
return -EEXIST;
948+
924949
*seq = cm->seq;
925950
put_comm(cm);
926951
return 0;

fs/dlm/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int dlm_config_init(void);
5050
void dlm_config_exit(void);
5151
int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out,
5252
int *count_out);
53-
int dlm_comm_seq(int nodeid, uint32_t *seq);
53+
int dlm_comm_seq(int nodeid, uint32_t *seq, bool locked);
5454
int dlm_our_nodeid(void);
5555
int dlm_our_addr(struct sockaddr_storage *addr, int num);
5656

fs/dlm/member.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ static void dlm_lsop_recover_slot(struct dlm_ls *ls, struct dlm_member *memb)
493493
we consider the node to have failed (versus
494494
being removed due to dlm_release_lockspace) */
495495

496-
error = dlm_comm_seq(memb->nodeid, &seq);
496+
error = dlm_comm_seq(memb->nodeid, &seq, false);
497497

498498
if (!error && seq == memb->comm_seq)
499499
return;

0 commit comments

Comments
 (0)