Patchwork [1/3,v4] Expose a mechanisem to trace block writes

login
register
mail settings
Submitter lirans@il.ibm.com
Date Oct. 12, 2009, 3:08 p.m.
Message ID <1255360081435-git-send-email-lirans@il.ibm.com>
Download mbox | patch
Permalink /patch/35766/
State New
Headers show

Comments

lirans@il.ibm.com - Oct. 12, 2009, 3:08 p.m.
Signed-off-by: Liran Schour <lirans@il.ibm.com>
---

Patch

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;
 };