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)
517517static 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)
555561static 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
623638static 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
628650static 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
773791static 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
778803static 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 ;
0 commit comments