src/dpdk/drivers/bus/vmbus/linux/vmbus_bus.c
static int
vmbus_scan_one(const char *name)
{
	struct rte_vmbus_device *dev, *dev2;
	char filename[PATH_MAX];
	char dirname[PATH_MAX];
	unsigned long tmp;

	dev = calloc(1, sizeof(*dev));
	if (dev == NULL)
		return -1;

	dev->device.bus = &rte_vmbus_bus.bus;
	dev->device.name = strdup(name);
	if (!dev->device.name)
		goto error;

	/* sysfs base directory
	 *   /sys/bus/vmbus/devices/7a08391f-f5a0-4ac0-9802-d13fd964f8df
	 * or on older kernel
	 *   /sys/bus/vmbus/devices/vmbus_1
	 */
	snprintf(dirname, sizeof(dirname), "%s/%s",
		 SYSFS_VMBUS_DEVICES, name);

	/* get device class  */
	snprintf(filename, sizeof(filename), "%s/class_id", dirname);
	if (parse_sysfs_uuid(filename, dev->class_id) < 0)
		goto error;

	/* skip non-network devices */
	if (rte_uuid_compare(dev->class_id, vmbus_nic_uuid) != 0) {
		free(dev);
		return 0;
	}

	/* get device id */
	snprintf(filename, sizeof(filename), "%s/device_id", dirname);
	if (parse_sysfs_uuid(filename, dev->device_id) < 0)
		goto error;

	/* get relid */
	snprintf(filename, sizeof(filename), "%s/id", dirname);
	if (eal_parse_sysfs_value(filename, &tmp) < 0)
		goto error;
	dev->relid = tmp;

	/* get monitor id */
	snprintf(filename, sizeof(filename), "%s/monitor_id", dirname);
	if (eal_parse_sysfs_value(filename, &tmp) < 0)
		goto error;
	dev->monitor_id = tmp;

	/* get numa node (if present) */
	snprintf(filename, sizeof(filename), "%s/numa_node",
		 dirname);

	if (access(filename, R_OK) == 0) {
		if (eal_parse_sysfs_value(filename, &tmp) < 0)
			goto error;
		dev->device.numa_node = tmp;
	} else {
		/* if no NUMA support, set default to 0 */
		dev->device.numa_node = SOCKET_ID_ANY;
	}

	dev->device.devargs = vmbus_devargs_lookup(dev);

	/* device is valid, add in list (sorted) */
	VMBUS_LOG(DEBUG, "Adding vmbus device %s", name);

	TAILQ_FOREACH(dev2, &rte_vmbus_bus.device_list, next) {
		int ret;

		ret = rte_uuid_compare(dev->device_id, dev2->device_id);
		if (ret > 0)
			continue;

		if (ret < 0) {
			vmbus_insert_device(dev2, dev);
		} else { /* already registered */
			VMBUS_LOG(NOTICE,
				"%s already registered", name);
			free(dev);
		}
		return 0;
	}

	vmbus_add_device(dev);
	return 0;
error:
	VMBUS_LOG(DEBUG, "failed");

	free(dev);
	return -1;
}
/* Scan one vmbus sysfs entry, and fill the devices list from it. */
Scan one vmbus sysfs entry, and fill the devices list from it.
Scan one vmbus sysfs entry and fill the devices list from it .
static int
vmbus_scan_one(const char *name)
{
	struct rte_vmbus_device *dev, *dev2;
	char filename[PATH_MAX];
	char dirname[PATH_MAX];
	unsigned long tmp;
	dev = calloc(1, sizeof(*dev));
	if (dev == NULL)
		return -1;
	dev->device.bus = &rte_vmbus_bus.bus;
	dev->device.name = strdup(name);
	if (!dev->device.name)
		goto error;
	snprintf(dirname, sizeof(dirname), "%s/%s",
		 SYSFS_VMBUS_DEVICES, name);
	snprintf(filename, sizeof(filename), "%s/class_id", dirname);
	if (parse_sysfs_uuid(filename, dev->class_id) < 0)
		goto error;
	if (rte_uuid_compare(dev->class_id, vmbus_nic_uuid) != 0) {
		free(dev);
		return 0;
	}
	snprintf(filename, sizeof(filename), "%s/device_id", dirname);
	if (parse_sysfs_uuid(filename, dev->device_id) < 0)
		goto error;
	snprintf(filename, sizeof(filename), "%s/id", dirname);
	if (eal_parse_sysfs_value(filename, &tmp) < 0)
		goto error;
	dev->relid = tmp;
	snprintf(filename, sizeof(filename), "%s/monitor_id", dirname);
	if (eal_parse_sysfs_value(filename, &tmp) < 0)
		goto error;
	dev->monitor_id = tmp;
	snprintf(filename, sizeof(filename), "%s/numa_node",
		 dirname);
	if (access(filename, R_OK) == 0) {
		if (eal_parse_sysfs_value(filename, &tmp) < 0)
			goto error;
		dev->device.numa_node = tmp;
	} else {
		dev->device.numa_node = SOCKET_ID_ANY;
	}
	dev->device.devargs = vmbus_devargs_lookup(dev);
	VMBUS_LOG(DEBUG, "Adding vmbus device %s", name);
	TAILQ_FOREACH(dev2, &rte_vmbus_bus.device_list, next) {
		int ret;
		ret = rte_uuid_compare(dev->device_id, dev2->device_id);
		if (ret > 0)
			continue;
		if (ret < 0) {
			vmbus_insert_device(dev2, dev);
		} else { 
			VMBUS_LOG(NOTICE,
				"%s already registered", name);
			free(dev);
		}
		return 0;
	}
	vmbus_add_device(dev);
	return 0;
error:
	VMBUS_LOG(DEBUG, "failed");
	free(dev);
	return -1;
}
static int vmbus_scan_one ( const char * name ) { struct rte_vmbus_device * dev , * dev2 ; char filename [ PATH_MAX ] ; char dirname [ PATH_MAX ] ; unsigned long tmp ; dev = calloc ( 1 , sizeof ( * dev ) ) ; if ( dev == NULL ) return -1 ; dev -> device . bus = & rte_vmbus_bus . bus ; dev -> device . name = strdup ( name ) ; if ( ! dev -> device . name ) goto error ; snprintf ( dirname , sizeof ( dirname ) , " " , SYSFS_VMBUS_DEVICES , name ) ; snprintf ( filename , sizeof ( filename ) , " " , dirname ) ; if ( parse_sysfs_uuid ( filename , dev -> class_id ) < 0 ) goto error ; if ( rte_uuid_compare ( dev -> class_id , vmbus_nic_uuid ) != 0 ) { free ( dev ) ; return 0 ; } snprintf ( filename , sizeof ( filename ) , " " , dirname ) ; if ( parse_sysfs_uuid ( filename , dev -> device_id ) < 0 ) goto error ; snprintf ( filename , sizeof ( filename ) , " " , dirname ) ; if ( eal_parse_sysfs_value ( filename , & tmp ) < 0 ) goto error ; dev -> relid = tmp ; snprintf ( filename , sizeof ( filename ) , " " , dirname ) ; if ( eal_parse_sysfs_value ( filename , & tmp ) < 0 ) goto error ; dev -> monitor_id = tmp ; snprintf ( filename , sizeof ( filename ) , " " , dirname ) ; if ( access ( filename , R_OK ) == 0 ) { if ( eal_parse_sysfs_value ( filename , & tmp ) < 0 ) goto error ; dev -> device . numa_node = tmp ; } else { dev -> device . numa_node = SOCKET_ID_ANY ; } dev -> device . devargs = vmbus_devargs_lookup ( dev ) ; VMBUS_LOG ( DEBUG , " " , name ) ; TAILQ_FOREACH ( dev2 , & rte_vmbus_bus . device_list , next ) { int ret ; ret = rte_uuid_compare ( dev -> device_id , dev2 -> device_id ) ; if ( ret > 0 ) continue ; if ( ret < 0 ) { vmbus_insert_device ( dev2 , dev ) ; } else { VMBUS_LOG ( NOTICE , " " , name ) ; free ( dev ) ; } return 0 ; } vmbus_add_device ( dev ) ; return 0 ; error : VMBUS_LOG ( DEBUG , " " ) ; free ( dev ) ; return -1 ; }
Scan one vmbus sysfs entry, and fill the devices list from it.
Scan one vmbus sysfs entry and fill the devices list from it .
/* sysfs base directory
	 *   /sys/bus/vmbus/devices/7a08391f-f5a0-4ac0-9802-d13fd964f8df
	 * or on older kernel
	 *   /sys/bus/vmbus/devices/vmbus_1
	 */ /* get device class  */ /* skip non-network devices */ /* get device id */ /* get relid */ /* get monitor id */ /* get numa node (if present) */ /* if no NUMA support, set default to 0 */ /* device is valid, add in list (sorted) */ /* already registered */