io.c (49d2165d7d6b589d1ea28b15a8874c417bdc55ed) | io.c (27ccdd52598290f0f8b58be56e235aff7aebfaf3) |
---|---|
1/* 2 * Block layer I/O functions 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 --- 41 unchanged lines hidden (view full) --- 50void bdrv_set_io_limits(BlockDriverState *bs, 51 ThrottleConfig *cfg) 52{ 53 throttle_group_config(bs, cfg); 54} 55 56void bdrv_no_throttling_begin(BlockDriverState *bs) 57{ | 1/* 2 * Block layer I/O functions 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 --- 41 unchanged lines hidden (view full) --- 50void bdrv_set_io_limits(BlockDriverState *bs, 51 ThrottleConfig *cfg) 52{ 53 throttle_group_config(bs, cfg); 54} 55 56void bdrv_no_throttling_begin(BlockDriverState *bs) 57{ |
58 if (bs->io_limits_disabled++ == 0) { 59 throttle_group_restart_bs(bs); | 58 if (!bs->blk) { 59 return; |
60 } | 60 } |
61 62 if (blk_get_public(bs->blk)->io_limits_disabled++ == 0) { 63 throttle_group_restart_blk(bs->blk); 64 } |
|
61} 62 63void bdrv_no_throttling_end(BlockDriverState *bs) 64{ | 65} 66 67void bdrv_no_throttling_end(BlockDriverState *bs) 68{ |
65 assert(bs->io_limits_disabled); 66 --bs->io_limits_disabled; | 69 BlockBackendPublic *blkp; 70 71 if (!bs->blk) { 72 return; 73 } 74 75 blkp = blk_get_public(bs->blk); 76 assert(blkp->io_limits_disabled); 77 --blkp->io_limits_disabled; |
67} 68 69void bdrv_io_limits_disable(BlockDriverState *bs) 70{ | 78} 79 80void bdrv_io_limits_disable(BlockDriverState *bs) 81{ |
71 assert(bs->throttle_state); | 82 assert(blk_get_public(bs->blk)->throttle_state); |
72 bdrv_no_throttling_begin(bs); 73 throttle_group_unregister_blk(bs->blk); 74 bdrv_no_throttling_end(bs); 75} 76 77/* should be called before bdrv_set_io_limits if a limit is set */ 78void bdrv_io_limits_enable(BlockDriverState *bs, const char *group) 79{ | 83 bdrv_no_throttling_begin(bs); 84 throttle_group_unregister_blk(bs->blk); 85 bdrv_no_throttling_end(bs); 86} 87 88/* should be called before bdrv_set_io_limits if a limit is set */ 89void bdrv_io_limits_enable(BlockDriverState *bs, const char *group) 90{ |
80 assert(!bs->throttle_state); | 91 BlockBackendPublic *blkp = blk_get_public(bs->blk); 92 93 assert(!blkp->throttle_state); |
81 throttle_group_register_blk(bs->blk, group); 82} 83 84void bdrv_io_limits_update_group(BlockDriverState *bs, const char *group) 85{ 86 /* this bs is not part of any group */ | 94 throttle_group_register_blk(bs->blk, group); 95} 96 97void bdrv_io_limits_update_group(BlockDriverState *bs, const char *group) 98{ 99 /* this bs is not part of any group */ |
87 if (!bs->throttle_state) { | 100 if (!blk_get_public(bs->blk)->throttle_state) { |
88 return; 89 } 90 91 /* this bs is a part of the same group than the one we want */ 92 if (!g_strcmp0(throttle_group_get_name(bs->blk), group)) { 93 return; 94 } 95 --- 77 unchanged lines hidden (view full) --- 173 assert(bs->copy_on_read > 0); 174 bs->copy_on_read--; 175} 176 177/* Check if any requests are in-flight (including throttled requests) */ 178bool bdrv_requests_pending(BlockDriverState *bs) 179{ 180 BdrvChild *child; | 101 return; 102 } 103 104 /* this bs is a part of the same group than the one we want */ 105 if (!g_strcmp0(throttle_group_get_name(bs->blk), group)) { 106 return; 107 } 108 --- 77 unchanged lines hidden (view full) --- 186 assert(bs->copy_on_read > 0); 187 bs->copy_on_read--; 188} 189 190/* Check if any requests are in-flight (including throttled requests) */ 191bool bdrv_requests_pending(BlockDriverState *bs) 192{ 193 BdrvChild *child; |
194 BlockBackendPublic *blkp = bs->blk ? blk_get_public(bs->blk) : NULL; |
|
181 182 if (!QLIST_EMPTY(&bs->tracked_requests)) { 183 return true; 184 } | 195 196 if (!QLIST_EMPTY(&bs->tracked_requests)) { 197 return true; 198 } |
185 if (!qemu_co_queue_empty(&bs->throttled_reqs[0])) { | 199 if (blkp && !qemu_co_queue_empty(&blkp->throttled_reqs[0])) { |
186 return true; 187 } | 200 return true; 201 } |
188 if (!qemu_co_queue_empty(&bs->throttled_reqs[1])) { | 202 if (blkp && !qemu_co_queue_empty(&blkp->throttled_reqs[1])) { |
189 return true; 190 } 191 192 QLIST_FOREACH(child, &bs->children, next) { 193 if (bdrv_requests_pending(child->bs)) { 194 return true; 195 } 196 } --- 868 unchanged lines hidden (view full) --- 1065 } 1066 1067 /* Don't do copy-on-read if we read data before write operation */ 1068 if (bs->copy_on_read && !(flags & BDRV_REQ_NO_SERIALISING)) { 1069 flags |= BDRV_REQ_COPY_ON_READ; 1070 } 1071 1072 /* throttling disk I/O */ | 203 return true; 204 } 205 206 QLIST_FOREACH(child, &bs->children, next) { 207 if (bdrv_requests_pending(child->bs)) { 208 return true; 209 } 210 } --- 868 unchanged lines hidden (view full) --- 1079 } 1080 1081 /* Don't do copy-on-read if we read data before write operation */ 1082 if (bs->copy_on_read && !(flags & BDRV_REQ_NO_SERIALISING)) { 1083 flags |= BDRV_REQ_COPY_ON_READ; 1084 } 1085 1086 /* throttling disk I/O */ |
1073 if (bs->throttle_state) { | 1087 if (bs->blk && blk_get_public(bs->blk)->throttle_state) { |
1074 throttle_group_co_io_limits_intercept(bs, bytes, false); 1075 } 1076 1077 /* Align read if necessary by padding qiov */ 1078 if (offset & (align - 1)) { 1079 head_buf = qemu_blockalign(bs, align); 1080 qemu_iovec_init(&local_qiov, qiov->niov + 2); 1081 qemu_iovec_add(&local_qiov, head_buf, offset & (align - 1)); --- 344 unchanged lines hidden (view full) --- 1426 assert(!(bs->open_flags & BDRV_O_INACTIVE)); 1427 1428 ret = bdrv_check_byte_request(bs, offset, bytes); 1429 if (ret < 0) { 1430 return ret; 1431 } 1432 1433 /* throttling disk I/O */ | 1088 throttle_group_co_io_limits_intercept(bs, bytes, false); 1089 } 1090 1091 /* Align read if necessary by padding qiov */ 1092 if (offset & (align - 1)) { 1093 head_buf = qemu_blockalign(bs, align); 1094 qemu_iovec_init(&local_qiov, qiov->niov + 2); 1095 qemu_iovec_add(&local_qiov, head_buf, offset & (align - 1)); --- 344 unchanged lines hidden (view full) --- 1440 assert(!(bs->open_flags & BDRV_O_INACTIVE)); 1441 1442 ret = bdrv_check_byte_request(bs, offset, bytes); 1443 if (ret < 0) { 1444 return ret; 1445 } 1446 1447 /* throttling disk I/O */ |
1434 if (bs->throttle_state) { | 1448 if (bs->blk && blk_get_public(bs->blk)->throttle_state) { |
1435 throttle_group_co_io_limits_intercept(bs, bytes, true); 1436 } 1437 1438 /* 1439 * Align write if necessary by performing a read-modify-write cycle. 1440 * Pad qiov with the read parts and be sure to have a tracked request not 1441 * only for bdrv_aligned_pwritev, but also for the reads of the RMW cycle. 1442 */ --- 1360 unchanged lines hidden --- | 1449 throttle_group_co_io_limits_intercept(bs, bytes, true); 1450 } 1451 1452 /* 1453 * Align write if necessary by performing a read-modify-write cycle. 1454 * Pad qiov with the read parts and be sure to have a tracked request not 1455 * only for bdrv_aligned_pwritev, but also for the reads of the RMW cycle. 1456 */ --- 1360 unchanged lines hidden --- |