ceph_fs.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Some non-inline ceph helpers
  3. */
  4. #include "types.h"
  5. int ceph_flags_to_mode(int flags)
  6. {
  7. #ifdef O_DIRECTORY /* fixme */
  8. if ((flags & O_DIRECTORY) == O_DIRECTORY)
  9. return CEPH_FILE_MODE_PIN;
  10. #endif
  11. #ifdef O_LAZY
  12. if (flags & O_LAZY)
  13. return CEPH_FILE_MODE_LAZY;
  14. #endif
  15. if ((flags & O_APPEND) == O_APPEND)
  16. flags |= O_WRONLY;
  17. flags &= O_ACCMODE;
  18. if ((flags & O_RDWR) == O_RDWR)
  19. return CEPH_FILE_MODE_RDWR;
  20. if ((flags & O_WRONLY) == O_WRONLY)
  21. return CEPH_FILE_MODE_WR;
  22. return CEPH_FILE_MODE_RD;
  23. }
  24. int ceph_caps_for_mode(int mode)
  25. {
  26. switch (mode) {
  27. case CEPH_FILE_MODE_PIN:
  28. return CEPH_CAP_PIN;
  29. case CEPH_FILE_MODE_RD:
  30. return CEPH_CAP_PIN | CEPH_CAP_FILE_SHARED |
  31. CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE;
  32. case CEPH_FILE_MODE_RDWR:
  33. return CEPH_CAP_PIN | CEPH_CAP_FILE_SHARED |
  34. CEPH_CAP_FILE_EXCL |
  35. CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE |
  36. CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER |
  37. CEPH_CAP_AUTH_SHARED | CEPH_CAP_AUTH_EXCL |
  38. CEPH_CAP_XATTR_SHARED | CEPH_CAP_XATTR_EXCL;
  39. case CEPH_FILE_MODE_WR:
  40. return CEPH_CAP_PIN | CEPH_CAP_FILE_SHARED |
  41. CEPH_CAP_FILE_EXCL |
  42. CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER |
  43. CEPH_CAP_AUTH_SHARED | CEPH_CAP_AUTH_EXCL |
  44. CEPH_CAP_XATTR_SHARED | CEPH_CAP_XATTR_EXCL;
  45. }
  46. return 0;
  47. }
  48. /* Name hashing routines. Initial hash value */
  49. /* Hash courtesy of the R5 hash in reiserfs modulo sign bits */
  50. #define ceph_init_name_hash() 0
  51. /* partial hash update function. Assume roughly 4 bits per character */
  52. static unsigned long ceph_partial_name_hash(unsigned long c,
  53. unsigned long prevhash)
  54. {
  55. return (prevhash + (c << 4) + (c >> 4)) * 11;
  56. }
  57. /*
  58. * Finally: cut down the number of bits to a int value (and try to avoid
  59. * losing bits)
  60. */
  61. static unsigned long ceph_end_name_hash(unsigned long hash)
  62. {
  63. return hash & 0xffffffff;
  64. }
  65. /* Compute the hash for a name string. */
  66. unsigned int ceph_full_name_hash(const char *name, unsigned int len)
  67. {
  68. unsigned long hash = ceph_init_name_hash();
  69. while (len--)
  70. hash = ceph_partial_name_hash(*name++, hash);
  71. return ceph_end_name_hash(hash);
  72. }