diff mbox series

[v10,5/6] fsdev: QMP interface for throttling

Message ID 1504541267-36954-6-git-send-email-pradeep.jagadeesh@huawei.com
State New
Headers show
Series fsdev: qmp interface for io throttling | expand

Commit Message

Pradeep Jagadeesh Sept. 4, 2017, 4:07 p.m. UTC
This patch introduces qmp interfaces for the fsdev
devices. This provides two interfaces one
for querying info of all the fsdev devices. The second one
to set the IO limits for the required fsdev device.

Signed-off-by: Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com>
---
 Makefile                    |   4 ++
 fsdev/qemu-fsdev-dummy.c    |  11 ++++
 fsdev/qemu-fsdev-throttle.c | 145 ++++++++++++++++++++++++++++++++++++++++++--
 fsdev/qemu-fsdev-throttle.h |   9 ++-
 fsdev/qemu-fsdev.c          |  30 +++++++++
 monitor.c                   |   5 ++
 qapi-schema.json            |   3 +
 qapi/fsdev.json             |  81 +++++++++++++++++++++++++
 qmp.c                       |  14 +++++
 9 files changed, 294 insertions(+), 8 deletions(-)
 create mode 100644 qapi/fsdev.json

Comments

Markus Armbruster Sept. 8, 2017, 10:02 a.m. UTC | #1
Pradeep Jagadeesh <pradeepkiruvale@gmail.com> writes:

> This patch introduces qmp interfaces for the fsdev
> devices. This provides two interfaces one
> for querying info of all the fsdev devices. The second one
> to set the IO limits for the required fsdev device.
>
> Signed-off-by: Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com>
> ---
>  Makefile                    |   4 ++
>  fsdev/qemu-fsdev-dummy.c    |  11 ++++
>  fsdev/qemu-fsdev-throttle.c | 145 ++++++++++++++++++++++++++++++++++++++++++--
>  fsdev/qemu-fsdev-throttle.h |   9 ++-
>  fsdev/qemu-fsdev.c          |  30 +++++++++
>  monitor.c                   |   5 ++
>  qapi-schema.json            |   3 +
>  qapi/fsdev.json             |  81 +++++++++++++++++++++++++
>  qmp.c                       |  14 +++++
>  9 files changed, 294 insertions(+), 8 deletions(-)
>  create mode 100644 qapi/fsdev.json
>
> diff --git a/Makefile b/Makefile
> index 81447b1..ec31ffa 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -414,6 +414,10 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
>                 $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \
>                 $(SRC_PATH)/qapi/trace.json
>  
> +ifdef CONFIG_VIRTFS
> +qapi-modules += $(SRC_PATH)/qapi/fsdev.json
> +endif
> +

The ifdef is a *lie*: qapi.py *will* include this file no matter what.
Lying to make is not a good idea.  Drop the ifdef.

>  qapi-types.c qapi-types.h :\
>  $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
>  	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \
> diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c
> index 6dc0fbc..28c82d2 100644
> --- a/fsdev/qemu-fsdev-dummy.c
> +++ b/fsdev/qemu-fsdev-dummy.c
> @@ -14,8 +14,19 @@
>  #include "qemu-fsdev.h"
>  #include "qemu/config-file.h"
>  #include "qemu/module.h"
> +#include "qmp-commands.h"
>  
>  int qemu_fsdev_add(QemuOpts *opts)
>  {
>      return 0;
>  }
> +
> +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
> +{
> +    return;
> +}
> +
> +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
> +{
> +    return NULL;
> +}

Predates this patch: should this be in stubs/?  Might simplify
fsdev/Makefile.objs.

> diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c
> index 0e6fb86..525352e 100644
> --- a/fsdev/qemu-fsdev-throttle.c
> +++ b/fsdev/qemu-fsdev-throttle.c
[Skipping this one...]
> diff --git a/fsdev/qemu-fsdev-throttle.h b/fsdev/qemu-fsdev-throttle.h
> index e418643..bfeab40 100644
> --- a/fsdev/qemu-fsdev-throttle.h
> +++ b/fsdev/qemu-fsdev-throttle.h
> @@ -15,8 +15,6 @@
>  #ifndef _FSDEV_THROTTLE_H
>  #define _FSDEV_THROTTLE_H
>  
> -#include "block/aio.h"
> -#include "qemu/main-loop.h"
>  #include "qemu/coroutine.h"
>  #include "qapi/error.h"
>  #include "qemu/throttle.h"
> @@ -25,6 +23,7 @@ typedef struct FsThrottle {
>      ThrottleState ts;
>      ThrottleTimers tt;
>      ThrottleConfig cfg;
> +    AioContext *ctx;
>      CoQueue      throttled_reqs[2];
>  } FsThrottle;
>  
> @@ -36,4 +35,10 @@ void coroutine_fn fsdev_co_throttle_request(FsThrottle *, bool ,
>                                              struct iovec *, int);
>  
>  void fsdev_throttle_cleanup(FsThrottle *);
> +
> +void fsdev_set_io_throttle(IOThrottle *, FsThrottle *, Error **errp);
> +
> +void fsdev_get_io_throttle(FsThrottle *, IOThrottle **iothp,
> +                           char *);

Include the last parameter's name, for consistency with the other
parameter declarations.

> +
>  #endif /* _FSDEV_THROTTLE_H */
> diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
> index 266e442..0f701fc 100644
> --- a/fsdev/qemu-fsdev.c
> +++ b/fsdev/qemu-fsdev.c
> @@ -16,6 +16,7 @@
>  #include "qemu-common.h"
>  #include "qemu/config-file.h"
>  #include "qemu/error-report.h"
> +#include "qmp-commands.h"
>  
>  static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
>      QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
> @@ -98,3 +99,32 @@ FsDriverEntry *get_fsdev_fsentry(char *id)
>      }
>      return NULL;
>  }
> +
> +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
> +{
> +
> +    FsDriverEntry *fse;
> +
> +    fse = get_fsdev_fsentry(arg->has_id ? arg->id : NULL);

!arg->has_id implies !arg->id.  Therefore, Just arg->id would do, no
need to check arg->has_id first.  It's not wrong, though.

> +    if (!fse) {
> +        error_setg(errp, "Not a valid fsdev device");
> +        return;
> +    }
> +
> +    fsdev_set_io_throttle(arg, &fse->fst, errp);
> +}
> +
> +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
> +{
> +    IOThrottleList *head = NULL, *p_next;
> +    struct FsDriverListEntry *fsle;
> +
> +    QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
> +        p_next = g_new0(IOThrottleList, 1);
> +        fsdev_get_io_throttle(&fsle->fse.fst, &p_next->value,
> +                              fsle->fse.fsdev_id);
> +        p_next->next = head;
> +        head = p_next;
> +    }
> +    return head;
> +}
> diff --git a/monitor.c b/monitor.c
> index e0f8801..eebda1c 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -998,6 +998,11 @@ static void qmp_unregister_commands_hack(void)
>      && !defined(TARGET_S390X)
>      qmp_unregister_command(&qmp_commands, "query-cpu-definitions");
>  #endif
> +#ifndef CONFIG_VIRTFS
> +    qmp_unregister_command(&qmp_commands, "fsdev-set-io-throttle");
> +    qmp_unregister_command(&qmp_commands, "query-fsdev-io-throttle");
> +#endif
> +
>  }
>  
>  void monitor_init_qmp_commands(void)
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 802ea53..8cf8140 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -81,6 +81,9 @@
>  # QAPI block definitions
>  { 'include': 'qapi/block.json' }
>  
> +# QAPI fsdev definitions
> +{ 'include': 'qapi/fsdev.json' }
> +
>  # QAPI event definitions
>  { 'include': 'qapi/event.json' }
>  
> diff --git a/qapi/fsdev.json b/qapi/fsdev.json
> new file mode 100644
> index 0000000..21d074d
> --- /dev/null
> +++ b/qapi/fsdev.json
> @@ -0,0 +1,81 @@
> +# -*- Mode: Python -*-
> +
> +##
> +# == QAPI fsdev definitions
> +##
> +
> +##
> +# @fsdev-set-io-throttle:
> +#
> +# Change I/O limits for a 9p/fsdev device.
> +#
> +# I/O limits can be enabled by setting throttle value to non-zero number.
> +#
> +# I/O limits can be disabled by setting all throttle values to 0.
> +#
> +# Returns: Nothing on success
> +#          If @device is not a valid fsdev device, GenericError
> +#
> +# Since: 2.10

2.11

> +#
> +# Example:
> +#
> +# -> { "execute": "fsdev-set-io-throttle",
> +#      "arguments": { "id": "id0-1-0",
> +#                     "bps": 1000000,
> +#                     "bps_rd": 0,
> +#                     "bps_wr": 0,
> +#                     "iops": 0,
> +#                     "iops_rd": 0,
> +#                     "iops_wr": 0,
> +#                     "bps_max": 8000000,
> +#                     "bps_rd_max": 0,
> +#                     "bps_wr_max": 0,
> +#                     "iops_max": 0,
> +#                     "iops_rd_max": 0,
> +#                     "iops_wr_max": 0,
> +#                     "bps_max_length": 60,
> +#                     "iops_size": 0 } }
> +# <- { "returns": {} }
> +##
> +{ 'command': 'fsdev-set-io-throttle', 'boxed': true,
> +  'data': 'IOThrottle' }
> +##
> +# @query-fsdev-io-throttle:
> +#
> +# Returns: a list of @IOThrottle describing I/O throttle
> +#          values of each fsdev device
> +#
> +# Since: 2.10

2.11

IOThrottle serves both as parameter of fsdev-set-io-throttle and as
result of query-fsdev-io-throttle.

The former needs many of its members to be optional.

Which of the optional members are *actually* optional in the result of
query-fsdev-io-throttle?  Under what conditions can they be absent?

For what it's worth, the corresponding block layer query doesn't reuse
IOThrottle.  Instead, it repeats the throttling stuff in
BlockDeviceInfo, with the same members optional.  BlockDeviceInfo
documentation neglects to specify under what conditions they can be
absent.  Berto?

> +#
> +# Example:
> +#
> +# -> { "Execute": "query-fsdev-io-throttle" }
> +# <- { "returns" : [
> +#          {
> +#              "id": "id0-hd0",
> +#              "bps":1000000,
> +#              "bps_rd":0,
> +#              "bps_wr":0,
> +#              "iops":1000000,
> +#              "iops_rd":0,
> +#              "iops_wr":0,
> +#              "bps_max": 8000000,
> +#              "bps_rd_max": 0,
> +#              "bps_wr_max": 0,
> +#              "iops_max": 0,
> +#              "iops_rd_max": 0,
> +#              "iops_wr_max": 0,
> +#              "bps_max_length": 0,
> +#              "bps_rd_max_length": 0,
> +#              "bps_wr_max_length": 0,
> +#              "iops_max_length": 0,
> +#              "iops_rd_max_length": 0,
> +#              "iops_wr_max_length": 0,
> +#              "iops_size": 0
> +#            }
> +#          ]
> +#      }
> +#
> +##
> +{ 'command': 'query-fsdev-io-throttle', 'returns': [ 'IOThrottle' ] }
> diff --git a/qmp.c b/qmp.c
> index b86201e..eed91e5 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -130,6 +130,20 @@ void qmp_cpu_add(int64_t id, Error **errp)
>      }
>  }
>  
> +#if defined(_WIN64) || defined(_WIN32) || defined(__FreeBSD__)
> +
> +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
> +{
> +    return;
> +}
> +
> +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
> +{
> +    return NULL;
> +}
> +
> +#endif
> +
>  #ifndef CONFIG_VNC
>  /* If VNC support is enabled, the "true" query-vnc command is
>     defined in the VNC subsystem */

Why do we need *two* stubs for these functions, one here and one in
fsdev/qemu-fsdev-dummy.c?
Pradeep Jagadeesh Sept. 8, 2017, 12:19 p.m. UTC | #2
On 9/8/2017 12:02 PM, Markus Armbruster wrote:
> Pradeep Jagadeesh <pradeepkiruvale@gmail.com> writes:
>
>> This patch introduces qmp interfaces for the fsdev
>> devices. This provides two interfaces one
>> for querying info of all the fsdev devices. The second one
>> to set the IO limits for the required fsdev device.
>>
>> Signed-off-by: Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com>
>> ---
>>  Makefile                    |   4 ++
>>  fsdev/qemu-fsdev-dummy.c    |  11 ++++
>>  fsdev/qemu-fsdev-throttle.c | 145 ++++++++++++++++++++++++++++++++++++++++++--
>>  fsdev/qemu-fsdev-throttle.h |   9 ++-
>>  fsdev/qemu-fsdev.c          |  30 +++++++++
>>  monitor.c                   |   5 ++
>>  qapi-schema.json            |   3 +
>>  qapi/fsdev.json             |  81 +++++++++++++++++++++++++
>>  qmp.c                       |  14 +++++
>>  9 files changed, 294 insertions(+), 8 deletions(-)
>>  create mode 100644 qapi/fsdev.json
>>
>> diff --git a/Makefile b/Makefile
>> index 81447b1..ec31ffa 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -414,6 +414,10 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
>>                 $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \
>>                 $(SRC_PATH)/qapi/trace.json
>>
>> +ifdef CONFIG_VIRTFS
>> +qapi-modules += $(SRC_PATH)/qapi/fsdev.json
>> +endif
>> +
>
> The ifdef is a *lie*: qapi.py *will* include this file no matter what.
> Lying to make is not a good idea.  Drop the ifdef.
Yes, thats right. As of these are useless.
For the same reason I have these dummy functions in two different places.
>
>>  qapi-types.c qapi-types.h :\
>>  $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
>>  	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \
>> diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c
>> index 6dc0fbc..28c82d2 100644
>> --- a/fsdev/qemu-fsdev-dummy.c
>> +++ b/fsdev/qemu-fsdev-dummy.c
>> @@ -14,8 +14,19 @@
>>  #include "qemu-fsdev.h"
>>  #include "qemu/config-file.h"
>>  #include "qemu/module.h"
>> +#include "qmp-commands.h"
>>
>>  int qemu_fsdev_add(QemuOpts *opts)
>>  {
>>      return 0;
>>  }
>> +
>> +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
>> +{
>> +    return;
>> +}
>> +
>> +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
>> +{
>> +    return NULL;
>> +}
>
> Predates this patch: should this be in stubs/?  Might simplify
> fsdev/Makefile.objs.
Explained above
>
>> diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c
>> index 0e6fb86..525352e 100644
>> --- a/fsdev/qemu-fsdev-throttle.c
>> +++ b/fsdev/qemu-fsdev-throttle.c
> [Skipping this one...]
>> diff --git a/fsdev/qemu-fsdev-throttle.h b/fsdev/qemu-fsdev-throttle.h
>> index e418643..bfeab40 100644
>> --- a/fsdev/qemu-fsdev-throttle.h
>> +++ b/fsdev/qemu-fsdev-throttle.h
>> @@ -15,8 +15,6 @@
>>  #ifndef _FSDEV_THROTTLE_H
>>  #define _FSDEV_THROTTLE_H
>>
>> -#include "block/aio.h"
>> -#include "qemu/main-loop.h"
>>  #include "qemu/coroutine.h"
>>  #include "qapi/error.h"
>>  #include "qemu/throttle.h"
>> @@ -25,6 +23,7 @@ typedef struct FsThrottle {
>>      ThrottleState ts;
>>      ThrottleTimers tt;
>>      ThrottleConfig cfg;
>> +    AioContext *ctx;
>>      CoQueue      throttled_reqs[2];
>>  } FsThrottle;
>>
>> @@ -36,4 +35,10 @@ void coroutine_fn fsdev_co_throttle_request(FsThrottle *, bool ,
>>                                              struct iovec *, int);
>>
>>  void fsdev_throttle_cleanup(FsThrottle *);
>> +
>> +void fsdev_set_io_throttle(IOThrottle *, FsThrottle *, Error **errp);
>> +
>> +void fsdev_get_io_throttle(FsThrottle *, IOThrottle **iothp,
>> +                           char *);
>
> Include the last parameter's name, for consistency with the other
> parameter declarations.
OK
>
>> +
>>  #endif /* _FSDEV_THROTTLE_H */
>> diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
>> index 266e442..0f701fc 100644
>> --- a/fsdev/qemu-fsdev.c
>> +++ b/fsdev/qemu-fsdev.c
>> @@ -16,6 +16,7 @@
>>  #include "qemu-common.h"
>>  #include "qemu/config-file.h"
>>  #include "qemu/error-report.h"
>> +#include "qmp-commands.h"
>>
>>  static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
>>      QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
>> @@ -98,3 +99,32 @@ FsDriverEntry *get_fsdev_fsentry(char *id)
>>      }
>>      return NULL;
>>  }
>> +
>> +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
>> +{
>> +
>> +    FsDriverEntry *fse;
>> +
>> +    fse = get_fsdev_fsentry(arg->has_id ? arg->id : NULL);
>
> !arg->has_id implies !arg->id.  Therefore, Just arg->id would do, no
> need to check arg->has_id first.  It's not wrong, though.
>
>> +    if (!fse) {
>> +        error_setg(errp, "Not a valid fsdev device");
>> +        return;
>> +    }
>> +
>> +    fsdev_set_io_throttle(arg, &fse->fst, errp);
>> +}
>> +
>> +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
>> +{
>> +    IOThrottleList *head = NULL, *p_next;
>> +    struct FsDriverListEntry *fsle;
>> +
>> +    QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
>> +        p_next = g_new0(IOThrottleList, 1);
>> +        fsdev_get_io_throttle(&fsle->fse.fst, &p_next->value,
>> +                              fsle->fse.fsdev_id);
>> +        p_next->next = head;
>> +        head = p_next;
>> +    }
>> +    return head;
>> +}
>> diff --git a/monitor.c b/monitor.c
>> index e0f8801..eebda1c 100644
>> --- a/monitor.c
>> +++ b/monitor.c
>> @@ -998,6 +998,11 @@ static void qmp_unregister_commands_hack(void)
>>      && !defined(TARGET_S390X)
>>      qmp_unregister_command(&qmp_commands, "query-cpu-definitions");
>>  #endif
>> +#ifndef CONFIG_VIRTFS
>> +    qmp_unregister_command(&qmp_commands, "fsdev-set-io-throttle");
>> +    qmp_unregister_command(&qmp_commands, "query-fsdev-io-throttle");
>> +#endif
>> +
>>  }
>>
>>  void monitor_init_qmp_commands(void)
>> diff --git a/qapi-schema.json b/qapi-schema.json
>> index 802ea53..8cf8140 100644
>> --- a/qapi-schema.json
>> +++ b/qapi-schema.json
>> @@ -81,6 +81,9 @@
>>  # QAPI block definitions
>>  { 'include': 'qapi/block.json' }
>>
>> +# QAPI fsdev definitions
>> +{ 'include': 'qapi/fsdev.json' }
>> +
>>  # QAPI event definitions
>>  { 'include': 'qapi/event.json' }
>>
>> diff --git a/qapi/fsdev.json b/qapi/fsdev.json
>> new file mode 100644
>> index 0000000..21d074d
>> --- /dev/null
>> +++ b/qapi/fsdev.json
>> @@ -0,0 +1,81 @@
>> +# -*- Mode: Python -*-
>> +
>> +##
>> +# == QAPI fsdev definitions
>> +##
>> +
>> +##
>> +# @fsdev-set-io-throttle:
>> +#
>> +# Change I/O limits for a 9p/fsdev device.
>> +#
>> +# I/O limits can be enabled by setting throttle value to non-zero number.
>> +#
>> +# I/O limits can be disabled by setting all throttle values to 0.
>> +#
>> +# Returns: Nothing on success
>> +#          If @device is not a valid fsdev device, GenericError
>> +#
>> +# Since: 2.10
>
> 2.11
>
ok
>> +#
>> +# Example:
>> +#
>> +# -> { "execute": "fsdev-set-io-throttle",
>> +#      "arguments": { "id": "id0-1-0",
>> +#                     "bps": 1000000,
>> +#                     "bps_rd": 0,
>> +#                     "bps_wr": 0,
>> +#                     "iops": 0,
>> +#                     "iops_rd": 0,
>> +#                     "iops_wr": 0,
>> +#                     "bps_max": 8000000,
>> +#                     "bps_rd_max": 0,
>> +#                     "bps_wr_max": 0,
>> +#                     "iops_max": 0,
>> +#                     "iops_rd_max": 0,
>> +#                     "iops_wr_max": 0,
>> +#                     "bps_max_length": 60,
>> +#                     "iops_size": 0 } }
>> +# <- { "returns": {} }
>> +##
>> +{ 'command': 'fsdev-set-io-throttle', 'boxed': true,
>> +  'data': 'IOThrottle' }
>> +##
>> +# @query-fsdev-io-throttle:
>> +#
>> +# Returns: a list of @IOThrottle describing I/O throttle
>> +#          values of each fsdev device
>> +#
>> +# Since: 2.10
>
> 2.11
>
> IOThrottle serves both as parameter of fsdev-set-io-throttle and as
> result of query-fsdev-io-throttle.
>
> The former needs many of its members to be optional.
>
> Which of the optional members are *actually* optional in the result of
> query-fsdev-io-throttle?  Under what conditions can they be absent?
>
> For what it's worth, the corresponding block layer query doesn't reuse
> IOThrottle.  Instead, it repeats the throttling stuff in
> BlockDeviceInfo, with the same members optional.  BlockDeviceInfo
> documentation neglects to specify under what conditions they can be
> absent.  Berto?
>
>> +#
>> +# Example:
>> +#
>> +# -> { "Execute": "query-fsdev-io-throttle" }
>> +# <- { "returns" : [
>> +#          {
>> +#              "id": "id0-hd0",
>> +#              "bps":1000000,
>> +#              "bps_rd":0,
>> +#              "bps_wr":0,
>> +#              "iops":1000000,
>> +#              "iops_rd":0,
>> +#              "iops_wr":0,
>> +#              "bps_max": 8000000,
>> +#              "bps_rd_max": 0,
>> +#              "bps_wr_max": 0,
>> +#              "iops_max": 0,
>> +#              "iops_rd_max": 0,
>> +#              "iops_wr_max": 0,
>> +#              "bps_max_length": 0,
>> +#              "bps_rd_max_length": 0,
>> +#              "bps_wr_max_length": 0,
>> +#              "iops_max_length": 0,
>> +#              "iops_rd_max_length": 0,
>> +#              "iops_wr_max_length": 0,
>> +#              "iops_size": 0
>> +#            }
>> +#          ]
>> +#      }
>> +#
>> +##
>> +{ 'command': 'query-fsdev-io-throttle', 'returns': [ 'IOThrottle' ] }
>> diff --git a/qmp.c b/qmp.c
>> index b86201e..eed91e5 100644
>> --- a/qmp.c
>> +++ b/qmp.c
>> @@ -130,6 +130,20 @@ void qmp_cpu_add(int64_t id, Error **errp)
>>      }
>>  }
>>
>> +#if defined(_WIN64) || defined(_WIN32) || defined(__FreeBSD__)
>> +
>> +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
>> +{
>> +    return;
>> +}
>> +
>> +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
>> +{
>> +    return NULL;
>> +}
>> +
>> +#endif
>> +
>>  #ifndef CONFIG_VNC
>>  /* If VNC support is enabled, the "true" query-vnc command is
>>     defined in the VNC subsystem */
>
> Why do we need *two* stubs for these functions, one here and one in
> fsdev/qemu-fsdev-dummy.c?
At two different platforms the build fails. So, there are needed.

-Pradeep
>
Markus Armbruster Sept. 8, 2017, 12:34 p.m. UTC | #3
Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com> writes:

> On 9/8/2017 12:02 PM, Markus Armbruster wrote:
>> Pradeep Jagadeesh <pradeepkiruvale@gmail.com> writes:
[...]
>>> diff --git a/qmp.c b/qmp.c
>>> index b86201e..eed91e5 100644
>>> --- a/qmp.c
>>> +++ b/qmp.c
>>> @@ -130,6 +130,20 @@ void qmp_cpu_add(int64_t id, Error **errp)
>>>      }
>>>  }
>>>
>>> +#if defined(_WIN64) || defined(_WIN32) || defined(__FreeBSD__)
>>> +
>>> +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
>>> +{
>>> +    return;
>>> +}
>>> +
>>> +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
>>> +{
>>> +    return NULL;
>>> +}
>>> +
>>> +#endif
>>> +
>>>  #ifndef CONFIG_VNC
>>>  /* If VNC support is enabled, the "true" query-vnc command is
>>>     defined in the VNC subsystem */
>>
>> Why do we need *two* stubs for these functions, one here and one in
>> fsdev/qemu-fsdev-dummy.c?
> At two different platforms the build fails. So, there are needed.

We don't add stubs to random places until the linker succeeds for all
the configurations we happen to test.  We figure out *how* the linker
fails to correct our idea of where a certain stub belongs until we find
the one appropriate home for it.

If you can't figure that out, that's okay, just tell us how exactly the
linker fails for you, and we'll be happy to help.
Pradeep Jagadeesh Sept. 8, 2017, 12:49 p.m. UTC | #4
On 9/8/2017 2:34 PM, Markus Armbruster wrote:
> Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com> writes:
>
>> On 9/8/2017 12:02 PM, Markus Armbruster wrote:
>>> Pradeep Jagadeesh <pradeepkiruvale@gmail.com> writes:
> [...]
>>>> diff --git a/qmp.c b/qmp.c
>>>> index b86201e..eed91e5 100644
>>>> --- a/qmp.c
>>>> +++ b/qmp.c
>>>> @@ -130,6 +130,20 @@ void qmp_cpu_add(int64_t id, Error **errp)
>>>>      }
>>>>  }
>>>>
>>>> +#if defined(_WIN64) || defined(_WIN32) || defined(__FreeBSD__)
>>>> +
>>>> +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
>>>> +{
>>>> +    return;
>>>> +}
>>>> +
>>>> +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
>>>> +{
>>>> +    return NULL;
>>>> +}
>>>> +
>>>> +#endif
>>>> +
>>>>  #ifndef CONFIG_VNC
>>>>  /* If VNC support is enabled, the "true" query-vnc command is
>>>>     defined in the VNC subsystem */
>>>
>>> Why do we need *two* stubs for these functions, one here and one in
>>> fsdev/qemu-fsdev-dummy.c?
>> At two different platforms the build fails. So, there are needed.
>
> We don't add stubs to random places until the linker succeeds for all
> the configurations we happen to test.  We figure out *how* the linker
> fails to correct our idea of where a certain stub belongs until we find
> the one appropriate home for it.
>
OK, I will figure it out and send it across. But these were discussed 
since the v1, now I do not remember on top of my mind. I will have to 
dig my old emails and send it across or I should reproduce them again.

> If you can't figure that out, that's okay, just tell us how exactly the
> linker fails for you, and we'll be happy to help.
Thanks for offering help!

-Pradeep
>
Markus Armbruster Sept. 8, 2017, 12:51 p.m. UTC | #5
Alberto Garcia <berto@igalia.com> writes:

> On Fri 08 Sep 2017 12:02:14 PM CEST, Markus Armbruster wrote:
>
>>> +    fse = get_fsdev_fsentry(arg->has_id ? arg->id : NULL);
>>
>> !arg->has_id implies !arg->id.
>
> Hey Markus,
>
> I have the impression that I've also written code that never uses
> arg->foo when arg->has_foo is false.
>
> Can we then assume that to be NULL/0 in all cases? Also for other data
> types (int, bool, ...)?

QAPI code always passes zero FOOs along with false has_FOOs.  Anything
that doesn't is a bug.  This is particular important when FOO is a
pointer; we don't want to pass around pointers pointing to random junk
in the hope that everybody will obediently check their has_FOO before
dereferencing.

Other code might not always be as well-behaved.  In random context,
checking has_FOO is probably safer.

I still want to eliminate has_FOO for pointer-valued FOO.  So much to
do, so little time!
Pradeep Jagadeesh Sept. 11, 2017, 9:23 a.m. UTC | #6
On 9/8/2017 2:34 PM, Markus Armbruster wrote:
> Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com> writes:
>
>> On 9/8/2017 12:02 PM, Markus Armbruster wrote:
>>> Pradeep Jagadeesh <pradeepkiruvale@gmail.com> writes:
> [...]
>>>> diff --git a/qmp.c b/qmp.c
>>>> index b86201e..eed91e5 100644
>>>> --- a/qmp.c
>>>> +++ b/qmp.c
>>>> @@ -130,6 +130,20 @@ void qmp_cpu_add(int64_t id, Error **errp)
>>>>      }
>>>>  }
>>>>
>>>> +#if defined(_WIN64) || defined(_WIN32) || defined(__FreeBSD__)
>>>> +
>>>> +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
>>>> +{
>>>> +    return;
>>>> +}
>>>> +
>>>> +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
>>>> +{
>>>> +    return NULL;
>>>> +}
>>>> +
>>>> +#endif
>>>> +
>>>>  #ifndef CONFIG_VNC
>>>>  /* If VNC support is enabled, the "true" query-vnc command is
>>>>     defined in the VNC subsystem */
>>>
>>> Why do we need *two* stubs for these functions, one here and one in
>>> fsdev/qemu-fsdev-dummy.c?
>> At two different platforms the build fails. So, there are needed.
>
> We don't add stubs to random places until the linker succeeds for all
> the configurations we happen to test.  We figure out *how* the linker
> fails to correct our idea of where a certain stub belongs until we find
> the one appropriate home for it.
>
> If you can't figure that out, that's okay, just tell us how exactly the
> linker fails for you, and we'll be happy to help.
If I do not have those stubs in qmp.c.The linking fails when I compile 
like "make docker-test-mingw@fedora"

The stubs in qemu-fsdev-dummy.c required because when I configure on x86 
as --disable-virtfs, then the compilation fails.

So, I need the stubs at both the places. Please let me know if I can 
avoid some how.

Regards,
Pradeep
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 81447b1..ec31ffa 100644
--- a/Makefile
+++ b/Makefile
@@ -414,6 +414,10 @@  qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
                $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \
                $(SRC_PATH)/qapi/trace.json
 
+ifdef CONFIG_VIRTFS
+qapi-modules += $(SRC_PATH)/qapi/fsdev.json
+endif
+
 qapi-types.c qapi-types.h :\
 $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \
diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c
index 6dc0fbc..28c82d2 100644
--- a/fsdev/qemu-fsdev-dummy.c
+++ b/fsdev/qemu-fsdev-dummy.c
@@ -14,8 +14,19 @@ 
 #include "qemu-fsdev.h"
 #include "qemu/config-file.h"
 #include "qemu/module.h"
+#include "qmp-commands.h"
 
 int qemu_fsdev_add(QemuOpts *opts)
 {
     return 0;
 }
+
+void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
+{
+    return;
+}
+
+IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
+{
+    return NULL;
+}
diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c
index 0e6fb86..525352e 100644
--- a/fsdev/qemu-fsdev-throttle.c
+++ b/fsdev/qemu-fsdev-throttle.c
@@ -16,6 +16,7 @@ 
 #include "qemu/error-report.h"
 #include "qemu-fsdev-throttle.h"
 #include "qemu/iov.h"
+#include "qemu/main-loop.h"
 #include "qemu/throttle-options.h"
 
 static void fsdev_throttle_read_timer_cb(void *opaque)
@@ -30,6 +31,141 @@  static void fsdev_throttle_write_timer_cb(void *opaque)
     qemu_co_enter_next(&fst->throttled_reqs[true]);
 }
 
+typedef struct {
+    FsThrottle *fst;
+    bool is_write;
+} RestartData;
+
+static bool coroutine_fn throttle_co_restart_queue(FsThrottle *fst,
+                                                   bool is_write)
+{
+    return qemu_co_queue_next(&fst->throttled_reqs[is_write]);
+}
+
+static void schedule_next_request(FsThrottle *fst, bool is_write)
+{
+    bool must_wait = throttle_schedule_timer(&fst->ts, &fst->tt, is_write);
+    if (!must_wait) {
+        if (qemu_in_coroutine() &&
+            throttle_co_restart_queue(fst, is_write)) {
+            return;
+        } else {
+            int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+            timer_mod(fst->tt.timers[is_write], now);
+        }
+    }
+}
+
+static void coroutine_fn throttle_restart_queue_entry(void *opaque)
+{
+    RestartData *data = opaque;
+    bool is_write = data->is_write;
+    bool empty_queue = !throttle_co_restart_queue(data->fst, is_write);
+    if (empty_queue) {
+        schedule_next_request(data->fst, is_write);
+    }
+}
+
+static void throttle_restart_queues(FsThrottle *fst)
+{
+    Coroutine *co;
+    RestartData rd = {
+        .fst = fst,
+        .is_write = true
+    };
+
+    co = qemu_coroutine_create(throttle_restart_queue_entry, &rd);
+    aio_co_enter(fst->ctx, co);
+
+    rd.is_write = false;
+
+    co = qemu_coroutine_create(throttle_restart_queue_entry, &rd);
+    aio_co_enter(fst->ctx, co);
+}
+
+static void coroutine_fn fsdev_throttle_config(FsThrottle *fst)
+{
+    if (throttle_enabled(&fst->cfg)) {
+        throttle_config(&fst->ts, QEMU_CLOCK_REALTIME, &fst->cfg);
+    } else {
+        throttle_restart_queues(fst);
+    }
+}
+
+void fsdev_set_io_throttle(IOThrottle *arg, FsThrottle *fst, Error **errp)
+{
+    ThrottleConfig cfg;
+
+    throttle_set_io_limits(&cfg, arg);
+
+    if (throttle_is_valid(&cfg, errp)) {
+        fst->cfg = cfg;
+        fsdev_throttle_config(fst);
+    }
+}
+
+void fsdev_get_io_throttle(FsThrottle *fst, IOThrottle **fs9pcfg,
+                           char *fsdevice)
+{
+    ThrottleConfig cfg = fst->cfg;
+    IOThrottle *fscfg = g_malloc0(sizeof(*fscfg));
+
+    fscfg->has_id = true;
+    fscfg->id = g_strdup(fsdevice);
+    fscfg->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg;
+    fscfg->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg;
+    fscfg->bps_wr = cfg.buckets[THROTTLE_BPS_WRITE].avg;
+
+    fscfg->iops = cfg.buckets[THROTTLE_OPS_TOTAL].avg;
+    fscfg->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg;
+    fscfg->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg;
+
+    fscfg->has_bps_max     = cfg.buckets[THROTTLE_BPS_TOTAL].max;
+    fscfg->bps_max         = cfg.buckets[THROTTLE_BPS_TOTAL].max;
+    fscfg->has_bps_rd_max  = cfg.buckets[THROTTLE_BPS_READ].max;
+    fscfg->bps_rd_max      = cfg.buckets[THROTTLE_BPS_READ].max;
+    fscfg->has_bps_wr_max  = cfg.buckets[THROTTLE_BPS_WRITE].max;
+    fscfg->bps_wr_max      = cfg.buckets[THROTTLE_BPS_WRITE].max;
+
+    fscfg->has_iops_max    = cfg.buckets[THROTTLE_OPS_TOTAL].max;
+    fscfg->iops_max        = cfg.buckets[THROTTLE_OPS_TOTAL].max;
+    fscfg->has_iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max;
+    fscfg->iops_rd_max     = cfg.buckets[THROTTLE_OPS_READ].max;
+    fscfg->has_iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max;
+    fscfg->iops_wr_max     = cfg.buckets[THROTTLE_OPS_WRITE].max;
+
+    fscfg->has_bps_max_length     = fscfg->has_bps_max;
+    fscfg->bps_max_length         =
+         cfg.buckets[THROTTLE_BPS_TOTAL].burst_length;
+    fscfg->has_bps_rd_max_length  = fscfg->has_bps_rd_max;
+    fscfg->bps_rd_max_length      =
+         cfg.buckets[THROTTLE_BPS_READ].burst_length;
+    fscfg->has_bps_wr_max_length  = fscfg->has_bps_wr_max;
+    fscfg->bps_wr_max_length      =
+         cfg.buckets[THROTTLE_BPS_WRITE].burst_length;
+
+    fscfg->has_iops_max_length    = fscfg->has_iops_max;
+    fscfg->iops_max_length        =
+         cfg.buckets[THROTTLE_OPS_TOTAL].burst_length;
+    fscfg->has_iops_rd_max_length = fscfg->has_iops_rd_max;
+    fscfg->iops_rd_max_length     =
+         cfg.buckets[THROTTLE_OPS_READ].burst_length;
+    fscfg->has_iops_wr_max_length = fscfg->has_iops_wr_max;
+    fscfg->iops_wr_max_length     =
+         cfg.buckets[THROTTLE_OPS_WRITE].burst_length;
+
+    fscfg->bps_max_length = cfg.buckets[THROTTLE_BPS_TOTAL].burst_length;
+    fscfg->bps_rd_max_length = cfg.buckets[THROTTLE_BPS_READ].burst_length;
+    fscfg->bps_wr_max_length = cfg.buckets[THROTTLE_BPS_WRITE].burst_length;
+    fscfg->iops_max_length = cfg.buckets[THROTTLE_OPS_TOTAL].burst_length;
+    fscfg->iops_rd_max_length = cfg.buckets[THROTTLE_OPS_READ].burst_length;
+    fscfg->iops_wr_max_length = cfg.buckets[THROTTLE_OPS_WRITE].burst_length;
+
+    fscfg->iops_size = cfg.op_size;
+
+    *fs9pcfg = fscfg;
+}
+
 void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp)
 {
     throttle_parse_options(&fst->cfg, opts);
@@ -40,8 +176,9 @@  void fsdev_throttle_init(FsThrottle *fst)
 {
     if (throttle_enabled(&fst->cfg)) {
         throttle_init(&fst->ts);
+        fst->ctx = qemu_get_aio_context();
         throttle_timers_init(&fst->tt,
-                             qemu_get_aio_context(),
+                             fst->ctx,
                              QEMU_CLOCK_REALTIME,
                              fsdev_throttle_read_timer_cb,
                              fsdev_throttle_write_timer_cb,
@@ -62,11 +199,7 @@  void coroutine_fn fsdev_co_throttle_request(FsThrottle *fst, bool is_write,
         }
 
         throttle_account(&fst->ts, is_write, iov_size(iov, iovcnt));
-
-        if (!qemu_co_queue_empty(&fst->throttled_reqs[is_write]) &&
-            !throttle_schedule_timer(&fst->ts, &fst->tt, is_write)) {
-            qemu_co_queue_next(&fst->throttled_reqs[is_write]);
-        }
+        schedule_next_request(fst, is_write);
     }
 }
 
diff --git a/fsdev/qemu-fsdev-throttle.h b/fsdev/qemu-fsdev-throttle.h
index e418643..bfeab40 100644
--- a/fsdev/qemu-fsdev-throttle.h
+++ b/fsdev/qemu-fsdev-throttle.h
@@ -15,8 +15,6 @@ 
 #ifndef _FSDEV_THROTTLE_H
 #define _FSDEV_THROTTLE_H
 
-#include "block/aio.h"
-#include "qemu/main-loop.h"
 #include "qemu/coroutine.h"
 #include "qapi/error.h"
 #include "qemu/throttle.h"
@@ -25,6 +23,7 @@  typedef struct FsThrottle {
     ThrottleState ts;
     ThrottleTimers tt;
     ThrottleConfig cfg;
+    AioContext *ctx;
     CoQueue      throttled_reqs[2];
 } FsThrottle;
 
@@ -36,4 +35,10 @@  void coroutine_fn fsdev_co_throttle_request(FsThrottle *, bool ,
                                             struct iovec *, int);
 
 void fsdev_throttle_cleanup(FsThrottle *);
+
+void fsdev_set_io_throttle(IOThrottle *, FsThrottle *, Error **errp);
+
+void fsdev_get_io_throttle(FsThrottle *, IOThrottle **iothp,
+                           char *);
+
 #endif /* _FSDEV_THROTTLE_H */
diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
index 266e442..0f701fc 100644
--- a/fsdev/qemu-fsdev.c
+++ b/fsdev/qemu-fsdev.c
@@ -16,6 +16,7 @@ 
 #include "qemu-common.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
+#include "qmp-commands.h"
 
 static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
     QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
@@ -98,3 +99,32 @@  FsDriverEntry *get_fsdev_fsentry(char *id)
     }
     return NULL;
 }
+
+void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
+{
+
+    FsDriverEntry *fse;
+
+    fse = get_fsdev_fsentry(arg->has_id ? arg->id : NULL);
+    if (!fse) {
+        error_setg(errp, "Not a valid fsdev device");
+        return;
+    }
+
+    fsdev_set_io_throttle(arg, &fse->fst, errp);
+}
+
+IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
+{
+    IOThrottleList *head = NULL, *p_next;
+    struct FsDriverListEntry *fsle;
+
+    QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
+        p_next = g_new0(IOThrottleList, 1);
+        fsdev_get_io_throttle(&fsle->fse.fst, &p_next->value,
+                              fsle->fse.fsdev_id);
+        p_next->next = head;
+        head = p_next;
+    }
+    return head;
+}
diff --git a/monitor.c b/monitor.c
index e0f8801..eebda1c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -998,6 +998,11 @@  static void qmp_unregister_commands_hack(void)
     && !defined(TARGET_S390X)
     qmp_unregister_command(&qmp_commands, "query-cpu-definitions");
 #endif
+#ifndef CONFIG_VIRTFS
+    qmp_unregister_command(&qmp_commands, "fsdev-set-io-throttle");
+    qmp_unregister_command(&qmp_commands, "query-fsdev-io-throttle");
+#endif
+
 }
 
 void monitor_init_qmp_commands(void)
diff --git a/qapi-schema.json b/qapi-schema.json
index 802ea53..8cf8140 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -81,6 +81,9 @@ 
 # QAPI block definitions
 { 'include': 'qapi/block.json' }
 
+# QAPI fsdev definitions
+{ 'include': 'qapi/fsdev.json' }
+
 # QAPI event definitions
 { 'include': 'qapi/event.json' }
 
diff --git a/qapi/fsdev.json b/qapi/fsdev.json
new file mode 100644
index 0000000..21d074d
--- /dev/null
+++ b/qapi/fsdev.json
@@ -0,0 +1,81 @@ 
+# -*- Mode: Python -*-
+
+##
+# == QAPI fsdev definitions
+##
+
+##
+# @fsdev-set-io-throttle:
+#
+# Change I/O limits for a 9p/fsdev device.
+#
+# I/O limits can be enabled by setting throttle value to non-zero number.
+#
+# I/O limits can be disabled by setting all throttle values to 0.
+#
+# Returns: Nothing on success
+#          If @device is not a valid fsdev device, GenericError
+#
+# Since: 2.10
+#
+# Example:
+#
+# -> { "execute": "fsdev-set-io-throttle",
+#      "arguments": { "id": "id0-1-0",
+#                     "bps": 1000000,
+#                     "bps_rd": 0,
+#                     "bps_wr": 0,
+#                     "iops": 0,
+#                     "iops_rd": 0,
+#                     "iops_wr": 0,
+#                     "bps_max": 8000000,
+#                     "bps_rd_max": 0,
+#                     "bps_wr_max": 0,
+#                     "iops_max": 0,
+#                     "iops_rd_max": 0,
+#                     "iops_wr_max": 0,
+#                     "bps_max_length": 60,
+#                     "iops_size": 0 } }
+# <- { "returns": {} }
+##
+{ 'command': 'fsdev-set-io-throttle', 'boxed': true,
+  'data': 'IOThrottle' }
+##
+# @query-fsdev-io-throttle:
+#
+# Returns: a list of @IOThrottle describing I/O throttle
+#          values of each fsdev device
+#
+# Since: 2.10
+#
+# Example:
+#
+# -> { "Execute": "query-fsdev-io-throttle" }
+# <- { "returns" : [
+#          {
+#              "id": "id0-hd0",
+#              "bps":1000000,
+#              "bps_rd":0,
+#              "bps_wr":0,
+#              "iops":1000000,
+#              "iops_rd":0,
+#              "iops_wr":0,
+#              "bps_max": 8000000,
+#              "bps_rd_max": 0,
+#              "bps_wr_max": 0,
+#              "iops_max": 0,
+#              "iops_rd_max": 0,
+#              "iops_wr_max": 0,
+#              "bps_max_length": 0,
+#              "bps_rd_max_length": 0,
+#              "bps_wr_max_length": 0,
+#              "iops_max_length": 0,
+#              "iops_rd_max_length": 0,
+#              "iops_wr_max_length": 0,
+#              "iops_size": 0
+#            }
+#          ]
+#      }
+#
+##
+{ 'command': 'query-fsdev-io-throttle', 'returns': [ 'IOThrottle' ] }
diff --git a/qmp.c b/qmp.c
index b86201e..eed91e5 100644
--- a/qmp.c
+++ b/qmp.c
@@ -130,6 +130,20 @@  void qmp_cpu_add(int64_t id, Error **errp)
     }
 }
 
+#if defined(_WIN64) || defined(_WIN32) || defined(__FreeBSD__)
+
+void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp)
+{
+    return;
+}
+
+IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp)
+{
+    return NULL;
+}
+
+#endif
+
 #ifndef CONFIG_VNC
 /* If VNC support is enabled, the "true" query-vnc command is
    defined in the VNC subsystem */