]> git.openfabrics.org - ~shefty/libibverbs.git/commitdiff
Use sysfs_open_attribute() and sysfs_read_attribute()
authorRoland Dreier <rolandd@cisco.com>
Tue, 14 Mar 2006 00:24:55 +0000 (00:24 +0000)
committerRoland Dreier <rolandd@cisco.com>
Thu, 9 Nov 2006 19:35:59 +0000 (11:35 -0800)
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 <rolandd@cisco.com>
ChangeLog
src/init.c
src/verbs.c

index 5e47fd487fe47f1940cc6b17090d76b096998e0b..8a6fa6a793d7d0755b80849adf3391d4edc69199 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 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>
index 91e3a966831e330d3fadd175fab9d2ffbcad6375..5fa2eb5c0b689c6e615a550f315af558cc9f0844 100644 (file)
@@ -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;
 }
 
 
index a5c031cb8e71de0bcb852874c4b258811ec0e1bf..2574e79aa101f4f362b4282ae21b2fd5759a49c9 100644 (file)
@@ -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)