int rte_eal_dev_attach(const char *name, const char *devargs)
{
+ struct rte_bus *bus;
int ret;
if (name == NULL || devargs == NULL) {
return -EINVAL;
}
- ret = rte_eal_hotplug_add("pci", name, devargs);
- if (ret && ret != -EINVAL)
- return ret;
+ bus = rte_bus_find_by_device_name(name);
+ if (bus == NULL) {
+ RTE_LOG(ERR, EAL, "Unable to find a bus for the device '%s'\n",
+ name);
+ return -EINVAL;
+ }
+ if (strcmp(bus->name, "pci") == 0)
+ return rte_eal_hotplug_add("pci", name, devargs);
+ if (strcmp(bus->name, "vdev") != 0) {
+ RTE_LOG(ERR, EAL, "Device attach is only supported for PCI and vdev devices.\n");
+ return -ENOTSUP;
+ }
/*
* If we haven't found a bus device the user meant to "hotplug" a
char *name;
size_t len;
- len = strlen(bus) + 1 +
- strlen(dev) + 1 +
- strlen(args) + 1;
+ len = snprintf(NULL, 0, "%s:%s,%s", bus, dev, args);
name = calloc(1, len);
if (name == NULL) {
RTE_LOG(ERR, EAL, "Could not allocate full device name\n");
return NULL;
}
- snprintf(name, len, "%s:%s,%s", bus, dev,
- args ? args : "");
+ snprintf(name, len, "%s:%s,%s", bus, dev, args);
return name;
}
return 0;
err_devarg:
- rte_eal_devargs_remove(busname, devname);
+ if (rte_eal_devargs_remove(busname, devname)) {
+ free(da->args);
+ free(da);
+ }
err_name:
free(name);
return ret;