Lines Matching refs:bio

7 #include <linux/bio.h>
257 * bio helper functions.
259 static inline void remap_to_source(struct clone *clone, struct bio *bio)
261 bio_set_dev(bio, clone->source_dev->bdev);
264 static inline void remap_to_dest(struct clone *clone, struct bio *bio)
266 bio_set_dev(bio, clone->dest_dev->bdev);
269 static bool bio_triggers_commit(struct clone *clone, struct bio *bio)
271 return op_is_flush(bio->bi_opf) &&
281 /* Get the region number of the bio */
282 static inline unsigned long bio_to_region(struct clone *clone, struct bio *bio)
284 return (bio->bi_iter.bi_sector >> clone->region_shift);
287 /* Get the region range covered by the bio */
288 static void bio_region_range(struct clone *clone, struct bio *bio,
293 *rs = dm_sector_div_up(bio->bi_iter.bi_sector, clone->region_size);
294 end = bio_end_sector(bio) >> clone->region_shift;
302 /* Check whether a bio overwrites a region */
303 static inline bool is_overwrite_bio(struct clone *clone, struct bio *bio)
305 return (bio_data_dir(bio) == WRITE && bio_sectors(bio) == clone->region_size);
310 struct bio *bio;
312 while ((bio = bio_list_pop(bios))) {
313 bio->bi_status = status;
314 bio_endio(bio);
320 struct bio *bio;
325 while ((bio = bio_list_pop(bios)))
326 submit_bio_noacct(bio);
332 * Submit bio to the underlying device.
334 * If the bio triggers a commit, delay it, until after the metadata have been
337 * NOTE: The bio remapping must be performed by the caller.
339 static void issue_bio(struct clone *clone, struct bio *bio)
341 if (!bio_triggers_commit(clone, bio)) {
342 submit_bio_noacct(bio);
348 * metadata, so we complete the bio with an error.
351 bio_io_error(bio);
360 bio_list_add(&clone->deferred_flush_bios, bio);
367 * Remap bio to the destination device and submit it.
369 * If the bio triggers a commit, delay it, until after the metadata have been
372 static void remap_and_issue(struct clone *clone, struct bio *bio)
374 remap_to_dest(clone, bio);
375 issue_bio(clone, bio);
382 * We delegate the bio submission to the worker thread, so this is safe to call
387 struct bio *bio;
395 while ((bio = bio_list_pop(bios))) {
396 if (bio_triggers_commit(clone, bio))
397 bio_list_add(&flush_bios, bio);
399 bio_list_add(&normal_bios, bio);
410 static void complete_overwrite_bio(struct clone *clone, struct bio *bio)
415 * If the bio has the REQ_FUA flag set we must commit the metadata
424 if (!(bio->bi_opf & REQ_FUA)) {
425 bio_endio(bio);
431 * metadata, so we complete the bio with an error.
434 bio_io_error(bio);
443 bio_list_add(&clone->deferred_flush_completions, bio);
449 static void trim_bio(struct bio *bio, sector_t sector, unsigned int len)
451 bio->bi_iter.bi_sector = sector;
452 bio->bi_iter.bi_size = to_bytes(len);
455 static void complete_discard_bio(struct clone *clone, struct bio *bio, bool success)
461 * discard bio and pass it down. Otherwise complete the bio
465 remap_to_dest(clone, bio);
466 bio_region_range(clone, bio, &rs, &nr_regions);
467 trim_bio(bio, region_to_sector(clone, rs),
469 submit_bio_noacct(bio);
471 bio_endio(bio);
474 static void process_discard_bio(struct clone *clone, struct bio *bio)
478 bio_region_range(clone, bio, &rs, &nr_regions);
480 bio_endio(bio);
489 (unsigned long long)bio->bi_iter.bi_sector,
490 bio_sectors(bio));
491 bio_endio(bio);
500 complete_discard_bio(clone, bio, true);
510 bio_endio(bio);
518 bio_list_add(&clone->deferred_discard_bios, bio);
533 struct bio *overwrite_bio;
728 * 3. Complete overwrite bio.
837 static void overwrite_endio(struct bio *bio)
839 struct dm_clone_region_hydration *hd = bio->bi_private;
841 bio->bi_end_io = hd->overwrite_bio_end_io;
842 hd->status = bio->bi_status;
847 static void hydration_overwrite(struct dm_clone_region_hydration *hd, struct bio *bio)
850 * We don't need to save and restore bio->bi_private because device
851 * mapper core generates a new bio for us to use, with clean
854 hd->overwrite_bio = bio;
855 hd->overwrite_bio_end_io = bio->bi_end_io;
857 bio->bi_end_io = overwrite_endio;
858 bio->bi_private = hd;
861 submit_bio_noacct(bio);
865 * Hydrate bio's region.
867 * This function starts the hydration of the bio's region and puts the bio in
872 * NOTE: The bio remapping must be performed by the caller.
874 static void hydrate_bio_region(struct clone *clone, struct bio *bio)
880 region_nr = bio_to_region(clone, bio);
888 bio_list_add(&hd->deferred_bios, bio);
896 issue_bio(clone, bio);
915 issue_bio(clone, bio);
922 bio_list_add(&hd2->deferred_bios, bio);
937 bio_io_error(bio);
944 * If a bio overwrites a region, i.e., its size is equal to the
948 if (is_overwrite_bio(clone, bio)) {
950 hydration_overwrite(hd, bio);
952 bio_list_add(&hd->deferred_bios, bio);
1178 struct bio *bio;
1194 bio_list_for_each(bio, &discards) {
1195 bio_region_range(clone, bio, &rs, &nr_regions);
1207 while ((bio = bio_list_pop(&discards)))
1208 complete_discard_bio(clone, bio, r == 0);
1228 struct bio *bio;
1250 while ((bio = bio_list_pop(&bios)))
1251 bio_io_error(bio);
1258 while ((bio = bio_list_pop(&bio_completions)))
1259 bio_endio(bio);
1261 while ((bio = bio_list_pop(&bios))) {
1262 if ((bio->bi_opf & REQ_PREFLUSH) && dest_dev_flushed) {
1267 bio_endio(bio);
1269 submit_bio_noacct(bio);
1314 static int clone_map(struct dm_target *ti, struct bio *bio)
1331 if (bio->bi_opf & REQ_PREFLUSH) {
1332 remap_and_issue(clone, bio);
1336 bio->bi_iter.bi_sector = dm_target_offset(ti, bio->bi_iter.bi_sector);
1343 if (bio_op(bio) == REQ_OP_DISCARD) {
1344 process_discard_bio(clone, bio);
1349 * If the bio's region is hydrated, redirect it to the destination
1352 * If the region is not hydrated and the bio is a READ, redirect it to
1355 * Else, defer WRITE bio until after its region has been hydrated and
1358 region_nr = bio_to_region(clone, bio);
1360 remap_and_issue(clone, bio);
1362 } else if (bio_data_dir(bio) == READ) {
1363 remap_to_source(clone, bio);
1367 remap_to_dest(clone, bio);
1368 hydrate_bio_region(clone, bio);
1373 static int clone_endio(struct dm_target *ti, struct bio *bio, blk_status_t *error)