Message ID | 1580466773-24342-1-git-send-email-devesh.sharma@broadcom.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | rdma-core/libibverbs: display gid type in ibv_devinfo | expand |
Hi Devesh, > From: linux-rdma-owner@vger.kernel.org <linux-rdma- > owner@vger.kernel.org> On Behalf Of Devesh Sharma [..] > static int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int > tbl_len) { > + enum ibv_gid_type type; > union ibv_gid gid; > int rc = 0; > int i; > @@ -175,8 +185,16 @@ static int print_all_port_gids(struct ibv_context *ctx, > uint8_t port_num, int tb > port_num, i); > return rc; > } > + > + rc = ibv_query_gid_type(ctx, port_num, i, &type); > + if (rc) { > + fprintf(stderr, "Failed to query gid type to port %d, > index %d\n", > + port_num, i); > + return rc; GID table can have holes depending on how IP addresses, vlan configured/removed. ibv_query_gid_type() is masking the EINVAL error with RoCEv1 type so here return is ok. But as good practice, instead of bailing out the loop, if it returns failure, skip the particular GID entry print. This way rest of valid entries can be still printed.
On Fri, Jan 31, 2020, 16:30 Parav Pandit <parav@mellanox.com> wrote: > > Hi Devesh, > > > From: linux-rdma-owner@vger.kernel.org <linux-rdma- > > owner@vger.kernel.org> On Behalf Of Devesh Sharma > > > [..] > > > static int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int > > tbl_len) { > > + enum ibv_gid_type type; > > union ibv_gid gid; > > int rc = 0; > > int i; > > @@ -175,8 +185,16 @@ static int print_all_port_gids(struct ibv_context *ctx, > > uint8_t port_num, int tb > > port_num, i); > > return rc; > > } > > + > > + rc = ibv_query_gid_type(ctx, port_num, i, &type); > > + if (rc) { > > + fprintf(stderr, "Failed to query gid type to port %d, > > index %d\n", > > + port_num, i); > > + return rc; > GID table can have holes depending on how IP addresses, vlan configured/removed. > ibv_query_gid_type() is masking the EINVAL error with RoCEv1 type so here return is ok. > But as good practice, instead of bailing out the loop, if it returns failure, skip the particular GID entry print. > This way rest of valid entries can be still printed. Okay, will send V2 shortly.
On Fri, Jan 31, 2020 at 9:10 PM Devesh Sharma <devesh.sharma@broadcom.com> wrote: > > On Fri, Jan 31, 2020, 16:30 Parav Pandit <parav@mellanox.com> wrote: > > > > Hi Devesh, > > > > > From: linux-rdma-owner@vger.kernel.org <linux-rdma- > > > owner@vger.kernel.org> On Behalf Of Devesh Sharma > > > > > > [..] > > > > > static int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int > > > tbl_len) { > > > + enum ibv_gid_type type; > > > union ibv_gid gid; > > > int rc = 0; > > > int i; > > > @@ -175,8 +185,16 @@ static int print_all_port_gids(struct ibv_context *ctx, > > > uint8_t port_num, int tb > > > port_num, i); > > > return rc; > > > } > > > + > > > + rc = ibv_query_gid_type(ctx, port_num, i, &type); > > > + if (rc) { > > > + fprintf(stderr, "Failed to query gid type to port %d, > > > index %d\n", > > > + port_num, i); > > > + return rc; > > GID table can have holes depending on how IP addresses, vlan configured/removed. > > ibv_query_gid_type() is masking the EINVAL error with RoCEv1 type so here return is ok. > > But as good practice, instead of bailing out the loop, if it returns failure, skip the particular GID entry print. > > This way rest of valid entries can be still printed. > > Okay, will send V2 shortly. Is this what you want: if (rc) { print msg; save rc in tmp var; continue; } in the end after loop over return saved-rc-tmp-var; Alter saved-rc-tmp-var accordingly for good cases.
> From: Devesh Sharma <devesh.sharma@broadcom.com> > Sent: Friday, January 31, 2020 9:23 PM > To: Parav Pandit <parav@mellanox.com> > Cc: linux-rdma <linux-rdma@vger.kernel.org>; Jason Gunthorpe > <jgg@mellanox.com>; leon@kernel.org > Subject: Re: [PATCH] rdma-core/libibverbs: display gid type in ibv_devinfo > > On Fri, Jan 31, 2020 at 9:10 PM Devesh Sharma > <devesh.sharma@broadcom.com> wrote: > > > > On Fri, Jan 31, 2020, 16:30 Parav Pandit <parav@mellanox.com> wrote: > > > > > > Hi Devesh, > > > > > > > From: linux-rdma-owner@vger.kernel.org <linux-rdma- > > > > owner@vger.kernel.org> On Behalf Of Devesh Sharma > > > > > > > > > [..] > > > > > > > static int print_all_port_gids(struct ibv_context *ctx, uint8_t > > > > port_num, int > > > > tbl_len) { > > > > + enum ibv_gid_type type; > > > > union ibv_gid gid; > > > > int rc = 0; > > > > int i; > > > > @@ -175,8 +185,16 @@ static int print_all_port_gids(struct > > > > ibv_context *ctx, uint8_t port_num, int tb > > > > port_num, i); > > > > return rc; > > > > } > > > > + > > > > + rc = ibv_query_gid_type(ctx, port_num, i, &type); > > > > + if (rc) { > > > > + fprintf(stderr, "Failed to query gid type to > > > > + port %d, > > > > index %d\n", > > > > + port_num, i); > > > > + return rc; > > > GID table can have holes depending on how IP addresses, vlan > configured/removed. > > > ibv_query_gid_type() is masking the EINVAL error with RoCEv1 type so here > return is ok. > > > But as good practice, instead of bailing out the loop, if it returns failure, > skip the particular GID entry print. > > > This way rest of valid entries can be still printed. > > > > Okay, will send V2 shortly. > > Is this what you want: > if (rc) { > print msg; > save rc in tmp var; > continue; > } > Bit simpler than that to just ignore the error (for an invalid gid entry). rc = ibv_query_gid_type(ctx, port_num, i, &type); if (rc) { rc = 0; continue; } > in the end after loop over > return saved-rc-tmp-var; > Alter saved-rc-tmp-var accordingly for good cases.
diff --git a/libibverbs/examples/devinfo.c b/libibverbs/examples/devinfo.c index bf53eac..63988ba 100644 --- a/libibverbs/examples/devinfo.c +++ b/libibverbs/examples/devinfo.c @@ -162,8 +162,18 @@ static const char *vl_str(uint8_t vl_num) } } +static const char *gid_type_str(enum ibv_gid_type type) +{ + switch (type) { + case 0: return "IB/RoCE v1"; + case 1: return "RoCE v2"; + default: return "invalid value"; + } +} + static int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int tbl_len) { + enum ibv_gid_type type; union ibv_gid gid; int rc = 0; int i; @@ -175,8 +185,16 @@ static int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int tb port_num, i); return rc; } + + rc = ibv_query_gid_type(ctx, port_num, i, &type); + if (rc) { + fprintf(stderr, "Failed to query gid type to port %d, index %d\n", + port_num, i); + return rc; + } + if (!null_gid(&gid)) - printf("\t\t\tGID[%3d]:\t\t%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", + printf("\t\t\tGID[%3d]:\t\t%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x, %s\n", i, gid.raw[ 0], gid.raw[ 1], gid.raw[ 2], gid.raw[ 3], @@ -185,7 +203,8 @@ static int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int tb gid.raw[ 8], gid.raw[ 9], gid.raw[10], gid.raw[11], gid.raw[12], gid.raw[13], - gid.raw[14], gid.raw[15]); + gid.raw[14], gid.raw[15], + gid_type_str(type)); } return rc; }
It becomes difficult to make out from the output of ibv_devinfo if a particular gid index is RoCE v2 or not. Adding a string to the output of ibv_devinfo -v to display the gid type at the end of gid. Signed-off-by: Devesh Sharma <devesh.sharma@broadcom.com> --- libibverbs/examples/devinfo.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)