Lines Matching full:sdio

158 static inline unsigned dio_pages_present(struct dio_submit *sdio)  in dio_pages_present()  argument
160 return sdio->tail - sdio->head; in dio_pages_present()
166 static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio) in dio_refill_pages() argument
172 ret = iov_iter_extract_pages(sdio->iter, &pages, LONG_MAX, in dio_refill_pages()
173 DIO_PAGES, 0, &sdio->from); in dio_refill_pages()
175 if (ret < 0 && sdio->blocks_available && dio_op == REQ_OP_WRITE) { in dio_refill_pages()
184 sdio->head = 0; in dio_refill_pages()
185 sdio->tail = 1; in dio_refill_pages()
186 sdio->from = 0; in dio_refill_pages()
187 sdio->to = PAGE_SIZE; in dio_refill_pages()
192 ret += sdio->from; in dio_refill_pages()
193 sdio->head = 0; in dio_refill_pages()
194 sdio->tail = (ret + PAGE_SIZE - 1) / PAGE_SIZE; in dio_refill_pages()
195 sdio->to = ((ret - 1) & (PAGE_SIZE - 1)) + 1; in dio_refill_pages()
208 struct dio_submit *sdio) in dio_get_page() argument
210 if (dio_pages_present(sdio) == 0) { in dio_get_page()
213 ret = dio_refill_pages(dio, sdio); in dio_get_page()
216 BUG_ON(dio_pages_present(sdio) == 0); in dio_get_page()
218 return dio->pages[sdio->head]; in dio_get_page()
394 dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, in dio_bio_alloc() argument
414 sdio->bio = bio; in dio_bio_alloc()
415 sdio->logical_offset_in_bio = sdio->cur_page_fs_offset; in dio_bio_alloc()
425 static inline void dio_bio_submit(struct dio *dio, struct dio_submit *sdio) in dio_bio_submit() argument
428 struct bio *bio = sdio->bio; in dio_bio_submit()
444 sdio->bio = NULL; in dio_bio_submit()
445 sdio->boundary = 0; in dio_bio_submit()
446 sdio->logical_offset_in_bio = 0; in dio_bio_submit()
452 static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio) in dio_cleanup() argument
455 unpin_user_pages(dio->pages + sdio->head, in dio_cleanup()
456 sdio->tail - sdio->head); in dio_cleanup()
457 sdio->head = sdio->tail; in dio_cleanup()
545 static inline int dio_bio_reap(struct dio *dio, struct dio_submit *sdio) in dio_bio_reap() argument
549 if (sdio->reap_counter++ >= 64) { in dio_bio_reap()
563 sdio->reap_counter = 0; in dio_bio_reap()
582 * of available blocks at sdio->blocks_available. These are in units of the
603 static int get_more_blocks(struct dio *dio, struct dio_submit *sdio, in get_more_blocks() argument
612 unsigned int i_blkbits = sdio->blkbits + sdio->blkfactor; in get_more_blocks()
621 BUG_ON(sdio->block_in_file >= sdio->final_block_in_request); in get_more_blocks()
622 fs_startblk = sdio->block_in_file >> sdio->blkfactor; in get_more_blocks()
623 fs_endblk = (sdio->final_block_in_request - 1) >> in get_more_blocks()
624 sdio->blkfactor; in get_more_blocks()
648 ret = (*sdio->get_block)(dio->inode, fs_startblk, in get_more_blocks()
663 static inline int dio_new_bio(struct dio *dio, struct dio_submit *sdio, in dio_new_bio() argument
669 ret = dio_bio_reap(dio, sdio); in dio_new_bio()
672 sector = start_sector << (sdio->blkbits - 9); in dio_new_bio()
673 nr_pages = bio_max_segs(sdio->pages_in_io); in dio_new_bio()
675 dio_bio_alloc(dio, sdio, map_bh->b_bdev, sector, nr_pages); in dio_new_bio()
676 sdio->boundary = 0; in dio_new_bio()
688 static inline int dio_bio_add_page(struct dio *dio, struct dio_submit *sdio) in dio_bio_add_page() argument
692 ret = bio_add_page(sdio->bio, sdio->cur_page, in dio_bio_add_page()
693 sdio->cur_page_len, sdio->cur_page_offset); in dio_bio_add_page()
694 if (ret == sdio->cur_page_len) { in dio_bio_add_page()
698 if ((sdio->cur_page_len + sdio->cur_page_offset) == PAGE_SIZE) in dio_bio_add_page()
699 sdio->pages_in_io--; in dio_bio_add_page()
700 dio_pin_page(dio, sdio->cur_page); in dio_bio_add_page()
701 sdio->final_block_in_bio = sdio->cur_page_block + in dio_bio_add_page()
702 (sdio->cur_page_len >> sdio->blkbits); in dio_bio_add_page()
720 static inline int dio_send_cur_page(struct dio *dio, struct dio_submit *sdio, in dio_send_cur_page() argument
725 if (sdio->bio) { in dio_send_cur_page()
726 loff_t cur_offset = sdio->cur_page_fs_offset; in dio_send_cur_page()
727 loff_t bio_next_offset = sdio->logical_offset_in_bio + in dio_send_cur_page()
728 sdio->bio->bi_iter.bi_size; in dio_send_cur_page()
744 if (sdio->final_block_in_bio != sdio->cur_page_block || in dio_send_cur_page()
746 dio_bio_submit(dio, sdio); in dio_send_cur_page()
749 if (sdio->bio == NULL) { in dio_send_cur_page()
750 ret = dio_new_bio(dio, sdio, sdio->cur_page_block, map_bh); in dio_send_cur_page()
755 if (dio_bio_add_page(dio, sdio) != 0) { in dio_send_cur_page()
756 dio_bio_submit(dio, sdio); in dio_send_cur_page()
757 ret = dio_new_bio(dio, sdio, sdio->cur_page_block, map_bh); in dio_send_cur_page()
759 ret = dio_bio_add_page(dio, sdio); in dio_send_cur_page()
785 submit_page_section(struct dio *dio, struct dio_submit *sdio, struct page *page, in submit_page_section() argument
791 int boundary = sdio->boundary; /* dio_send_cur_page may clear it */ in submit_page_section()
803 if (sdio->cur_page == page && in submit_page_section()
804 sdio->cur_page_offset + sdio->cur_page_len == offset && in submit_page_section()
805 sdio->cur_page_block + in submit_page_section()
806 (sdio->cur_page_len >> sdio->blkbits) == blocknr) { in submit_page_section()
807 sdio->cur_page_len += len; in submit_page_section()
814 if (sdio->cur_page) { in submit_page_section()
815 ret = dio_send_cur_page(dio, sdio, map_bh); in submit_page_section()
816 dio_unpin_page(dio, sdio->cur_page); in submit_page_section()
817 sdio->cur_page = NULL; in submit_page_section()
823 sdio->cur_page = page; in submit_page_section()
824 sdio->cur_page_offset = offset; in submit_page_section()
825 sdio->cur_page_len = len; in submit_page_section()
826 sdio->cur_page_block = blocknr; in submit_page_section()
827 sdio->cur_page_fs_offset = sdio->block_in_file << sdio->blkbits; in submit_page_section()
834 ret = dio_send_cur_page(dio, sdio, map_bh); in submit_page_section()
835 if (sdio->bio) in submit_page_section()
836 dio_bio_submit(dio, sdio); in submit_page_section()
837 dio_unpin_page(dio, sdio->cur_page); in submit_page_section()
838 sdio->cur_page = NULL; in submit_page_section()
852 static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio, in dio_zero_block() argument
860 sdio->start_zero_done = 1; in dio_zero_block()
861 if (!sdio->blkfactor || !buffer_new(map_bh)) in dio_zero_block()
864 dio_blocks_per_fs_block = 1 << sdio->blkfactor; in dio_zero_block()
865 this_chunk_blocks = sdio->block_in_file & (dio_blocks_per_fs_block - 1); in dio_zero_block()
877 this_chunk_bytes = this_chunk_blocks << sdio->blkbits; in dio_zero_block()
880 if (submit_page_section(dio, sdio, page, 0, this_chunk_bytes, in dio_zero_block()
881 sdio->next_block_for_io, map_bh)) in dio_zero_block()
884 sdio->next_block_for_io += this_chunk_blocks; in dio_zero_block()
903 static int do_direct_IO(struct dio *dio, struct dio_submit *sdio, in do_direct_IO() argument
907 const unsigned blkbits = sdio->blkbits; in do_direct_IO()
908 const unsigned i_blkbits = blkbits + sdio->blkfactor; in do_direct_IO()
911 while (sdio->block_in_file < sdio->final_block_in_request) { in do_direct_IO()
915 page = dio_get_page(dio, sdio); in do_direct_IO()
920 from = sdio->head ? 0 : sdio->from; in do_direct_IO()
921 to = (sdio->head == sdio->tail - 1) ? sdio->to : PAGE_SIZE; in do_direct_IO()
922 sdio->head++; in do_direct_IO()
929 if (sdio->blocks_available == 0) { in do_direct_IO()
936 ret = get_more_blocks(dio, sdio, map_bh); in do_direct_IO()
944 sdio->blocks_available = in do_direct_IO()
946 sdio->next_block_for_io = in do_direct_IO()
947 map_bh->b_blocknr << sdio->blkfactor; in do_direct_IO()
955 if (!sdio->blkfactor) in do_direct_IO()
958 blkmask = (1 << sdio->blkfactor) - 1; in do_direct_IO()
959 dio_remainder = (sdio->block_in_file & blkmask); in do_direct_IO()
973 sdio->next_block_for_io += dio_remainder; in do_direct_IO()
974 sdio->blocks_available -= dio_remainder; in do_direct_IO()
993 if (sdio->block_in_file >= in do_direct_IO()
1000 sdio->block_in_file++; in do_direct_IO()
1011 if (unlikely(sdio->blkfactor && !sdio->start_zero_done)) in do_direct_IO()
1012 dio_zero_block(dio, sdio, 0, map_bh); in do_direct_IO()
1018 this_chunk_blocks = sdio->blocks_available; in do_direct_IO()
1022 u = sdio->final_block_in_request - sdio->block_in_file; in do_direct_IO()
1028 if (this_chunk_blocks == sdio->blocks_available) in do_direct_IO()
1029 sdio->boundary = buffer_boundary(map_bh); in do_direct_IO()
1030 ret = submit_page_section(dio, sdio, page, in do_direct_IO()
1033 sdio->next_block_for_io, in do_direct_IO()
1039 sdio->next_block_for_io += this_chunk_blocks; in do_direct_IO()
1041 sdio->block_in_file += this_chunk_blocks; in do_direct_IO()
1044 sdio->blocks_available -= this_chunk_blocks; in do_direct_IO()
1046 BUG_ON(sdio->block_in_file > sdio->final_block_in_request); in do_direct_IO()
1047 if (sdio->block_in_file == sdio->final_block_in_request) in do_direct_IO()
1100 * NOTE: if you pass "sdio" to anything by pointer make sure that function
1118 struct dio_submit sdio = { NULL, }; in __blockdev_direct_IO() local
1214 sdio.blkbits = blkbits; in __blockdev_direct_IO()
1215 sdio.blkfactor = i_blkbits - blkbits; in __blockdev_direct_IO()
1216 sdio.block_in_file = offset >> blkbits; in __blockdev_direct_IO()
1218 sdio.get_block = get_block; in __blockdev_direct_IO()
1220 sdio.final_block_in_bio = -1; in __blockdev_direct_IO()
1221 sdio.next_block_for_io = -1; in __blockdev_direct_IO()
1229 sdio.iter = iter; in __blockdev_direct_IO()
1230 sdio.final_block_in_request = end >> blkbits; in __blockdev_direct_IO()
1236 if (unlikely(sdio.blkfactor)) in __blockdev_direct_IO()
1237 sdio.pages_in_io = 2; in __blockdev_direct_IO()
1239 sdio.pages_in_io += iov_iter_npages(iter, INT_MAX); in __blockdev_direct_IO()
1243 retval = do_direct_IO(dio, &sdio, &map_bh); in __blockdev_direct_IO()
1245 dio_cleanup(dio, &sdio); in __blockdev_direct_IO()
1258 dio_zero_block(dio, &sdio, 1, &map_bh); in __blockdev_direct_IO()
1260 if (sdio.cur_page) { in __blockdev_direct_IO()
1263 ret2 = dio_send_cur_page(dio, &sdio, &map_bh); in __blockdev_direct_IO()
1266 dio_unpin_page(dio, sdio.cur_page); in __blockdev_direct_IO()
1267 sdio.cur_page = NULL; in __blockdev_direct_IO()
1269 if (sdio.bio) in __blockdev_direct_IO()
1270 dio_bio_submit(dio, &sdio); in __blockdev_direct_IO()
1278 dio_cleanup(dio, &sdio); in __blockdev_direct_IO()