Linux-RDMA Archive on lore.kernel.org
 help / color / Atom feed
From: Haim Boozaglo <haimbo@mellanox.com>
To: Ira Weiny <ira.weiny@intel.com>
Cc: "linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	Vladimir Koushnir <vladimirk@mellanox.com>
Subject: Re: [PATCH 1/3] libibumad: Support arbitrary number of IB devices
Date: Sun, 18 Aug 2019 07:31:45 +0000
Message-ID: <f94e74f1-a4de-0457-6860-f7ee7ac5e1bb@mellanox.com> (raw)
In-Reply-To: <20190813163939.GA11882@iweiny-DESK2.sc.intel.com>



On 8/13/2019 7:39 PM, Ira Weiny wrote:
> 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

Hi Ira,
Thats what I am going to do and fix (to use strdup),

Thanks,
Haim.

> 
>> +			}
>> +			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 index

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
2019-08-18  7:31     ` Haim Boozaglo [this message]
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 publically 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=f94e74f1-a4de-0457-6860-f7ee7ac5e1bb@mellanox.com \
    --to=haimbo@mellanox.com \
    --cc=ira.weiny@intel.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

Linux-RDMA Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rdma/0 linux-rdma/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rdma linux-rdma/ https://lore.kernel.org/linux-rdma \
		linux-rdma@vger.kernel.org
	public-inbox-index linux-rdma

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rdma


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git