blk-cgroup-fc-appid.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "blk-cgroup.h"
  3. /**
  4. * blkcg_set_fc_appid - set the fc_app_id field associted to blkcg
  5. * @app_id: application identifier
  6. * @cgrp_id: cgroup id
  7. * @app_id_len: size of application identifier
  8. */
  9. int blkcg_set_fc_appid(char *app_id, u64 cgrp_id, size_t app_id_len)
  10. {
  11. struct cgroup *cgrp;
  12. struct cgroup_subsys_state *css;
  13. struct blkcg *blkcg;
  14. int ret = 0;
  15. if (app_id_len > FC_APPID_LEN)
  16. return -EINVAL;
  17. cgrp = cgroup_get_from_id(cgrp_id);
  18. if (IS_ERR(cgrp))
  19. return PTR_ERR(cgrp);
  20. css = cgroup_get_e_css(cgrp, &io_cgrp_subsys);
  21. if (!css) {
  22. ret = -ENOENT;
  23. goto out_cgrp_put;
  24. }
  25. blkcg = css_to_blkcg(css);
  26. /*
  27. * There is a slight race condition on setting the appid.
  28. * Worst case an I/O may not find the right id.
  29. * This is no different from the I/O we let pass while obtaining
  30. * the vmid from the fabric.
  31. * Adding the overhead of a lock is not necessary.
  32. */
  33. strlcpy(blkcg->fc_app_id, app_id, app_id_len);
  34. css_put(css);
  35. out_cgrp_put:
  36. cgroup_put(cgrp);
  37. return ret;
  38. }
  39. EXPORT_SYMBOL_GPL(blkcg_set_fc_appid);
  40. /**
  41. * blkcg_get_fc_appid - get the fc app identifier associated with a bio
  42. * @bio: target bio
  43. *
  44. * On success return the fc_app_id, on failure return NULL
  45. */
  46. char *blkcg_get_fc_appid(struct bio *bio)
  47. {
  48. if (!bio->bi_blkg || bio->bi_blkg->blkcg->fc_app_id[0] == '\0')
  49. return NULL;
  50. return bio->bi_blkg->blkcg->fc_app_id;
  51. }
  52. EXPORT_SYMBOL_GPL(blkcg_get_fc_appid);