From d4d8c89c2e7a715cdf3906055a4715db5c61b22b Mon Sep 17 00:00:00 2001 From: Roland Dreier Date: Tue, 14 Mar 2006 00:24:55 +0000 Subject: [PATCH] Use sysfs_open_attribute() and sysfs_read_attribute() 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). Signed-off-by: Roland Dreier --- ChangeLog | 6 ++++++ src/init.c | 21 +++++++++++++++------ src/verbs.c | 38 ++++++++++++++++++++++++++++---------- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5e47fd4..8a6fa6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2006-03-13 Roland Dreier + * 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 diff --git a/src/init.c b/src/init.c index 91e3a96..5fa2eb5 100644 --- a/src/init.c +++ b/src/init.c @@ -162,7 +162,8 @@ static struct ibv_device *init_drivers(struct sysfs_class_device *verbs_dev) 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"); @@ -171,22 +172,30 @@ static int check_abi_version(void) 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; } diff --git a/src/verbs.c b/src/verbs.c index a5c031c..2574e79 100644 --- a/src/verbs.c +++ b/src/verbs.c @@ -60,44 +60,62 @@ int ibv_query_gid(struct ibv_context *context, uint8_t port_num, 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) -- 2.46.0