]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/super.h
Delete more unused shim code, update bcache code
[bcachefs-tools-debian] / libbcache / super.h
1 #ifndef _BCACHE_SUPER_H
2 #define _BCACHE_SUPER_H
3
4 #include "extents.h"
5
6 static inline size_t sector_to_bucket(const struct cache *ca, sector_t s)
7 {
8         return s >> ca->bucket_bits;
9 }
10
11 static inline sector_t bucket_to_sector(const struct cache *ca, size_t b)
12 {
13         return ((sector_t) b) << ca->bucket_bits;
14 }
15
16 static inline sector_t bucket_remainder(const struct cache *ca, sector_t s)
17 {
18         return s & (ca->mi.bucket_size - 1);
19 }
20
21 static inline struct cache *bch_next_cache_rcu(struct cache_set *c,
22                                                unsigned *iter)
23 {
24         struct cache *ret = NULL;
25
26         while (*iter < c->sb.nr_devices &&
27                !(ret = rcu_dereference(c->cache[*iter])))
28                 (*iter)++;
29
30         return ret;
31 }
32
33 #define for_each_cache_rcu(ca, c, iter)                                 \
34         for ((iter) = 0; ((ca) = bch_next_cache_rcu((c), &(iter))); (iter)++)
35
36 static inline struct cache *bch_get_next_cache(struct cache_set *c,
37                                                unsigned *iter)
38 {
39         struct cache *ret;
40
41         rcu_read_lock();
42         if ((ret = bch_next_cache_rcu(c, iter)))
43                 percpu_ref_get(&ret->ref);
44         rcu_read_unlock();
45
46         return ret;
47 }
48
49 /*
50  * If you break early, you must drop your ref on the current cache
51  */
52 #define for_each_cache(ca, c, iter)                                     \
53         for ((iter) = 0;                                                \
54              (ca = bch_get_next_cache(c, &(iter)));                     \
55              percpu_ref_put(&ca->ref), (iter)++)
56
57 static inline bool bch_dev_may_remove(struct cache *ca)
58 {
59         struct cache_set *c = ca->set;
60         struct cache_group *tier = &c->cache_tiers[ca->mi.tier];
61
62         /*
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
67          *   empty tier 1.
68          */
69
70         /*
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
76          * whole cache set RO.
77          */
78
79         return tier->nr_devices != 1 ||
80                 rcu_access_pointer(tier->d[0].dev) != ca;
81 }
82
83 void bch_dev_release(struct kobject *);
84
85 bool bch_dev_read_only(struct cache *);
86 const char *bch_dev_read_write(struct cache *);
87 bool bch_dev_remove(struct cache *, bool force);
88 int bch_dev_add(struct cache_set *, const char *);
89
90 void bch_fs_detach(struct cache_set *);
91
92 bool bch_fs_read_only(struct cache_set *);
93 bool bch_fs_emergency_read_only(struct cache_set *);
94 void bch_fs_read_only_sync(struct cache_set *);
95 const char *bch_fs_read_write(struct cache_set *);
96
97 void bch_fs_release(struct kobject *);
98 void bch_fs_stop(struct cache_set *);
99 void bch_fs_stop_sync(struct cache_set *);
100
101 const char *bch_fs_open(char * const *, unsigned, struct bch_opts,
102                         struct cache_set **);
103 const char *bch_fs_open_incremental(const char *path);
104
105 extern struct mutex bch_register_lock;
106 extern struct list_head bch_fs_list;
107 extern struct workqueue_struct *bcache_io_wq;
108 extern struct crypto_shash *bch_sha256;
109
110 extern struct kobj_type bch_fs_ktype;
111 extern struct kobj_type bch_fs_internal_ktype;
112 extern struct kobj_type bch_fs_time_stats_ktype;
113 extern struct kobj_type bch_fs_opts_dir_ktype;
114 extern struct kobj_type bch_dev_ktype;
115
116 #endif /* _BCACHE_SUPER_H */