disk_groups.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _BCACHEFS_DISK_GROUPS_H
  3. #define _BCACHEFS_DISK_GROUPS_H
  4. #include "disk_groups_types.h"
  5. extern const struct bch_sb_field_ops bch_sb_field_ops_disk_groups;
  6. static inline unsigned disk_groups_nr(struct bch_sb_field_disk_groups *groups)
  7. {
  8. return groups
  9. ? (vstruct_end(&groups->field) -
  10. (void *) &groups->entries[0]) / sizeof(struct bch_disk_group)
  11. : 0;
  12. }
  13. struct target {
  14. enum {
  15. TARGET_NULL,
  16. TARGET_DEV,
  17. TARGET_GROUP,
  18. } type;
  19. union {
  20. unsigned dev;
  21. unsigned group;
  22. };
  23. };
  24. #define TARGET_DEV_START 1
  25. #define TARGET_GROUP_START (256 + TARGET_DEV_START)
  26. static inline u16 dev_to_target(unsigned dev)
  27. {
  28. return TARGET_DEV_START + dev;
  29. }
  30. static inline u16 group_to_target(unsigned group)
  31. {
  32. return TARGET_GROUP_START + group;
  33. }
  34. static inline struct target target_decode(unsigned target)
  35. {
  36. if (target >= TARGET_GROUP_START)
  37. return (struct target) {
  38. .type = TARGET_GROUP,
  39. .group = target - TARGET_GROUP_START
  40. };
  41. if (target >= TARGET_DEV_START)
  42. return (struct target) {
  43. .type = TARGET_DEV,
  44. .group = target - TARGET_DEV_START
  45. };
  46. return (struct target) { .type = TARGET_NULL };
  47. }
  48. const struct bch_devs_mask *bch2_target_to_mask(struct bch_fs *, unsigned);
  49. static inline struct bch_devs_mask target_rw_devs(struct bch_fs *c,
  50. enum bch_data_type data_type,
  51. u16 target)
  52. {
  53. struct bch_devs_mask devs = c->rw_devs[data_type];
  54. const struct bch_devs_mask *t = bch2_target_to_mask(c, target);
  55. if (t)
  56. bitmap_and(devs.d, devs.d, t->d, BCH_SB_MEMBERS_MAX);
  57. return devs;
  58. }
  59. static inline bool bch2_target_accepts_data(struct bch_fs *c,
  60. enum bch_data_type data_type,
  61. u16 target)
  62. {
  63. struct bch_devs_mask rw_devs = target_rw_devs(c, data_type, target);
  64. return !bitmap_empty(rw_devs.d, BCH_SB_MEMBERS_MAX);
  65. }
  66. bool bch2_dev_in_target(struct bch_fs *, unsigned, unsigned);
  67. int bch2_disk_path_find(struct bch_sb_handle *, const char *);
  68. /* Exported for userspace bcachefs-tools: */
  69. int bch2_disk_path_find_or_create(struct bch_sb_handle *, const char *);
  70. void bch2_disk_path_to_text(struct printbuf *, struct bch_fs *, unsigned);
  71. void bch2_disk_path_to_text_sb(struct printbuf *, struct bch_sb *, unsigned);
  72. void bch2_target_to_text(struct printbuf *out, struct bch_fs *, unsigned);
  73. int bch2_opt_target_parse(struct bch_fs *, const char *, u64 *, struct printbuf *);
  74. void bch2_opt_target_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
  75. #define bch2_opt_target (struct bch_opt_fn) { \
  76. .parse = bch2_opt_target_parse, \
  77. .to_text = bch2_opt_target_to_text, \
  78. }
  79. int bch2_sb_disk_groups_to_cpu(struct bch_fs *);
  80. int __bch2_dev_group_set(struct bch_fs *, struct bch_dev *, const char *);
  81. int bch2_dev_group_set(struct bch_fs *, struct bch_dev *, const char *);
  82. const char *bch2_sb_validate_disk_groups(struct bch_sb *,
  83. struct bch_sb_field *);
  84. void bch2_disk_groups_to_text(struct printbuf *, struct bch_fs *);
  85. #endif /* _BCACHEFS_DISK_GROUPS_H */