linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ira Weiny <ira.weiny@intel.com>
To: Haim Boozaglo <haimbo@mellanox.com>
Cc: linux-rdma@vger.kernel.org, Vladimir Koushnir <vladimirk@mellanox.com>
Subject: Re: [PATCH 1/3] libibumad: Support arbitrary number of IB devices
Date: Tue, 13 Aug 2019 09:39:40 -0700	[thread overview]
Message-ID: <20190813163939.GA11882@iweiny-DESK2.sc.intel.com> (raw)
In-Reply-To: <1565540962-20188-2-git-send-email-haimbo@mellanox.com>

On Sun, Aug 11, 2019 at 04:29:20PM +0000, Haim Boozaglo wrote:
> From: Vladimir Koushnir <vladimirk@mellanox.com>
> 
> Added new function returning a list of available InfiniBand device names.
> The returned list is not limited to 32 devices.
> 
> Signed-off-by: Vladimir Koushnir <vladimirk@mellanox.com>
> Signed-off-by: Haim Boozaglo <haimbo@mellanox.com>
> ---

[snip]

> diff --git a/libibumad/umad.c b/libibumad/umad.c
> index 5f8656e..9d0303b 100644
> --- a/libibumad/umad.c
> +++ b/libibumad/umad.c
> @@ -1123,3 +1123,44 @@ void umad_dump(void *umad)
>  	       mad->agent_id, mad->status, mad->timeout_ms);
>  	umad_addr_dump(&mad->addr);
>  }
> +
> +int umad_get_ca_namelist(char **cas)
> +{
> +	struct dirent **namelist;
> +	int n, i, j = 0;
> +
> +	n = scandir(SYS_INFINIBAND, &namelist, NULL, alphasort);
> +
> +	if (n > 0) {
> +		*cas = (char *) calloc(1, n * sizeof(char) * UMAD_CA_NAME_LEN);
> +		for (i = 0; i < n; i++) {
> +			if (*cas && strcmp(namelist[i]->d_name, ".") &&
> +			    strcmp(namelist[i]->d_name, "..")) {
> +				if (is_ib_type(namelist[i]->d_name)) {
> +					strncpy(*cas + j * UMAD_CA_NAME_LEN,
> +						namelist[i]->d_name,
> +						UMAD_CA_NAME_LEN);
> +					j++;
> +				}

This all seems overly complicated to avoid allocating the strings separate from
the pointer array.  Why not just allocate the pointer array and strdup() the
names into the array?  And then make unamd_free_ca_namelist() do some work?

Ira

> +			}
> +			free(namelist[i]);
> +		}
> +		DEBUG("return %d cas", j);
> +	} else {
> +		/* Is this still needed ? */
> +		if ((*cas = calloc(1, UMAD_CA_NAME_LEN * sizeof(char)))) {
> +			strncpy(*cas, def_ca_name, UMAD_CA_NAME_LEN);
> +			DEBUG("return 1 ca");
> +			j = 1;
> +		}
> +	}
> +	if (n >= 0)
> +		free(namelist);
> +
> +	return j;
> +}
> +
> +void umad_free_ca_namelist(char *cas)
> +{
> +	free(cas);
> +}
> diff --git a/libibumad/umad.h b/libibumad/umad.h
> index 3cc551f..70bc213 100644
> --- a/libibumad/umad.h
> +++ b/libibumad/umad.h
> @@ -208,6 +208,8 @@ int umad_register(int portid, int mgmt_class, int mgmt_version,
>  int umad_register_oui(int portid, int mgmt_class, uint8_t rmpp_version,
>  		      uint8_t oui[3], long method_mask[16 / sizeof(long)]);
>  int umad_unregister(int portid, int agentid);
> +int umad_get_ca_namelist(char **cas);
> +void umad_free_ca_namelist(char *cas);
>  
>  enum {
>  	UMAD_USER_RMPP = (1 << 0)
> -- 
> 1.8.3.1
> 

  reply	other threads:[~2019-08-13 16:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-11 16:29 [PATCH rdma-core 0/3] get more than 32 available InfiniBand device names Haim Boozaglo
2019-08-11 16:29 ` [PATCH 1/3] libibumad: Support arbitrary number of IB devices Haim Boozaglo
2019-08-13 16:39   ` Ira Weiny [this message]
2019-08-18  7:31     ` Haim Boozaglo
2019-08-11 16:29 ` [PATCH 2/3] libibumad: Redesign resolve_ca_name to support " Haim Boozaglo
2019-08-11 16:29 ` [PATCH 3/3] ibdiags: Support arbitrary number of IB devices in ibstat Haim Boozaglo
2019-08-12 15:13 ` [PATCH rdma-core 0/3] get more than 32 available InfiniBand device names Doug Ledford
  -- strict thread matches above, loose matches on Subject: below --
2019-08-06 14:38 [PATCH 1/3] libibumad: Support arbitrary number of IB devices Haim Boozaglo
2019-08-06 15:52 ` Leon Romanovsky
2019-08-07  7:26   ` Vladimir Koushnir
2019-08-07  7:44     ` Leon Romanovsky
2019-08-07  8:09       ` Vladimir Koushnir

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190813163939.GA11882@iweiny-DESK2.sc.intel.com \
    --to=ira.weiny@intel.com \
    --cc=haimbo@mellanox.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=vladimirk@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).