2 * Copyright (C) 2016 Parav Pandit <pandit.parav@gmail.com>
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.
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
14 #include "core_priv.h"
17 * ib_device_register_rdmacg - register with rdma cgroup.
18 * @device: device to register to participate in resource
19 * accounting by rdma cgroup.
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.
26 int ib_device_register_rdmacg(struct ib_device
*device
)
28 device
->cg_device
.name
= device
->name
;
29 return rdmacg_register_device(&device
->cg_device
);
33 * ib_device_unregister_rdmacg - unregister with rdma cgroup.
34 * @device: device to unregister.
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.
41 void ib_device_unregister_rdmacg(struct ib_device
*device
)
43 rdmacg_unregister_device(&device
->cg_device
);
46 int ib_rdmacg_try_charge(struct ib_rdmacg_object
*cg_obj
,
47 struct ib_device
*device
,
48 enum rdmacg_resource_type resource_index
)
50 return rdmacg_try_charge(&cg_obj
->cg
, &device
->cg_device
,
53 EXPORT_SYMBOL(ib_rdmacg_try_charge
);
55 void ib_rdmacg_uncharge(struct ib_rdmacg_object
*cg_obj
,
56 struct ib_device
*device
,
57 enum rdmacg_resource_type resource_index
)
59 rdmacg_uncharge(cg_obj
->cg
, &device
->cg_device
,
62 EXPORT_SYMBOL(ib_rdmacg_uncharge
);