[dpdk-dev] [PATCH] bus/vdev: add custom scan hook
Thomas Monjalon
thomas at monjalon.net
Wed Dec 6 10:21:48 CET 2017
06/12/2017 03:52, Tan, Jianfeng:
> On 12/1/2017 8:36 AM, Thomas Monjalon wrote:
> > +int
> > +rte_vdev_add_custom_scan(rte_vdev_scan_callback callback, void *user_arg)
> > +{
> > + struct vdev_custom_scan *custom_scan;
> > +
> > + rte_spinlock_lock(&vdev_custom_scan_lock);
> > +
> > + /* check if already registered */
> > + TAILQ_FOREACH(custom_scan, &vdev_custom_scans, next) {
> > + if (custom_scan->callback == callback &&
> > + custom_scan->user_arg == user_arg)
> > + break;
> > + }
> > +
> > + if (custom_scan == NULL) {
> > + custom_scan = malloc(sizeof(struct vdev_custom_scan));
> > + if (custom_scan != NULL) {
> > + custom_scan->callback = callback;
> > + custom_scan->user_arg = user_arg;
> > + TAILQ_INSERT_TAIL(&vdev_custom_scans, custom_scan, next);
> > + }
> > + }
> > +
> > + rte_spinlock_unlock(&vdev_custom_scan_lock);
> > +
> > + return (custom_scan == NULL) ? -ENOMEM : 0;
> > +}
> > +
> > +int
> > +rte_vdev_remove_custom_scan(rte_vdev_scan_callback callback, void *user_arg)
> > +{
> > + struct vdev_custom_scan *custom_scan, *tmp_scan;
> > +
> > + rte_spinlock_lock(&vdev_custom_scan_lock);
> > + TAILQ_FOREACH_SAFE(custom_scan, &vdev_custom_scans, next, tmp_scan) {
> > + if (custom_scan->callback != callback ||
> > + (custom_scan->user_arg != (void *)-1 &&
> > + custom_scan->user_arg != user_arg))
> > + continue;
> > + TAILQ_REMOVE(&vdev_custom_scans, custom_scan, next);
> > + free(custom_scan);
> > + }
> > + rte_spinlock_unlock(&vdev_custom_scan_lock);
> > +
> > + return 0;
> > +}
> > +
> > static int
> > vdev_parse(const char *name, void *addr)
> > {
> > @@ -260,6 +319,22 @@ vdev_scan(void)
> > {
> > struct rte_vdev_device *dev;
> > struct rte_devargs *devargs;
> > + struct vdev_custom_scan *custom_scan;
> > +
> > + /* call custom scan callbacks if any */
> > + rte_spinlock_lock(&vdev_custom_scan_lock);
> > + TAILQ_FOREACH(custom_scan, &vdev_custom_scans, next) {
> > + if (custom_scan->callback != NULL)
> > + /*
> > + * the callback should update devargs list
> > + * by calling rte_eal_devargs_insert() with
> > + * devargs.bus = rte_bus_find_by_name("vdev");
> > + * devargs.type = RTE_DEVTYPE_VIRTUAL;
> > + * devargs.policy = RTE_DEV_WHITELISTED;
> > + */
> > + custom_scan->callback(custom_scan->user_arg);
> > + }
> > + rte_spinlock_unlock(&vdev_custom_scan_lock);
>
> You mentioned that we want to call the hook in the scan(), but it's now
> in parse()?
No, it is in vdev_scan.
Look carefully the patch, especially after @@.
More information about the dev
mailing list