block.c (a5614993d79584af93bb845f69f59872b3f76cf8) | block.c (27ccdd52598290f0f8b58be56e235aff7aebfaf3) |
---|---|
1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 223 unchanged lines hidden (view full) --- 232 int i; 233 234 bs = g_new0(BlockDriverState, 1); 235 QLIST_INIT(&bs->dirty_bitmaps); 236 for (i = 0; i < BLOCK_OP_TYPE_MAX; i++) { 237 QLIST_INIT(&bs->op_blockers[i]); 238 } 239 notifier_with_return_list_init(&bs->before_write_notifiers); | 1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 223 unchanged lines hidden (view full) --- 232 int i; 233 234 bs = g_new0(BlockDriverState, 1); 235 QLIST_INIT(&bs->dirty_bitmaps); 236 for (i = 0; i < BLOCK_OP_TYPE_MAX; i++) { 237 QLIST_INIT(&bs->op_blockers[i]); 238 } 239 notifier_with_return_list_init(&bs->before_write_notifiers); |
240 qemu_co_queue_init(&bs->throttled_reqs[0]); 241 qemu_co_queue_init(&bs->throttled_reqs[1]); | |
242 bs->refcnt = 1; 243 bs->aio_context = qemu_get_aio_context(); 244 245 QTAILQ_INSERT_TAIL(&all_bdrv_states, bs, bs_list); 246 247 return bs; 248} 249 --- 1270 unchanged lines hidden (view full) --- 1520 return -EINVAL; 1521 } 1522 1523 bs = bdrv_lookup_bs(reference, reference, errp); 1524 if (!bs) { 1525 return -ENODEV; 1526 } 1527 | 240 bs->refcnt = 1; 241 bs->aio_context = qemu_get_aio_context(); 242 243 QTAILQ_INSERT_TAIL(&all_bdrv_states, bs, bs_list); 244 245 return bs; 246} 247 --- 1270 unchanged lines hidden (view full) --- 1518 return -EINVAL; 1519 } 1520 1521 bs = bdrv_lookup_bs(reference, reference, errp); 1522 if (!bs) { 1523 return -ENODEV; 1524 } 1525 |
1528 if (bs->throttle_state) { | 1526 if (bs->blk && blk_get_public(bs->blk)->throttle_state) { |
1529 error_setg(errp, "Cannot reference an existing block device for " 1530 "which I/O throttling is enabled"); 1531 return -EINVAL; 1532 } 1533 1534 bdrv_ref(bs); 1535 *pbs = bs; 1536 return 0; --- 582 unchanged lines hidden (view full) --- 2119 2120static void bdrv_close(BlockDriverState *bs) 2121{ 2122 BdrvAioNotifier *ban, *ban_next; 2123 2124 assert(!bs->job); 2125 2126 /* Disable I/O limits and drain all pending throttled requests */ | 1527 error_setg(errp, "Cannot reference an existing block device for " 1528 "which I/O throttling is enabled"); 1529 return -EINVAL; 1530 } 1531 1532 bdrv_ref(bs); 1533 *pbs = bs; 1534 return 0; --- 582 unchanged lines hidden (view full) --- 2117 2118static void bdrv_close(BlockDriverState *bs) 2119{ 2120 BdrvAioNotifier *ban, *ban_next; 2121 2122 assert(!bs->job); 2123 2124 /* Disable I/O limits and drain all pending throttled requests */ |
2127 if (bs->throttle_state) { | 2125 if (bs->blk && blk_get_public(bs->blk)->throttle_state) { |
2128 bdrv_io_limits_disable(bs); 2129 } 2130 2131 bdrv_drained_begin(bs); /* complete I/O */ 2132 bdrv_flush(bs); 2133 bdrv_drain(bs); /* in case flush left pending I/O */ 2134 2135 bdrv_release_named_dirty_bitmaps(bs); --- 116 unchanged lines hidden (view full) --- 2252 BlockDriverState *bs_new) 2253{ 2254 BlockDriverState tmp; 2255 2256 bdrv_move_feature_fields(&tmp, bs_top); 2257 bdrv_move_feature_fields(bs_top, bs_new); 2258 bdrv_move_feature_fields(bs_new, &tmp); 2259 | 2126 bdrv_io_limits_disable(bs); 2127 } 2128 2129 bdrv_drained_begin(bs); /* complete I/O */ 2130 bdrv_flush(bs); 2131 bdrv_drain(bs); /* in case flush left pending I/O */ 2132 2133 bdrv_release_named_dirty_bitmaps(bs); --- 116 unchanged lines hidden (view full) --- 2250 BlockDriverState *bs_new) 2251{ 2252 BlockDriverState tmp; 2253 2254 bdrv_move_feature_fields(&tmp, bs_top); 2255 bdrv_move_feature_fields(bs_top, bs_new); 2256 bdrv_move_feature_fields(bs_new, &tmp); 2257 |
2260 assert(!bs_new->throttle_state); 2261 if (bs_top->throttle_state) { | 2258 assert(!bs_new->blk); 2259 if (bs_top->blk && blk_get_public(bs_top->blk)->throttle_state) { |
2262 /* 2263 * FIXME Need to break I/O throttling with graph manipulations 2264 * temporarily because of conflicting invariants (3. will go away when 2265 * throttling is fully converted to work on BlockBackends): 2266 * 2267 * 1. Every BlockBackend has a single root BDS 2268 * 2. I/O throttling functions require an attached BlockBackend 2269 * 3. We need to first enable throttling on the new BDS and then --- 25 unchanged lines hidden (view full) --- 2295 * reference of its own, it must call bdrv_ref(). 2296 */ 2297void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) 2298{ 2299 assert(!bdrv_requests_pending(bs_top)); 2300 assert(!bdrv_requests_pending(bs_new)); 2301 2302 bdrv_ref(bs_top); | 2260 /* 2261 * FIXME Need to break I/O throttling with graph manipulations 2262 * temporarily because of conflicting invariants (3. will go away when 2263 * throttling is fully converted to work on BlockBackends): 2264 * 2265 * 1. Every BlockBackend has a single root BDS 2266 * 2. I/O throttling functions require an attached BlockBackend 2267 * 3. We need to first enable throttling on the new BDS and then --- 25 unchanged lines hidden (view full) --- 2293 * reference of its own, it must call bdrv_ref(). 2294 */ 2295void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) 2296{ 2297 assert(!bdrv_requests_pending(bs_top)); 2298 assert(!bdrv_requests_pending(bs_new)); 2299 2300 bdrv_ref(bs_top); |
2303 change_parent_backing_link(bs_top, bs_new); | |
2304 2305 /* Some fields always stay on top of the backing file chain */ 2306 swap_feature_fields(bs_top, bs_new); 2307 | 2301 2302 /* Some fields always stay on top of the backing file chain */ 2303 swap_feature_fields(bs_top, bs_new); 2304 |
2305 change_parent_backing_link(bs_top, bs_new); |
|
2308 bdrv_set_backing_hd(bs_new, bs_top); 2309 bdrv_unref(bs_top); 2310 2311 /* bs_new is now referenced by its new parents, we don't need the 2312 * additional reference any more. */ 2313 bdrv_unref(bs_new); 2314} 2315 --- 1355 unchanged lines hidden (view full) --- 3671 if (!bs->drv) { 3672 return; 3673 } 3674 3675 QLIST_FOREACH(baf, &bs->aio_notifiers, list) { 3676 baf->detach_aio_context(baf->opaque); 3677 } 3678 | 2306 bdrv_set_backing_hd(bs_new, bs_top); 2307 bdrv_unref(bs_top); 2308 2309 /* bs_new is now referenced by its new parents, we don't need the 2310 * additional reference any more. */ 2311 bdrv_unref(bs_new); 2312} 2313 --- 1355 unchanged lines hidden (view full) --- 3669 if (!bs->drv) { 3670 return; 3671 } 3672 3673 QLIST_FOREACH(baf, &bs->aio_notifiers, list) { 3674 baf->detach_aio_context(baf->opaque); 3675 } 3676 |
3679 if (bs->throttle_state) { 3680 throttle_timers_detach_aio_context(&bs->throttle_timers); | 3677 if (bs->blk && blk_get_public(bs->blk)->throttle_state) { 3678 throttle_timers_detach_aio_context( 3679 &blk_get_public(bs->blk)->throttle_timers); |
3681 } 3682 if (bs->drv->bdrv_detach_aio_context) { 3683 bs->drv->bdrv_detach_aio_context(bs); 3684 } 3685 if (bs->file) { 3686 bdrv_detach_aio_context(bs->file->bs); 3687 } 3688 if (bs->backing) { --- 18 unchanged lines hidden (view full) --- 3707 bdrv_attach_aio_context(bs->backing->bs, new_context); 3708 } 3709 if (bs->file) { 3710 bdrv_attach_aio_context(bs->file->bs, new_context); 3711 } 3712 if (bs->drv->bdrv_attach_aio_context) { 3713 bs->drv->bdrv_attach_aio_context(bs, new_context); 3714 } | 3680 } 3681 if (bs->drv->bdrv_detach_aio_context) { 3682 bs->drv->bdrv_detach_aio_context(bs); 3683 } 3684 if (bs->file) { 3685 bdrv_detach_aio_context(bs->file->bs); 3686 } 3687 if (bs->backing) { --- 18 unchanged lines hidden (view full) --- 3706 bdrv_attach_aio_context(bs->backing->bs, new_context); 3707 } 3708 if (bs->file) { 3709 bdrv_attach_aio_context(bs->file->bs, new_context); 3710 } 3711 if (bs->drv->bdrv_attach_aio_context) { 3712 bs->drv->bdrv_attach_aio_context(bs, new_context); 3713 } |
3715 if (bs->throttle_state) { 3716 throttle_timers_attach_aio_context(&bs->throttle_timers, new_context); | 3714 if (bs->blk && blk_get_public(bs->blk)->throttle_state) { 3715 throttle_timers_attach_aio_context( 3716 &blk_get_public(bs->blk)->throttle_timers, new_context); |
3717 } 3718 3719 QLIST_FOREACH(ban, &bs->aio_notifiers, list) { 3720 ban->attached_aio_context(new_context, ban->opaque); 3721 } 3722} 3723 3724void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context) --- 352 unchanged lines hidden --- | 3717 } 3718 3719 QLIST_FOREACH(ban, &bs->aio_notifiers, list) { 3720 ban->attached_aio_context(new_context, ban->opaque); 3721 } 3722} 3723 3724void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context) --- 352 unchanged lines hidden --- |