Lines Matching full:ca
21 static inline bool bch2_dev_is_online(struct bch_dev *ca) in bch2_dev_is_online() argument
23 return !percpu_ref_is_zero(&ca->io_ref); in bch2_dev_is_online()
26 static inline bool bch2_dev_is_readable(struct bch_dev *ca) in bch2_dev_is_readable() argument
28 return bch2_dev_is_online(ca) && in bch2_dev_is_readable()
29 ca->mi.state != BCH_MEMBER_STATE_failed; in bch2_dev_is_readable()
73 struct bch_dev *ca = NULL; in __bch2_next_dev_idx() local
78 !(ca = rcu_dereference_check(c->devs[idx], in __bch2_next_dev_idx()
82 return ca; in __bch2_next_dev_idx()
85 static inline struct bch_dev *__bch2_next_dev(struct bch_fs *c, struct bch_dev *ca, in __bch2_next_dev() argument
88 return __bch2_next_dev_idx(c, ca ? ca->dev_idx + 1 : 0, mask); in __bch2_next_dev()
95 static inline void bch2_dev_get(struct bch_dev *ca) in bch2_dev_get() argument
98 BUG_ON(atomic_long_inc_return(&ca->ref) <= 1L); in bch2_dev_get()
100 percpu_ref_get(&ca->ref); in bch2_dev_get()
104 static inline void __bch2_dev_put(struct bch_dev *ca) in __bch2_dev_put() argument
107 long r = atomic_long_dec_return(&ca->ref); in __bch2_dev_put()
108 if (r < (long) !ca->dying) in __bch2_dev_put()
109 panic("bch_dev->ref underflow, last put: %pS\n", (void *) ca->last_put); in __bch2_dev_put()
110 ca->last_put = _THIS_IP_; in __bch2_dev_put()
112 complete(&ca->ref_completion); in __bch2_dev_put()
114 percpu_ref_put(&ca->ref); in __bch2_dev_put()
118 static inline void bch2_dev_put(struct bch_dev *ca) in bch2_dev_put() argument
120 if (ca) in bch2_dev_put()
121 __bch2_dev_put(ca); in bch2_dev_put()
124 static inline struct bch_dev *bch2_get_next_dev(struct bch_fs *c, struct bch_dev *ca) in bch2_get_next_dev() argument
127 bch2_dev_put(ca); in bch2_get_next_dev()
128 if ((ca = __bch2_next_dev(c, ca, NULL))) in bch2_get_next_dev()
129 bch2_dev_get(ca); in bch2_get_next_dev()
132 return ca; in bch2_get_next_dev()
146 struct bch_dev *ca, in bch2_get_next_online_dev() argument
150 if (ca) in bch2_get_next_online_dev()
151 percpu_ref_put(&ca->io_ref); in bch2_get_next_online_dev()
153 while ((ca = __bch2_next_dev(c, ca, NULL)) && in bch2_get_next_online_dev()
154 (!((1 << ca->mi.state) & state_mask) || in bch2_get_next_online_dev()
155 !percpu_ref_tryget(&ca->io_ref))) in bch2_get_next_online_dev()
159 return ca; in bch2_get_next_online_dev()
166 #define for_each_online_member(c, ca) \ argument
167 __for_each_online_member(c, ca, ~0)
169 #define for_each_rw_member(c, ca) \ argument
170 __for_each_online_member(c, ca, BIT(BCH_MEMBER_STATE_rw))
172 #define for_each_readable_member(c, ca) \ argument
173 __for_each_online_member(c, ca, BIT( BCH_MEMBER_STATE_rw)|BIT(BCH_MEMBER_STATE_ro))
180 static inline bool bucket_valid(const struct bch_dev *ca, u64 b) in bucket_valid() argument
182 return b - ca->mi.first_bucket < ca->mi.nbuckets_minus_first; in bucket_valid()
212 struct bch_dev *ca = bch2_dev_rcu_noerror(c, dev); in bch2_dev_rcu() local
213 if (unlikely(!ca)) in bch2_dev_rcu()
215 return ca; in bch2_dev_rcu()
221 struct bch_dev *ca = bch2_dev_rcu_noerror(c, dev); in bch2_dev_tryget_noerror() local
222 if (ca) in bch2_dev_tryget_noerror()
223 bch2_dev_get(ca); in bch2_dev_tryget_noerror()
225 return ca; in bch2_dev_tryget_noerror()
230 struct bch_dev *ca = bch2_dev_tryget_noerror(c, dev); in bch2_dev_tryget() local
231 if (unlikely(!ca)) in bch2_dev_tryget()
233 return ca; in bch2_dev_tryget()
238 struct bch_dev *ca = bch2_dev_tryget_noerror(c, bucket.inode); in bch2_dev_bucket_tryget_noerror() local
239 if (ca && !bucket_valid(ca, bucket.offset)) { in bch2_dev_bucket_tryget_noerror()
240 bch2_dev_put(ca); in bch2_dev_bucket_tryget_noerror()
241 ca = NULL; in bch2_dev_bucket_tryget_noerror()
243 return ca; in bch2_dev_bucket_tryget_noerror()
250 struct bch_dev *ca = bch2_dev_bucket_tryget_noerror(c, bucket); in bch2_dev_bucket_tryget() local
251 if (!ca) in bch2_dev_bucket_tryget()
253 return ca; in bch2_dev_bucket_tryget()
256 static inline struct bch_dev *bch2_dev_iterate_noerror(struct bch_fs *c, struct bch_dev *ca, unsign… in bch2_dev_iterate_noerror() argument
258 if (ca && ca->dev_idx == dev_idx) in bch2_dev_iterate_noerror()
259 return ca; in bch2_dev_iterate_noerror()
260 bch2_dev_put(ca); in bch2_dev_iterate_noerror()
264 static inline struct bch_dev *bch2_dev_iterate(struct bch_fs *c, struct bch_dev *ca, unsigned dev_i… in bch2_dev_iterate() argument
266 if (ca && ca->dev_idx == dev_idx) in bch2_dev_iterate()
267 return ca; in bch2_dev_iterate()
268 bch2_dev_put(ca); in bch2_dev_iterate()
275 struct bch_dev *ca = bch2_dev_rcu(c, dev); in bch2_dev_get_ioref() local
276 if (ca && !percpu_ref_tryget(&ca->io_ref)) in bch2_dev_get_ioref()
277 ca = NULL; in bch2_dev_get_ioref()
280 if (ca && in bch2_dev_get_ioref()
281 (ca->mi.state == BCH_MEMBER_STATE_rw || in bch2_dev_get_ioref()
282 (ca->mi.state == BCH_MEMBER_STATE_ro && rw == READ))) in bch2_dev_get_ioref()
283 return ca; in bch2_dev_get_ioref()
285 if (ca) in bch2_dev_get_ioref()
286 percpu_ref_put(&ca->io_ref); in bch2_dev_get_ioref()
296 for_each_online_member(c, ca) in bch2_online_devs()
297 __set_bit(ca->dev_idx, devs.d); in bch2_online_devs()
347 static inline bool bch2_dev_btree_bitmap_marked_sectors(struct bch_dev *ca, u64 start, unsigned sec… in bch2_dev_btree_bitmap_marked_sectors() argument
351 if (end > 64ULL << ca->mi.btree_bitmap_shift) in bch2_dev_btree_bitmap_marked_sectors()
354 for (unsigned bit = start >> ca->mi.btree_bitmap_shift; in bch2_dev_btree_bitmap_marked_sectors()
355 (u64) bit << ca->mi.btree_bitmap_shift < end; in bch2_dev_btree_bitmap_marked_sectors()
357 if (!(ca->mi.btree_allocated_bitmap & BIT_ULL(bit))) in bch2_dev_btree_bitmap_marked_sectors()