IB/core: Replace ib_query_gid with rdma_get_gid_attr
These call sites have a use of ib_query_gid with a simple lifetime for the struct gid_attr pointer, with an easy conversion. Signed-off-by: Parav Pandit <parav@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
This commit is contained in:
parent
bf399c2cad
commit
77e786fcbe
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include <rdma/ib_mad.h>
|
#include <rdma/ib_mad.h>
|
||||||
#include <rdma/ib_pma.h>
|
#include <rdma/ib_pma.h>
|
||||||
|
#include <rdma/ib_cache.h>
|
||||||
|
|
||||||
struct ib_port;
|
struct ib_port;
|
||||||
|
|
||||||
@ -346,7 +347,7 @@ static struct attribute *port_default_attrs[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static size_t print_ndev(struct ib_gid_attr *gid_attr, char *buf)
|
static size_t print_ndev(const struct ib_gid_attr *gid_attr, char *buf)
|
||||||
{
|
{
|
||||||
if (!gid_attr->ndev)
|
if (!gid_attr->ndev)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -354,33 +355,26 @@ static size_t print_ndev(struct ib_gid_attr *gid_attr, char *buf)
|
|||||||
return sprintf(buf, "%s\n", gid_attr->ndev->name);
|
return sprintf(buf, "%s\n", gid_attr->ndev->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t print_gid_type(struct ib_gid_attr *gid_attr, char *buf)
|
static size_t print_gid_type(const struct ib_gid_attr *gid_attr, char *buf)
|
||||||
{
|
{
|
||||||
return sprintf(buf, "%s\n", ib_cache_gid_type_str(gid_attr->gid_type));
|
return sprintf(buf, "%s\n", ib_cache_gid_type_str(gid_attr->gid_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t _show_port_gid_attr(struct ib_port *p,
|
static ssize_t _show_port_gid_attr(
|
||||||
struct port_attribute *attr,
|
struct ib_port *p, struct port_attribute *attr, char *buf,
|
||||||
char *buf,
|
size_t (*print)(const struct ib_gid_attr *gid_attr, char *buf))
|
||||||
size_t (*print)(struct ib_gid_attr *gid_attr,
|
|
||||||
char *buf))
|
|
||||||
{
|
{
|
||||||
struct port_table_attribute *tab_attr =
|
struct port_table_attribute *tab_attr =
|
||||||
container_of(attr, struct port_table_attribute, attr);
|
container_of(attr, struct port_table_attribute, attr);
|
||||||
union ib_gid gid;
|
const struct ib_gid_attr *gid_attr;
|
||||||
struct ib_gid_attr gid_attr = {};
|
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid,
|
gid_attr = rdma_get_gid_attr(p->ibdev, p->port_num, tab_attr->index);
|
||||||
&gid_attr);
|
if (IS_ERR(gid_attr))
|
||||||
if (ret)
|
return PTR_ERR(gid_attr);
|
||||||
goto err;
|
|
||||||
|
|
||||||
ret = print(&gid_attr, buf);
|
ret = print(gid_attr, buf);
|
||||||
|
rdma_put_gid_attr(gid_attr);
|
||||||
err:
|
|
||||||
if (gid_attr.ndev)
|
|
||||||
dev_put(gid_attr.ndev);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,26 +383,28 @@ static ssize_t show_port_gid(struct ib_port *p, struct port_attribute *attr,
|
|||||||
{
|
{
|
||||||
struct port_table_attribute *tab_attr =
|
struct port_table_attribute *tab_attr =
|
||||||
container_of(attr, struct port_table_attribute, attr);
|
container_of(attr, struct port_table_attribute, attr);
|
||||||
union ib_gid *pgid;
|
const struct ib_gid_attr *gid_attr;
|
||||||
union ib_gid gid;
|
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid, NULL);
|
gid_attr = rdma_get_gid_attr(p->ibdev, p->port_num, tab_attr->index);
|
||||||
|
if (IS_ERR(gid_attr)) {
|
||||||
|
const union ib_gid zgid = {};
|
||||||
|
|
||||||
/* If reading GID fails, it is likely due to GID entry being empty
|
/* If reading GID fails, it is likely due to GID entry being
|
||||||
* (invalid) or reserved GID in the table.
|
* empty (invalid) or reserved GID in the table. User space
|
||||||
* User space expects to read GID table entries as long as it given
|
* expects to read GID table entries as long as it given index
|
||||||
* index is within GID table size.
|
* is within GID table size. Administrative/debugging tool
|
||||||
* Administrative/debugging tool fails to query rest of the GID entries
|
* fails to query rest of the GID entries if it hits error
|
||||||
* if it hits error while querying a GID of the given index.
|
* while querying a GID of the given index. To avoid user
|
||||||
* To avoid user space throwing such error on fail to read gid, return
|
* space throwing such error on fail to read gid, return zero
|
||||||
* zero GID as before. This maintains backward compatibility.
|
* GID as before. This maintains backward compatibility.
|
||||||
*/
|
*/
|
||||||
if (ret)
|
return sprintf(buf, "%pI6\n", zgid.raw);
|
||||||
pgid = &zgid;
|
}
|
||||||
else
|
|
||||||
pgid = &gid;
|
ret = sprintf(buf, "%pI6\n", gid_attr->gid.raw);
|
||||||
return sprintf(buf, "%pI6\n", pgid->raw);
|
rdma_put_gid_attr(gid_attr);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t show_port_gid_attr_ndev(struct ib_port *p,
|
static ssize_t show_port_gid_attr_ndev(struct ib_port *p,
|
||||||
|
Loading…
Reference in New Issue
Block a user