diff mbox

[3/5] disk_deadlines: add disk-deadlines option per drive

Message ID 1441699228-25767-4-git-send-email-den@openvz.org
State New
Headers show

Commit Message

Denis V. Lunev Sept. 8, 2015, 8 a.m. UTC
From: Raushaniya Maksudova <rmaksudova@virtuozzo.com>

This patch adds per-drive option disk-deadlines.
If it is enabled, one tracks which disk'requests were not completed in time.
By default it is unset.

Signed-off-by: Raushaniya Maksudova <rmaksudova@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
CC: Markus Armbruster <armbru@redhat.com>
---
 block/Makefile.objs            |  1 +
 block/disk-deadlines.c         | 30 ++++++++++++++++++++++++++++++
 blockdev.c                     | 19 +++++++++++++++++++
 include/block/accounting.h     |  2 ++
 include/block/disk-deadlines.h | 35 +++++++++++++++++++++++++++++++++++
 5 files changed, 87 insertions(+)
 create mode 100644 block/disk-deadlines.c
 create mode 100644 include/block/disk-deadlines.h

Comments

Stefan Hajnoczi Sept. 10, 2015, 9:05 a.m. UTC | #1
On Tue, Sep 08, 2015 at 11:00:26AM +0300, Denis V. Lunev wrote:
> diff --git a/blockdev.c b/blockdev.c
> index 6b48be6..6cd9c6e 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -361,6 +361,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
>      ThrottleConfig cfg;
>      int snapshot = 0;
>      bool copy_on_read;
> +    bool disk_deadlines;
>      Error *error = NULL;
>      QemuOpts *opts;
>      const char *id;
> @@ -394,6 +395,11 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
>      ro = qemu_opt_get_bool(opts, "read-only", 0);
>      copy_on_read = qemu_opt_get_bool(opts, "copy-on-read", false);
>  
> +    disk_deadlines = qdict_get_try_bool(bs_opts, "disk-deadlines", false);
> +    if (disk_deadlines) {
> +        qdict_del(bs_opts, "disk-deadlines");

qdict_del() should be unconditional so that -drive disk-deadlines=off
works.  qdict_del() is a nop if the key cannot be found in the dict, so
it is always safe to call it.

> +    }
> +
>      if ((buf = qemu_opt_get(opts, "discard")) != NULL) {
>          if (bdrv_parse_discard_flags(buf, &bdrv_flags) != 0) {
>              error_setg(errp, "invalid discard option");
> @@ -555,6 +561,8 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
>  
>      bs->detect_zeroes = detect_zeroes;
>  
> +    disk_deadlines_init(&bs->stats.disk_deadlines, disk_deadlines);
> +
>      bdrv_set_on_error(bs, on_read_error, on_write_error);
>  
>      /* disk I/O throttling */
> @@ -658,6 +666,10 @@ QemuOptsList qemu_legacy_drive_opts = {
>              .name = "file",
>              .type = QEMU_OPT_STRING,
>              .help = "file name",
> +        },{
> +            .name = "disk-deadlines",
> +            .type = QEMU_OPT_BOOL,
> +            .help = "control of disk requests' time execution",

It would be nice to mention that the guest will be paused:

"pause guest if disk request timeout expires"

> diff --git a/include/block/accounting.h b/include/block/accounting.h
> index 4c406cf..4e2b345 100644
> --- a/include/block/accounting.h
> +++ b/include/block/accounting.h
> @@ -27,6 +27,7 @@
>  #include <stdint.h>
>  
>  #include "qemu/typedefs.h"
> +#include "block/disk-deadlines.h"
>  
>  enum BlockAcctType {
>      BLOCK_ACCT_READ,
> @@ -41,6 +42,7 @@ typedef struct BlockAcctStats {
>      uint64_t total_time_ns[BLOCK_MAX_IOTYPE];
>      uint64_t merged[BLOCK_MAX_IOTYPE];
>      uint64_t wr_highest_sector;
> +    DiskDeadlines disk_deadlines;

I'm not sure that BlockAcctStats is the most appropriate place for
DiskDeadlines.  BlockAcctStats holds accounting information which can be
queried on the QEMU monitor.  It is for reporting disk statistics.

Please add the DiskDeadlines field to BlockDriverState instead.
diff mbox

Patch

diff --git a/block/Makefile.objs b/block/Makefile.objs
index 58ef2ef..cf30ce5 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -20,6 +20,7 @@  block-obj-$(CONFIG_RBD) += rbd.o
 block-obj-$(CONFIG_GLUSTERFS) += gluster.o
 block-obj-$(CONFIG_ARCHIPELAGO) += archipelago.o
 block-obj-$(CONFIG_LIBSSH2) += ssh.o
+block-obj-y += disk-deadlines.o
 block-obj-y += accounting.o
 block-obj-y += write-threshold.o
 
diff --git a/block/disk-deadlines.c b/block/disk-deadlines.c
new file mode 100644
index 0000000..39dec53
--- /dev/null
+++ b/block/disk-deadlines.c
@@ -0,0 +1,30 @@ 
+/*
+ * QEMU System Emulator disk deadlines control
+ *
+ * Copyright (c) 2015 Raushaniya Maksudova <rmaksudova@virtuozzo.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "block/disk-deadlines.h"
+
+void disk_deadlines_init(DiskDeadlines *disk_deadlines, bool enabled)
+{
+    disk_deadlines->enabled = enabled;
+}
diff --git a/blockdev.c b/blockdev.c
index 6b48be6..6cd9c6e 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -361,6 +361,7 @@  static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
     ThrottleConfig cfg;
     int snapshot = 0;
     bool copy_on_read;
+    bool disk_deadlines;
     Error *error = NULL;
     QemuOpts *opts;
     const char *id;
@@ -394,6 +395,11 @@  static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
     ro = qemu_opt_get_bool(opts, "read-only", 0);
     copy_on_read = qemu_opt_get_bool(opts, "copy-on-read", false);
 
+    disk_deadlines = qdict_get_try_bool(bs_opts, "disk-deadlines", false);
+    if (disk_deadlines) {
+        qdict_del(bs_opts, "disk-deadlines");
+    }
+
     if ((buf = qemu_opt_get(opts, "discard")) != NULL) {
         if (bdrv_parse_discard_flags(buf, &bdrv_flags) != 0) {
             error_setg(errp, "invalid discard option");
@@ -555,6 +561,8 @@  static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
 
     bs->detect_zeroes = detect_zeroes;
 
+    disk_deadlines_init(&bs->stats.disk_deadlines, disk_deadlines);
+
     bdrv_set_on_error(bs, on_read_error, on_write_error);
 
     /* disk I/O throttling */
@@ -658,6 +666,10 @@  QemuOptsList qemu_legacy_drive_opts = {
             .name = "file",
             .type = QEMU_OPT_STRING,
             .help = "file name",
+        },{
+            .name = "disk-deadlines",
+            .type = QEMU_OPT_BOOL,
+            .help = "control of disk requests' time execution",
         },
 
         /* Options that are passed on, but have special semantics with -drive */
@@ -698,6 +710,7 @@  DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     const char *werror, *rerror;
     bool read_only = false;
     bool copy_on_read;
+    bool disk_deadlines;
     const char *serial;
     const char *filename;
     Error *local_err = NULL;
@@ -812,6 +825,12 @@  DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     qdict_put(bs_opts, "copy-on-read",
               qstring_from_str(copy_on_read ? "on" :"off"));
 
+    /* Enable control of disk requests' time execution */
+    disk_deadlines = qemu_opt_get_bool(legacy_opts, "disk-deadlines", false);
+    if (disk_deadlines) {
+        qdict_put(bs_opts, "disk-deadlines", qbool_from_bool(disk_deadlines));
+    }
+
     /* Controller type */
     value = qemu_opt_get(legacy_opts, "if");
     if (value) {
diff --git a/include/block/accounting.h b/include/block/accounting.h
index 4c406cf..4e2b345 100644
--- a/include/block/accounting.h
+++ b/include/block/accounting.h
@@ -27,6 +27,7 @@ 
 #include <stdint.h>
 
 #include "qemu/typedefs.h"
+#include "block/disk-deadlines.h"
 
 enum BlockAcctType {
     BLOCK_ACCT_READ,
@@ -41,6 +42,7 @@  typedef struct BlockAcctStats {
     uint64_t total_time_ns[BLOCK_MAX_IOTYPE];
     uint64_t merged[BLOCK_MAX_IOTYPE];
     uint64_t wr_highest_sector;
+    DiskDeadlines disk_deadlines;
 } BlockAcctStats;
 
 typedef struct BlockAcctCookie {
diff --git a/include/block/disk-deadlines.h b/include/block/disk-deadlines.h
new file mode 100644
index 0000000..2ea193b
--- /dev/null
+++ b/include/block/disk-deadlines.h
@@ -0,0 +1,35 @@ 
+/*
+ * QEMU System Emulator disk deadlines control
+ *
+ * Copyright (c) 2015 Raushaniya Maksudova <rmaksudova@virtuozzo.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef DISK_DEADLINES_H
+#define DISK_DEADLINES_H
+
+#include <stdbool.h>
+
+typedef struct DiskDeadlines {
+    bool enabled;
+} DiskDeadlines;
+
+void disk_deadlines_init(DiskDeadlines *disk_deadlines, bool enabled);
+
+#endif