osdmap.h 3.8 KB

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