ceph_fs.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 = le32_to_cpu(layout->fl_stripe_unit);
  12. __u32 sc = le32_to_cpu(layout->fl_stripe_count);
  13. __u32 os = le32_to_cpu(layout->fl_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. int ceph_flags_to_mode(int flags)
  28. {
  29. int mode;
  30. #ifdef O_DIRECTORY /* fixme */
  31. if ((flags & O_DIRECTORY) == O_DIRECTORY)
  32. return CEPH_FILE_MODE_PIN;
  33. #endif
  34. switch (flags & O_ACCMODE) {
  35. case O_WRONLY:
  36. mode = CEPH_FILE_MODE_WR;
  37. break;
  38. case O_RDONLY:
  39. mode = CEPH_FILE_MODE_RD;
  40. break;
  41. case O_RDWR:
  42. case O_ACCMODE: /* this is what the VFS does */
  43. mode = CEPH_FILE_MODE_RDWR;
  44. break;
  45. }
  46. #ifdef O_LAZY
  47. if (flags & O_LAZY)
  48. mode |= CEPH_FILE_MODE_LAZY;
  49. #endif
  50. return mode;
  51. }
  52. EXPORT_SYMBOL(ceph_flags_to_mode);
  53. int ceph_caps_for_mode(int mode)
  54. {
  55. int caps = CEPH_CAP_PIN;
  56. if (mode & CEPH_FILE_MODE_RD)
  57. caps |= CEPH_CAP_FILE_SHARED |
  58. CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE;
  59. if (mode & CEPH_FILE_MODE_WR)
  60. caps |= CEPH_CAP_FILE_EXCL |
  61. CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER |
  62. CEPH_CAP_AUTH_SHARED | CEPH_CAP_AUTH_EXCL |
  63. CEPH_CAP_XATTR_SHARED | CEPH_CAP_XATTR_EXCL;
  64. if (mode & CEPH_FILE_MODE_LAZY)
  65. caps |= CEPH_CAP_FILE_LAZYIO;
  66. return caps;
  67. }
  68. EXPORT_SYMBOL(ceph_caps_for_mode);