ceph_fs.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Some non-inline ceph helpers
  4. */
  5. #include <linux/module.h>
  6. #include <linux/ceph/types.h>
  7. /*
  8. * return true if @layout appears to be valid
  9. */
  10. int ceph_file_layout_is_valid(const struct ceph_file_layout *layout)
  11. {
  12. __u32 su = layout->stripe_unit;
  13. __u32 sc = layout->stripe_count;
  14. __u32 os = layout->object_size;
  15. /* stripe unit, object size must be non-zero, 64k increment */
  16. if (!su || (su & (CEPH_MIN_STRIPE_UNIT-1)))
  17. return 0;
  18. if (!os || (os & (CEPH_MIN_STRIPE_UNIT-1)))
  19. return 0;
  20. /* object size must be a multiple of stripe unit */
  21. if (os < su || os % su)
  22. return 0;
  23. /* stripe count must be non-zero */
  24. if (!sc)
  25. return 0;
  26. return 1;
  27. }
  28. void ceph_file_layout_from_legacy(struct ceph_file_layout *fl,
  29. struct ceph_file_layout_legacy *legacy)
  30. {
  31. fl->stripe_unit = le32_to_cpu(legacy->fl_stripe_unit);
  32. fl->stripe_count = le32_to_cpu(legacy->fl_stripe_count);
  33. fl->object_size = le32_to_cpu(legacy->fl_object_size);
  34. fl->pool_id = le32_to_cpu(legacy->fl_pg_pool);
  35. if (fl->pool_id == 0 && fl->stripe_unit == 0 &&
  36. fl->stripe_count == 0 && fl->object_size == 0)
  37. fl->pool_id = -1;
  38. }
  39. EXPORT_SYMBOL(ceph_file_layout_from_legacy);
  40. void ceph_file_layout_to_legacy(struct ceph_file_layout *fl,
  41. struct ceph_file_layout_legacy *legacy)
  42. {
  43. legacy->fl_stripe_unit = cpu_to_le32(fl->stripe_unit);
  44. legacy->fl_stripe_count = cpu_to_le32(fl->stripe_count);
  45. legacy->fl_object_size = cpu_to_le32(fl->object_size);
  46. if (fl->pool_id >= 0)
  47. legacy->fl_pg_pool = cpu_to_le32(fl->pool_id);
  48. else
  49. legacy->fl_pg_pool = 0;
  50. }
  51. EXPORT_SYMBOL(ceph_file_layout_to_legacy);
  52. int ceph_flags_to_mode(int flags)
  53. {
  54. int mode;
  55. #ifdef O_DIRECTORY /* fixme */
  56. if ((flags & O_DIRECTORY) == O_DIRECTORY)
  57. return CEPH_FILE_MODE_PIN;
  58. #endif
  59. switch (flags & O_ACCMODE) {
  60. case O_WRONLY:
  61. mode = CEPH_FILE_MODE_WR;
  62. break;
  63. case O_RDONLY:
  64. mode = CEPH_FILE_MODE_RD;
  65. break;
  66. case O_RDWR:
  67. case O_ACCMODE: /* this is what the VFS does */
  68. mode = CEPH_FILE_MODE_RDWR;
  69. break;
  70. }
  71. #ifdef O_LAZY
  72. if (flags & O_LAZY)
  73. mode |= CEPH_FILE_MODE_LAZY;
  74. #endif
  75. return mode;
  76. }
  77. EXPORT_SYMBOL(ceph_flags_to_mode);
  78. int ceph_caps_for_mode(int mode)
  79. {
  80. int caps = CEPH_CAP_PIN;
  81. if (mode & CEPH_FILE_MODE_RD)
  82. caps |= CEPH_CAP_FILE_SHARED |
  83. CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE;
  84. if (mode & CEPH_FILE_MODE_WR)
  85. caps |= CEPH_CAP_FILE_EXCL |
  86. CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER |
  87. CEPH_CAP_AUTH_SHARED | CEPH_CAP_AUTH_EXCL |
  88. CEPH_CAP_XATTR_SHARED | CEPH_CAP_XATTR_EXCL;
  89. if (mode & CEPH_FILE_MODE_LAZY)
  90. caps |= CEPH_CAP_FILE_LAZYIO;
  91. return caps;
  92. }
  93. EXPORT_SYMBOL(ceph_caps_for_mode);