block-backend.c (49d2165d7d6b589d1ea28b15a8874c417bdc55ed) block-backend.c (27ccdd52598290f0f8b58be56e235aff7aebfaf3)
1/*
2 * QEMU Block backends
3 *
4 * Copyright (C) 2014-2016 Red Hat, Inc.
5 *
6 * Authors:
7 * Markus Armbruster <armbru@redhat.com>,
8 *

--- 93 unchanged lines hidden (view full) ---

102 * Return the new BlockBackend on success, null on failure.
103 */
104BlockBackend *blk_new(Error **errp)
105{
106 BlockBackend *blk;
107
108 blk = g_new0(BlockBackend, 1);
109 blk->refcnt = 1;
1/*
2 * QEMU Block backends
3 *
4 * Copyright (C) 2014-2016 Red Hat, Inc.
5 *
6 * Authors:
7 * Markus Armbruster <armbru@redhat.com>,
8 *

--- 93 unchanged lines hidden (view full) ---

102 * Return the new BlockBackend on success, null on failure.
103 */
104BlockBackend *blk_new(Error **errp)
105{
106 BlockBackend *blk;
107
108 blk = g_new0(BlockBackend, 1);
109 blk->refcnt = 1;
110 qemu_co_queue_init(&blk->public.throttled_reqs[0]);
111 qemu_co_queue_init(&blk->public.throttled_reqs[1]);
112
110 notifier_list_init(&blk->remove_bs_notifiers);
111 notifier_list_init(&blk->insert_bs_notifiers);
113 notifier_list_init(&blk->remove_bs_notifiers);
114 notifier_list_init(&blk->insert_bs_notifiers);
115
112 QTAILQ_INSERT_TAIL(&block_backends, blk, link);
113 return blk;
114}
115
116/*
117 * Create a new BlockBackend with a new BlockDriverState attached.
118 * Otherwise just like blk_new(), which see.
119 */

--- 312 unchanged lines hidden (view full) ---

432 */
433void blk_remove_bs(BlockBackend *blk)
434{
435 assert(blk->root->bs->blk == blk);
436
437 notifier_list_notify(&blk->remove_bs_notifiers, blk);
438
439 blk_update_root_state(blk);
116 QTAILQ_INSERT_TAIL(&block_backends, blk, link);
117 return blk;
118}
119
120/*
121 * Create a new BlockBackend with a new BlockDriverState attached.
122 * Otherwise just like blk_new(), which see.
123 */

--- 312 unchanged lines hidden (view full) ---

436 */
437void blk_remove_bs(BlockBackend *blk)
438{
439 assert(blk->root->bs->blk == blk);
440
441 notifier_list_notify(&blk->remove_bs_notifiers, blk);
442
443 blk_update_root_state(blk);
440 if (blk->root->bs->throttle_state) {
444 if (blk->public.throttle_state) {
441 bdrv_io_limits_disable(blk->root->bs);
442 }
443
444 blk->root->bs->blk = NULL;
445 bdrv_root_unref_child(blk->root);
446 blk->root = NULL;
447}
448

--- 341 unchanged lines hidden (view full) ---

790 }
791
792 return rwco.ret;
793}
794
795int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf,
796 int count)
797{
445 bdrv_io_limits_disable(blk->root->bs);
446 }
447
448 blk->root->bs->blk = NULL;
449 bdrv_root_unref_child(blk->root);
450 blk->root = NULL;
451}
452

--- 341 unchanged lines hidden (view full) ---

794 }
795
796 return rwco.ret;
797}
798
799int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf,
800 int count)
801{
798 BlockDriverState *bs = blk_bs(blk);
799 int ret;
800
801 ret = blk_check_byte_request(blk, offset, count);
802 if (ret < 0) {
803 return ret;
804 }
805
802 int ret;
803
804 ret = blk_check_byte_request(blk, offset, count);
805 if (ret < 0) {
806 return ret;
807 }
808
806 bdrv_no_throttling_begin(bs);
809 bdrv_no_throttling_begin(blk_bs(blk));
807 ret = blk_pread(blk, offset, buf, count);
810 ret = blk_pread(blk, offset, buf, count);
808 bdrv_no_throttling_end(bs);
811 bdrv_no_throttling_end(blk_bs(blk));
809 return ret;
810}
811
812int blk_write_zeroes(BlockBackend *blk, int64_t offset,
813 int count, BdrvRequestFlags flags)
814{
815 return blk_prw(blk, offset, NULL, count, blk_write_entry,
816 flags | BDRV_REQ_ZERO_WRITE);

--- 702 unchanged lines hidden (view full) ---

1519 blk->root_state.open_flags = blk->root->bs->open_flags;
1520 blk->root_state.read_only = blk->root->bs->read_only;
1521 blk->root_state.detect_zeroes = blk->root->bs->detect_zeroes;
1522
1523 if (blk->root_state.throttle_group) {
1524 g_free(blk->root_state.throttle_group);
1525 throttle_group_unref(blk->root_state.throttle_state);
1526 }
812 return ret;
813}
814
815int blk_write_zeroes(BlockBackend *blk, int64_t offset,
816 int count, BdrvRequestFlags flags)
817{
818 return blk_prw(blk, offset, NULL, count, blk_write_entry,
819 flags | BDRV_REQ_ZERO_WRITE);

--- 702 unchanged lines hidden (view full) ---

1522 blk->root_state.open_flags = blk->root->bs->open_flags;
1523 blk->root_state.read_only = blk->root->bs->read_only;
1524 blk->root_state.detect_zeroes = blk->root->bs->detect_zeroes;
1525
1526 if (blk->root_state.throttle_group) {
1527 g_free(blk->root_state.throttle_group);
1528 throttle_group_unref(blk->root_state.throttle_state);
1529 }
1527 if (blk->root->bs->throttle_state) {
1530 if (blk->public.throttle_state) {
1528 const char *name = throttle_group_get_name(blk);
1529 blk->root_state.throttle_group = g_strdup(name);
1530 blk->root_state.throttle_state = throttle_group_incref(name);
1531 } else {
1532 blk->root_state.throttle_group = NULL;
1533 blk->root_state.throttle_state = NULL;
1534 }
1535}

--- 74 unchanged lines hidden ---
1531 const char *name = throttle_group_get_name(blk);
1532 blk->root_state.throttle_group = g_strdup(name);
1533 blk->root_state.throttle_state = throttle_group_incref(name);
1534 } else {
1535 blk->root_state.throttle_group = NULL;
1536 blk->root_state.throttle_state = NULL;
1537 }
1538}

--- 74 unchanged lines hidden ---