[dpdk-dev,v3,13/28] eal/pci: Prevent double registration for devargs_list
Commit Message
The patch fixes rte_eal_devargs_add() not to register same device twice.
Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
lib/librte_eal/common/eal_common_devargs.c | 35 ++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
Comments
On 2014/12/9 14:33, Tetsuya Mukawa wrote:
> The patch fixes rte_eal_devargs_add() not to register same device twice.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
> lib/librte_eal/common/eal_common_devargs.c | 35 ++++++++++++++++++++++++++++++
> 1 file changed, 35 insertions(+)
>
> diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
> index 4c7d11a..f95a12d 100644
> --- a/lib/librte_eal/common/eal_common_devargs.c
> +++ b/lib/librte_eal/common/eal_common_devargs.c
> @@ -44,6 +44,35 @@
> struct rte_devargs_list devargs_list =
> TAILQ_HEAD_INITIALIZER(devargs_list);
>
> +
> +/* find a entry specified by pci address or device name */
> +static struct rte_devargs *
> +rte_eal_devargs_find(enum rte_devtype devtype, void *args)
> +{
> + struct rte_devargs *devargs;
> +
> + if (args == NULL)
> + return NULL;
> +
> + TAILQ_FOREACH(devargs, &devargs_list, next) {
> + switch (devtype) {
> + case RTE_DEVTYPE_WHITELISTED_PCI:
> + case RTE_DEVTYPE_BLACKLISTED_PCI:
> + if (eal_compare_pci_addr(&devargs->pci.addr, args) == 0)
> + goto found;
> + break;
> + case RTE_DEVTYPE_VIRTUAL:
> + if (memcmp(&devargs->virtual.drv_name, args,
> + strlen((char *)args)) == 0)
> + goto found;
> + break;
> + }
> + }
> + return NULL;
> +found:
> + return devargs;
> +}
> +
> /* store a whitelist parameter for later parsing */
> int
> rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
> @@ -101,6 +130,12 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
> break;
> }
>
> + /* make sure there is no same entry */
> + if (rte_eal_devargs_find(devtype, &devargs->pci.addr)) {
Am I miss something? If devtype == RTE_DEVTYPE_VIRTUAL, what will happen?
Thanks,
Michael
> + RTE_LOG(ERR, EAL, "device already registered: <%s>\n", buf);
> + return -1;
> + }
> +
> TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
> return 0;
> }
Hi Michael,
(2014/12/09 23:55), Qiu, Michael wrote:
> On 2014/12/9 14:33, Tetsuya Mukawa wrote:
>> The patch fixes rte_eal_devargs_add() not to register same device twice.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>> lib/librte_eal/common/eal_common_devargs.c | 35 ++++++++++++++++++++++++++++++
>> 1 file changed, 35 insertions(+)
>>
>> diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
>> index 4c7d11a..f95a12d 100644
>> --- a/lib/librte_eal/common/eal_common_devargs.c
>> +++ b/lib/librte_eal/common/eal_common_devargs.c
>> @@ -44,6 +44,35 @@
>> struct rte_devargs_list devargs_list =
>> TAILQ_HEAD_INITIALIZER(devargs_list);
>>
>> +
>> +/* find a entry specified by pci address or device name */
>> +static struct rte_devargs *
>> +rte_eal_devargs_find(enum rte_devtype devtype, void *args)
>> +{
>> + struct rte_devargs *devargs;
>> +
>> + if (args == NULL)
>> + return NULL;
>> +
>> + TAILQ_FOREACH(devargs, &devargs_list, next) {
>> + switch (devtype) {
>> + case RTE_DEVTYPE_WHITELISTED_PCI:
>> + case RTE_DEVTYPE_BLACKLISTED_PCI:
>> + if (eal_compare_pci_addr(&devargs->pci.addr, args) == 0)
>> + goto found;
>> + break;
>> + case RTE_DEVTYPE_VIRTUAL:
>> + if (memcmp(&devargs->virtual.drv_name, args,
>> + strlen((char *)args)) == 0)
>> + goto found;
>> + break;
>> + }
>> + }
>> + return NULL;
>> +found:
>> + return devargs;
>> +}
>> +
>> /* store a whitelist parameter for later parsing */
>> int
>> rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
>> @@ -101,6 +130,12 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
>> break;
>> }
>>
>> + /* make sure there is no same entry */
>> + if (rte_eal_devargs_find(devtype, &devargs->pci.addr)) {
> Am I miss something? If devtype == RTE_DEVTYPE_VIRTUAL, what will happen?
This will be issues.
When I implement, I guess devargs->pci.addr and
devargs->virtual.drv_name will have same address, because they are
accessed as union.
But it's rough coding and will have issue with some compilers. I will
change it.
Thanks,
Tetsuya
> Thanks,
> Michael
>> + RTE_LOG(ERR, EAL, "device already registered: <%s>\n", buf);
>> + return -1;
>> + }
>> +
>> TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
>> return 0;
>> }
@@ -44,6 +44,35 @@
struct rte_devargs_list devargs_list =
TAILQ_HEAD_INITIALIZER(devargs_list);
+
+/* find a entry specified by pci address or device name */
+static struct rte_devargs *
+rte_eal_devargs_find(enum rte_devtype devtype, void *args)
+{
+ struct rte_devargs *devargs;
+
+ if (args == NULL)
+ return NULL;
+
+ TAILQ_FOREACH(devargs, &devargs_list, next) {
+ switch (devtype) {
+ case RTE_DEVTYPE_WHITELISTED_PCI:
+ case RTE_DEVTYPE_BLACKLISTED_PCI:
+ if (eal_compare_pci_addr(&devargs->pci.addr, args) == 0)
+ goto found;
+ break;
+ case RTE_DEVTYPE_VIRTUAL:
+ if (memcmp(&devargs->virtual.drv_name, args,
+ strlen((char *)args)) == 0)
+ goto found;
+ break;
+ }
+ }
+ return NULL;
+found:
+ return devargs;
+}
+
/* store a whitelist parameter for later parsing */
int
rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
@@ -101,6 +130,12 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
break;
}
+ /* make sure there is no same entry */
+ if (rte_eal_devargs_find(devtype, &devargs->pci.addr)) {
+ RTE_LOG(ERR, EAL, "device already registered: <%s>\n", buf);
+ return -1;
+ }
+
TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
return 0;
}