Lines Matching refs:s

71 	while (atomic_read(&s->cl.remaining) & CLOSURE_WAITING)  in bch_data_insert_keys()
72 closure_sync(&s->cl); in bch_data_insert_keys()
484 struct search *s = container_of(cl, struct search, cl); in bch_cache_read_endio() local
494 s->iop.error = bio->bi_error; in bch_cache_read_endio()
496 ptr_stale(s->iop.c, &b->key, 0)) { in bch_cache_read_endio()
497 atomic_long_inc(&s->iop.c->cache_read_races); in bch_cache_read_endio()
498 s->iop.error = -EINTR; in bch_cache_read_endio()
501 bch_bbio_endio(s->iop.c, bio, bio->bi_error, "reading from cache"); in bch_cache_read_endio()
510 struct search *s = container_of(op, struct search, op); in cache_lookup_fn() local
511 struct bio *n, *bio = &s->bio.bio; in cache_lookup_fn()
515 if (bkey_cmp(k, &KEY(s->iop.inode, bio->bi_iter.bi_sector, 0)) <= 0) in cache_lookup_fn()
518 if (KEY_INODE(k) != s->iop.inode || in cache_lookup_fn()
521 unsigned sectors = KEY_INODE(k) == s->iop.inode in cache_lookup_fn()
526 int ret = s->d->cache_miss(b, s, bio, sectors); in cache_lookup_fn()
543 s->read_dirty_data = true; in cache_lookup_fn()
547 GFP_NOIO, s->d->bio_split); in cache_lookup_fn()
552 bch_cut_front(&KEY(s->iop.inode, n->bi_iter.bi_sector, 0), bio_key); in cache_lookup_fn()
553 bch_cut_back(&KEY(s->iop.inode, bio_end_sector(n), 0), bio_key); in cache_lookup_fn()
556 n->bi_private = &s->cl; in cache_lookup_fn()
575 struct search *s = container_of(cl, struct search, iop.cl); in cache_lookup() local
576 struct bio *bio = &s->bio.bio; in cache_lookup()
579 bch_btree_op_init(&s->op, -1); in cache_lookup()
581 ret = bch_btree_map_keys(&s->op, s->iop.c, in cache_lookup()
582 &KEY(s->iop.inode, bio->bi_iter.bi_sector, 0), in cache_lookup()
599 struct search *s = container_of(cl, struct search, cl); in request_endio() local
600 s->iop.error = bio->bi_error; in request_endio()
602 s->recoverable = false; in request_endio()
609 static void bio_complete(struct search *s) in bio_complete() argument
611 if (s->orig_bio) { in bio_complete()
612 generic_end_io_acct(bio_data_dir(s->orig_bio), in bio_complete()
613 &s->d->disk->part0, s->start_time); in bio_complete()
615 trace_bcache_request_end(s->d, s->orig_bio); in bio_complete()
616 s->orig_bio->bi_error = s->iop.error; in bio_complete()
617 bio_endio(s->orig_bio); in bio_complete()
618 s->orig_bio = NULL; in bio_complete()
622 static void do_bio_hook(struct search *s, struct bio *orig_bio) in do_bio_hook() argument
624 struct bio *bio = &s->bio.bio; in do_bio_hook()
629 bio->bi_private = &s->cl; in do_bio_hook()
636 struct search *s = container_of(cl, struct search, cl); in search_free() local
637 bio_complete(s); in search_free()
639 if (s->iop.bio) in search_free()
640 bio_put(s->iop.bio); in search_free()
643 mempool_free(s, s->d->c->search); in search_free()
649 struct search *s; in search_alloc() local
651 s = mempool_alloc(d->c->search, GFP_NOIO); in search_alloc()
653 closure_init(&s->cl, NULL); in search_alloc()
654 do_bio_hook(s, bio); in search_alloc()
656 s->orig_bio = bio; in search_alloc()
657 s->cache_miss = NULL; in search_alloc()
658 s->d = d; in search_alloc()
659 s->recoverable = 1; in search_alloc()
660 s->write = (bio->bi_rw & REQ_WRITE) != 0; in search_alloc()
661 s->read_dirty_data = 0; in search_alloc()
662 s->start_time = jiffies; in search_alloc()
664 s->iop.c = d->c; in search_alloc()
665 s->iop.bio = NULL; in search_alloc()
666 s->iop.inode = d->id; in search_alloc()
667 s->iop.write_point = hash_long((unsigned long) current, 16); in search_alloc()
668 s->iop.write_prio = 0; in search_alloc()
669 s->iop.error = 0; in search_alloc()
670 s->iop.flags = 0; in search_alloc()
671 s->iop.flush_journal = (bio->bi_rw & (REQ_FLUSH|REQ_FUA)) != 0; in search_alloc()
672 s->iop.wq = bcache_wq; in search_alloc()
674 return s; in search_alloc()
681 struct search *s = container_of(cl, struct search, cl); in cached_dev_bio_complete() local
682 struct cached_dev *dc = container_of(s->d, struct cached_dev, disk); in cached_dev_bio_complete()
692 struct search *s = container_of(cl, struct search, cl); in cached_dev_cache_miss_done() local
694 if (s->iop.replace_collision) in cached_dev_cache_miss_done()
695 bch_mark_cache_miss_collision(s->iop.c, s->d); in cached_dev_cache_miss_done()
697 if (s->iop.bio) { in cached_dev_cache_miss_done()
701 bio_for_each_segment_all(bv, s->iop.bio, i) in cached_dev_cache_miss_done()
710 struct search *s = container_of(cl, struct search, cl); in cached_dev_read_error() local
711 struct bio *bio = &s->bio.bio; in cached_dev_read_error()
713 if (s->recoverable) { in cached_dev_read_error()
715 trace_bcache_read_retry(s->orig_bio); in cached_dev_read_error()
717 s->iop.error = 0; in cached_dev_read_error()
718 do_bio_hook(s, s->orig_bio); in cached_dev_read_error()
730 struct search *s = container_of(cl, struct search, cl); in cached_dev_read_done() local
731 struct cached_dev *dc = container_of(s->d, struct cached_dev, disk); in cached_dev_read_done()
741 if (s->iop.bio) { in cached_dev_read_done()
742 bio_reset(s->iop.bio); in cached_dev_read_done()
743 s->iop.bio->bi_iter.bi_sector = s->cache_miss->bi_iter.bi_sector; in cached_dev_read_done()
744 s->iop.bio->bi_bdev = s->cache_miss->bi_bdev; in cached_dev_read_done()
745 s->iop.bio->bi_iter.bi_size = s->insert_bio_sectors << 9; in cached_dev_read_done()
746 bch_bio_map(s->iop.bio, NULL); in cached_dev_read_done()
748 bio_copy_data(s->cache_miss, s->iop.bio); in cached_dev_read_done()
750 bio_put(s->cache_miss); in cached_dev_read_done()
751 s->cache_miss = NULL; in cached_dev_read_done()
754 if (verify(dc, &s->bio.bio) && s->recoverable && !s->read_dirty_data) in cached_dev_read_done()
755 bch_data_verify(dc, s->orig_bio); in cached_dev_read_done()
757 bio_complete(s); in cached_dev_read_done()
759 if (s->iop.bio && in cached_dev_read_done()
760 !test_bit(CACHE_SET_STOPPING, &s->iop.c->flags)) { in cached_dev_read_done()
761 BUG_ON(!s->iop.replace); in cached_dev_read_done()
762 closure_call(&s->iop.cl, bch_data_insert, NULL, cl); in cached_dev_read_done()
770 struct search *s = container_of(cl, struct search, cl); in cached_dev_read_done_bh() local
771 struct cached_dev *dc = container_of(s->d, struct cached_dev, disk); in cached_dev_read_done_bh()
773 bch_mark_cache_accounting(s->iop.c, s->d, in cached_dev_read_done_bh()
774 !s->cache_miss, s->iop.bypass); in cached_dev_read_done_bh()
775 trace_bcache_read(s->orig_bio, !s->cache_miss, s->iop.bypass); in cached_dev_read_done_bh()
777 if (s->iop.error) in cached_dev_read_done_bh()
779 else if (s->iop.bio || verify(dc, &s->bio.bio)) in cached_dev_read_done_bh()
785 static int cached_dev_cache_miss(struct btree *b, struct search *s, in cached_dev_cache_miss() argument
790 struct cached_dev *dc = container_of(s->d, struct cached_dev, disk); in cached_dev_cache_miss()
793 if (s->cache_miss || s->iop.bypass) { in cached_dev_cache_miss()
794 miss = bio_next_split(bio, sectors, GFP_NOIO, s->d->bio_split); in cached_dev_cache_miss()
801 s->iop.c->gc_stats.in_use < CUTOFF_CACHE_READA) in cached_dev_cache_miss()
805 s->insert_bio_sectors = min(sectors, bio_sectors(bio) + reada); in cached_dev_cache_miss()
807 s->iop.replace_key = KEY(s->iop.inode, in cached_dev_cache_miss()
808 bio->bi_iter.bi_sector + s->insert_bio_sectors, in cached_dev_cache_miss()
809 s->insert_bio_sectors); in cached_dev_cache_miss()
811 ret = bch_btree_insert_check_key(b, &s->op, &s->iop.replace_key); in cached_dev_cache_miss()
815 s->iop.replace = true; in cached_dev_cache_miss()
817 miss = bio_next_split(bio, sectors, GFP_NOIO, s->d->bio_split); in cached_dev_cache_miss()
823 DIV_ROUND_UP(s->insert_bio_sectors, PAGE_SECTORS), in cached_dev_cache_miss()
830 cache_bio->bi_iter.bi_size = s->insert_bio_sectors << 9; in cached_dev_cache_miss()
833 cache_bio->bi_private = &s->cl; in cached_dev_cache_miss()
840 bch_mark_cache_readahead(s->iop.c, s->d); in cached_dev_cache_miss()
842 s->cache_miss = miss; in cached_dev_cache_miss()
843 s->iop.bio = cache_bio; in cached_dev_cache_miss()
845 closure_bio_submit(cache_bio, &s->cl); in cached_dev_cache_miss()
852 miss->bi_private = &s->cl; in cached_dev_cache_miss()
853 closure_bio_submit(miss, &s->cl); in cached_dev_cache_miss()
857 static void cached_dev_read(struct cached_dev *dc, struct search *s) in cached_dev_read() argument
859 struct closure *cl = &s->cl; in cached_dev_read()
861 closure_call(&s->iop.cl, cache_lookup, NULL, cl); in cached_dev_read()
869 struct search *s = container_of(cl, struct search, cl); in cached_dev_write_complete() local
870 struct cached_dev *dc = container_of(s->d, struct cached_dev, disk); in cached_dev_write_complete()
876 static void cached_dev_write(struct cached_dev *dc, struct search *s) in cached_dev_write() argument
878 struct closure *cl = &s->cl; in cached_dev_write()
879 struct bio *bio = &s->bio.bio; in cached_dev_write()
883 bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys, &start, &end); in cached_dev_write()
891 s->iop.bypass = false; in cached_dev_write()
892 s->iop.writeback = true; in cached_dev_write()
903 s->iop.bypass = true; in cached_dev_write()
905 if (should_writeback(dc, s->orig_bio, in cached_dev_write()
907 s->iop.bypass)) { in cached_dev_write()
908 s->iop.bypass = false; in cached_dev_write()
909 s->iop.writeback = true; in cached_dev_write()
912 if (s->iop.bypass) { in cached_dev_write()
913 s->iop.bio = s->orig_bio; in cached_dev_write()
914 bio_get(s->iop.bio); in cached_dev_write()
919 } else if (s->iop.writeback) { in cached_dev_write()
921 s->iop.bio = bio; in cached_dev_write()
936 s->iop.bio = bio_clone_fast(bio, GFP_NOIO, dc->disk.bio_split); in cached_dev_write()
941 closure_call(&s->iop.cl, bch_data_insert, NULL, cl); in cached_dev_write()
947 struct search *s = container_of(cl, struct search, cl); in cached_dev_nodata() local
948 struct bio *bio = &s->bio.bio; in cached_dev_nodata()
950 if (s->iop.flush_journal) in cached_dev_nodata()
951 bch_journal_meta(s->iop.c, cl); in cached_dev_nodata()
964 struct search *s; in cached_dev_make_request() local
975 s = search_alloc(bio, d); in cached_dev_make_request()
976 trace_bcache_request_start(s->d, bio); in cached_dev_make_request()
983 continue_at_nobarrier(&s->cl, in cached_dev_make_request()
987 s->iop.bypass = check_should_bypass(dc, bio); in cached_dev_make_request()
990 cached_dev_write(dc, s); in cached_dev_make_request()
992 cached_dev_read(dc, s); in cached_dev_make_request()
1049 static int flash_dev_cache_miss(struct btree *b, struct search *s, in flash_dev_cache_miss() argument
1068 struct search *s = container_of(cl, struct search, cl); in flash_dev_nodata() local
1070 if (s->iop.flush_journal) in flash_dev_nodata()
1071 bch_journal_meta(s->iop.c, cl); in flash_dev_nodata()
1079 struct search *s; in flash_dev_make_request() local
1086 s = search_alloc(bio, d); in flash_dev_make_request()
1087 cl = &s->cl; in flash_dev_make_request()
1088 bio = &s->bio.bio; in flash_dev_make_request()
1090 trace_bcache_request_start(s->d, bio); in flash_dev_make_request()
1097 continue_at_nobarrier(&s->cl, in flash_dev_make_request()
1102 bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys, in flash_dev_make_request()
1106 s->iop.bypass = (bio->bi_rw & REQ_DISCARD) != 0; in flash_dev_make_request()
1107 s->iop.writeback = true; in flash_dev_make_request()
1108 s->iop.bio = bio; in flash_dev_make_request()
1110 closure_call(&s->iop.cl, bch_data_insert, NULL, cl); in flash_dev_make_request()
1112 closure_call(&s->iop.cl, cache_lookup, NULL, cl); in flash_dev_make_request()