ceph_frag.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef FS_CEPH_FRAG_H
  2. #define FS_CEPH_FRAG_H
  3. /*
  4. * "Frags" are a way to describe a subset of a 32-bit number space,
  5. * using a mask and a value to match against that mask. Any given frag
  6. * (subset of the number space) can be partitioned into 2^n sub-frags.
  7. *
  8. * Frags are encoded into a 32-bit word:
  9. * 8 upper bits = "bits"
  10. * 24 lower bits = "value"
  11. * (We could go to 5+27 bits, but who cares.)
  12. *
  13. * We use the _most_ significant bits of the 24 bit value. This makes
  14. * values logically sort.
  15. *
  16. * Unfortunately, because the "bits" field is still in the high bits, we
  17. * can't sort encoded frags numerically. However, it does allow you
  18. * to feed encoded frags as values into frag_contains_value.
  19. */
  20. static inline __u32 ceph_frag_make(__u32 b, __u32 v)
  21. {
  22. return (b << 24) |
  23. (v & (0xffffffu << (24-b)) & 0xffffffu);
  24. }
  25. static inline __u32 ceph_frag_bits(__u32 f)
  26. {
  27. return f >> 24;
  28. }
  29. static inline __u32 ceph_frag_value(__u32 f)
  30. {
  31. return f & 0xffffffu;
  32. }
  33. static inline __u32 ceph_frag_mask(__u32 f)
  34. {
  35. return (0xffffffu << (24-ceph_frag_bits(f))) & 0xffffffu;
  36. }
  37. static inline __u32 ceph_frag_mask_shift(__u32 f)
  38. {
  39. return 24 - ceph_frag_bits(f);
  40. }
  41. static inline bool ceph_frag_contains_value(__u32 f, __u32 v)
  42. {
  43. return (v & ceph_frag_mask(f)) == ceph_frag_value(f);
  44. }
  45. static inline __u32 ceph_frag_make_child(__u32 f, int by, int i)
  46. {
  47. int newbits = ceph_frag_bits(f) + by;
  48. return ceph_frag_make(newbits,
  49. ceph_frag_value(f) | (i << (24 - newbits)));
  50. }
  51. static inline bool ceph_frag_is_leftmost(__u32 f)
  52. {
  53. return ceph_frag_value(f) == 0;
  54. }
  55. static inline bool ceph_frag_is_rightmost(__u32 f)
  56. {
  57. return ceph_frag_value(f) == ceph_frag_mask(f);
  58. }
  59. static inline __u32 ceph_frag_next(__u32 f)
  60. {
  61. return ceph_frag_make(ceph_frag_bits(f),
  62. ceph_frag_value(f) + (0x1000000 >> ceph_frag_bits(f)));
  63. }
  64. /*
  65. * comparator to sort frags logically, as when traversing the
  66. * number space in ascending order...
  67. */
  68. int ceph_frag_compare(__u32 a, __u32 b);
  69. #endif