24
24
#include "lowcomms.h"
25
25
26
26
/*
27
- * /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid
27
+ * /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid (refers to <node>)
28
28
* /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>)
30
30
* /config/dlm/<cluster>/comms/<comm>/local
31
31
* /config/dlm/<cluster>/comms/<comm>/addr (write only)
32
32
* /config/dlm/<cluster>/comms/<comm>/addr_list (read only)
@@ -517,6 +517,12 @@ static void release_space(struct config_item *i)
517
517
static struct config_item * make_comm (struct config_group * g , const char * name )
518
518
{
519
519
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 );
520
526
521
527
cm = kzalloc (sizeof (struct dlm_comm ), GFP_NOFS );
522
528
if (!cm )
@@ -528,7 +534,7 @@ static struct config_item *make_comm(struct config_group *g, const char *name)
528
534
if (!cm -> seq )
529
535
cm -> seq = dlm_comm_count ++ ;
530
536
531
- cm -> nodeid = -1 ;
537
+ cm -> nodeid = nodeid ;
532
538
cm -> local = 0 ;
533
539
cm -> addr_count = 0 ;
534
540
cm -> mark = 0 ;
@@ -555,16 +561,25 @@ static void release_comm(struct config_item *i)
555
561
static struct config_item * make_node (struct config_group * g , const char * name )
556
562
{
557
563
struct dlm_space * sp = config_item_to_space (g -> cg_item .ci_parent );
564
+ unsigned int nodeid ;
558
565
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 );
559
572
560
573
nd = kzalloc (sizeof (struct dlm_node ), GFP_NOFS );
561
574
if (!nd )
562
575
return ERR_PTR (- ENOMEM );
563
576
564
577
config_item_init_type_name (& nd -> item , name , & node_type );
565
- nd -> nodeid = -1 ;
578
+ nd -> nodeid = nodeid ;
566
579
nd -> weight = 1 ; /* default weight of 1 if none is set */
567
580
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 ;
568
583
569
584
mutex_lock (& sp -> members_lock );
570
585
list_add (& nd -> list , & sp -> members );
@@ -622,16 +637,19 @@ void dlm_config_exit(void)
622
637
623
638
static ssize_t comm_nodeid_show (struct config_item * item , char * buf )
624
639
{
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 );
626
648
}
627
649
628
650
static ssize_t comm_nodeid_store (struct config_item * item , const char * buf ,
629
651
size_t len )
630
652
{
631
- int rc = kstrtoint (buf , 0 , & config_item_to_comm (item )-> nodeid );
632
-
633
- if (rc )
634
- return rc ;
635
653
return len ;
636
654
}
637
655
@@ -772,20 +790,19 @@ static struct configfs_attribute *comm_attrs[] = {
772
790
773
791
static ssize_t node_nodeid_show (struct config_item * item , char * buf )
774
792
{
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 );
776
801
}
777
802
778
803
static ssize_t node_nodeid_store (struct config_item * item , const char * buf ,
779
804
size_t len )
780
805
{
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 ;
789
806
return len ;
790
807
}
791
808
@@ -845,7 +862,7 @@ static struct dlm_comm *get_comm(int nodeid)
845
862
if (!comm_list )
846
863
return NULL ;
847
864
848
- mutex_lock ( & clusters_root .subsys .su_mutex );
865
+ WARN_ON_ONCE (! mutex_is_locked ( & clusters_root .subsys .su_mutex ) );
849
866
850
867
list_for_each_entry (i , & comm_list -> cg_children , ci_entry ) {
851
868
cm = config_item_to_comm (i );
@@ -856,7 +873,6 @@ static struct dlm_comm *get_comm(int nodeid)
856
873
config_item_get (i );
857
874
break ;
858
875
}
859
- mutex_unlock (& clusters_root .subsys .su_mutex );
860
876
861
877
if (!found )
862
878
cm = NULL ;
@@ -916,11 +932,20 @@ int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out,
916
932
return rv ;
917
933
}
918
934
919
- int dlm_comm_seq (int nodeid , uint32_t * seq )
935
+ int dlm_comm_seq (int nodeid , uint32_t * seq , bool locked )
920
936
{
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
+ }
922
946
if (!cm )
923
947
return - EEXIST ;
948
+
924
949
* seq = cm -> seq ;
925
950
put_comm (cm );
926
951
return 0 ;
0 commit comments