4747#define SC_DEBUG_NAME "sock_containers"
4848#define NST_DEBUG_NAME "send_tracking"
4949#define STATS_DEBUG_NAME "stats"
50+ #define NODES_DEBUG_NAME "connected_nodes"
5051
5152#define SHOW_SOCK_CONTAINERS 0
5253#define SHOW_SOCK_STATS 1
@@ -55,6 +56,7 @@ static struct dentry *o2net_dentry;
5556static struct dentry * sc_dentry ;
5657static struct dentry * nst_dentry ;
5758static struct dentry * stats_dentry ;
59+ static struct dentry * nodes_dentry ;
5860
5961static DEFINE_SPINLOCK (o2net_debug_lock );
6062
@@ -491,53 +493,87 @@ static const struct file_operations sc_seq_fops = {
491493 .release = sc_fop_release ,
492494};
493495
494- int o2net_debugfs_init ( void )
496+ static int o2net_fill_bitmap ( char * buf , int len )
495497{
496- o2net_dentry = debugfs_create_dir (O2NET_DEBUG_DIR , NULL );
497- if (!o2net_dentry ) {
498- mlog_errno (- ENOMEM );
499- goto bail ;
500- }
498+ unsigned long map [BITS_TO_LONGS (O2NM_MAX_NODES )];
499+ int i = -1 , out = 0 ;
501500
502- nst_dentry = debugfs_create_file (NST_DEBUG_NAME , S_IFREG |S_IRUSR ,
503- o2net_dentry , NULL ,
504- & nst_seq_fops );
505- if (!nst_dentry ) {
506- mlog_errno (- ENOMEM );
507- goto bail ;
508- }
501+ o2net_fill_node_map (map , sizeof (map ));
509502
510- sc_dentry = debugfs_create_file (SC_DEBUG_NAME , S_IFREG |S_IRUSR ,
511- o2net_dentry , NULL ,
512- & sc_seq_fops );
513- if (!sc_dentry ) {
514- mlog_errno (- ENOMEM );
515- goto bail ;
516- }
503+ while ((i = find_next_bit (map , O2NM_MAX_NODES , i + 1 )) < O2NM_MAX_NODES )
504+ out += snprintf (buf + out , PAGE_SIZE - out , "%d " , i );
505+ out += snprintf (buf + out , PAGE_SIZE - out , "\n" );
517506
518- stats_dentry = debugfs_create_file (STATS_DEBUG_NAME , S_IFREG |S_IRUSR ,
519- o2net_dentry , NULL ,
520- & stats_seq_fops );
521- if (!stats_dentry ) {
522- mlog_errno (- ENOMEM );
523- goto bail ;
524- }
507+ return out ;
508+ }
509+
510+ static int nodes_fop_open (struct inode * inode , struct file * file )
511+ {
512+ char * buf ;
513+
514+ buf = kmalloc (PAGE_SIZE , GFP_KERNEL );
515+ if (!buf )
516+ return - ENOMEM ;
517+
518+ i_size_write (inode , o2net_fill_bitmap (buf , PAGE_SIZE ));
519+
520+ file -> private_data = buf ;
525521
526522 return 0 ;
527- bail :
528- debugfs_remove (stats_dentry );
529- debugfs_remove (sc_dentry );
530- debugfs_remove (nst_dentry );
531- debugfs_remove (o2net_dentry );
532- return - ENOMEM ;
533523}
534524
525+ static int o2net_debug_release (struct inode * inode , struct file * file )
526+ {
527+ kfree (file -> private_data );
528+ return 0 ;
529+ }
530+
531+ static ssize_t o2net_debug_read (struct file * file , char __user * buf ,
532+ size_t nbytes , loff_t * ppos )
533+ {
534+ return simple_read_from_buffer (buf , nbytes , ppos , file -> private_data ,
535+ i_size_read (file -> f_mapping -> host ));
536+ }
537+
538+ static const struct file_operations nodes_fops = {
539+ .open = nodes_fop_open ,
540+ .release = o2net_debug_release ,
541+ .read = o2net_debug_read ,
542+ .llseek = generic_file_llseek ,
543+ };
544+
535545void o2net_debugfs_exit (void )
536546{
547+ debugfs_remove (nodes_dentry );
537548 debugfs_remove (stats_dentry );
538549 debugfs_remove (sc_dentry );
539550 debugfs_remove (nst_dentry );
540551 debugfs_remove (o2net_dentry );
541552}
542553
554+ int o2net_debugfs_init (void )
555+ {
556+ mode_t mode = S_IFREG |S_IRUSR ;
557+
558+ o2net_dentry = debugfs_create_dir (O2NET_DEBUG_DIR , NULL );
559+ if (o2net_dentry )
560+ nst_dentry = debugfs_create_file (NST_DEBUG_NAME , mode ,
561+ o2net_dentry , NULL , & nst_seq_fops );
562+ if (nst_dentry )
563+ sc_dentry = debugfs_create_file (SC_DEBUG_NAME , mode ,
564+ o2net_dentry , NULL , & sc_seq_fops );
565+ if (sc_dentry )
566+ stats_dentry = debugfs_create_file (STATS_DEBUG_NAME , mode ,
567+ o2net_dentry , NULL , & stats_seq_fops );
568+ if (stats_dentry )
569+ nodes_dentry = debugfs_create_file (NODES_DEBUG_NAME , mode ,
570+ o2net_dentry , NULL , & nodes_fops );
571+ if (nodes_dentry )
572+ return 0 ;
573+
574+ o2net_debugfs_exit ();
575+ mlog_errno (- ENOMEM );
576+ return - ENOMEM ;
577+ }
578+
543579#endif /* CONFIG_DEBUG_FS */
0 commit comments