qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, uril@redhat.com
Subject: [Qemu-devel] [PATCH 2/3] monitor: Introduce block_watermark command
Date: Tue,  9 Mar 2010 19:53:35 -0300	[thread overview]
Message-ID: <1268175216-3600-3-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1268175216-3600-1-git-send-email-lcapitulino@redhat.com>

This command sets a watermark value for a device. The next commit
will add the BLOCK_WATERMARK event, which is emitted when this
value is reached.

Please, note that currently only the 'high' watermark value is
supported.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 block.c         |    5 +++++
 block.h         |    2 ++
 block_int.h     |    3 +++
 monitor.c       |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 qemu-monitor.hx |   16 ++++++++++++++++
 5 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index 31d1ba4..260502a 100644
--- a/block.c
+++ b/block.c
@@ -1209,6 +1209,11 @@ void bdrv_flush_all(void)
             bdrv_flush(bs);
 }
 
+void bdrv_set_high_watermark(BlockDriverState *bs, uint64_t offset)
+{
+    bs->high_watermark = offset;
+}
+
 /*
  * Returns true iff the specified sector is present in the disk image. Drivers
  * not implementing the functionality are assumed to not support backing files,
diff --git a/block.h b/block.h
index edf5704..af32436 100644
--- a/block.h
+++ b/block.h
@@ -130,6 +130,8 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
 void bdrv_flush(BlockDriverState *bs);
 void bdrv_flush_all(void);
 
+void bdrv_set_high_watermark(BlockDriverState *bs, uint64_t offset);
+
 int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
 	int *pnum);
 
diff --git a/block_int.h b/block_int.h
index 50e1a0b..53e087d 100644
--- a/block_int.h
+++ b/block_int.h
@@ -156,6 +156,9 @@ struct BlockDriverState {
 
     void *sync_aiocb;
 
+    /* high watermark for monitor event */
+    uint64_t high_watermark;
+
     /* I/O stats (display with "info blockstats"). */
     uint64_t rd_bytes;
     uint64_t wr_bytes;
diff --git a/monitor.c b/monitor.c
index 672ae47..595bd62 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1041,6 +1041,52 @@ static int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data)
     return eject_device(mon, bs, force);
 }
 
+static int do_block_set_watermark(Monitor *mon, const QDict *qdict,
+                                  QObject **ret_data)
+{
+    int64_t offset;
+    char format[32];
+    BlockDriverState *bs;
+
+    bs = bdrv_find(qdict_get_str(qdict, "device"));
+    if (!bs) {
+        qemu_error_new(QERR_DEVICE_NOT_FOUND, qdict_get_str(qdict, "device"));
+        return -1;
+    }
+
+    bdrv_get_format(bs, format, sizeof(format));
+
+    if (format[0] == '\0') {
+        qemu_error_new(QERR_DEVICE_NOT_ACTIVE, qdict_get_str(qdict, "device"));
+        return -1;
+    }
+
+    /* we only support qcow2 currently */
+    if (strcmp(format, "qcow2")) {
+        qemu_error_new(QERR_INVALID_BLOCK_FORMAT, format);
+        return -1;
+    }
+
+    if (strcmp(qdict_get_str(qdict, "type"), "high")) {
+        qemu_error_new(QERR_INVALID_PARAMETER, "type");
+        return -1;
+    }
+
+    offset = qdict_get_int(qdict, "offset");
+    if (offset < 0) {
+        qemu_error_new(QERR_INVALID_PARAMETER, "offset");
+        return -1;
+    }
+
+    /* 
+     * XXX: 'offset' is int64_t because the monitor code doesn't
+     * work with uint64_t. Does it matter? If it does, the
+     * monitor has to be fixed.
+     */
+    bdrv_set_high_watermark(bs, offset);
+    return 0;
+}
+
 static int do_block_set_passwd(Monitor *mon, const QDict *qdict,
                                 QObject **ret_data)
 {
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index 7f9d261..c4b48db 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -1127,6 +1127,22 @@ Set the encrypted device @var{device} password to @var{password}
 ETEXI
 
     {
+        .name       = "block_watermark",
+        .args_type  = "device:B,type:s,offset:l",
+        .params     = "device type offset",
+        .help       = "set block device watermark",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set_watermark,
+    },
+
+STEXI
+@item block_watermark @var{device} @var{type} @var{offset}
+@findex block_watermark
+Set the block device @var{device} watermark @var{type} to @var{offset}
+ETEXI
+
+
+    {
         .name       = "qmp_capabilities",
         .args_type  = "",
         .params     = "",
-- 
1.7.0.1

  parent reply	other threads:[~2010-03-09 22:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-09 22:53 [Qemu-devel] [PATCH 0/3]: BLOCK_WATERMARK QMP event Luiz Capitulino
2010-03-09 22:53 ` [Qemu-devel] [PATCH 1/3] block-qcow2: keep highest allocated offset Luiz Capitulino
2010-03-09 22:53 ` Luiz Capitulino [this message]
2010-03-09 22:53 ` [Qemu-devel] [PATCH 3/3] QMP: Introduce BLOCK_WATERMARK event Luiz Capitulino
2010-03-09 23:03 ` [Qemu-devel] [PATCH 0/3]: BLOCK_WATERMARK QMP event Anthony Liguori
2010-03-09 23:18   ` Luiz Capitulino
2010-03-09 23:08 ` Anthony Liguori
2010-03-09 23:22   ` Luiz Capitulino
2010-03-09 23:25     ` Luiz Capitulino
2010-03-09 23:55       ` Anthony Liguori
2010-03-10 21:02         ` Luiz Capitulino
2010-03-09 23:46     ` Anthony Liguori
2010-03-10  8:40   ` Kevin Wolf
2010-03-10 21:09     ` Luiz Capitulino
2010-03-10 21:20     ` Anthony Liguori
2010-03-11  8:34       ` Kevin Wolf
2010-03-11 14:19         ` Anthony Liguori
2010-03-11 14:58           ` Avi Kivity
2010-03-11 15:07             ` Anthony Liguori
2010-03-11 15:09               ` Avi Kivity
2010-03-11 16:16           ` Kevin Wolf
2010-03-10  8:33 ` [Qemu-devel] " Kevin Wolf
2010-03-10  9:28   ` Christoph Hellwig
2010-03-10 21:11     ` Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1268175216-3600-3-git-send-email-lcapitulino@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=uril@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).