osdmap.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef _FS_CEPH_OSDMAP_H
  2. #define _FS_CEPH_OSDMAP_H
  3. #include <linux/rbtree.h>
  4. #include <linux/ceph/types.h>
  5. #include <linux/ceph/ceph_fs.h>
  6. #include <linux/crush/crush.h>
  7. /*
  8. * The osd map describes the current membership of the osd cluster and
  9. * specifies the mapping of objects to placement groups and placement
  10. * groups to (sets of) osds. That is, it completely specifies the
  11. * (desired) distribution of all data objects in the system at some
  12. * point in time.
  13. *
  14. * Each map version is identified by an epoch, which increases monotonically.
  15. *
  16. * The map can be updated either via an incremental map (diff) describing
  17. * the change between two successive epochs, or as a fully encoded map.
  18. */
  19. struct ceph_pg {
  20. uint64_t pool;
  21. uint32_t seed;
  22. };
  23. #define CEPH_POOL_FLAG_HASHPSPOOL 1
  24. struct ceph_pg_pool_info {
  25. struct rb_node node;
  26. s64 id;
  27. u8 type;
  28. u8 size;
  29. u8 crush_ruleset;
  30. u8 object_hash;
  31. u32 pg_num, pgp_num;
  32. int pg_num_mask, pgp_num_mask;
  33. u64 flags;
  34. char *name;
  35. };
  36. struct ceph_object_locator {
  37. uint64_t pool;
  38. char *key;
  39. };
  40. struct ceph_pg_mapping {
  41. struct rb_node node;
  42. struct ceph_pg pgid;
  43. int len;
  44. int osds[];
  45. };
  46. struct ceph_osdmap {
  47. struct ceph_fsid fsid;
  48. u32 epoch;
  49. u32 mkfs_epoch;
  50. struct ceph_timespec created, modified;
  51. u32 flags; /* CEPH_OSDMAP_* */
  52. u32 max_osd; /* size of osd_state, _offload, _addr arrays */
  53. u8 *osd_state; /* CEPH_OSD_* */
  54. u32 *osd_weight; /* 0 = failed, 0x10000 = 100% normal */
  55. struct ceph_entity_addr *osd_addr;
  56. struct rb_root pg_temp;
  57. struct rb_root pg_pools;
  58. u32 pool_max;
  59. /* the CRUSH map specifies the mapping of placement groups to
  60. * the list of osds that store+replicate them. */
  61. struct crush_map *crush;
  62. };
  63. /*
  64. * file layout helpers
  65. */
  66. #define ceph_file_layout_su(l) ((__s32)le32_to_cpu((l).fl_stripe_unit))
  67. #define ceph_file_layout_stripe_count(l) \
  68. ((__s32)le32_to_cpu((l).fl_stripe_count))
  69. #define ceph_file_layout_object_size(l) ((__s32)le32_to_cpu((l).fl_object_size))
  70. #define ceph_file_layout_cas_hash(l) ((__s32)le32_to_cpu((l).fl_cas_hash))
  71. #define ceph_file_layout_object_su(l) \
  72. ((__s32)le32_to_cpu((l).fl_object_stripe_unit))
  73. #define ceph_file_layout_pg_pool(l) \
  74. ((__s32)le32_to_cpu((l).fl_pg_pool))
  75. static inline unsigned ceph_file_layout_stripe_width(struct ceph_file_layout *l)
  76. {
  77. return le32_to_cpu(l->fl_stripe_unit) *
  78. le32_to_cpu(l->fl_stripe_count);
  79. }
  80. /* "period" == bytes before i start on a new set of objects */
  81. static inline unsigned ceph_file_layout_period(struct ceph_file_layout *l)
  82. {
  83. return le32_to_cpu(l->fl_object_size) *
  84. le32_to_cpu(l->fl_stripe_count);
  85. }
  86. static inline int ceph_osd_is_up(struct ceph_osdmap *map, int osd)
  87. {
  88. return (osd < map->max_osd) && (map->osd_state[osd] & CEPH_OSD_UP);
  89. }
  90. static inline bool ceph_osdmap_flag(struct ceph_osdmap *map, int flag)
  91. {
  92. return map && (map->flags & flag);
  93. }
  94. extern char *ceph_osdmap_state_str(char *str, int len, int state);
  95. static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map,
  96. int osd)
  97. {
  98. if (osd >= map->max_osd)
  99. return NULL;
  100. return &map->osd_addr[osd];
  101. }
  102. extern struct ceph_osdmap *osdmap_decode(void **p, void *end);
  103. extern struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
  104. struct ceph_osdmap *map,
  105. struct ceph_messenger *msgr);
  106. extern void ceph_osdmap_destroy(struct ceph_osdmap *map);
  107. /* calculate mapping of a file extent to an object */
  108. extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
  109. u64 off, u64 len,
  110. u64 *bno, u64 *oxoff, u64 *oxlen);
  111. /* calculate mapping of object to a placement group */
  112. extern int ceph_calc_ceph_pg(struct ceph_pg *pg, const char *oid,
  113. struct ceph_osdmap *osdmap, uint64_t pool);
  114. extern int ceph_calc_pg_acting(struct ceph_osdmap *osdmap,
  115. struct ceph_pg pgid,
  116. int *acting);
  117. extern int ceph_calc_pg_primary(struct ceph_osdmap *osdmap,
  118. struct ceph_pg pgid);
  119. extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id);
  120. extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name);
  121. #endif