osdmap.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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/decode.h>
  6. #include <linux/ceph/ceph_fs.h>
  7. #include <linux/crush/crush.h>
  8. /*
  9. * The osd map describes the current membership of the osd cluster and
  10. * specifies the mapping of objects to placement groups and placement
  11. * groups to (sets of) osds. That is, it completely specifies the
  12. * (desired) distribution of all data objects in the system at some
  13. * point in time.
  14. *
  15. * Each map version is identified by an epoch, which increases monotonically.
  16. *
  17. * The map can be updated either via an incremental map (diff) describing
  18. * the change between two successive epochs, or as a fully encoded map.
  19. */
  20. struct ceph_pg {
  21. uint64_t pool;
  22. uint32_t seed;
  23. };
  24. #define CEPH_POOL_FLAG_HASHPSPOOL 1
  25. struct ceph_pg_pool_info {
  26. struct rb_node node;
  27. s64 id;
  28. u8 type;
  29. u8 size;
  30. u8 crush_ruleset;
  31. u8 object_hash;
  32. u32 pg_num, pgp_num;
  33. int pg_num_mask, pgp_num_mask;
  34. s64 read_tier;
  35. s64 write_tier; /* wins for read+write ops */
  36. u64 flags;
  37. char *name;
  38. };
  39. static inline bool ceph_can_shift_osds(struct ceph_pg_pool_info *pool)
  40. {
  41. switch (pool->type) {
  42. case CEPH_POOL_TYPE_REP:
  43. return true;
  44. case CEPH_POOL_TYPE_EC:
  45. return false;
  46. default:
  47. BUG();
  48. }
  49. }
  50. struct ceph_object_locator {
  51. s64 pool;
  52. };
  53. /*
  54. * Maximum supported by kernel client object name length
  55. *
  56. * (probably outdated: must be >= RBD_MAX_MD_NAME_LEN -- currently 100)
  57. */
  58. #define CEPH_MAX_OID_NAME_LEN 100
  59. struct ceph_object_id {
  60. char name[CEPH_MAX_OID_NAME_LEN];
  61. int name_len;
  62. };
  63. struct ceph_pg_mapping {
  64. struct rb_node node;
  65. struct ceph_pg pgid;
  66. union {
  67. struct {
  68. int len;
  69. int osds[];
  70. } pg_temp;
  71. struct {
  72. int osd;
  73. } primary_temp;
  74. };
  75. };
  76. struct ceph_osdmap {
  77. struct ceph_fsid fsid;
  78. u32 epoch;
  79. u32 mkfs_epoch;
  80. struct ceph_timespec created, modified;
  81. u32 flags; /* CEPH_OSDMAP_* */
  82. u32 max_osd; /* size of osd_state, _offload, _addr arrays */
  83. u8 *osd_state; /* CEPH_OSD_* */
  84. u32 *osd_weight; /* 0 = failed, 0x10000 = 100% normal */
  85. struct ceph_entity_addr *osd_addr;
  86. struct rb_root pg_temp;
  87. struct rb_root primary_temp;
  88. u32 *osd_primary_affinity;
  89. struct rb_root pg_pools;
  90. u32 pool_max;
  91. /* the CRUSH map specifies the mapping of placement groups to
  92. * the list of osds that store+replicate them. */
  93. struct crush_map *crush;
  94. struct mutex crush_scratch_mutex;
  95. int crush_scratch_ary[CEPH_PG_MAX_SIZE * 3];
  96. };
  97. static inline void ceph_oid_set_name(struct ceph_object_id *oid,
  98. const char *name)
  99. {
  100. int len;
  101. len = strlen(name);
  102. if (len > sizeof(oid->name)) {
  103. WARN(1, "ceph_oid_set_name '%s' len %d vs %zu, truncating\n",
  104. name, len, sizeof(oid->name));
  105. len = sizeof(oid->name);
  106. }
  107. memcpy(oid->name, name, len);
  108. oid->name_len = len;
  109. }
  110. static inline void ceph_oid_copy(struct ceph_object_id *dest,
  111. struct ceph_object_id *src)
  112. {
  113. BUG_ON(src->name_len > sizeof(dest->name));
  114. memcpy(dest->name, src->name, src->name_len);
  115. dest->name_len = src->name_len;
  116. }
  117. static inline int ceph_osd_exists(struct ceph_osdmap *map, int osd)
  118. {
  119. return osd >= 0 && osd < map->max_osd &&
  120. (map->osd_state[osd] & CEPH_OSD_EXISTS);
  121. }
  122. static inline int ceph_osd_is_up(struct ceph_osdmap *map, int osd)
  123. {
  124. return ceph_osd_exists(map, osd) &&
  125. (map->osd_state[osd] & CEPH_OSD_UP);
  126. }
  127. static inline int ceph_osd_is_down(struct ceph_osdmap *map, int osd)
  128. {
  129. return !ceph_osd_is_up(map, osd);
  130. }
  131. static inline bool ceph_osdmap_flag(struct ceph_osdmap *map, int flag)
  132. {
  133. return map && (map->flags & flag);
  134. }
  135. extern char *ceph_osdmap_state_str(char *str, int len, int state);
  136. extern u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd);
  137. static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map,
  138. int osd)
  139. {
  140. if (osd >= map->max_osd)
  141. return NULL;
  142. return &map->osd_addr[osd];
  143. }
  144. static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid)
  145. {
  146. __u8 version;
  147. if (!ceph_has_room(p, end, 1 + 8 + 4 + 4)) {
  148. pr_warn("incomplete pg encoding\n");
  149. return -EINVAL;
  150. }
  151. version = ceph_decode_8(p);
  152. if (version > 1) {
  153. pr_warn("do not understand pg encoding %d > 1\n",
  154. (int)version);
  155. return -EINVAL;
  156. }
  157. pgid->pool = ceph_decode_64(p);
  158. pgid->seed = ceph_decode_32(p);
  159. *p += 4; /* skip deprecated preferred value */
  160. return 0;
  161. }
  162. extern struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end);
  163. extern struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
  164. struct ceph_osdmap *map,
  165. struct ceph_messenger *msgr);
  166. extern void ceph_osdmap_destroy(struct ceph_osdmap *map);
  167. /* calculate mapping of a file extent to an object */
  168. extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
  169. u64 off, u64 len,
  170. u64 *bno, u64 *oxoff, u64 *oxlen);
  171. /* calculate mapping of object to a placement group */
  172. extern int ceph_oloc_oid_to_pg(struct ceph_osdmap *osdmap,
  173. struct ceph_object_locator *oloc,
  174. struct ceph_object_id *oid,
  175. struct ceph_pg *pg_out);
  176. extern int ceph_calc_pg_acting(struct ceph_osdmap *osdmap,
  177. struct ceph_pg pgid,
  178. int *osds, int *primary);
  179. extern int ceph_calc_pg_primary(struct ceph_osdmap *osdmap,
  180. struct ceph_pg pgid);
  181. extern struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map,
  182. u64 id);
  183. extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id);
  184. extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name);
  185. #endif