From patchwork Tue Mar 9 22:53:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 47194 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CE875B7D0A for ; Wed, 10 Mar 2010 10:00:45 +1100 (EST) Received: from localhost ([127.0.0.1]:42645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Np8Pq-0007pg-7q for incoming@patchwork.ozlabs.org; Tue, 09 Mar 2010 18:00:42 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Np8JE-0004eF-D5 for qemu-devel@nongnu.org; Tue, 09 Mar 2010 17:53:52 -0500 Received: from [199.232.76.173] (port=36555 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Np8JD-0004dk-LC for qemu-devel@nongnu.org; Tue, 09 Mar 2010 17:53:51 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Np8JB-0004I8-Lc for qemu-devel@nongnu.org; Tue, 09 Mar 2010 17:53:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60205) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Np8JB-0004Ho-91 for qemu-devel@nongnu.org; Tue, 09 Mar 2010 17:53:49 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o29Mrmhv001574 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Mar 2010 17:53:48 -0500 Received: from localhost (vpn-11-176.rdu.redhat.com [10.11.11.176]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o29MrlQr023176; Tue, 9 Mar 2010 17:53:47 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 9 Mar 2010 19:53:36 -0300 Message-Id: <1268175216-3600-4-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1268175216-3600-1-git-send-email-lcapitulino@redhat.com> References: <1268175216-3600-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, uril@redhat.com Subject: [Qemu-devel] [PATCH 3/3] QMP: Introduce BLOCK_WATERMARK event X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Emitted whenever the watermark value set by the Monitor 'block_watermark' command is reached. This value is not permanently stored and it's automatically set to zero when the event is emitted. Signed-off-by: Luiz Capitulino --- QMP/qmp-events.txt | 26 ++++++++++++++++++++++++++ block/qcow2-refcount.c | 20 ++++++++++++++++++++ monitor.c | 3 +++ monitor.h | 1 + 4 files changed, 50 insertions(+), 0 deletions(-) diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt index a94e9b4..f1fe3aa 100644 --- a/QMP/qmp-events.txt +++ b/QMP/qmp-events.txt @@ -26,6 +26,32 @@ Example: Note: If action is "stop", a STOP event will eventually follow the BLOCK_IO_ERROR event. +BLOCK_WATERMARK +--------------- + +Emitted when the watermark value for a device is reached. + +Data: + +- "device": device name (json-string) +- "type": watermark type (json-string, only "high" currently) +- "mark": current device's high watermark value (json-int) +- "allocation": current allocation (json-int) + +Example: + +{ "event": "BLOCK_WATERMARK", + "data": { "device": "ide0-hd0", + "ide0-hd0", + "mark": 1048576, + "allocation": 1376256 }, + "timestamp": { "seconds": 1268170711, "microseconds": 698676 } } + +Note: (1) The watermark value is set by the 'block_watermark' Monitor's command + (2) The device's watermark value is set to zero when the event is + emitted. Thus, this event is emitted only once. + (3) Currently only the high watermark value is supported + RESET ----- diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 9cb38c8..684e0ff 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -23,6 +23,8 @@ */ #include "qemu-common.h" +#include "qjson.h" +#include "monitor.h" #include "block_int.h" #include "block/qcow2.h" @@ -531,6 +533,17 @@ static int update_cluster_refcount(BlockDriverState *bs, /* cluster allocation functions */ +static void watermark_mon_event(const BlockDriverState *bs, int64_t ha) +{ + QObject *data; + + data = qobject_from_jsonf("{ 'device': %s, 'type': 'high', " + "'allocation': %" PRId64 ", 'mark': %" PRId64 "}", + bs->device_name, ha, bs->high_watermark); + + monitor_protocol_event(QEVENT_BLOCK_WATERMARK, data); + qobject_decref(data); +} /* return < 0 if error */ static int64_t alloc_clusters_noref(BlockDriverState *bs, int64_t size) @@ -552,6 +565,13 @@ retry: #endif if (s->highest_alloc < s->free_cluster_index) { s->highest_alloc = s->free_cluster_index; + if (bs->high_watermark) { + uint64_t ha = (s->highest_alloc << s->cluster_bits); + if (ha >= bs->high_watermark) { + watermark_mon_event(bs, ha); + bs->high_watermark = 0; + } + } } return (s->free_cluster_index - nb_clusters) << s->cluster_bits; } diff --git a/monitor.c b/monitor.c index 595bd62..3f74994 100644 --- a/monitor.c +++ b/monitor.c @@ -423,6 +423,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data) case QEVENT_BLOCK_IO_ERROR: event_name = "BLOCK_IO_ERROR"; break; + case QEVENT_BLOCK_WATERMARK: + event_name = "BLOCK_WATERMARK"; + break; case QEVENT_RTC_CHANGE: event_name = "RTC_CHANGE"; break; diff --git a/monitor.h b/monitor.h index e5f2d2b..e767990 100644 --- a/monitor.h +++ b/monitor.h @@ -23,6 +23,7 @@ typedef enum MonitorEvent { QEVENT_VNC_INITIALIZED, QEVENT_VNC_DISCONNECTED, QEVENT_BLOCK_IO_ERROR, + QEVENT_BLOCK_WATERMARK, QEVENT_RTC_CHANGE, QEVENT_WATCHDOG, QEVENT_MAX,