@@ -39,10 +39,11 @@ static struct nvme_host *default_host;
3939static void __nvme_free_host (nvme_host_t h );
4040static void __nvme_free_ctrl (nvme_ctrl_t c );
4141static int nvme_subsystem_scan_namespace (nvme_root_t r ,
42- struct nvme_subsystem * s , char * name );
42+ struct nvme_subsystem * s , char * name ,
43+ nvme_scan_filter_t f , void * f_args );
4344static int nvme_init_subsystem (nvme_subsystem_t s , const char * name );
4445static int nvme_scan_subsystem (nvme_root_t r , const char * name ,
45- nvme_scan_filter_t f );
46+ nvme_scan_filter_t f , void * f_args );
4647static int nvme_ctrl_scan_namespace (nvme_root_t r , struct nvme_ctrl * c ,
4748 char * name );
4849static int nvme_ctrl_scan_path (nvme_root_t r , struct nvme_ctrl * c , char * name );
@@ -75,7 +76,7 @@ nvme_host_t nvme_default_host(nvme_root_t r)
7576 return h ;
7677}
7778
78- int nvme_scan_topology (struct nvme_root * r , nvme_scan_filter_t f )
79+ int nvme_scan_topology (struct nvme_root * r , nvme_scan_filter_t f , void * f_args )
7980{
8081 struct dirent * * subsys , * * ctrls ;
8182 int i , num_subsys , num_ctrls , ret ;
@@ -97,7 +98,7 @@ int nvme_scan_topology(struct nvme_root *r, nvme_scan_filter_t f)
9798 ctrls [i ]-> d_name , strerror (errno ));
9899 continue ;
99100 }
100- if ((f ) && !f (c -> s )) {
101+ if ((f ) && !f (NULL , c , NULL , f_args )) {
101102 nvme_msg (r , LOG_DEBUG , "filter out controller %s\n" ,
102103 ctrls [i ]-> d_name );
103104 nvme_free_ctrl (c );
@@ -114,7 +115,7 @@ int nvme_scan_topology(struct nvme_root *r, nvme_scan_filter_t f)
114115 }
115116
116117 for (i = 0 ; i < num_subsys ; i ++ ) {
117- ret = nvme_scan_subsystem (r , subsys [i ]-> d_name , f );
118+ ret = nvme_scan_subsystem (r , subsys [i ]-> d_name , f , f_args );
118119 if (ret < 0 ) {
119120 nvme_msg (r , LOG_DEBUG ,
120121 "failed to scan subsystem %s: %s\n" ,
@@ -172,7 +173,7 @@ nvme_root_t nvme_scan(const char *config_file)
172173{
173174 nvme_root_t r = nvme_create_root (NULL , DEFAULT_LOGLEVEL );
174175
175- nvme_scan_topology (r , NULL );
176+ nvme_scan_topology (r , NULL , NULL );
176177 nvme_read_config (r , config_file );
177178 return r ;
178179}
@@ -266,7 +267,7 @@ void nvme_refresh_topology(nvme_root_t r)
266267
267268 nvme_for_each_host_safe (r , h , _h )
268269 __nvme_free_host (h );
269- nvme_scan_topology (r , NULL );
270+ nvme_scan_topology (r , NULL , NULL );
270271}
271272
272273void nvme_free_tree (nvme_root_t r )
@@ -325,6 +326,16 @@ nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n)
325326 return n ? list_next (& s -> namespaces , n , entry ) : NULL ;
326327}
327328
329+ nvme_path_t nvme_namespace_first_path (nvme_ns_t ns )
330+ {
331+ return list_top (& ns -> paths , struct nvme_path , nentry );
332+ }
333+
334+ nvme_path_t nvme_namespace_next_path (nvme_ns_t ns , nvme_path_t p )
335+ {
336+ return p ? list_next (& ns -> paths , p , nentry ) : NULL ;
337+ }
338+
328339static void __nvme_free_ns (struct nvme_ns * n )
329340{
330341 list_del_init (& n -> entry );
@@ -465,7 +476,8 @@ struct nvme_host *nvme_lookup_host(nvme_root_t r, const char *hostnqn,
465476 return h ;
466477}
467478
468- static int nvme_subsystem_scan_namespaces (nvme_root_t r , nvme_subsystem_t s )
479+ static int nvme_subsystem_scan_namespaces (nvme_root_t r , nvme_subsystem_t s ,
480+ nvme_scan_filter_t f , void * f_args )
469481{
470482 struct dirent * * namespaces ;
471483 int i , num_ns , ret ;
@@ -480,7 +492,7 @@ static int nvme_subsystem_scan_namespaces(nvme_root_t r, nvme_subsystem_t s)
480492
481493 for (i = 0 ; i < num_ns ; i ++ ) {
482494 ret = nvme_subsystem_scan_namespace (r , s ,
483- namespaces [i ]-> d_name );
495+ namespaces [i ]-> d_name , f , f_args );
484496 if (ret < 0 )
485497 nvme_msg (r , LOG_DEBUG ,
486498 "failed to scan namespace %s: %s\n" ,
@@ -517,7 +529,7 @@ static int nvme_init_subsystem(nvme_subsystem_t s, const char *name)
517529}
518530
519531static int nvme_scan_subsystem (struct nvme_root * r , const char * name ,
520- nvme_scan_filter_t f )
532+ nvme_scan_filter_t f , void * f_args )
521533{
522534 struct nvme_subsystem * s = NULL , * _s ;
523535 char * path , * subsysnqn ;
@@ -573,13 +585,14 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
573585 if (!s )
574586 return -1 ;
575587
576- nvme_subsystem_scan_namespaces (r , s );
577-
578- if (f && !f (s )) {
588+ if (f && !f (s , NULL , NULL , f_args )) {
579589 nvme_msg (r , LOG_DEBUG , "filter out subsystem %s\n" , name );
580590 __nvme_free_subsystem (s );
591+ return 0 ;
581592 }
582593
594+ nvme_subsystem_scan_namespaces (r , s , f , f_args );
595+
583596 return 0 ;
584597}
585598
@@ -789,19 +802,6 @@ const char *nvme_ctrl_get_host_iface(nvme_ctrl_t c)
789802 return c -> cfg .host_iface ;
790803}
791804
792- const char * nvme_ctrl_get_ana_state (nvme_ctrl_t c , __u32 nsid )
793- {
794- if (nsid != NVME_NSID_ALL ) {
795- nvme_path_t p ;
796-
797- nvme_ctrl_for_each_path (c , p ) {
798- if (p -> n && p -> n -> nsid == nsid )
799- return p -> ana_state ;
800- }
801- }
802- return NULL ;
803- }
804-
805805struct nvme_fabrics_config * nvme_ctrl_get_config (nvme_ctrl_t c )
806806{
807807 return & c -> cfg ;
@@ -1411,9 +1411,9 @@ void nvme_rescan_ctrl(struct nvme_ctrl *c)
14111411 nvme_root_t r = c -> s && c -> s -> h ? c -> s -> h -> r : NULL ;
14121412 if (!c -> s )
14131413 return ;
1414- nvme_subsystem_scan_namespaces (r , c -> s );
14151414 nvme_ctrl_scan_namespaces (r , c );
14161415 nvme_ctrl_scan_paths (r , c );
1416+ nvme_subsystem_scan_namespaces (r , c -> s , NULL , NULL );
14171417}
14181418
14191419static int nvme_bytes_to_lba (nvme_ns_t n , off_t offset , size_t count ,
@@ -1884,7 +1884,7 @@ static void nvme_subsystem_set_ns_path(nvme_subsystem_t s, nvme_ns_t n)
18841884}
18851885
18861886static int nvme_subsystem_scan_namespace (nvme_root_t r , nvme_subsystem_t s ,
1887- char * name )
1887+ char * name , nvme_scan_filter_t f , void * f_args )
18881888{
18891889 struct nvme_ns * n ;
18901890
@@ -1895,7 +1895,11 @@ static int nvme_subsystem_scan_namespace(nvme_root_t r, nvme_subsystem_t s,
18951895 nvme_msg (r , LOG_DEBUG , "failed to scan namespace %s\n" , name );
18961896 return -1 ;
18971897 }
1898-
1898+ if (f && !f (NULL , NULL , n , f_args )) {
1899+ nvme_msg (r , LOG_DEBUG , "filter out namespace %s\n" , name );
1900+ __nvme_free_ns (n );
1901+ return 0 ;
1902+ }
18991903 n -> s = s ;
19001904 list_add (& s -> namespaces , & n -> entry );
19011905 nvme_subsystem_set_ns_path (s , n );
0 commit comments