Commit 4d7e8cc5 authored by Yishai Hadas's avatar Yishai Hadas Committed by Doug Ledford

IB/core: Introduce UVERBS_IDR_ANY_OBJECT

Introduce the UVERBS_IDR_ANY_OBJECT type to match any IDR object.

Once used, the infrastructure skips checking for the IDR type, it
becomes the driver handler responsibility.

This enables drivers to get in a given method an object from various of
types.
Signed-off-by: default avatarYishai Hadas <yishaih@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent f33cb7e7
...@@ -398,7 +398,13 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj, ...@@ -398,7 +398,13 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
struct ib_uobject *uobj; struct ib_uobject *uobj;
int ret; int ret;
if (!obj) if (IS_ERR(obj) && PTR_ERR(obj) == -ENOMSG) {
/* must be UVERBS_IDR_ANY_OBJECT, see uapi_get_object() */
uobj = lookup_get_idr_uobject(NULL, ufile, id, mode);
if (IS_ERR(uobj))
return uobj;
} else {
if (IS_ERR(obj))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
uobj = obj->type_class->lookup_get(obj, ufile, id, mode); uobj = obj->type_class->lookup_get(obj, ufile, id, mode);
...@@ -409,6 +415,7 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj, ...@@ -409,6 +415,7 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
ret = -EINVAL; ret = -EINVAL;
goto free; goto free;
} }
}
/* /*
* If we have been disassociated block every command except for * If we have been disassociated block every command except for
...@@ -427,7 +434,7 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj, ...@@ -427,7 +434,7 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
return uobj; return uobj;
free: free:
obj->type_class->lookup_put(uobj, mode); uobj->uapi_object->type_class->lookup_put(uobj, mode);
uverbs_uobject_put(uobj); uverbs_uobject_put(uobj);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -491,7 +498,7 @@ struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj, ...@@ -491,7 +498,7 @@ struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
{ {
struct ib_uobject *ret; struct ib_uobject *ret;
if (!obj) if (IS_ERR(obj))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
/* /*
......
...@@ -162,10 +162,24 @@ struct uverbs_api { ...@@ -162,10 +162,24 @@ struct uverbs_api {
const struct uverbs_api_write_method **write_ex_methods; const struct uverbs_api_write_method **write_ex_methods;
}; };
/*
* Get an uverbs_api_object that corresponds to the given object_id.
* Note:
* -ENOMSG means that any object is allowed to match during lookup.
*/
static inline const struct uverbs_api_object * static inline const struct uverbs_api_object *
uapi_get_object(struct uverbs_api *uapi, u16 object_id) uapi_get_object(struct uverbs_api *uapi, u16 object_id)
{ {
return radix_tree_lookup(&uapi->radix, uapi_key_obj(object_id)); const struct uverbs_api_object *res;
if (object_id == UVERBS_IDR_ANY_OBJECT)
return ERR_PTR(-ENOMSG);
res = radix_tree_lookup(&uapi->radix, uapi_key_obj(object_id));
if (!res)
return ERR_PTR(-ENOENT);
return res;
} }
char *uapi_key_format(char *S, unsigned int key); char *uapi_key_format(char *S, unsigned int key);
......
...@@ -580,8 +580,13 @@ static void uapi_finalize_disable(struct uverbs_api *uapi) ...@@ -580,8 +580,13 @@ static void uapi_finalize_disable(struct uverbs_api *uapi)
if (obj_key == UVERBS_API_KEY_ERR) if (obj_key == UVERBS_API_KEY_ERR)
continue; continue;
tmp_obj = uapi_get_object(uapi, obj_key); tmp_obj = uapi_get_object(uapi, obj_key);
if (tmp_obj && !tmp_obj->disabled) if (IS_ERR(tmp_obj)) {
if (PTR_ERR(tmp_obj) == -ENOMSG)
continue; continue;
} else {
if (!tmp_obj->disabled)
continue;
}
starting_key = iter.index; starting_key = iter.index;
uapi_remove_method( uapi_remove_method(
......
...@@ -524,6 +524,12 @@ struct uapi_definition { ...@@ -524,6 +524,12 @@ struct uapi_definition {
.u2.objs_arr.max_len = _max_len, \ .u2.objs_arr.max_len = _max_len, \
__VA_ARGS__ } }) __VA_ARGS__ } })
/*
* Only for use with UVERBS_ATTR_IDR, allows any uobject type to be accepted,
* the user must validate the type of the uobject instead.
*/
#define UVERBS_IDR_ANY_OBJECT 0xFFFF
#define UVERBS_ATTR_IDR(_attr_id, _idr_type, _access, ...) \ #define UVERBS_ATTR_IDR(_attr_id, _idr_type, _access, ...) \
(&(const struct uverbs_attr_def){ \ (&(const struct uverbs_attr_def){ \
.id = _attr_id, \ .id = _attr_id, \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment