proc_net_dev_renames.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "proc_net_dev_renames.h"
  3. DICTIONARY *netdev_renames = NULL;
  4. static void dictionary_netdev_rename_delete_cb(const DICTIONARY_ITEM *item __maybe_unused, void *value, void *data __maybe_unused) {
  5. struct rename_task *r = value;
  6. cgroup_netdev_release(r->cgroup_netdev_link);
  7. rrdlabels_destroy(r->chart_labels);
  8. freez((void *) r->container_name);
  9. freez((void *) r->container_device);
  10. freez((void *) r->ctx_prefix);
  11. }
  12. void netdev_renames_init(void) {
  13. static SPINLOCK spinlock = NETDATA_SPINLOCK_INITIALIZER;
  14. spinlock_lock(&spinlock);
  15. if(!netdev_renames) {
  16. netdev_renames = dictionary_create_advanced(DICT_OPTION_FIXED_SIZE, NULL, sizeof(struct rename_task));
  17. dictionary_register_delete_callback(netdev_renames, dictionary_netdev_rename_delete_cb, NULL);
  18. }
  19. spinlock_unlock(&spinlock);
  20. }
  21. void cgroup_rename_task_add(
  22. const char *host_device,
  23. const char *container_device,
  24. const char *container_name,
  25. RRDLABELS *labels,
  26. const char *ctx_prefix,
  27. const DICTIONARY_ITEM *cgroup_netdev_link)
  28. {
  29. netdev_renames_init();
  30. struct rename_task tmp = {
  31. .container_device = strdupz(container_device),
  32. .container_name = strdupz(container_name),
  33. .ctx_prefix = strdupz(ctx_prefix),
  34. .chart_labels = rrdlabels_create(),
  35. .cgroup_netdev_link = cgroup_netdev_link,
  36. };
  37. rrdlabels_migrate_to_these(tmp.chart_labels, labels);
  38. dictionary_set(netdev_renames, host_device, &tmp, sizeof(tmp));
  39. }
  40. // other threads can call this function to delete a rename to a netdev
  41. void cgroup_rename_task_device_del(const char *host_device) {
  42. dictionary_del(netdev_renames, host_device);
  43. }