[Sheepdog] [PATCH 5/8] sheepdog: handle request send failures properly
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Tue Apr 27 08:33:51 CEST 2010
When failed to send requests or receive responses, we should return -EIO
rather than `exit(1)';
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
block/sheepdog.c | 92 +++++++++++++-----------------------------------------
1 files changed, 22 insertions(+), 70 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 2047788..410c8b2 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -661,7 +661,7 @@ static void aio_read_response(void *opaque)
ret = do_read(fd, (void *)rsp, sizeof(*rsp));
if (ret) {
eprintf("failed to get the header, %m\n");
- goto new_node_list;
+ return;
}
aio_req = get_req_from_id(s, rsp->id);
@@ -680,62 +680,19 @@ static void aio_read_response(void *opaque)
aio_req->iov_offset);
if (ret) {
eprintf("failed to get the data, %m\n");
- goto new_node_list;
+ return;
}
break;
}
- if (rsp->result != SD_RES_SUCCESS)
+ if (rsp->result != SD_RES_SUCCESS) {
+ acb->ret = -EIO;
eprintf("%s\n", sd_strerror(rsp->result));
-
- switch (rsp->result) {
- case SD_RES_SUCCESS:
- break;
- /*
- * we simply try a new node list but we could do
- * better
- */
- case SD_RES_UNKNOWN:
- case SD_RES_NO_OBJ:
- case SD_RES_EIO:
- case SD_RES_OLD_NODE_VER:
- case SD_RES_NEW_NODE_VER:
- case SD_RES_INVALID_PARMS:
- case SD_RES_SYSTEM_ERROR:
- case SD_RES_DIFFERENT_EPOCH:
- case SD_RES_DIR_READ:
- case SD_RES_DIR_WRITE:
- goto new_node_list;
- break;
- /* we should not get the followings */
- case SD_RES_VDI_EXIST:
- case SD_RES_VDI_LOCKED:
- case SD_RES_NO_SUPER_OBJ:
- case SD_RES_NO_VDI:
- case SD_RES_NO_BASE_VDI:
- case SD_RES_VDI_READ:
- case SD_RES_VDI_WRITE:
- case SD_RES_BASE_VDI_READ:
- case SD_RES_BASE_VDI_WRITE:
- case SD_RES_NO_TAG:
- case SD_RES_STARTUP:
- case SD_RES_NO_EPOCH:
- case SD_RES_VDI_NOT_LOCKED:
- case SD_RES_SHUTDOWN:
- default:
- eprintf("protocol error %d\n", rsp->result);
}
rest = free_aio_req(s, aio_req);
if (!rest)
acb->aio_done_func(acb);
-
- return; /* TODO: update node list and resend request */
-new_node_list:
- eprintf("\n");
- exit(1);
-
- return;
}
static int aio_flush_request(void *opaque)
@@ -1236,10 +1193,6 @@ static inline int nr_chunks(struct sd_aiocb *acb)
(acb->sector_num * 512 / CHUNK_SIZE) + 1;
}
-/* FIXME */
-#define reset_all_aios(s) \
- { eprintf(""); exit(1); }
-
static void sd_write_done(struct sd_aiocb *acb)
{
int ret;
@@ -1253,18 +1206,17 @@ static void sd_write_done(struct sd_aiocb *acb)
ret = add_aio_request(s, acb, s->inode.oid, &iov, 1,
sizeof(s->inode),
0, 0, 0, 0, 1, 0);
- if (ret)
- goto new_node_list;
+ if (ret) {
+ acb->ret = -EIO;
+ goto out;
+ }
acb->aio_done_func = sd_finish_aiocb;
acb->aiocb_type = AIOCB_WRITE_UDATA;
return;
}
-
+out:
sd_finish_aiocb(acb);
- return;
-new_node_list:
- reset_all_aios(s);
}
static int sd_create_branch(struct bdrv_sd_state *s)
@@ -1307,7 +1259,7 @@ out:
static void sd_write_bh_cb(void *p)
{
struct sd_aiocb *acb = p;
- int i, ret;
+ int i, ret = 0;
unsigned long len, done = 0, total = acb->nb_sectors * 512;
unsigned long idx = acb->sector_num * 512 / CHUNK_SIZE;
uint64_t oid;
@@ -1360,9 +1312,9 @@ static void sd_write_bh_cb(void *p)
ret = add_aio_request(s, acb, oid, acb->qiov->iov, acb->qiov->niov,
len, offset, flags, old_oid, create, 1, done);
if (ret < 0) {
- eprintf("may be add_aio_request is faled\n");
+ eprintf("add_aio_request is faled\n");
ret = -EIO;
- goto new_node_list;
+ goto abort;
}
done:
@@ -1372,13 +1324,11 @@ static void sd_write_bh_cb(void *p)
i++;
}
- return;
abort:
acb->ret = ret;
- sd_finish_aiocb(acb);
- return;
-new_node_list:
- reset_all_aios(s);
+
+ if (QLIST_EMPTY(&acb->aioreq_head))
+ sd_finish_aiocb(acb);
}
static BlockDriverAIOCB *sd_aio_writev(BlockDriverState *bs,
@@ -1416,8 +1366,10 @@ static void sd_read_done(struct sd_aiocb *acb)
if (oid) {
ret = add_aio_request(s, acb, oid, NULL, 0, len, offset,
0, 0, 0, 0, done);
- if (ret)
- goto new_node_list;
+ if (ret) {
+ acb->ret = -EIO;
+ goto out;
+ }
}
idx++;
@@ -1425,9 +1377,9 @@ static void sd_read_done(struct sd_aiocb *acb)
done += len;
i++;
}
- return;
-new_node_list:
- reset_all_aios(s);
+out:
+ if (QLIST_EMPTY(&acb->aioreq_head))
+ sd_finish_aiocb(acb);
}
static void sd_readv_bh_cb(void *p)
--
1.5.6.5
More information about the sheepdog
mailing list