osdmap.h 3.6 KB

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