svn commit: r211274 - projects/ofed/head/contrib/ofed/libibverbs/src
Jeff Roberson
jeff at FreeBSD.org
Fri Aug 13 05:46:37 UTC 2010
Author: jeff
Date: Fri Aug 13 05:46:37 2010
New Revision: 211274
URL: http://svn.freebsd.org/changeset/base/211274
Log:
- Update paths and sysfs access to account for sysctl and freebsd
device paths.
Sponsored by: Isilon Systems, iX Systems, and Panasas.
Modified:
projects/ofed/head/contrib/ofed/libibverbs/src/device.c
projects/ofed/head/contrib/ofed/libibverbs/src/init.c
projects/ofed/head/contrib/ofed/libibverbs/src/sysfs.c
Modified: projects/ofed/head/contrib/ofed/libibverbs/src/device.c
==============================================================================
--- projects/ofed/head/contrib/ofed/libibverbs/src/device.c Fri Aug 13 05:45:36 2010 (r211273)
+++ projects/ofed/head/contrib/ofed/libibverbs/src/device.c Fri Aug 13 05:46:37 2010 (r211274)
@@ -128,7 +128,7 @@ struct ibv_context *__ibv_open_device(st
int cmd_fd;
struct ibv_context *context;
- if (asprintf(&devpath, "/dev/infiniband/%s", device->dev_name) < 0)
+ if (asprintf(&devpath, "/dev/%s", device->dev_name) < 0)
return NULL;
/*
Modified: projects/ofed/head/contrib/ofed/libibverbs/src/init.c
==============================================================================
--- projects/ofed/head/contrib/ofed/libibverbs/src/init.c Fri Aug 13 05:45:36 2010 (r211273)
+++ projects/ofed/head/contrib/ofed/libibverbs/src/init.c Fri Aug 13 05:46:37 2010 (r211274)
@@ -79,6 +79,7 @@ static struct ibv_driver *head_driver, *
static int find_sysfs_devs(void)
{
+#ifdef __linux__
char class_path[IBV_SYSFS_PATH_MAX];
DIR *class_dir;
struct dirent *dent;
@@ -151,6 +152,57 @@ static int find_sysfs_devs(void)
closedir(class_dir);
return ret;
+#else
+ char class_path[IBV_SYSFS_PATH_MAX];
+ struct ibv_sysfs_dev *sysfs_dev = NULL;
+ char value[8];
+ int ret = 0;
+ int i;
+
+ snprintf(class_path, sizeof class_path, "%s/class/infiniband_verbs",
+ ibv_get_sysfs_path());
+
+ for (i = 0; i < 256; i++) {
+ if (!sysfs_dev)
+ sysfs_dev = malloc(sizeof *sysfs_dev);
+ if (!sysfs_dev) {
+ ret = ENOMEM;
+ goto out;
+ }
+
+ snprintf(sysfs_dev->sysfs_path, sizeof sysfs_dev->sysfs_path,
+ "%s/uverbs%d", class_path, i);
+
+ snprintf(sysfs_dev->sysfs_name, sizeof sysfs_dev->sysfs_name,
+ "uverbs%d", i);
+
+ if (ibv_read_sysfs_file(sysfs_dev->sysfs_path, "ibdev",
+ sysfs_dev->ibdev_name,
+ sizeof sysfs_dev->ibdev_name) < 0)
+ continue;
+
+ snprintf(sysfs_dev->ibdev_path, sizeof sysfs_dev->ibdev_path,
+ "/dev/%s", sysfs_dev->ibdev_name);
+
+ sysfs_dev->next = sysfs_dev_list;
+ sysfs_dev->have_driver = 0;
+ if (ibv_read_sysfs_file(sysfs_dev->sysfs_path, "abi_version",
+ value, sizeof value) > 0)
+ sysfs_dev->abi_ver = strtol(value, NULL, 10);
+ else
+ sysfs_dev->abi_ver = 0;
+
+ sysfs_dev_list = sysfs_dev;
+ sysfs_dev = NULL;
+ }
+
+ out:
+ if (sysfs_dev)
+ free(sysfs_dev);
+
+ return ret;
+
+#endif
}
void ibv_register_driver(const char *name, ibv_driver_init_func init_func)
@@ -333,13 +385,19 @@ static struct ibv_device *try_driver(str
struct ibv_sysfs_dev *sysfs_dev)
{
struct ibv_device *dev;
+ char *path;
char value[8];
dev = driver->init_func(sysfs_dev->sysfs_path, sysfs_dev->abi_ver);
if (!dev)
return NULL;
- if (ibv_read_sysfs_file(sysfs_dev->ibdev_path, "node_type", value, sizeof value) < 0) {
+ if (asprintf(&path, "/sys/class/infiniband/%s",
+ strrchr(sysfs_dev->ibdev_path, '/')+1) < 0) {
+ dev->node_type = IBV_NODE_UNKNOWN;
+ goto out;
+ }
+ if (ibv_read_sysfs_file(path, "node_type", value, sizeof value) < 0) {
fprintf(stderr, PFX "Warning: no node_type attr under %s.\n",
sysfs_dev->ibdev_path);
dev->node_type = IBV_NODE_UNKNOWN;
@@ -348,6 +406,8 @@ static struct ibv_device *try_driver(str
if (dev->node_type < IBV_NODE_CA || dev->node_type > IBV_NODE_RNIC)
dev->node_type = IBV_NODE_UNKNOWN;
}
+ free(path);
+out:
switch (dev->node_type) {
case IBV_NODE_CA:
Modified: projects/ofed/head/contrib/ofed/libibverbs/src/sysfs.c
==============================================================================
--- projects/ofed/head/contrib/ofed/libibverbs/src/sysfs.c Fri Aug 13 05:45:36 2010 (r211273)
+++ projects/ofed/head/contrib/ofed/libibverbs/src/sysfs.c Fri Aug 13 05:46:37 2010 (r211274)
@@ -42,6 +42,8 @@
#include <fcntl.h>
#include <string.h>
+#include <sys/sysctl.h>
+
#include "ibverbs.h"
static char *sysfs_path;
@@ -78,22 +80,21 @@ const char *ibv_get_sysfs_path(void)
int ibv_read_sysfs_file(const char *dir, const char *file,
char *buf, size_t size)
{
- char *path;
+ char *path, *s;
int fd;
- int len;
+ size_t len;
if (asprintf(&path, "%s/%s", dir, file) < 0)
return -1;
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- free(path);
- return -1;
- }
+ for (s = &path[0]; *s != '\0'; s++)
+ if (*s == '/')
+ *s = '.';
- len = read(fd, buf, size);
+ len = size;
+ if (sysctlbyname(&path[1], buf, &len, NULL, 0) == -1)
+ return -1;
- close(fd);
free(path);
if (len > 0 && buf[len - 1] == '\n')
More information about the svn-src-projects
mailing list