diff options
author | Michael S. Tsirkin <mst@mellanox.co.il> | 2005-07-25 22:25:59 +0000 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2006-11-09 11:35:57 -0800 |
commit | f099161445560b1310312321a1ee749e8a52b507 (patch) | |
tree | aa8ff402dd9dc2acd115e1bfdc8c1ee6e621977e | |
parent | e57ddb4763af5a77a1f13c6a7bacd504742f2e5f (diff) | |
download | libibverbs-f099161445560b1310312321a1ee749e8a52b507.tar.gz |
Lazy initialization of libibverbs on ibv_get_devices
Signed-off-by: Michael S. Tsirkin <mst@mellanox.co.il>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
-rw-r--r-- | src/device.c | 4 | ||||
-rw-r--r-- | src/ibverbs.h | 2 | ||||
-rw-r--r-- | src/init.c | 24 |
3 files changed, 18 insertions, 12 deletions
diff --git a/src/device.c b/src/device.c index 120507a..4df506d 100644 --- a/src/device.c +++ b/src/device.c @@ -46,8 +46,12 @@ #include "ibverbs.h" +static struct dlist *device_list; + struct dlist *ibv_get_devices(void) { + if (!device_list) + device_list = ibverbs_init(); return device_list; } diff --git a/src/ibverbs.h b/src/ibverbs.h index 1f754f3..58565c8 100644 --- a/src/ibverbs.h +++ b/src/ibverbs.h @@ -50,7 +50,7 @@ struct ibv_driver { ibv_driver_init_func init_func; }; -extern Dlist *device_list; +extern struct dlist *ibverbs_init(void); extern int ibv_init_mem_map(void); extern int ibv_lock_range(void *base, size_t size); @@ -50,12 +50,10 @@ # define OPENIB_DRIVER_PATH_ENV "OPENIB_DRIVER_PATH" #endif -Dlist *device_list; - static char default_path[] = DRIVER_PATH; static const char *user_path; -static Dlist *driver_list; +static struct dlist *driver_list; static void load_driver(char *so_path) { @@ -112,7 +110,8 @@ static void find_drivers(char *dir) load_driver(so_glob.gl_pathv[i]); } -static void init_drivers(struct sysfs_class_device *verbs_dev) +static void init_drivers(struct sysfs_class_device *verbs_dev, + struct dlist *device_list) { struct sysfs_class_device *ib_dev; struct sysfs_attribute *attr; @@ -187,11 +186,12 @@ static int check_abi_version(void) } -static void INIT ibverbs_init(void) +struct dlist *ibverbs_init(void) { char *wr_path, *dir; struct sysfs_class *cls; - Dlist *verbs_dev_list; + struct dlist *verbs_dev_list; + struct dlist *device_list; struct sysfs_class_device *verbs_dev; driver_list = dlist_new(sizeof (struct ibv_driver)); @@ -202,7 +202,7 @@ static void INIT ibverbs_init(void) } if (ibv_init_mem_map()) - return; + return NULL; /* * Check if a driver is statically linked, and if so load it first. @@ -227,18 +227,20 @@ static void INIT ibverbs_init(void) cls = sysfs_open_class("infiniband_verbs"); if (!cls) { fprintf(stderr, PFX "Fatal: couldn't open sysfs class 'infiniband_verbs'.\n"); - return; + return NULL; } if (check_abi_version()) - return; + return NULL; verbs_dev_list = sysfs_get_class_devices(cls); if (!verbs_dev_list) { fprintf(stderr, PFX "Fatal: no infiniband class devices found.\n"); - return; + return NULL; } dlist_for_each_data(verbs_dev_list, verbs_dev, struct sysfs_class_device) - init_drivers(verbs_dev); + init_drivers(verbs_dev, device_list); + + return device_list; } |