prfile.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Mainly for aufs which mmap(2) different file and wants to print different
  4. * path in /proc/PID/maps.
  5. * Call these functions via macros defined in linux/mm.h.
  6. *
  7. * See Documentation/filesystems/aufs/design/06mmap.txt
  8. *
  9. * Copyright (c) 2014-2019 Junjro R. Okajima
  10. * Copyright (c) 2014 Ian Campbell
  11. */
  12. #include <linux/mm.h>
  13. #include <linux/file.h>
  14. #include <linux/fs.h>
  15. /* #define PRFILE_TRACE */
  16. static inline void prfile_trace(struct file *f, struct file *pr,
  17. const char func[], int line, const char func2[])
  18. {
  19. #ifdef PRFILE_TRACE
  20. if (pr)
  21. pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
  22. #endif
  23. }
  24. void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
  25. int line)
  26. {
  27. struct file *f = vma->vm_file, *pr = vma->vm_prfile;
  28. prfile_trace(f, pr, func, line, __func__);
  29. file_update_time(f);
  30. if (f && pr)
  31. file_update_time(pr);
  32. }
  33. struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
  34. int line)
  35. {
  36. struct file *f = vma->vm_file, *pr = vma->vm_prfile;
  37. prfile_trace(f, pr, func, line, __func__);
  38. return (f && pr) ? pr : f;
  39. }
  40. void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
  41. {
  42. struct file *f = vma->vm_file, *pr = vma->vm_prfile;
  43. prfile_trace(f, pr, func, line, __func__);
  44. get_file(f);
  45. if (f && pr)
  46. get_file(pr);
  47. }
  48. void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
  49. {
  50. struct file *f = vma->vm_file, *pr = vma->vm_prfile;
  51. prfile_trace(f, pr, func, line, __func__);
  52. fput(f);
  53. if (f && pr)
  54. fput(pr);
  55. }
  56. #ifndef CONFIG_MMU
  57. struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
  58. int line)
  59. {
  60. struct file *f = region->vm_file, *pr = region->vm_prfile;
  61. prfile_trace(f, pr, func, line, __func__);
  62. return (f && pr) ? pr : f;
  63. }
  64. void vmr_do_fput(struct vm_region *region, const char func[], int line)
  65. {
  66. struct file *f = region->vm_file, *pr = region->vm_prfile;
  67. prfile_trace(f, pr, func, line, __func__);
  68. fput(f);
  69. if (f && pr)
  70. fput(pr);
  71. }
  72. #endif /* !CONFIG_MMU */