1 #ifndef _BCACHE_SUPER_H
2 #define _BCACHE_SUPER_H
6 static inline size_t sector_to_bucket(const struct cache *ca, sector_t s)
8 return s >> ca->bucket_bits;
11 static inline sector_t bucket_to_sector(const struct cache *ca, size_t b)
13 return ((sector_t) b) << ca->bucket_bits;
16 static inline sector_t bucket_remainder(const struct cache *ca, sector_t s)
18 return s & (ca->mi.bucket_size - 1);
21 static inline struct cache *bch_next_cache_rcu(struct cache_set *c,
24 struct cache *ret = NULL;
26 while (*iter < c->sb.nr_devices &&
27 !(ret = rcu_dereference(c->cache[*iter])))
33 #define for_each_cache_rcu(ca, c, iter) \
34 for ((iter) = 0; ((ca) = bch_next_cache_rcu((c), &(iter))); (iter)++)
36 static inline struct cache *bch_get_next_cache(struct cache_set *c,
42 if ((ret = bch_next_cache_rcu(c, iter)))
43 percpu_ref_get(&ret->ref);
50 * If you break early, you must drop your ref on the current cache
52 #define for_each_cache(ca, c, iter) \
54 (ca = bch_get_next_cache(c, &(iter))); \
55 percpu_ref_put(&ca->ref), (iter)++)
57 static inline bool bch_cache_may_remove(struct cache *ca)
59 struct cache_set *c = ca->set;
60 struct cache_group *tier = &c->cache_tiers[ca->mi.tier];
63 * Right now, we can't remove the last device from a tier,
64 * - For tier 0, because all metadata lives in tier 0 and because
65 * there is no way to have foreground writes go directly to tier 1.
66 * - For tier 1, because the code doesn't completely support an
71 * Turning a device read-only removes it from the cache group,
72 * so there may only be one read-write device in a tier, and yet
73 * the device we are removing is in the same tier, so we have
74 * to check for identity.
75 * Removing the last RW device from a tier requires turning the
79 return tier->nr_devices != 1 ||
80 rcu_access_pointer(tier->d[0].dev) != ca;
83 void bch_cache_set_release(struct kobject *);
84 void bch_cache_release(struct kobject *);
86 void bch_cache_set_unregister(struct cache_set *);
87 void bch_cache_set_stop(struct cache_set *);
89 const char *bch_register_one(const char *path);
90 const char *bch_register_cache_set(char * const *, unsigned,
91 struct cache_set_opts,
94 bool bch_cache_set_read_only(struct cache_set *);
95 bool bch_cache_set_emergency_read_only(struct cache_set *);
96 void bch_cache_set_read_only_sync(struct cache_set *);
97 const char *bch_cache_set_read_write(struct cache_set *);
99 bool bch_cache_read_only(struct cache *);
100 const char *bch_cache_read_write(struct cache *);
101 bool bch_cache_remove(struct cache *, bool force);
102 int bch_cache_set_add_cache(struct cache_set *, const char *);
104 extern struct mutex bch_register_lock;
105 extern struct list_head bch_cache_sets;
106 extern struct idr bch_cache_set_minor;
107 extern struct workqueue_struct *bcache_io_wq;
108 extern struct crypto_shash *bch_sha256;
110 extern struct kobj_type bch_cache_set_ktype;
111 extern struct kobj_type bch_cache_set_internal_ktype;
112 extern struct kobj_type bch_cache_set_time_stats_ktype;
113 extern struct kobj_type bch_cache_set_opts_dir_ktype;
114 extern struct kobj_type bch_cache_ktype;
116 #endif /* _BCACHE_SUPER_H */