FreeBSD/sys/dev/netmap/netmap_monitor.c
/* add the monitor mkring to the list of monitors of kring.
 * If this is the first monitor, intercept the callbacks
 */
add the monitor mkring to the list of monitors of kring.
If this is the first monitor, intercept the callbacks
add the monitor mkring to the list of monitors of kring . If this is the first monitor intercept the callbacks
static int
netmap_monitor_add(struct netmap_kring *mkring, struct netmap_kring *kring, int zcopy)
{
	int error = 0;
	nm_kr_get(kring);
	error = nm_monitor_alloc(kring, kring->n_monitors + 1);
	if (error)
		goto out;
	kring->monitors[kring->n_monitors] = mkring;
	mkring->mon_pos = kring->n_monitors;
	kring->n_monitors++;
	if (kring->n_monitors == 1) {
		D("%s: intercept callbacks on %s", mkring->name, kring->name);
		kring->mon_sync = kring->nm_sync;
		kring->mon_notify = kring->nm_notify;
		if (kring->tx == NR_TX) {
			kring->nm_sync = (zcopy ? netmap_zmon_parent_txsync :
						  netmap_monitor_parent_txsync);
		} else {
			kring->nm_sync = (zcopy ? netmap_zmon_parent_rxsync :
						  netmap_monitor_parent_rxsync);
			if (!zcopy) {
				kring->nm_notify = netmap_monitor_parent_notify;
				kring->mon_tail = kring->nr_hwtail;
			}
		}
	}
out:
	nm_kr_put(kring);
	return error;
}
static int netmap_monitor_add ( struct netmap_kring * mkring , struct netmap_kring * kring , int zcopy ) { int error = 0 ; nm_kr_get ( kring ) ; error = nm_monitor_alloc ( kring , kring -> n_monitors + 1 ) ; if ( error ) goto out ; kring -> monitors [ kring -> n_monitors ] = mkring ; mkring -> mon_pos = kring -> n_monitors ; kring -> n_monitors ++ ; if ( kring -> n_monitors == 1 ) { D ( " " , mkring -> name , kring -> name ) ; kring -> mon_sync = kring -> nm_sync ; kring -> mon_notify = kring -> nm_notify ; if ( kring -> tx == NR_TX ) { kring -> nm_sync = ( zcopy ? netmap_zmon_parent_txsync : netmap_monitor_parent_txsync ) ; } else { kring -> nm_sync = ( zcopy ? netmap_zmon_parent_rxsync : netmap_monitor_parent_rxsync ) ; if ( ! zcopy ) { kring -> nm_notify = netmap_monitor_parent_notify ; kring -> mon_tail = kring -> nr_hwtail ; } } } out : nm_kr_put ( kring ) ; return error ; }
add the monitor mkring to the list of monitors of kring.
add the monitor mkring to the list of monitors of kring .
/* sinchronize with concurrently running nm_sync()s */ /* make sure the monitor array exists and is big enough */ /* this is the first monitor, intercept callbacks */ /* zcopy monitors do not override nm_notify(), but
		 * we save the original one regardless, so that
		 * netmap_monitor_del() does not need to know the
		 * monitor type
		 */ /* also intercept notify */