[Sheepdog] [PATCH 3/4] sheepdog: remove aio_state_array from struct bdrv_sd_state

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Fri Apr 23 08:35:16 CEST 2010


At Thu, 22 Apr 2010 02:32:19 +0900,
MORITA Kazutaka wrote:
> 
> qemu sends only one request for each object operation now, so we don't
> need aio_state_array.
> 
> Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
> ---
>  block/sheepdog.c |   69 ++++++++++++++++++++++--------------------------------
>  1 files changed, 28 insertions(+), 41 deletions(-)
> 
The patch has a prolblem when opening socket.

Fixed version is the below.

=
From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
Date: Fri, 23 Apr 2010 15:25:39 +0900
Subject: [PATCH v2] sheepdog: remove aio_state_array from struct bdrv_sd_state

qemu sends only one request for each object operation now, so we don't
need aio_state_array.

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

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 1675cdc..a379511 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -256,22 +256,17 @@ struct sd_aiocb {
 
 #define MAX_AIO_REQS 4096
 
-struct sd_aiostate {
-	struct bdrv_sd_state *s;
-	int fd;
-
-	struct aio_req aio_req_list[MAX_AIO_REQS];
-	struct aio_req *aio_req_free[MAX_AIO_REQS];
-	int nr_aio_req_free;
-};
-
 struct bdrv_sd_state {
 	struct sd_inode inode;
 
 	char *name;
 	int is_current;
 
-	struct sd_aiostate aio_state_array[1];
+	int fd;
+
+	struct aio_req aio_req_list[MAX_AIO_REQS];
+	struct aio_req *aio_req_free[MAX_AIO_REQS];
+	int nr_aio_req_free;
 };
 
 static const char * sd_strerror(int err)
@@ -362,7 +357,7 @@ static inline uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
         return hval;
 }
 
-static inline struct aio_req *alloc_aio_req(struct sd_aiostate *s,
+static inline struct aio_req *alloc_aio_req(struct bdrv_sd_state *s,
 					    struct sd_aiocb *acb)
 {
 	struct aio_req *aio_req;
@@ -378,7 +373,7 @@ static inline struct aio_req *alloc_aio_req(struct sd_aiostate *s,
 	return aio_req;
 }
 
-static inline int free_aio_req(struct sd_aiostate *s, struct aio_req *aio_req)
+static inline int free_aio_req(struct bdrv_sd_state *s, struct aio_req *aio_req)
 {
 	struct sd_aiocb *acb = aio_req->aiocb;
 	QLIST_REMOVE(aio_req, aioreq_siblings);
@@ -388,17 +383,17 @@ static inline int free_aio_req(struct sd_aiostate *s, struct aio_req *aio_req)
 	return !QLIST_EMPTY(&acb->aioreq_head);
 }
 
-static inline int nr_outstanding_aio_req(struct sd_aiostate *s)
+static inline int nr_outstanding_aio_req(struct bdrv_sd_state *s)
 {
 	return MAX_AIO_REQS - s->nr_aio_req_free;
 }
 
-static inline int get_id_from_req(struct sd_aiostate *s, struct aio_req *aio_req)
+static inline int get_id_from_req(struct bdrv_sd_state *s, struct aio_req *aio_req)
 {
 	return aio_req - s->aio_req_list;
 }
 
-static inline struct aio_req *get_req_from_id(struct sd_aiostate *s, int id)
+static inline struct aio_req *get_req_from_id(struct bdrv_sd_state *s, int id)
 {
 	return s->aio_req_list + id;
 }
@@ -644,7 +639,7 @@ static void aio_read_response(void *opaque)
 {
 	struct sd_obj_req hdr;
 	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
-	struct sd_aiostate *s = (struct sd_aiostate *)opaque;
+	struct bdrv_sd_state *s = (struct bdrv_sd_state *)opaque;
 	int fd = s->fd;
 	int ret;
 	struct aio_req *aio_req;
@@ -761,7 +756,7 @@ new_node_list:
 
 static int aio_flush_request(void *opaque)
 {
-	return nr_outstanding_aio_req((struct sd_aiostate *)opaque);
+	return nr_outstanding_aio_req((struct bdrv_sd_state *)opaque);
 }
 
 static int set_nonblocking(int fd)
@@ -794,9 +789,6 @@ static int get_sheep_fd(struct bdrv_sd_state *s)
 {
 	int ret, fd;
 
-	if (s->aio_state_array[0].fd != -1)
-		return s->aio_state_array[0].fd;
-
 	fd = connect_to_vost();
 	if (fd < 0) {
 		eprintf("%m\n");
@@ -818,8 +810,8 @@ static int get_sheep_fd(struct bdrv_sd_state *s)
 	}
 
 	qemu_aio_set_fd_handler(fd, aio_read_response, NULL, aio_flush_request,
-				NULL, &s->aio_state_array[0]);
-	s->aio_state_array[0].fd = fd;
+				NULL, s);
+	s->fd = fd;
 
 	return fd;
 }
@@ -898,7 +890,6 @@ static int add_aio_request(struct bdrv_sd_state *s, struct sd_aiocb *acb,
 {
 	int nr_copies = s->inode.nr_copies;
 	struct sd_obj_req hdr;
-	int fd;
 	unsigned int wlen;
 	int ret;
 	struct aio_req *aio_req;
@@ -929,22 +920,17 @@ static int add_aio_request(struct bdrv_sd_state *s, struct sd_aiocb *acb,
 	hdr.data_length = datalen;
 	hdr.offset = offset;
 
-	fd = get_sheep_fd(s);
-	if (fd < 0)
-		return -EIO;
-
-	struct sd_aiostate *aio_state = &s->aio_state_array[0];
-	aio_req = alloc_aio_req(aio_state, acb);
+	aio_req = alloc_aio_req(s, acb);
 	if (!aio_req) {
 		eprintf("too many requests\n");
 		return -ENOMEM;
 	}
 	aio_req->iov_offset = iov_offset;
-	hdr.id = get_id_from_req(aio_state, aio_req);
+	hdr.id = get_id_from_req(s, aio_req);
 
-	ret = send_req(fd, (struct sd_req *)&hdr, data, &wlen);
+	ret = send_req(s->fd, (struct sd_req *)&hdr, data, &wlen);
 	if (ret) {
-		free_aio_req(aio_state, aio_req);
+		free_aio_req(s, aio_req);
 		return -EIO;
 	}
 
@@ -1016,7 +1002,7 @@ static uint64_t get_vmstate_oid(uint64_t oid, uint32_t vdi_index)
 /* TODO: error cleanups */
 static int sd_open(BlockDriverState *bs, const char *filename, int flags)
 {
-	int ret, i, j;
+	int ret, i;
 	uint64_t oid = 0;
 	struct bdrv_sd_state *s = bs->opaque;
 	char vdi[256];
@@ -1030,16 +1016,14 @@ static int sd_open(BlockDriverState *bs, const char *filename, int flags)
 		return -1;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(s->aio_state_array); i++) {
-		struct sd_aiostate *aio_state = &s->aio_state_array[i];
-		for (j = 0; j < MAX_AIO_REQS; j++) {
-			aio_state->aio_req_free[j] = &aio_state->aio_req_list[j];
-			aio_state->aio_req_list[j].aiocb = NULL;
-		}
-		aio_state->s = s;
-		aio_state->fd = -1;
-		aio_state->nr_aio_req_free = MAX_AIO_REQS;
+	for (i = 0; i < MAX_AIO_REQS; i++) {
+		s->aio_req_free[i] = &s->aio_req_list[i];
+		s->aio_req_list[i].aiocb = NULL;
 	}
+	s->fd = get_sheep_fd(s);
+	if (s->fd < 0)
+		return -1;
+	s->nr_aio_req_free = MAX_AIO_REQS;
 
 	if (strstart(filename, "sheepdog:", NULL))
 		for_snapshot = 1;
@@ -1170,6 +1154,7 @@ static void sd_close(BlockDriverState *bs)
 {
 	struct bdrv_sd_state *s = bs->opaque;
 
+	close(s->fd);
 	free(s->name);
 }
 
-- 
1.5.6.5




More information about the sheepdog mailing list