]>
Commit | Line | Data |
---|---|---|
e2462113 FR |
1 | /* |
2 | * QEMU System Emulator block write threshold notification | |
3 | * | |
4 | * Copyright Red Hat, Inc. 2014 | |
5 | * | |
6 | * Authors: | |
7 | * Francesco Romani <fromani@redhat.com> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU LGPL, version 2 or later. | |
10 | * See the COPYING.LIB file in the top-level directory. | |
11 | */ | |
12 | ||
80c71a24 | 13 | #include "qemu/osdep.h" |
e2c1c34f | 14 | #include "block/block-io.h" |
e2462113 | 15 | #include "block/block_int.h" |
e2462113 | 16 | #include "block/write-threshold.h" |
e688df6b | 17 | #include "qapi/error.h" |
9af23989 MA |
18 | #include "qapi/qapi-commands-block-core.h" |
19 | #include "qapi/qapi-events-block-core.h" | |
e2462113 | 20 | |
e2462113 FR |
21 | uint64_t bdrv_write_threshold_get(const BlockDriverState *bs) |
22 | { | |
23 | return bs->write_threshold_offset; | |
24 | } | |
25 | ||
e2462113 FR |
26 | void bdrv_write_threshold_set(BlockDriverState *bs, uint64_t threshold_bytes) |
27 | { | |
94783301 | 28 | bs->write_threshold_offset = threshold_bytes; |
e2462113 FR |
29 | } |
30 | ||
31 | void qmp_block_set_write_threshold(const char *node_name, | |
32 | uint64_t threshold_bytes, | |
33 | Error **errp) | |
34 | { | |
35 | BlockDriverState *bs; | |
36 | AioContext *aio_context; | |
37 | ||
38 | bs = bdrv_find_node(node_name); | |
39 | if (!bs) { | |
6ec46ad5 | 40 | error_setg(errp, "Device '%s' not found", node_name); |
e2462113 FR |
41 | return; |
42 | } | |
43 | ||
44 | aio_context = bdrv_get_aio_context(bs); | |
45 | aio_context_acquire(aio_context); | |
46 | ||
47 | bdrv_write_threshold_set(bs, threshold_bytes); | |
48 | ||
49 | aio_context_release(aio_context); | |
50 | } | |
94783301 VSO |
51 | |
52 | void bdrv_write_threshold_check_write(BlockDriverState *bs, int64_t offset, | |
53 | int64_t bytes) | |
54 | { | |
55 | int64_t end = offset + bytes; | |
56 | uint64_t wtr = bs->write_threshold_offset; | |
57 | ||
58 | if (wtr > 0 && end > wtr) { | |
59 | qapi_event_send_block_write_threshold(bs->node_name, end - wtr, wtr); | |
60 | ||
61 | /* autodisable to avoid flooding the monitor */ | |
62 | bdrv_write_threshold_set(bs, 0); | |
63 | } | |
64 | } |