From patchwork Mon Oct 12 16:23:37 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Schour X-Patchwork-Id: 35774 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 E25E3B7B74 for ; Tue, 13 Oct 2009 02:55:21 +1100 (EST) Received: from localhost ([127.0.0.1]:55106 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxNF0-0003Vh-CJ for incoming@patchwork.ozlabs.org; Mon, 12 Oct 2009 11:55:18 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MxNBp-0002JA-R8 for qemu-devel@nongnu.org; Mon, 12 Oct 2009 11:52:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MxNBk-0002FT-0i for qemu-devel@nongnu.org; Mon, 12 Oct 2009 11:52:00 -0400 Received: from [199.232.76.173] (port=36157 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxNBj-0002FH-Ps for qemu-devel@nongnu.org; Mon, 12 Oct 2009 11:51:55 -0400 Received: from mtagate6.uk.ibm.com ([195.212.29.139]:65118) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MxNBj-00044y-5h for qemu-devel@nongnu.org; Mon, 12 Oct 2009 11:51:55 -0400 Received: from d06nrmr1407.portsmouth.uk.ibm.com (d06nrmr1407.portsmouth.uk.ibm.com [9.149.38.185]) by mtagate6.uk.ibm.com (8.14.3/8.13.8) with ESMTP id n9CFpc3S240018 for ; Mon, 12 Oct 2009 15:51:43 GMT Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id n9CFpS681675332 for ; Mon, 12 Oct 2009 16:51:28 +0100 Received: from d06av04.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n9CFpSvV032004 for ; Mon, 12 Oct 2009 16:51:28 +0100 Received: from localhost.localdomain (im4-64s.haifa.ibm.com [9.148.27.41]) by d06av04.portsmouth.uk.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n9CFpRS2031994 for ; Mon, 12 Oct 2009 16:51:27 +0100 From: lirans@il.ibm.com To: qemu-devel@nongnu.org Date: Mon, 12 Oct 2009 18:23:37 +0200 Message-Id: <12553646173152-git-send-email-lirans@il.ibm.com> X-Mailer: git-send-email 1.5.2.4 Signed-off-by: Liran Schour X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.0.3x (2) Subject: [Qemu-devel] [PATCH 1/3 v4] Expose a mechanisem to trace block writes 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 To support live migration without shared storage we need to be able to trace writes to disk while migrating. This Patch expose handler registration for above components to be notified about block writes. diff --git a/block.c b/block.c index 33f3d65..bf5f7a6 100644 --- a/block.c +++ b/block.c @@ -61,6 +61,8 @@ BlockDriverState *bdrv_first; static BlockDriver *first_drv; +static BlockDriverDirtyHandler *bdrv_dirty_handler = NULL; + int path_is_absolute(const char *path) { const char *p; @@ -626,6 +628,10 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num, if (bdrv_check_request(bs, sector_num, nb_sectors)) return -EIO; + if(bdrv_dirty_handler != NULL) { + bdrv_dirty_handler(bs, sector_num, nb_sectors); + } + return drv->bdrv_write(bs, sector_num, buf, nb_sectors); } @@ -1162,6 +1168,11 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num, return -ENOTSUP; if (bdrv_check_request(bs, sector_num, nb_sectors)) return -EIO; + + if(bdrv_dirty_handler != NULL) { + bdrv_dirty_handler(bs, sector_num, nb_sectors); + } + return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors); } @@ -1359,6 +1370,10 @@ BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num, if (bdrv_check_request(bs, sector_num, nb_sectors)) return NULL; + if(bdrv_dirty_handler != NULL) { + bdrv_dirty_handler(bs, sector_num, nb_sectors); + } + ret = drv->bdrv_aio_writev(bs, sector_num, qiov, nb_sectors, cb, opaque); @@ -1869,7 +1884,19 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs, return NULL; } + + void *qemu_blockalign(BlockDriverState *bs, size_t size) { return qemu_memalign((bs && bs->buffer_alignment) ? bs->buffer_alignment : 512, size); } + +void register_bdrv_dirty_tracking(BlockDriverDirtyHandler *dirty_handler) +{ + bdrv_dirty_handler = dirty_handler; +} + +void unregister_bdrv_dirty_tracking(void) +{ + bdrv_dirty_handler = NULL; +} diff --git a/block.h b/block.h index a966afb..9757a42 100644 --- a/block.h +++ b/block.h @@ -78,7 +78,8 @@ void bdrv_register(BlockDriver *bdrv); /* async block I/O */ typedef struct BlockDriverAIOCB BlockDriverAIOCB; typedef void BlockDriverCompletionFunc(void *opaque, int ret); - +typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector, + int sector_num); BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *iov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque); @@ -184,4 +185,7 @@ int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, int64_t pos, int size); +void register_bdrv_dirty_tracking(BlockDriverDirtyHandler *dirty_handler); +void unregister_bdrv_dirty_tracking(void); + #endif diff --git a/block_int.h b/block_int.h index 8e72abe..c524860 100644 --- a/block_int.h +++ b/block_int.h @@ -168,6 +168,7 @@ struct BlockDriverState { int cyls, heads, secs, translation; int type; char device_name[32]; + void *dirty_control; BlockDriverState *next; void *private; };