tmem: bugfix in obj allocate path
There is a potential bug in the obj allocate path. When there are parallel
callers allocate a obj and insert it to pool->obj_rb_root, an unexpected
obj might be returned (both callers use the same oid).
Caller A: Caller B:
obj_find(oidp) == NULL obj_find(oidp) == NULL
write_lock(&pool->pool_rwlock)
obj_new():
objA = tmem_malloc()
obj_rb_insert(objA)
wirte_unlock()
write_lock(&pool->pool_rwlock)
obj_new():
objB = tmem_malloc()
obj_rb_insert(objB)
write_unlock()
Continue write data to objA
But in future obj_find(), objB
will always be returned.
The route cause is the allocate path didn't check the return value of
obj_rb_insert(). This patch fix it and replace obj_new() with better name
obj_alloc().
Signed-off-by: Bob Liu <bob.liu@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>