From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Monjalon Subject: Re: [PATCH] bus/vdev: add custom scan hook Date: Wed, 06 Dec 2017 10:21:48 +0100 Message-ID: <3098333.2ghLid1hiy@xps> References: <20171201003642.19827-1-thomas@monjalon.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit Cc: dev@dpdk.org To: "Tan, Jianfeng" Return-path: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by dpdk.org (Postfix) with ESMTP id 0277C1B19E for ; Wed, 6 Dec 2017 10:21:49 +0100 (CET) In-Reply-To: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 @@.