[PATCH 1/3] Add support for per cache flags

Thomas Graf tgraf at suug.ch
Mon Nov 12 04:40:06 EST 2012


On 11/11/12 at 05:08pm, roopa at cumulusnetworks.com wrote:
> From: roopa <roopa at cumulusnetworks.com>
> 
> This patch adds support for per cache flags
> and adds a flag NL_CACHE_AF_ITER to iter over all
> supported families when filling the cache.

> @@ -246,6 +254,16 @@ struct nl_cache_ops
>  	int   (*co_include_event)(struct nl_cache *cache, struct nl_object *obj,
>  				  change_func_t change_cb, void *data);
>  
> +	/**
> +	 * Called to set cache flags
> +	 */
> +	int   (*co_set_flags)(struct nl_cache *, unsigned int flags);
> +
> +	/**
> +	 * Called to get cache flags
> +	 */
> +	unsigned int    (*co_get_flags)(struct nl_cache *);
> +

What are you intending to use these for?


> @@ -566,6 +566,36 @@ void nl_cache_set_arg2(struct nl_cache *cache, int arg)
>  }
>  
>  /**
> + * Set cache flags
> + * @arg cache		Cache
> + * @arg arg		flags
> + *
> + */
> +void nl_cache_set_flags(struct nl_cache *cache, unsigned int flags)
> +{
> +	if (cache->c_ops->co_set_flags) {
> +		cache->c_ops->co_set_flags(cache, flags);
> +		return;
> +	}
> +
> +	cache->c_ops->co_flags |= flags;
> +}

Storing the flag in the cache ops is OK but it should only be used as
the default for the per cache object flags.

We want to allow having two link cache objects, one having ITER
enabled while the other link cache doesn't.

I think we need:

Use Case 1: (Change default setting of a cache type)
        struct nl_cache_ops *ops;
        struct nl_cache *link_cache;

	ops  = nl_cache_ops_lookup("route/link");
        nl_cache_ops_set_flags(ops, NL_CACHE_AF_ITER)
        link_cache = rtnl_link_alloc_cache([...]);

Use Case 2: (Change setting of an individual cache)
        struct nl_cache *link_cache;

        link_cache = rtnl_link_alloc_cache([...]);
	nl_cache_set_flags(link_cache, NL_CACHE_AFTER_ITER);
	nl_cache_mngr_add_cache([...], link_cache);

i.e. add a new c_flags to struct nl_cache and inherit its value
from ops->co_flags and always use cache->c_flags when checking
whether the feature is enabled.



More information about the libnl mailing list