osdmap.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef _FS_CEPH_OSDMAP_H
  2. #define _FS_CEPH_OSDMAP_H
  3. #include <linux/rbtree.h>
  4. #include "types.h"
  5. #include "ceph_fs.h"
  6. #include "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_pool_info {
  20. struct rb_node node;
  21. int id;
  22. struct ceph_pg_pool v;
  23. int pg_num_mask, pgp_num_mask, lpg_num_mask, lpgp_num_mask;
  24. };
  25. struct ceph_pg_mapping {
  26. struct rb_node node;
  27. struct ceph_pg pgid;
  28. int len;
  29. int osds[];
  30. };
  31. struct ceph_osdmap {
  32. struct ceph_fsid fsid;
  33. u32 epoch;
  34. u32 mkfs_epoch;
  35. struct ceph_timespec created, modified;
  36. u32 flags; /* CEPH_OSDMAP_* */
  37. u32 max_osd; /* size of osd_state, _offload, _addr arrays */
  38. u8 *osd_state; /* CEPH_OSD_* */
  39. u32 *osd_weight; /* 0 = failed, 0x10000 = 100% normal */
  40. struct ceph_entity_addr *osd_addr;
  41. struct rb_root pg_temp;
  42. struct rb_root pg_pools;
  43. u32 pool_max;
  44. /* the CRUSH map specifies the mapping of placement groups to
  45. * the list of osds that store+replicate them. */
  46. struct crush_map *crush;
  47. };
  48. /*
  49. * file layout helpers
  50. */
  51. #define ceph_file_layout_su(l) ((__s32)le32_to_cpu((l).fl_stripe_unit))
  52. #define ceph_file_layout_stripe_count(l) \
  53. ((__s32)le32_to_cpu((l).fl_stripe_count))
  54. #define ceph_file_layout_object_size(l) ((__s32)le32_to_cpu((l).fl_object_size))
  55. #define ceph_file_layout_cas_hash(l) ((__s32)le32_to_cpu((l).fl_cas_hash))
  56. #define ceph_file_layout_object_su(l) \
  57. ((__s32)le32_to_cpu((l).fl_object_stripe_unit))
  58. #define ceph_file_layout_pg_preferred(l) \
  59. ((__s32)le32_to_cpu((l).fl_pg_preferred))
  60. #define ceph_file_layout_pg_pool(l) \
  61. ((__s32)le32_to_cpu((l).fl_pg_pool))
  62. static inline unsigned ceph_file_layout_stripe_width(struct ceph_file_layout *l)
  63. {
  64. return le32_to_cpu(l->fl_stripe_unit) *
  65. le32_to_cpu(l->fl_stripe_count);
  66. }
  67. /* "period" == bytes before i start on a new set of objects */
  68. static inline unsigned ceph_file_layout_period(struct ceph_file_layout *l)
  69. {
  70. return le32_to_cpu(l->fl_object_size) *
  71. le32_to_cpu(l->fl_stripe_count);
  72. }
  73. static inline int ceph_osd_is_up(struct ceph_osdmap *map, int osd)
  74. {
  75. return (osd < map->max_osd) && (map->osd_state[osd] & CEPH_OSD_UP);
  76. }
  77. static inline bool ceph_osdmap_flag(struct ceph_osdmap *map, int flag)
  78. {
  79. return map && (map->flags & flag);
  80. }
  81. extern char *ceph_osdmap_state_str(char *str, int len, int state);
  82. static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map,
  83. int osd)
  84. {
  85. if (osd >= map->max_osd)
  86. return NULL;
  87. return &map->osd_addr[osd];
  88. }
  89. extern struct ceph_osdmap *osdmap_decode(void **p, void *end);
  90. extern struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
  91. struct ceph_osdmap *map,
  92. struct ceph_messenger *msgr);
  93. extern void ceph_osdmap_destroy(struct ceph_osdmap *map);
  94. /* calculate mapping of a file extent to an object */
  95. extern void ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
  96. u64 off, u64 *plen,
  97. u64 *bno, u64 *oxoff, u64 *oxlen);
  98. /* calculate mapping of object to a placement group */
  99. extern int ceph_calc_object_layout(struct ceph_object_layout *ol,
  100. const char *oid,
  101. struct ceph_file_layout *fl,
  102. struct ceph_osdmap *osdmap);
  103. extern int ceph_calc_pg_primary(struct ceph_osdmap *osdmap,
  104. struct ceph_pg pgid);
  105. #endif