[Sheepdog] [PATCH] sheepdog: update vdi object partially

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Fri Apr 30 02:01:50 CEST 2010


We don't need to entire vdi object always.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 block/sheepdog.c |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index f8863f8..a2c08a0 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -237,7 +237,9 @@ struct sd_aiocb {
 
 struct bdrv_sd_state {
 	struct sd_inode inode;
-	int inode_dirty;
+
+	int nr_dirty_data_oids;
+	uint32_t dirty_data_oids[MAX_AIO_REQS];
 
 	char *name;
 	int is_current;
@@ -711,7 +713,7 @@ static void aio_read_response(void *opaque)
 
 		if (s->inode.data_vdi_id[idx] != s->inode.vdi_id) {
 			s->inode.data_vdi_id[idx] = s->inode.vdi_id;
-			s->inode_dirty = 1;
+			s->dirty_data_oids[s->nr_dirty_data_oids++] = idx;
 
 			send_pending_req(s, vid_to_data_oid(s->inode.vdi_id, idx),
 					 rsp->id);
@@ -1017,7 +1019,7 @@ static int sd_open(BlockDriverState *bs, const char *filename, int flags)
 		goto out;
 
 	memcpy(&s->inode, buf, sizeof(s->inode));
-	s->inode_dirty = 0;
+	s->nr_dirty_data_oids = 0;
 
 	bs->total_sectors = s->inode.vdi_size >> 9;
 	s->name = strdup(vdi);
@@ -1208,17 +1210,29 @@ static inline int nr_chunks(struct sd_aiocb *acb)
 
 static void sd_write_done(struct sd_aiocb *acb)
 {
-	int ret;
+	int ret, i;
 	struct bdrv_sd_state *s = acb->common.bs->opaque;
 	struct iovec iov;
 	struct aio_req *aio_req;
+	uint32_t offset, data_len, mn, mx;
+
+	if (s->nr_dirty_data_oids) {
+		mn = mx = s->dirty_data_oids[0];
+		for (i = 0; i < s->nr_dirty_data_oids; i++) {
+			if (mn > s->dirty_data_oids[i])
+				mn = s->dirty_data_oids[i];
+			if (mx < s->dirty_data_oids[i])
+				mx = s->dirty_data_oids[i];
+		}
+		offset = sizeof(s->inode) - sizeof(s->inode.data_vdi_id) +
+			mn * sizeof(s->inode.data_vdi_id[0]);
+		data_len = (mx - mn + 1) * sizeof(s->inode.data_vdi_id[0]);
+		s->nr_dirty_data_oids = 0;
 
-	if (s->inode_dirty) {
-		s->inode_dirty = 0;
 		iov.iov_base = &s->inode;
 		iov.iov_len = sizeof(s->inode);
 		aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id),
-					sizeof(s->inode), 0, 0, 0, 0);
+					data_len, offset, 0, 0, offset);
 		if (!aio_req) {
 			eprintf("too many requests\n");
 			acb->ret = -EIO;
-- 
1.5.6.5




More information about the sheepdog mailing list