[Sheepdog] [PATCH] sheepdog: remove redundant member `write' from struct sd_aiocb
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Thu Apr 29 17:54:04 CEST 2010
We can know the type of request from `aiocb_type', so we don't
need `write'.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
block/sheepdog.c | 39 +++++++++++++++++++++------------------
1 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index df20f09..780dc5e 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -229,7 +229,6 @@ struct sd_aiocb {
QEMUBH *bh;
void (*aio_done_func)(struct sd_aiocb *);
- int write;
int canceled;
QLIST_HEAD(aioreq_head, aio_req) aioreq_head;
@@ -418,8 +417,7 @@ static AIOPool sd_aio_pool = {
.cancel = sd_aio_cancel,
};
-static struct sd_aiocb *sd_aio_setup(BlockDriverState *bs,
- int write, QEMUIOVector *qiov,
+static struct sd_aiocb *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov,
int64_t sector_num, int nb_sectors,
BlockDriverCompletionFunc *cb,
void *opaque)
@@ -434,7 +432,6 @@ static struct sd_aiocb *sd_aio_setup(BlockDriverState *bs,
acb->nb_sectors = nb_sectors;
acb->aio_done_func = NULL;
- acb->write = write;
acb->canceled = 0;
acb->bh = NULL;
acb->ret = 0;
@@ -445,13 +442,13 @@ static struct sd_aiocb *sd_aio_setup(BlockDriverState *bs,
static int sd_schedule_bh(QEMUBHFunc *cb, struct sd_aiocb *acb)
{
if (acb->bh) {
- eprintf("bug: %d %d\n", acb->write, acb->aiocb_type);
+ eprintf("bug: %d %d\n", acb->aiocb_type, acb->aiocb_type);
return -EIO;
}
acb->bh = qemu_bh_new(cb, acb);
if (!acb->bh) {
- eprintf("oom: %d %d\n", acb->write, acb->aiocb_type);
+ eprintf("oom: %d %d\n", acb->aiocb_type, acb->aiocb_type);
return -EIO;
}
@@ -659,7 +656,8 @@ out:
}
static int add_aio_request(struct bdrv_sd_state *s, struct aio_req *aio_req,
- struct iovec *iov, int niov, int create, int write);
+ struct iovec *iov, int niov, int create,
+ enum aiocb_state aiocb_type);
static void send_pending_req(struct bdrv_sd_state *s, uint64_t oid, uint32_t id)
{
@@ -675,7 +673,7 @@ static void send_pending_req(struct bdrv_sd_state *s, uint64_t oid, uint32_t id)
acb = aio_req->aiocb;
ret = add_aio_request(s, aio_req, acb->qiov->iov,
- acb->qiov->niov, 0, 1);
+ acb->qiov->niov, 0, acb->aiocb_type);
if (ret < 0) {
eprintf("add_aio_request is faled\n");
free_aio_req(s, aio_req);
@@ -871,7 +869,8 @@ out:
}
static int add_aio_request(struct bdrv_sd_state *s, struct aio_req *aio_req,
- struct iovec *iov, int niov, int create, int write)
+ struct iovec *iov, int niov, int create,
+ enum aiocb_state aiocb_type)
{
int nr_copies = s->inode.nr_copies;
struct sd_obj_req hdr;
@@ -888,7 +887,7 @@ static int add_aio_request(struct bdrv_sd_state *s, struct aio_req *aio_req,
memset(&hdr, 0, sizeof(hdr));
- if (!write) {
+ if (aiocb_type == AIOCB_READ_UDATA) {
wlen = 0;
hdr.opcode = SD_OP_READ_OBJ;
hdr.flags = flags;
@@ -1228,7 +1227,7 @@ static void sd_write_done(struct sd_aiocb *acb)
acb->ret = -EIO;
goto out;
}
- ret = add_aio_request(s, aio_req, &iov, 1, 0, 1);
+ ret = add_aio_request(s, aio_req, &iov, 1, 0, AIOCB_WRITE_UDATA);
if (ret) {
free_aio_req(s, aio_req);
acb->ret = -EIO;
@@ -1295,7 +1294,7 @@ static void sd_readv_writev_bh_cb(void *p)
qemu_bh_delete(acb->bh);
acb->bh = NULL;
- if (acb->write && !s->is_current) {
+ if (acb->aiocb_type == AIOCB_WRITE_UDATA && !s->is_current) {
ret = sd_create_branch(s);
if (ret) {
acb->ret = -EIO;
@@ -1313,11 +1312,12 @@ static void sd_readv_writev_bh_cb(void *p)
len = min_t(unsigned long, total - done, SD_DATA_OBJ_SIZE - offset);
if (!oid) {
- if (!acb->write)
+ if (acb->aiocb_type == AIOCB_READ_UDATA)
goto done;
create = 1;
- } else if (acb->write && !is_data_obj_writeable(inode, idx)) {
+ } else if (acb->aiocb_type == AIOCB_WRITE_UDATA
+ && !is_data_obj_writeable(inode, idx)) {
create = 1;
old_oid = oid;
flags = SD_FLAG_CMD_COW;
@@ -1344,13 +1344,16 @@ static void sd_readv_writev_bh_cb(void *p)
QLIST_FOREACH(areq, &s->pending_head, pending_siblings) {
if (get_id_from_req(s, areq) == get_id_from_req(s, aio_req))
continue;
- if (areq->oid == oid)
+ if (areq->oid == oid) {
+ aio_req->flags = 0;
+ aio_req->base_oid = 0;
goto done;
+ }
}
}
ret = add_aio_request(s, aio_req, acb->qiov->iov, acb->qiov->niov,
- create, acb->write);
+ create, acb->aiocb_type);
if (ret < 0) {
eprintf("add_aio_request is faled\n");
free_aio_req(s, aio_req);
@@ -1376,7 +1379,7 @@ static BlockDriverAIOCB *sd_aio_writev(BlockDriverState *bs,
{
struct sd_aiocb *acb;
- acb = sd_aio_setup(bs, 1, qiov, sector_num, nb_sectors, cb, opaque);
+ acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors, cb, opaque);
acb->aio_done_func = sd_write_done;
acb->aiocb_type = AIOCB_WRITE_UDATA;
@@ -1394,7 +1397,7 @@ static BlockDriverAIOCB *sd_aio_readv(BlockDriverState *bs,
struct sd_aiocb *acb;
int i;
- acb = sd_aio_setup(bs, 0, qiov, sector_num, nb_sectors, cb, opaque);
+ acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors, cb, opaque);
acb->aiocb_type = AIOCB_READ_UDATA;
acb->aio_done_func = sd_finish_aiocb;
--
1.5.6.5
More information about the sheepdog
mailing list