cgroup.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include "core_priv.h"
  14. /**
  15. * ib_device_register_rdmacg - register with rdma cgroup.
  16. * @device: device to register to participate in resource
  17. * accounting by rdma cgroup.
  18. *
  19. * Register with the rdma cgroup. Should be called before
  20. * exposing rdma device to user space applications to avoid
  21. * resource accounting leak.
  22. * Returns 0 on success or otherwise failure code.
  23. */
  24. int ib_device_register_rdmacg(struct ib_device *device)
  25. {
  26. device->cg_device.name = device->name;
  27. return rdmacg_register_device(&device->cg_device);
  28. }
  29. /**
  30. * ib_device_unregister_rdmacg - unregister with rdma cgroup.
  31. * @device: device to unregister.
  32. *
  33. * Unregister with the rdma cgroup. Should be called after
  34. * all the resources are deallocated, and after a stage when any
  35. * other resource allocation by user application cannot be done
  36. * for this device to avoid any leak in accounting.
  37. */
  38. void ib_device_unregister_rdmacg(struct ib_device *device)
  39. {
  40. rdmacg_unregister_device(&device->cg_device);
  41. }
  42. int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
  43. struct ib_device *device,
  44. enum rdmacg_resource_type resource_index)
  45. {
  46. return rdmacg_try_charge(&cg_obj->cg, &device->cg_device,
  47. resource_index);
  48. }
  49. EXPORT_SYMBOL(ib_rdmacg_try_charge);
  50. void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
  51. struct ib_device *device,
  52. enum rdmacg_resource_type resource_index)
  53. {
  54. rdmacg_uncharge(cg_obj->cg, &device->cg_device,
  55. resource_index);
  56. }
  57. EXPORT_SYMBOL(ib_rdmacg_uncharge);