cache pickup: Avoid duplicates during cache pickup

This patch adds search and replace/update functionality
to cache pickup_cb. This change is required to avoid
duplicates getting into the cache during pickup. Also
helps updating existing objects during cache pickup.
We have seen this in cases of ipv6 equal cost multipath
routes

changes v1 to v2:
	- Updated documentation

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
This commit is contained in:
roopa 2012-12-20 18:32:00 -08:00 committed by Thomas Graf
parent 91ab1bea5e
commit 96bb7c9a4c

View file

@ -696,7 +696,21 @@ static int __cache_pickup(struct nl_sock *sk, struct nl_cache *cache,
static int pickup_cb(struct nl_object *c, struct nl_parser_param *p)
{
return nl_cache_add((struct nl_cache *) p->pp_arg, c);
struct nl_cache *cache = (struct nl_cache *)p->pp_arg;
struct nl_object *old;
old = nl_cache_search(cache, c);
if (old) {
if (nl_object_update(old, c) == 0) {
nl_object_put(old);
return 0;
}
nl_cache_remove(old);
nl_object_put(old);
}
return nl_cache_add(cache, c);
}
/**
@ -705,7 +719,10 @@ static int pickup_cb(struct nl_object *c, struct nl_parser_param *p)
* @arg cache Cache to put items into.
*
* Waits for netlink messages to arrive, parses them and puts them into
* the specified cache.
* the specified cache. If an old object with same key attributes is
* present in the cache, it is replaced with the new object.
* If the old object type supports an update operation, an update is
* attempted before a replace.
*
* @return 0 on success or a negative error code.
*/
@ -889,7 +906,10 @@ errout:
* @arg msg netlink message
*
* Parses a netlink message by calling the cache specific message parser
* and adds the new element to the cache.
* and adds the new element to the cache. If an old object with same key
* attributes is present in the cache, it is replaced with the new object.
* If the old object type supports an update operation, an update is
* attempted before a replace.
*
* @return 0 or a negative error code.
*/