[ofa-general] Re: [PATCH v2] Add enum strings and *_str functions for enums

Ira Weiny weiny2 at llnl.gov
Tue Jun 24 15:17:28 PDT 2008


On Tue, 24 Jun 2008 14:54:14 -0700
Roland Dreier <rdreier at cisco.com> wrote:

> How about if we just revert the devinfo.c change that used the new
> conversion function?  I think "down" is a lot nicer in general than
> "PORT_DOWN" so we might as well let new code use that.  But I do agree
> we don't want to break any apps that are parsing ibv_devinfo output.
> 
> So the following seems like i twould work?

I like this idea.

Ira

> 
> diff --git a/examples/devinfo.c b/examples/devinfo.c
> index 86ad7da..caa5d5f 100644
> --- a/examples/devinfo.c
> +++ b/examples/devinfo.c
> @@ -67,6 +67,17 @@ static const char *guid_str(uint64_t node_guid, char *str)
>  	return str;
>  }
>  
> +static const char *port_state_str(enum ibv_port_state pstate)
> +{
> +	switch (pstate) {
> +	case IBV_PORT_DOWN:   return "PORT_DOWN";
> +	case IBV_PORT_INIT:   return "PORT_INIT";
> +	case IBV_PORT_ARMED:  return "PORT_ARMED";
> +	case IBV_PORT_ACTIVE: return "PORT_ACTIVE";
> +	default:              return "invalid state";
> +	}
> +}
> +
>  static const char *port_phy_state_str(uint8_t phys_state)
>  {
>  	switch (phys_state) {
> @@ -254,7 +265,7 @@ static int print_hca_cap(struct ibv_device *ib_dev, uint8_t ib_port)
>  		}
>  		printf("\t\tport:\t%d\n", port);
>  		printf("\t\t\tstate:\t\t\t%s (%d)\n",
> -		       ibv_port_state_str(port_attr.state), port_attr.state);
> +		       port_state_str(port_attr.state), port_attr.state);
>  		printf("\t\t\tmax_mtu:\t\t%s (%d)\n",
>  		       mtu_str(port_attr.max_mtu), port_attr.max_mtu);
>  		printf("\t\t\tactive_mtu:\t\t%s (%d)\n",



More information about the general mailing list