xref: /openbmc/linux/drivers/infiniband/core/cgroup.c (revision 6d99a79c)
1 /*
2  * Copyright (C) 2016 Parav Pandit <pandit.parav@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms and conditions of the GNU General Public License,
6  * version 2, as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  */
13 
14 #include "core_priv.h"
15 
16 /**
17  * ib_device_register_rdmacg - register with rdma cgroup.
18  * @device: device to register to participate in resource
19  *          accounting by rdma cgroup.
20  *
21  * Register with the rdma cgroup. Should be called before
22  * exposing rdma device to user space applications to avoid
23  * resource accounting leak.
24  * Returns 0 on success or otherwise failure code.
25  */
26 int ib_device_register_rdmacg(struct ib_device *device)
27 {
28 	device->cg_device.name = device->name;
29 	return rdmacg_register_device(&device->cg_device);
30 }
31 
32 /**
33  * ib_device_unregister_rdmacg - unregister with rdma cgroup.
34  * @device: device to unregister.
35  *
36  * Unregister with the rdma cgroup. Should be called after
37  * all the resources are deallocated, and after a stage when any
38  * other resource allocation by user application cannot be done
39  * for this device to avoid any leak in accounting.
40  */
41 void ib_device_unregister_rdmacg(struct ib_device *device)
42 {
43 	rdmacg_unregister_device(&device->cg_device);
44 }
45 
46 int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
47 			 struct ib_device *device,
48 			 enum rdmacg_resource_type resource_index)
49 {
50 	return rdmacg_try_charge(&cg_obj->cg, &device->cg_device,
51 				 resource_index);
52 }
53 EXPORT_SYMBOL(ib_rdmacg_try_charge);
54 
55 void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
56 			struct ib_device *device,
57 			enum rdmacg_resource_type resource_index)
58 {
59 	rdmacg_uncharge(cg_obj->cg, &device->cg_device,
60 			resource_index);
61 }
62 EXPORT_SYMBOL(ib_rdmacg_uncharge);
63