Lines Matching full:sdio

159 static inline unsigned dio_pages_present(struct dio_submit *sdio)  in dio_pages_present()  argument
161 return sdio->tail - sdio->head; in dio_pages_present()
167 static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio) in dio_refill_pages() argument
172 ret = iov_iter_get_pages2(sdio->iter, dio->pages, LONG_MAX, DIO_PAGES, in dio_refill_pages()
173 &sdio->from); in dio_refill_pages()
175 if (ret < 0 && sdio->blocks_available && dio_op == REQ_OP_WRITE) { in dio_refill_pages()
186 sdio->head = 0; in dio_refill_pages()
187 sdio->tail = 1; in dio_refill_pages()
188 sdio->from = 0; in dio_refill_pages()
189 sdio->to = PAGE_SIZE; in dio_refill_pages()
194 ret += sdio->from; in dio_refill_pages()
195 sdio->head = 0; in dio_refill_pages()
196 sdio->tail = (ret + PAGE_SIZE - 1) / PAGE_SIZE; in dio_refill_pages()
197 sdio->to = ((ret - 1) & (PAGE_SIZE - 1)) + 1; in dio_refill_pages()
210 struct dio_submit *sdio) in dio_get_page() argument
212 if (dio_pages_present(sdio) == 0) { in dio_get_page()
215 ret = dio_refill_pages(dio, sdio); in dio_get_page()
218 BUG_ON(dio_pages_present(sdio) == 0); in dio_get_page()
220 return dio->pages[sdio->head]; in dio_get_page()
390 dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, in dio_bio_alloc() argument
406 sdio->bio = bio; in dio_bio_alloc()
407 sdio->logical_offset_in_bio = sdio->cur_page_fs_offset; in dio_bio_alloc()
417 static inline void dio_bio_submit(struct dio *dio, struct dio_submit *sdio) in dio_bio_submit() argument
420 struct bio *bio = sdio->bio; in dio_bio_submit()
434 if (sdio->submit_io) in dio_bio_submit()
435 sdio->submit_io(bio, dio->inode, sdio->logical_offset_in_bio); in dio_bio_submit()
439 sdio->bio = NULL; in dio_bio_submit()
440 sdio->boundary = 0; in dio_bio_submit()
441 sdio->logical_offset_in_bio = 0; in dio_bio_submit()
447 static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio) in dio_cleanup() argument
449 while (sdio->head < sdio->tail) in dio_cleanup()
450 put_page(dio->pages[sdio->head++]); in dio_cleanup()
538 static inline int dio_bio_reap(struct dio *dio, struct dio_submit *sdio) in dio_bio_reap() argument
542 if (sdio->reap_counter++ >= 64) { in dio_bio_reap()
556 sdio->reap_counter = 0; in dio_bio_reap()
599 * of available blocks at sdio->blocks_available. These are in units of the
620 static int get_more_blocks(struct dio *dio, struct dio_submit *sdio, in get_more_blocks() argument
629 unsigned int i_blkbits = sdio->blkbits + sdio->blkfactor; in get_more_blocks()
638 BUG_ON(sdio->block_in_file >= sdio->final_block_in_request); in get_more_blocks()
639 fs_startblk = sdio->block_in_file >> sdio->blkfactor; in get_more_blocks()
640 fs_endblk = (sdio->final_block_in_request - 1) >> in get_more_blocks()
641 sdio->blkfactor; in get_more_blocks()
665 ret = (*sdio->get_block)(dio->inode, fs_startblk, in get_more_blocks()
680 static inline int dio_new_bio(struct dio *dio, struct dio_submit *sdio, in dio_new_bio() argument
686 ret = dio_bio_reap(dio, sdio); in dio_new_bio()
689 sector = start_sector << (sdio->blkbits - 9); in dio_new_bio()
690 nr_pages = bio_max_segs(sdio->pages_in_io); in dio_new_bio()
692 dio_bio_alloc(dio, sdio, map_bh->b_bdev, sector, nr_pages); in dio_new_bio()
693 sdio->boundary = 0; in dio_new_bio()
705 static inline int dio_bio_add_page(struct dio_submit *sdio) in dio_bio_add_page() argument
709 ret = bio_add_page(sdio->bio, sdio->cur_page, in dio_bio_add_page()
710 sdio->cur_page_len, sdio->cur_page_offset); in dio_bio_add_page()
711 if (ret == sdio->cur_page_len) { in dio_bio_add_page()
715 if ((sdio->cur_page_len + sdio->cur_page_offset) == PAGE_SIZE) in dio_bio_add_page()
716 sdio->pages_in_io--; in dio_bio_add_page()
717 get_page(sdio->cur_page); in dio_bio_add_page()
718 sdio->final_block_in_bio = sdio->cur_page_block + in dio_bio_add_page()
719 (sdio->cur_page_len >> sdio->blkbits); in dio_bio_add_page()
737 static inline int dio_send_cur_page(struct dio *dio, struct dio_submit *sdio, in dio_send_cur_page() argument
742 if (sdio->bio) { in dio_send_cur_page()
743 loff_t cur_offset = sdio->cur_page_fs_offset; in dio_send_cur_page()
744 loff_t bio_next_offset = sdio->logical_offset_in_bio + in dio_send_cur_page()
745 sdio->bio->bi_iter.bi_size; in dio_send_cur_page()
761 if (sdio->final_block_in_bio != sdio->cur_page_block || in dio_send_cur_page()
763 dio_bio_submit(dio, sdio); in dio_send_cur_page()
766 if (sdio->bio == NULL) { in dio_send_cur_page()
767 ret = dio_new_bio(dio, sdio, sdio->cur_page_block, map_bh); in dio_send_cur_page()
772 if (dio_bio_add_page(sdio) != 0) { in dio_send_cur_page()
773 dio_bio_submit(dio, sdio); in dio_send_cur_page()
774 ret = dio_new_bio(dio, sdio, sdio->cur_page_block, map_bh); in dio_send_cur_page()
776 ret = dio_bio_add_page(sdio); in dio_send_cur_page()
802 submit_page_section(struct dio *dio, struct dio_submit *sdio, struct page *page, in submit_page_section() argument
808 int boundary = sdio->boundary; /* dio_send_cur_page may clear it */ in submit_page_section()
820 if (sdio->cur_page == page && in submit_page_section()
821 sdio->cur_page_offset + sdio->cur_page_len == offset && in submit_page_section()
822 sdio->cur_page_block + in submit_page_section()
823 (sdio->cur_page_len >> sdio->blkbits) == blocknr) { in submit_page_section()
824 sdio->cur_page_len += len; in submit_page_section()
831 if (sdio->cur_page) { in submit_page_section()
832 ret = dio_send_cur_page(dio, sdio, map_bh); in submit_page_section()
833 put_page(sdio->cur_page); in submit_page_section()
834 sdio->cur_page = NULL; in submit_page_section()
840 sdio->cur_page = page; in submit_page_section()
841 sdio->cur_page_offset = offset; in submit_page_section()
842 sdio->cur_page_len = len; in submit_page_section()
843 sdio->cur_page_block = blocknr; in submit_page_section()
844 sdio->cur_page_fs_offset = sdio->block_in_file << sdio->blkbits; in submit_page_section()
851 ret = dio_send_cur_page(dio, sdio, map_bh); in submit_page_section()
852 if (sdio->bio) in submit_page_section()
853 dio_bio_submit(dio, sdio); in submit_page_section()
854 put_page(sdio->cur_page); in submit_page_section()
855 sdio->cur_page = NULL; in submit_page_section()
869 static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio, in dio_zero_block() argument
877 sdio->start_zero_done = 1; in dio_zero_block()
878 if (!sdio->blkfactor || !buffer_new(map_bh)) in dio_zero_block()
881 dio_blocks_per_fs_block = 1 << sdio->blkfactor; in dio_zero_block()
882 this_chunk_blocks = sdio->block_in_file & (dio_blocks_per_fs_block - 1); in dio_zero_block()
894 this_chunk_bytes = this_chunk_blocks << sdio->blkbits; in dio_zero_block()
897 if (submit_page_section(dio, sdio, page, 0, this_chunk_bytes, in dio_zero_block()
898 sdio->next_block_for_io, map_bh)) in dio_zero_block()
901 sdio->next_block_for_io += this_chunk_blocks; in dio_zero_block()
920 static int do_direct_IO(struct dio *dio, struct dio_submit *sdio, in do_direct_IO() argument
924 const unsigned blkbits = sdio->blkbits; in do_direct_IO()
925 const unsigned i_blkbits = blkbits + sdio->blkfactor; in do_direct_IO()
928 while (sdio->block_in_file < sdio->final_block_in_request) { in do_direct_IO()
932 page = dio_get_page(dio, sdio); in do_direct_IO()
937 from = sdio->head ? 0 : sdio->from; in do_direct_IO()
938 to = (sdio->head == sdio->tail - 1) ? sdio->to : PAGE_SIZE; in do_direct_IO()
939 sdio->head++; in do_direct_IO()
946 if (sdio->blocks_available == 0) { in do_direct_IO()
953 ret = get_more_blocks(dio, sdio, map_bh); in do_direct_IO()
961 sdio->blocks_available = in do_direct_IO()
963 sdio->next_block_for_io = in do_direct_IO()
964 map_bh->b_blocknr << sdio->blkfactor; in do_direct_IO()
972 if (!sdio->blkfactor) in do_direct_IO()
975 blkmask = (1 << sdio->blkfactor) - 1; in do_direct_IO()
976 dio_remainder = (sdio->block_in_file & blkmask); in do_direct_IO()
990 sdio->next_block_for_io += dio_remainder; in do_direct_IO()
991 sdio->blocks_available -= dio_remainder; in do_direct_IO()
1010 if (sdio->block_in_file >= in do_direct_IO()
1017 sdio->block_in_file++; in do_direct_IO()
1028 if (unlikely(sdio->blkfactor && !sdio->start_zero_done)) in do_direct_IO()
1029 dio_zero_block(dio, sdio, 0, map_bh); in do_direct_IO()
1035 this_chunk_blocks = sdio->blocks_available; in do_direct_IO()
1039 u = sdio->final_block_in_request - sdio->block_in_file; in do_direct_IO()
1045 if (this_chunk_blocks == sdio->blocks_available) in do_direct_IO()
1046 sdio->boundary = buffer_boundary(map_bh); in do_direct_IO()
1047 ret = submit_page_section(dio, sdio, page, in do_direct_IO()
1050 sdio->next_block_for_io, in do_direct_IO()
1056 sdio->next_block_for_io += this_chunk_blocks; in do_direct_IO()
1058 sdio->block_in_file += this_chunk_blocks; in do_direct_IO()
1061 sdio->blocks_available -= this_chunk_blocks; in do_direct_IO()
1063 BUG_ON(sdio->block_in_file > sdio->final_block_in_request); in do_direct_IO()
1064 if (sdio->block_in_file == sdio->final_block_in_request) in do_direct_IO()
1117 * NOTE: if you pass "sdio" to anything by pointer make sure that function
1135 struct dio_submit sdio = { 0, }; in __blockdev_direct_IO() local
1236 sdio.blkbits = blkbits; in __blockdev_direct_IO()
1237 sdio.blkfactor = i_blkbits - blkbits; in __blockdev_direct_IO()
1238 sdio.block_in_file = offset >> blkbits; in __blockdev_direct_IO()
1240 sdio.get_block = get_block; in __blockdev_direct_IO()
1242 sdio.submit_io = submit_io; in __blockdev_direct_IO()
1243 sdio.final_block_in_bio = -1; in __blockdev_direct_IO()
1244 sdio.next_block_for_io = -1; in __blockdev_direct_IO()
1252 sdio.iter = iter; in __blockdev_direct_IO()
1253 sdio.final_block_in_request = end >> blkbits; in __blockdev_direct_IO()
1259 if (unlikely(sdio.blkfactor)) in __blockdev_direct_IO()
1260 sdio.pages_in_io = 2; in __blockdev_direct_IO()
1262 sdio.pages_in_io += iov_iter_npages(iter, INT_MAX); in __blockdev_direct_IO()
1266 retval = do_direct_IO(dio, &sdio, &map_bh); in __blockdev_direct_IO()
1268 dio_cleanup(dio, &sdio); in __blockdev_direct_IO()
1281 dio_zero_block(dio, &sdio, 1, &map_bh); in __blockdev_direct_IO()
1283 if (sdio.cur_page) { in __blockdev_direct_IO()
1286 ret2 = dio_send_cur_page(dio, &sdio, &map_bh); in __blockdev_direct_IO()
1289 put_page(sdio.cur_page); in __blockdev_direct_IO()
1290 sdio.cur_page = NULL; in __blockdev_direct_IO()
1292 if (sdio.bio) in __blockdev_direct_IO()
1293 dio_bio_submit(dio, &sdio); in __blockdev_direct_IO()
1301 dio_cleanup(dio, &sdio); in __blockdev_direct_IO()