mirror.c (ccd6a37947574707613e826e2bf04d55f1d5f238) | mirror.c (004915a96a7a40e942ac85e6d22518cbcd283506) |
---|---|
1/* 2 * Image mirroring 3 * 4 * Copyright Red Hat, Inc. 2012 5 * 6 * Authors: 7 * Paolo Bonzini <pbonzini@redhat.com> 8 * --- 465 unchanged lines hidden (view full) --- 474 475 /* Same assertion as in mirror_co_read() (and for mirror_co_read() 476 * and mirror_co_discard(), bytes_handled == op->bytes, which 477 * is the @bytes parameter given to this function) */ 478 assert(bytes_handled <= UINT_MAX); 479 return bytes_handled; 480} 481 | 1/* 2 * Image mirroring 3 * 4 * Copyright Red Hat, Inc. 2012 5 * 6 * Authors: 7 * Paolo Bonzini <pbonzini@redhat.com> 8 * --- 465 unchanged lines hidden (view full) --- 474 475 /* Same assertion as in mirror_co_read() (and for mirror_co_read() 476 * and mirror_co_discard(), bytes_handled == op->bytes, which 477 * is the @bytes parameter given to this function) */ 478 assert(bytes_handled <= UINT_MAX); 479 return bytes_handled; 480} 481 |
482static void coroutine_fn mirror_iteration(MirrorBlockJob *s) | 482static void coroutine_fn GRAPH_RDLOCK mirror_iteration(MirrorBlockJob *s) |
483{ 484 BlockDriverState *source = s->mirror_top_bs->backing->bs; 485 MirrorOp *pseudo_op; 486 int64_t offset; 487 /* At least the first dirty chunk is mirrored in one iteration. */ 488 int nb_chunks = 1; 489 bool write_zeroes_ok = bdrv_can_write_zeroes_with_unmap(blk_bs(s->target)); 490 int max_io_bytes = MAX(s->buf_size / MAX_IN_FLIGHT, MAX_IO_BYTES); --- 343 unchanged lines hidden (view full) --- 834 if (now - s->last_pause_ns > BLOCK_JOB_SLICE_TIME) { 835 s->last_pause_ns = now; 836 job_sleep_ns(&s->common.job, 0); 837 } else { 838 job_pause_point(&s->common.job); 839 } 840} 841 | 483{ 484 BlockDriverState *source = s->mirror_top_bs->backing->bs; 485 MirrorOp *pseudo_op; 486 int64_t offset; 487 /* At least the first dirty chunk is mirrored in one iteration. */ 488 int nb_chunks = 1; 489 bool write_zeroes_ok = bdrv_can_write_zeroes_with_unmap(blk_bs(s->target)); 490 int max_io_bytes = MAX(s->buf_size / MAX_IN_FLIGHT, MAX_IO_BYTES); --- 343 unchanged lines hidden (view full) --- 834 if (now - s->last_pause_ns > BLOCK_JOB_SLICE_TIME) { 835 s->last_pause_ns = now; 836 job_sleep_ns(&s->common.job, 0); 837 } else { 838 job_pause_point(&s->common.job); 839 } 840} 841 |
842static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) | 842static int coroutine_fn GRAPH_UNLOCKED mirror_dirty_init(MirrorBlockJob *s) |
843{ 844 int64_t offset; | 843{ 844 int64_t offset; |
845 BlockDriverState *bs = s->mirror_top_bs->backing->bs; | 845 BlockDriverState *bs; |
846 BlockDriverState *target_bs = blk_bs(s->target); 847 int ret; 848 int64_t count; 849 | 846 BlockDriverState *target_bs = blk_bs(s->target); 847 int ret; 848 int64_t count; 849 |
850 bdrv_graph_co_rdlock(); 851 bs = s->mirror_top_bs->backing->bs; 852 bdrv_graph_co_rdunlock(); 853 |
|
850 if (s->zero_target) { 851 if (!bdrv_can_write_zeroes_with_unmap(target_bs)) { 852 bdrv_set_dirty_bitmap(s->dirty_bitmap, 0, s->bdev_length); 853 return 0; 854 } 855 856 s->initial_zeroing_ongoing = true; 857 for (offset = 0; offset < s->bdev_length; ) { --- 63 unchanged lines hidden (view full) --- 921 } 922 } 923 return ret; 924} 925 926static int coroutine_fn mirror_run(Job *job, Error **errp) 927{ 928 MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job); | 854 if (s->zero_target) { 855 if (!bdrv_can_write_zeroes_with_unmap(target_bs)) { 856 bdrv_set_dirty_bitmap(s->dirty_bitmap, 0, s->bdev_length); 857 return 0; 858 } 859 860 s->initial_zeroing_ongoing = true; 861 for (offset = 0; offset < s->bdev_length; ) { --- 63 unchanged lines hidden (view full) --- 925 } 926 } 927 return ret; 928} 929 930static int coroutine_fn mirror_run(Job *job, Error **errp) 931{ 932 MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job); |
929 BlockDriverState *bs = s->mirror_top_bs->backing->bs; | 933 BlockDriverState *bs; |
930 MirrorBDSOpaque *mirror_top_opaque = s->mirror_top_bs->opaque; 931 BlockDriverState *target_bs = blk_bs(s->target); 932 bool need_drain = true; 933 BlockDeviceIoStatus iostatus; 934 int64_t length; 935 int64_t target_length; 936 BlockDriverInfo bdi; 937 char backing_filename[2]; /* we only need 2 characters because we are only 938 checking for a NULL string */ 939 int ret = 0; 940 | 934 MirrorBDSOpaque *mirror_top_opaque = s->mirror_top_bs->opaque; 935 BlockDriverState *target_bs = blk_bs(s->target); 936 bool need_drain = true; 937 BlockDeviceIoStatus iostatus; 938 int64_t length; 939 int64_t target_length; 940 BlockDriverInfo bdi; 941 char backing_filename[2]; /* we only need 2 characters because we are only 942 checking for a NULL string */ 943 int ret = 0; 944 |
945 bdrv_graph_co_rdlock(); 946 bs = bdrv_filter_bs(s->mirror_top_bs); 947 bdrv_graph_co_rdunlock(); 948 |
|
941 if (job_is_cancelled(&s->common.job)) { 942 goto immediate_exit; 943 } 944 945 bdrv_graph_co_rdlock(); 946 s->bdev_length = bdrv_co_getlength(bs); 947 bdrv_graph_co_rdunlock(); 948 --- 116 unchanged lines hidden (view full) --- 1065 if (delta < BLOCK_JOB_SLICE_TIME && 1066 iostatus == BLOCK_DEVICE_IO_STATUS_OK) { 1067 if (s->in_flight >= MAX_IN_FLIGHT || s->buf_free_count == 0 || 1068 (cnt == 0 && s->in_flight > 0)) { 1069 trace_mirror_yield(s, cnt, s->buf_free_count, s->in_flight); 1070 mirror_wait_for_free_in_flight_slot(s); 1071 continue; 1072 } else if (cnt != 0) { | 949 if (job_is_cancelled(&s->common.job)) { 950 goto immediate_exit; 951 } 952 953 bdrv_graph_co_rdlock(); 954 s->bdev_length = bdrv_co_getlength(bs); 955 bdrv_graph_co_rdunlock(); 956 --- 116 unchanged lines hidden (view full) --- 1073 if (delta < BLOCK_JOB_SLICE_TIME && 1074 iostatus == BLOCK_DEVICE_IO_STATUS_OK) { 1075 if (s->in_flight >= MAX_IN_FLIGHT || s->buf_free_count == 0 || 1076 (cnt == 0 && s->in_flight > 0)) { 1077 trace_mirror_yield(s, cnt, s->buf_free_count, s->in_flight); 1078 mirror_wait_for_free_in_flight_slot(s); 1079 continue; 1080 } else if (cnt != 0) { |
1081 bdrv_graph_co_rdlock(); |
|
1073 mirror_iteration(s); | 1082 mirror_iteration(s); |
1083 bdrv_graph_co_rdunlock(); |
|
1074 } 1075 } 1076 1077 should_complete = false; 1078 if (s->in_flight == 0 && cnt == 0) { 1079 trace_mirror_before_flush(s); 1080 if (!job_is_ready(&s->common.job)) { 1081 if (mirror_flush(s) < 0) { --- 553 unchanged lines hidden (view full) --- 1635static int coroutine_fn GRAPH_RDLOCK 1636bdrv_mirror_top_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) 1637{ 1638 bool copy_to_target = should_copy_to_target(bs->opaque); 1639 return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_DISCARD, copy_to_target, 1640 offset, bytes, NULL, 0); 1641} 1642 | 1084 } 1085 } 1086 1087 should_complete = false; 1088 if (s->in_flight == 0 && cnt == 0) { 1089 trace_mirror_before_flush(s); 1090 if (!job_is_ready(&s->common.job)) { 1091 if (mirror_flush(s) < 0) { --- 553 unchanged lines hidden (view full) --- 1645static int coroutine_fn GRAPH_RDLOCK 1646bdrv_mirror_top_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) 1647{ 1648 bool copy_to_target = should_copy_to_target(bs->opaque); 1649 return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_DISCARD, copy_to_target, 1650 offset, bytes, NULL, 0); 1651} 1652 |
1643static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs) | 1653static void GRAPH_RDLOCK bdrv_mirror_top_refresh_filename(BlockDriverState *bs) |
1644{ 1645 if (bs->backing == NULL) { 1646 /* we can be here after failed bdrv_attach_child in 1647 * bdrv_set_backing_hd */ 1648 return; 1649 } 1650 pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), 1651 bs->backing->bs->filename); --- 431 unchanged lines hidden --- | 1654{ 1655 if (bs->backing == NULL) { 1656 /* we can be here after failed bdrv_attach_child in 1657 * bdrv_set_backing_hd */ 1658 return; 1659 } 1660 pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), 1661 bs->backing->bs->filename); --- 431 unchanged lines hidden --- |