Commit 19629537bd8d81fa7a32f2df5c39419afded04fa
Committed by
Anthony Liguori
1 parent
9f9e28cd
introduce set_rate_limit function for QEMUFile
This patch converts the current callers of qemu_fopen_ops(). Signed-off-by: Glauber Costa <glommer@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
3 changed files
with
43 additions
and
10 deletions
buffered_file.c
| ... | ... | @@ -198,6 +198,19 @@ static int buffered_rate_limit(void *opaque) |
| 198 | 198 | return 0; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | +static size_t buffered_set_rate_limit(void *opaque, size_t new_rate) | |
| 202 | +{ | |
| 203 | + QEMUFileBuffered *s = opaque; | |
| 204 | + | |
| 205 | + if (s->has_error) | |
| 206 | + goto out; | |
| 207 | + | |
| 208 | + s->xfer_limit = new_rate / 10; | |
| 209 | + | |
| 210 | +out: | |
| 211 | + return s->xfer_limit; | |
| 212 | +} | |
| 213 | + | |
| 201 | 214 | static void buffered_rate_tick(void *opaque) |
| 202 | 215 | { |
| 203 | 216 | QEMUFileBuffered *s = opaque; |
| ... | ... | @@ -237,7 +250,8 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque, |
| 237 | 250 | s->close = close; |
| 238 | 251 | |
| 239 | 252 | s->file = qemu_fopen_ops(s, buffered_put_buffer, NULL, |
| 240 | - buffered_close, buffered_rate_limit); | |
| 253 | + buffered_close, buffered_rate_limit, | |
| 254 | + buffered_set_rate_limit); | |
| 241 | 255 | |
| 242 | 256 | s->timer = qemu_new_timer(rt_clock, buffered_rate_tick, s); |
| 243 | 257 | ... | ... |
hw/hw.h
| ... | ... | @@ -36,10 +36,17 @@ typedef int (QEMUFileCloseFunc)(void *opaque); |
| 36 | 36 | */ |
| 37 | 37 | typedef int (QEMUFileRateLimit)(void *opaque); |
| 38 | 38 | |
| 39 | +/* Called to change the current bandwidth allocation. This function must return | |
| 40 | + * the new actual bandwidth. It should be new_rate if everything goes ok, and | |
| 41 | + * the old rate otherwise | |
| 42 | + */ | |
| 43 | +typedef size_t (QEMUFileSetRateLimit)(void *opaque, size_t new_rate); | |
| 44 | + | |
| 39 | 45 | QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, |
| 40 | 46 | QEMUFileGetBufferFunc *get_buffer, |
| 41 | 47 | QEMUFileCloseFunc *close, |
| 42 | - QEMUFileRateLimit *rate_limit); | |
| 48 | + QEMUFileRateLimit *rate_limit, | |
| 49 | + QEMUFileSetRateLimit *set_rate_limit); | |
| 43 | 50 | QEMUFile *qemu_fopen(const char *filename, const char *mode); |
| 44 | 51 | QEMUFile *qemu_fopen_socket(int fd); |
| 45 | 52 | QEMUFile *qemu_popen(FILE *popen_file, const char *mode); |
| ... | ... | @@ -73,6 +80,7 @@ unsigned int qemu_get_be16(QEMUFile *f); |
| 73 | 80 | unsigned int qemu_get_be32(QEMUFile *f); |
| 74 | 81 | uint64_t qemu_get_be64(QEMUFile *f); |
| 75 | 82 | int qemu_file_rate_limit(QEMUFile *f); |
| 83 | +size_t qemu_file_set_rate_limit(QEMUFile *f, size_t new_rate); | |
| 76 | 84 | int qemu_file_has_error(QEMUFile *f); |
| 77 | 85 | void qemu_file_set_error(QEMUFile *f); |
| 78 | 86 | ... | ... |
savevm.c
| ... | ... | @@ -159,6 +159,7 @@ struct QEMUFile { |
| 159 | 159 | QEMUFileGetBufferFunc *get_buffer; |
| 160 | 160 | QEMUFileCloseFunc *close; |
| 161 | 161 | QEMUFileRateLimit *rate_limit; |
| 162 | + QEMUFileSetRateLimit *set_rate_limit; | |
| 162 | 163 | void *opaque; |
| 163 | 164 | int is_write; |
| 164 | 165 | |
| ... | ... | @@ -239,9 +240,9 @@ QEMUFile *qemu_popen(FILE *popen_file, const char *mode) |
| 239 | 240 | s->popen_file = popen_file; |
| 240 | 241 | |
| 241 | 242 | if(mode[0] == 'r') { |
| 242 | - s->file = qemu_fopen_ops(s, NULL, popen_get_buffer, popen_close, NULL); | |
| 243 | + s->file = qemu_fopen_ops(s, NULL, popen_get_buffer, popen_close, NULL, NULL); | |
| 243 | 244 | } else { |
| 244 | - s->file = qemu_fopen_ops(s, popen_put_buffer, NULL, popen_close, NULL); | |
| 245 | + s->file = qemu_fopen_ops(s, popen_put_buffer, NULL, popen_close, NULL, NULL); | |
| 245 | 246 | } |
| 246 | 247 | fprintf(stderr, "qemu_popen: returning result of qemu_fopen_ops\n"); |
| 247 | 248 | return s->file; |
| ... | ... | @@ -264,7 +265,7 @@ QEMUFile *qemu_fopen_socket(int fd) |
| 264 | 265 | QEMUFileSocket *s = qemu_mallocz(sizeof(QEMUFileSocket)); |
| 265 | 266 | |
| 266 | 267 | s->fd = fd; |
| 267 | - s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, NULL); | |
| 268 | + s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, NULL, NULL); | |
| 268 | 269 | return s->file; |
| 269 | 270 | } |
| 270 | 271 | |
| ... | ... | @@ -308,9 +309,9 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode) |
| 308 | 309 | goto fail; |
| 309 | 310 | |
| 310 | 311 | if (!strcmp(mode, "wb")) |
| 311 | - return qemu_fopen_ops(s, file_put_buffer, NULL, file_close, NULL); | |
| 312 | + return qemu_fopen_ops(s, file_put_buffer, NULL, file_close, NULL, NULL); | |
| 312 | 313 | else if (!strcmp(mode, "rb")) |
| 313 | - return qemu_fopen_ops(s, NULL, file_get_buffer, file_close, NULL); | |
| 314 | + return qemu_fopen_ops(s, NULL, file_get_buffer, file_close, NULL, NULL); | |
| 314 | 315 | |
| 315 | 316 | fail: |
| 316 | 317 | if (s->outfile) |
| ... | ... | @@ -356,15 +357,16 @@ static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int64_t offset, int is_wr |
| 356 | 357 | s->base_offset = offset; |
| 357 | 358 | |
| 358 | 359 | if (is_writable) |
| 359 | - return qemu_fopen_ops(s, block_put_buffer, NULL, bdrv_fclose, NULL); | |
| 360 | + return qemu_fopen_ops(s, block_put_buffer, NULL, bdrv_fclose, NULL, NULL); | |
| 360 | 361 | |
| 361 | - return qemu_fopen_ops(s, NULL, block_get_buffer, bdrv_fclose, NULL); | |
| 362 | + return qemu_fopen_ops(s, NULL, block_get_buffer, bdrv_fclose, NULL, NULL); | |
| 362 | 363 | } |
| 363 | 364 | |
| 364 | 365 | QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, |
| 365 | 366 | QEMUFileGetBufferFunc *get_buffer, |
| 366 | 367 | QEMUFileCloseFunc *close, |
| 367 | - QEMUFileRateLimit *rate_limit) | |
| 368 | + QEMUFileRateLimit *rate_limit, | |
| 369 | + QEMUFileSetRateLimit *set_rate_limit) | |
| 368 | 370 | { |
| 369 | 371 | QEMUFile *f; |
| 370 | 372 | |
| ... | ... | @@ -375,6 +377,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, |
| 375 | 377 | f->get_buffer = get_buffer; |
| 376 | 378 | f->close = close; |
| 377 | 379 | f->rate_limit = rate_limit; |
| 380 | + f->set_rate_limit = set_rate_limit; | |
| 378 | 381 | f->is_write = 0; |
| 379 | 382 | |
| 380 | 383 | return f; |
| ... | ... | @@ -552,6 +555,14 @@ int qemu_file_rate_limit(QEMUFile *f) |
| 552 | 555 | return 0; |
| 553 | 556 | } |
| 554 | 557 | |
| 558 | +size_t qemu_file_set_rate_limit(QEMUFile *f, size_t new_rate) | |
| 559 | +{ | |
| 560 | + if (f->set_rate_limit) | |
| 561 | + return f->set_rate_limit(f->opaque, new_rate); | |
| 562 | + | |
| 563 | + return 0; | |
| 564 | +} | |
| 565 | + | |
| 555 | 566 | void qemu_put_be16(QEMUFile *f, unsigned int v) |
| 556 | 567 | { |
| 557 | 568 | qemu_put_byte(f, v >> 8); | ... | ... |