@@ -61,22 +61,6 @@ struct candidate_args {
6161};
6262typedef bool (* ctrl_match_t )(struct nvme_ctrl * c , struct candidate_args * candidate );
6363
64- #define PATH_SYSFS_SLOTS "/sys/bus/pci/slots"
65-
66- static char * nvme_slots_sysfs_dir (void )
67- {
68- char * basepath = getenv ("LIBNVME_SYSFS_PATH" );
69- char * str ;
70-
71- if (!basepath )
72- return strdup (PATH_SYSFS_SLOTS );
73-
74- if (!asprintf (& str , "%s" PATH_SYSFS_SLOTS , basepath ))
75- return NULL ;
76-
77- return str ;
78- }
79-
8064static struct nvme_host * default_host ;
8165
8266static void __nvme_free_host (nvme_host_t h );
@@ -672,10 +656,9 @@ static int nvme_subsystem_scan_namespaces(nvme_root_t r, nvme_subsystem_t s,
672656
673657static int nvme_init_subsystem (nvme_subsystem_t s , const char * name )
674658{
675- _cleanup_free_ char * subsys_dir = nvme_subsys_sysfs_dir ();
676659 char * path ;
677660
678- if (asprintf (& path , "%s/%s" , subsys_dir , name ) < 0 )
661+ if (asprintf (& path , "%s/%s" , nvme_subsys_sysfs_dir () , name ) < 0 )
679662 return -1 ;
680663
681664 s -> model = nvme_get_attr (path , "model" );
@@ -716,12 +699,11 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
716699{
717700 struct nvme_subsystem * s = NULL , * _s ;
718701 _cleanup_free_ char * path = NULL , * subsysnqn = NULL ;
719- _cleanup_free_ char * subsys_dir = nvme_subsys_sysfs_dir ();
720702 nvme_host_t h = NULL ;
721703 int ret ;
722704
723705 nvme_msg (r , LOG_DEBUG , "scan subsystem %s\n" , name );
724- ret = asprintf (& path , "%s/%s" , subsys_dir , name );
706+ ret = asprintf (& path , "%s/%s" , nvme_subsys_sysfs_dir () , name );
725707 if (ret < 0 )
726708 return ret ;
727709
@@ -1703,7 +1685,7 @@ static int nvme_ctrl_scan_namespaces(nvme_root_t r, struct nvme_ctrl *c)
17031685static char * nvme_ctrl_lookup_subsystem_name (nvme_root_t r ,
17041686 const char * ctrl_name )
17051687{
1706- _cleanup_free_ char * subsys_dir = nvme_subsys_sysfs_dir ();
1688+ const char * subsys_dir = nvme_subsys_sysfs_dir ();
17071689 _cleanup_dirents_ struct dirents subsys = {};
17081690 int i ;
17091691
@@ -1730,7 +1712,7 @@ static char *nvme_ctrl_lookup_subsystem_name(nvme_root_t r,
17301712
17311713static char * nvme_ctrl_lookup_phy_slot (nvme_root_t r , const char * address )
17321714{
1733- _cleanup_free_ char * slots_sysfs_dir = nvme_slots_sysfs_dir ();
1715+ const char * slots_sysfs_dir = nvme_slots_sysfs_dir ();
17341716 _cleanup_free_ char * target_addr = NULL ;
17351717 _cleanup_dir_ DIR * slots_dir = NULL ;
17361718 int ret ;
@@ -1827,7 +1809,6 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path,
18271809
18281810int nvme_init_ctrl (nvme_host_t h , nvme_ctrl_t c , int instance )
18291811{
1830- _cleanup_free_ char * ctrl_dir = nvme_ctrl_sysfs_dir ();
18311812 _cleanup_free_ char * subsys_name = NULL ;
18321813 _cleanup_free_ char * name = NULL ;
18331814 nvme_subsystem_t s ;
@@ -1839,7 +1820,7 @@ int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance)
18391820 errno = ENOMEM ;
18401821 return -1 ;
18411822 }
1842- ret = asprintf (& path , "%s/nvme%d " , ctrl_dir , instance );
1823+ ret = asprintf (& path , "%s/%s " , nvme_ctrl_sysfs_dir (), name );
18431824 if (ret < 0 ) {
18441825 errno = ENOMEM ;
18451826 return ret ;
@@ -1983,11 +1964,10 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name)
19831964 _cleanup_free_ char * path = NULL ;
19841965 _cleanup_free_ char * hostnqn = NULL , * hostid = NULL ;
19851966 _cleanup_free_ char * subsysnqn = NULL , * subsysname = NULL ;
1986- _cleanup_free_ char * ctrl_dir = nvme_ctrl_sysfs_dir ();
19871967 int ret ;
19881968
19891969 nvme_msg (r , LOG_DEBUG , "scan controller %s\n" , name );
1990- ret = asprintf (& path , "%s/%s" , ctrl_dir , name );
1970+ ret = asprintf (& path , "%s/%s" , nvme_ctrl_sysfs_dir () , name );
19911971 if (ret < 0 ) {
19921972 errno = ENOMEM ;
19931973 return NULL ;
@@ -2615,9 +2595,7 @@ static struct nvme_ns *__nvme_scan_namespace(const char *sysfs_dir, const char *
26152595
26162596nvme_ns_t nvme_scan_namespace (const char * name )
26172597{
2618- _cleanup_free_ char * ns_dir = nvme_ns_sysfs_dir ();
2619-
2620- return __nvme_scan_namespace (ns_dir , name );
2598+ return __nvme_scan_namespace (nvme_ns_sysfs_dir (), name );
26212599}
26222600
26232601static int nvme_ctrl_scan_namespace (nvme_root_t r , struct nvme_ctrl * c ,
0 commit comments