[Sheepdog] [PATCH 3/8] sheepdog: remove member `oid' from struct sd_aiocb

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue Apr 27 08:33:49 CEST 2010


We can calculate oid from the data object index, so we don't
need to remeber it.

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

diff --git a/block/sheepdog.c b/block/sheepdog.c
index dcbe9d6..afe5e68 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -212,8 +212,6 @@ enum aiocb_state {
 struct sd_aiocb {
 	BlockDriverAIOCB common;
 
-	uint64_t oid[2];
-
 	QEMUIOVector *qiov;
 
 	int64_t sector_num;
@@ -235,6 +233,7 @@ struct sd_aiocb {
 
 struct bdrv_sd_state {
 	struct sd_inode inode;
+	int inode_dirty;
 
 	char *name;
 	int is_current;
@@ -409,8 +408,6 @@ static struct sd_aiocb *sd_aio_setup(BlockDriverState *bs,
 	acb->sector_num = sector_num;
 	acb->nb_sectors = nb_sectors;
 
-	memset(acb->oid, 0, sizeof(acb->oid));
-
 	acb->aio_done_func = NULL;
 	acb->write = write;
 	acb->canceled = 0;
@@ -617,6 +614,7 @@ static void aio_read_response(void *opaque)
 	char *buf;
 	struct iovec *iov;
 	int rest;
+	unsigned long idx;
 
 	if (!nr_outstanding_aio_req(s))
 		return;
@@ -632,6 +630,11 @@ static void aio_read_response(void *opaque)
 
 	switch (acb->aiocb_type) {
 	case AIOCB_WRITE_UDATA:
+		idx = acb->sector_num * 512 / SD_DATA_OBJ_SIZE;
+		if (s->inode.data_oid[idx] != to_data_oid(s->inode.oid, idx)) {
+			s->inode.data_oid[idx] = to_data_oid(s->inode.oid, idx);
+			s->inode_dirty = 1;
+		}
 		break;
 	case AIOCB_READ_UDATA:
 		buf = malloc(rsp->data_length);
@@ -1015,6 +1018,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;
 
 	bs->total_sectors = s->inode.vdi_size >> 9;
 	s->name = strdup(vdi);
@@ -1210,35 +1214,23 @@ static inline int nr_chunks(struct sd_aiocb *acb)
 
 static void sd_write_done(struct sd_aiocb *acb)
 {
-	int i, ret, inode_dirty = 0;
-	unsigned long idx = acb->sector_num * 512 / CHUNK_SIZE;
+	int ret;
 	struct bdrv_sd_state *s = acb->common.bs->opaque;
 
-	for (i = 0; i < nr_chunks(acb); i++) {
-		if (acb->oid[i])
-			inode_dirty++;
-	}
-
-	if (inode_dirty) {
-		for (i = 0; i < nr_chunks(acb); i++) {
-			if (acb->oid[i])
-				s->inode.data_oid[idx + i] = acb->oid[i];
-		}
-
+	if (s->inode_dirty) {
+		s->inode_dirty = 0;
 		ret = add_aio_request(s, acb, s->inode.oid, &s->inode,
 				      sizeof(s->inode),
 				      0, 0, 0, 0, 1, 0);
 		if (ret)
 			goto new_node_list;
-	}
 
-	if (!inode_dirty)
-		sd_finish_aiocb(acb);
-	else {
 		acb->aio_done_func = sd_finish_aiocb;
 		acb->aiocb_type = AIOCB_WRITE_UDATA;
+		return;
 	}
 
+	sd_finish_aiocb(acb);
 	return;
 new_node_list:
 	reset_all_aios(s);
@@ -1341,8 +1333,7 @@ static void sd_write_bh_cb(void *p)
 				flags = SD_FLAG_CMD_COW;
 			}
 			oid = to_data_oid(inode->oid, idx);
-			acb->oid[i] = oid;
-			dprintf("new oid %lx\n", acb->oid[i]);
+			dprintf("new oid %lx\n", oid);
 		}
 
 		ret = add_aio_request(s, acb, oid, buf + done, len, offset, flags, old_oid,
-- 
1.5.6.5




More information about the sheepdog mailing list