Lines Matching refs:ctxt

126 	struct moving_context *ctxt = io->write.ctxt;  in move_free()  local
131 mutex_lock(&ctxt->lock); in move_free()
133 wake_up(&ctxt->wait); in move_free()
134 mutex_unlock(&ctxt->lock); in move_free()
149 struct moving_context *ctxt = io->write.ctxt; in move_write_done() local
161 ctxt->write_error = true; in move_write_done()
164 atomic_sub(io->write_sectors, &ctxt->write_sectors); in move_write_done()
165 atomic_dec(&ctxt->write_ios); in move_write_done()
167 closure_put(&ctxt->cl); in move_write_done()
173 struct moving_context *ctxt = io->write.ctxt; in move_write() local
176 if (ctxt->stats) { in move_write()
179 &ctxt->stats->sectors_error_uncorrected); in move_write()
182 &ctxt->stats->sectors_error_corrected); in move_write()
213 closure_get(&io->write.ctxt->cl); in move_write()
214 atomic_add(io->write_sectors, &io->write.ctxt->write_sectors); in move_write()
215 atomic_inc(&io->write.ctxt->write_ios); in move_write()
220 struct moving_io *bch2_moving_ctxt_next_pending_write(struct moving_context *ctxt) in bch2_moving_ctxt_next_pending_write() argument
223 list_first_entry_or_null(&ctxt->reads, struct moving_io, read_list); in bch2_moving_ctxt_next_pending_write()
231 struct moving_context *ctxt = io->write.ctxt; in move_read_endio() local
233 atomic_sub(io->read_sectors, &ctxt->read_sectors); in move_read_endio()
234 atomic_dec(&ctxt->read_ios); in move_read_endio()
237 wake_up(&ctxt->wait); in move_read_endio()
238 closure_put(&ctxt->cl); in move_read_endio()
241 void bch2_moving_ctxt_do_pending_writes(struct moving_context *ctxt) in bch2_moving_ctxt_do_pending_writes() argument
245 while ((io = bch2_moving_ctxt_next_pending_write(ctxt))) { in bch2_moving_ctxt_do_pending_writes()
246 bch2_trans_unlock_long(ctxt->trans); in bch2_moving_ctxt_do_pending_writes()
252 void bch2_move_ctxt_wait_for_io(struct moving_context *ctxt) in bch2_move_ctxt_wait_for_io() argument
254 unsigned sectors_pending = atomic_read(&ctxt->write_sectors); in bch2_move_ctxt_wait_for_io()
256 move_ctxt_wait_event(ctxt, in bch2_move_ctxt_wait_for_io()
257 !atomic_read(&ctxt->write_sectors) || in bch2_move_ctxt_wait_for_io()
258 atomic_read(&ctxt->write_sectors) != sectors_pending); in bch2_move_ctxt_wait_for_io()
261 void bch2_moving_ctxt_flush_all(struct moving_context *ctxt) in bch2_moving_ctxt_flush_all() argument
263 move_ctxt_wait_event(ctxt, list_empty(&ctxt->reads)); in bch2_moving_ctxt_flush_all()
264 bch2_trans_unlock_long(ctxt->trans); in bch2_moving_ctxt_flush_all()
265 closure_sync(&ctxt->cl); in bch2_moving_ctxt_flush_all()
268 void bch2_moving_ctxt_exit(struct moving_context *ctxt) in bch2_moving_ctxt_exit() argument
270 struct bch_fs *c = ctxt->trans->c; in bch2_moving_ctxt_exit()
272 bch2_moving_ctxt_flush_all(ctxt); in bch2_moving_ctxt_exit()
274 EBUG_ON(atomic_read(&ctxt->write_sectors)); in bch2_moving_ctxt_exit()
275 EBUG_ON(atomic_read(&ctxt->write_ios)); in bch2_moving_ctxt_exit()
276 EBUG_ON(atomic_read(&ctxt->read_sectors)); in bch2_moving_ctxt_exit()
277 EBUG_ON(atomic_read(&ctxt->read_ios)); in bch2_moving_ctxt_exit()
280 list_del(&ctxt->list); in bch2_moving_ctxt_exit()
289 bch2_trans_begin(ctxt->trans); in bch2_moving_ctxt_exit()
290 bch2_trans_put(ctxt->trans); in bch2_moving_ctxt_exit()
291 memset(ctxt, 0, sizeof(*ctxt)); in bch2_moving_ctxt_exit()
294 void bch2_moving_ctxt_init(struct moving_context *ctxt, in bch2_moving_ctxt_init() argument
301 memset(ctxt, 0, sizeof(*ctxt)); in bch2_moving_ctxt_init()
303 ctxt->trans = bch2_trans_get(c); in bch2_moving_ctxt_init()
304 ctxt->fn = (void *) _RET_IP_; in bch2_moving_ctxt_init()
305 ctxt->rate = rate; in bch2_moving_ctxt_init()
306 ctxt->stats = stats; in bch2_moving_ctxt_init()
307 ctxt->wp = wp; in bch2_moving_ctxt_init()
308 ctxt->wait_on_copygc = wait_on_copygc; in bch2_moving_ctxt_init()
310 closure_init_stack(&ctxt->cl); in bch2_moving_ctxt_init()
312 mutex_init(&ctxt->lock); in bch2_moving_ctxt_init()
313 INIT_LIST_HEAD(&ctxt->reads); in bch2_moving_ctxt_init()
314 INIT_LIST_HEAD(&ctxt->ios); in bch2_moving_ctxt_init()
315 init_waitqueue_head(&ctxt->wait); in bch2_moving_ctxt_init()
318 list_add(&ctxt->list, &c->moving_context_list); in bch2_moving_ctxt_init()
334 int bch2_move_extent(struct moving_context *ctxt, in bch2_move_extent() argument
341 struct btree_trans *trans = ctxt->trans; in bch2_move_extent()
349 if (ctxt->stats) in bch2_move_extent()
350 ctxt->stats->pos = BBPOS(iter->btree_id, iter->pos); in bch2_move_extent()
371 io->write.ctxt = ctxt; in bch2_move_extent()
376 ret = bch2_data_update_init(trans, iter, ctxt, &io->write, ctxt->wp, in bch2_move_extent()
399 if (ctxt->rate) in bch2_move_extent()
400 bch2_ratelimit_increment(ctxt->rate, k.k->size); in bch2_move_extent()
402 if (ctxt->stats) { in bch2_move_extent()
403 atomic64_inc(&ctxt->stats->keys_moved); in bch2_move_extent()
404 atomic64_add(k.k->size, &ctxt->stats->sectors_moved); in bch2_move_extent()
415 mutex_lock(&ctxt->lock); in bch2_move_extent()
416 atomic_add(io->read_sectors, &ctxt->read_sectors); in bch2_move_extent()
417 atomic_inc(&ctxt->read_ios); in bch2_move_extent()
419 list_add_tail(&io->read_list, &ctxt->reads); in bch2_move_extent()
420 list_add_tail(&io->io_list, &ctxt->ios); in bch2_move_extent()
421 mutex_unlock(&ctxt->lock); in bch2_move_extent()
427 closure_get(&ctxt->cl); in bch2_move_extent()
550 int bch2_move_ratelimit(struct moving_context *ctxt) in bch2_move_ratelimit() argument
552 struct bch_fs *c = ctxt->trans->c; in bch2_move_ratelimit()
556 if (ctxt->wait_on_copygc && c->copygc_running) { in bch2_move_ratelimit()
557 bch2_moving_ctxt_flush_all(ctxt); in bch2_move_ratelimit()
564 delay = ctxt->rate ? bch2_ratelimit_delay(ctxt->rate) : 0; in bch2_move_ratelimit()
570 move_ctxt_wait_event_timeout(ctxt, in bch2_move_ratelimit()
576 bch2_moving_ctxt_flush_all(ctxt); in bch2_move_ratelimit()
585 move_ctxt_wait_event(ctxt, in bch2_move_ratelimit()
586 atomic_read(&ctxt->write_sectors) < c->opts.move_bytes_in_flight >> 9 && in bch2_move_ratelimit()
587 atomic_read(&ctxt->read_sectors) < c->opts.move_bytes_in_flight >> 9 && in bch2_move_ratelimit()
588 atomic_read(&ctxt->write_ios) < c->opts.move_ios_in_flight && in bch2_move_ratelimit()
589 atomic_read(&ctxt->read_ios) < c->opts.move_ios_in_flight); in bch2_move_ratelimit()
625 int bch2_move_data_btree(struct moving_context *ctxt, in bch2_move_data_btree() argument
631 struct btree_trans *trans = ctxt->trans; in bch2_move_data_btree()
650 if (ctxt->stats) { in bch2_move_data_btree()
651 ctxt->stats->data_type = BCH_DATA_user; in bch2_move_data_btree()
652 ctxt->stats->pos = BBPOS(btree_id, start); in bch2_move_data_btree()
706 if (ctxt->rate) in bch2_move_data_btree()
707 bch2_ratelimit_reset(ctxt->rate); in bch2_move_data_btree()
709 while (!bch2_move_ratelimit(ctxt)) { in bch2_move_data_btree()
727 if (ctxt->stats) in bch2_move_data_btree()
728 ctxt->stats->pos = BBPOS(iter.btree_id, iter.pos); in bch2_move_data_btree()
775 ret2 = bch2_move_extent(ctxt, NULL, extent_iter, k, *io_opts, data_opts); in bch2_move_data_btree()
788 bch2_move_ctxt_wait_for_io(ctxt); in bch2_move_data_btree()
796 if (ctxt->stats) in bch2_move_data_btree()
797 atomic64_add(k.k->size, &ctxt->stats->sectors_seen); in bch2_move_data_btree()
811 int __bch2_move_data(struct moving_context *ctxt, in __bch2_move_data() argument
816 struct bch_fs *c = ctxt->trans->c; in __bch2_move_data()
823 ctxt->stats->pos = BBPOS(id, POS_MIN); in __bch2_move_data()
829 ret = bch2_move_data_btree(ctxt, in __bch2_move_data()
849 struct moving_context ctxt; in bch2_move_data() local
851 bch2_moving_ctxt_init(&ctxt, c, rate, stats, wp, wait_on_copygc); in bch2_move_data()
852 int ret = __bch2_move_data(&ctxt, start, end, pred, arg); in bch2_move_data()
853 bch2_moving_ctxt_exit(&ctxt); in bch2_move_data()
858 static int __bch2_move_data_phys(struct moving_context *ctxt, in __bch2_move_data_phys() argument
867 struct btree_trans *trans = ctxt->trans; in __bch2_move_data_phys()
904 while (!(ret = bch2_move_ratelimit(ctxt))) { in __bch2_move_data_phys()
933 if (ctxt->stats) in __bch2_move_data_phys()
934 ctxt->stats->offset = bp.k->p.offset >> MAX_EXTENT_COMPRESS_RATIO_SHIFT; in __bch2_move_data_phys()
985 ret = bch2_move_extent(ctxt, bucket_in_flight, &iter, k, io_opts, data_opts); in __bch2_move_data_phys()
998 bch2_move_ctxt_wait_for_io(ctxt); in __bch2_move_data_phys()
1004 if (ctxt->stats) in __bch2_move_data_phys()
1005 atomic64_add(sectors, &ctxt->stats->sectors_seen); in __bch2_move_data_phys()
1032 struct moving_context ctxt; in bch2_move_data_phys() local
1036 bch2_moving_ctxt_init(&ctxt, c, rate, stats, wp, wait_on_copygc); in bch2_move_data_phys()
1037 if (ctxt.stats) { in bch2_move_data_phys()
1038 ctxt.stats->phys = true; in bch2_move_data_phys()
1039 ctxt.stats->data_type = (int) DATA_PROGRESS_DATA_TYPE_phys; in bch2_move_data_phys()
1042 int ret = __bch2_move_data_phys(&ctxt, NULL, dev, start, end, in bch2_move_data_phys()
1044 bch2_moving_ctxt_exit(&ctxt); in bch2_move_data_phys()
1070 int bch2_evacuate_bucket(struct moving_context *ctxt, in bch2_evacuate_bucket() argument
1075 struct bch_fs *c = ctxt->trans->c; in bch2_evacuate_bucket()
1082 return __bch2_move_data_phys(ctxt, bucket_in_flight, in bch2_evacuate_bucket()
1103 struct moving_context ctxt; in bch2_move_btree() local
1111 bch2_moving_ctxt_init(&ctxt, c, NULL, stats, in bch2_move_btree()
1114 trans = ctxt.trans; in bch2_move_btree()
1163 bch2_moving_ctxt_exit(&ctxt); in bch2_move_btree()
1449 … void bch2_moving_ctxt_to_text(struct printbuf *out, struct bch_fs *c, struct moving_context *ctxt) in bch2_moving_ctxt_to_text() argument
1454 bch2_move_stats_to_text(out, ctxt->stats); in bch2_moving_ctxt_to_text()
1458 atomic_read(&ctxt->read_ios), in bch2_moving_ctxt_to_text()
1460 atomic_read(&ctxt->read_sectors), in bch2_moving_ctxt_to_text()
1464 atomic_read(&ctxt->write_ios), in bch2_moving_ctxt_to_text()
1466 atomic_read(&ctxt->write_sectors), in bch2_moving_ctxt_to_text()
1471 mutex_lock(&ctxt->lock); in bch2_moving_ctxt_to_text()
1473 list_for_each_entry(io, &ctxt->ios, io_list) in bch2_moving_ctxt_to_text()
1475 mutex_unlock(&ctxt->lock); in bch2_moving_ctxt_to_text()
1482 struct moving_context *ctxt; in bch2_fs_moving_ctxts_to_text() local
1485 list_for_each_entry(ctxt, &c->moving_context_list, list) in bch2_fs_moving_ctxts_to_text()
1486 bch2_moving_ctxt_to_text(out, c, ctxt); in bch2_fs_moving_ctxts_to_text()