2006-03-13 Roland Dreier <rdreier@cisco.com>
+ * src/init.c (check_abi_version), src/verbs.c (ibv_query_gid,
+ ibv_query_pkey): Use sysfs_open_attribute() and
+ sysfs_read_attribute() instead of the deprecated function
+ sysfs_read_attribute_value(), which is no longer present in
+ libsysfs2 (which is already in Debian and Ubuntu).
+
* Release version 1.0.
2006-03-06 Roland Dreier <rdreier@cisco.com>
static int check_abi_version(void)
{
char path[256];
- char val[16];
+ struct sysfs_attribute *attr;
+ int ret = -1;
if (sysfs_get_mnt_path(path, sizeof path)) {
fprintf(stderr, PFX "Fatal: couldn't find sysfs mount.\n");
strncat(path, "/class/infiniband_verbs/abi_version", sizeof path);
- if (sysfs_read_attribute_value(path, val, sizeof val)) {
- fprintf(stderr, PFX "Fatal: couldn't read uverbs ABI version.\n");
+ attr = sysfs_open_attribute(path);
+ if (!attr)
return -1;
+
+ if (sysfs_read_attribute(attr)) {
+ fprintf(stderr, PFX "Fatal: couldn't read uverbs ABI version.\n");
+ goto out;
}
- abi_ver = strtol(val, NULL, 10);
+ abi_ver = strtol(attr->value, NULL, 10);
if (abi_ver < IB_USER_VERBS_MIN_ABI_VERSION ||
abi_ver > IB_USER_VERBS_MAX_ABI_VERSION) {
fprintf(stderr, PFX "Fatal: kernel ABI version %d "
"doesn't match library version %d.\n",
abi_ver, IB_USER_VERBS_MAX_ABI_VERSION);
- return -1;
+ goto out;
}
- return 0;
+ ret = 0;
+
+out:
+ sysfs_close_attribute(attr);
+ return ret;
}
int index, union ibv_gid *gid)
{
char *attr_name;
- char attr[sizeof "0000:0000:0000:0000:0000:0000:0000:0000\0"];
+ struct sysfs_attribute *attr;
uint16_t val;
int i;
+ int ret = -1;
asprintf(&attr_name, "%s/ports/%d/gids/%d",
context->device->ibdev->path, port_num, index);
- if (sysfs_read_attribute_value(attr_name, attr, sizeof attr))
+ attr = sysfs_open_attribute(attr_name);
+ if (!attr)
return -1;
+ if (sysfs_read_attribute(attr))
+ goto out;
+
for (i = 0; i < 8; ++i) {
- if (sscanf(attr + i * 5, "%hx", &val) != 1)
- return -1;
+ if (sscanf(attr->value + i * 5, "%hx", &val) != 1)
+ goto out;
gid->raw[i * 2 ] = val >> 8;
gid->raw[i * 2 + 1] = val & 0xff;
}
- return 0;
+ ret = 0;
+
+out:
+ sysfs_close_attribute(attr);
+ return ret;
}
int ibv_query_pkey(struct ibv_context *context, uint8_t port_num,
int index, uint16_t *pkey)
{
char *attr_name;
- char attr[sizeof "0x0000\0"];
+ struct sysfs_attribute *attr;
uint16_t val;
+ int ret = -1;
asprintf(&attr_name, "%s/ports/%d/pkeys/%d",
context->device->ibdev->path, port_num, index);
- if (sysfs_read_attribute_value(attr_name, attr, sizeof attr))
+ attr = sysfs_open_attribute(attr_name);
+ if (!attr)
return -1;
- if (sscanf(attr, "%hx", &val) != 1)
- return -1;
+ if (sysfs_read_attribute(attr))
+ goto out;
+
+ if (sscanf(attr->value, "%hx", &val) != 1)
+ goto out;
*pkey = htons(val);
- return 0;
+ ret = 0;
+
+out:
+ sysfs_close_attribute(attr);
+ return ret;
}
struct ibv_pd *ibv_alloc_pd(struct ibv_context *context)