ceph_fs.c 2.5 KB

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