Commit cb38fa23 authored by Rusty Russell's avatar Rusty Russell

virtio: de-structify virtio_block status byte

Ron Minnich points out that a struct containing a char is not always
sizeof(char); simplest to remove the structure to avoid confusion.

Cc: "ron minnich" <rminnich@gmail.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 81473132
...@@ -1398,7 +1398,7 @@ static bool service_io(struct device *dev) ...@@ -1398,7 +1398,7 @@ static bool service_io(struct device *dev)
struct vblk_info *vblk = dev->priv; struct vblk_info *vblk = dev->priv;
unsigned int head, out_num, in_num, wlen; unsigned int head, out_num, in_num, wlen;
int ret; int ret;
struct virtio_blk_inhdr *in; u8 *in;
struct virtio_blk_outhdr *out; struct virtio_blk_outhdr *out;
struct iovec iov[dev->vq->vring.num]; struct iovec iov[dev->vq->vring.num];
off64_t off; off64_t off;
...@@ -1416,7 +1416,7 @@ static bool service_io(struct device *dev) ...@@ -1416,7 +1416,7 @@ static bool service_io(struct device *dev)
head, out_num, in_num); head, out_num, in_num);
out = convert(&iov[0], struct virtio_blk_outhdr); out = convert(&iov[0], struct virtio_blk_outhdr);
in = convert(&iov[out_num+in_num-1], struct virtio_blk_inhdr); in = convert(&iov[out_num+in_num-1], u8);
off = out->sector * 512; off = out->sector * 512;
/* The block device implements "barriers", where the Guest indicates /* The block device implements "barriers", where the Guest indicates
...@@ -1430,7 +1430,7 @@ static bool service_io(struct device *dev) ...@@ -1430,7 +1430,7 @@ static bool service_io(struct device *dev)
* It'd be nice if we supported eject, for example, but we don't. */ * It'd be nice if we supported eject, for example, but we don't. */
if (out->type & VIRTIO_BLK_T_SCSI_CMD) { if (out->type & VIRTIO_BLK_T_SCSI_CMD) {
fprintf(stderr, "Scsi commands unsupported\n"); fprintf(stderr, "Scsi commands unsupported\n");
in->status = VIRTIO_BLK_S_UNSUPP; *in = VIRTIO_BLK_S_UNSUPP;
wlen = sizeof(*in); wlen = sizeof(*in);
} else if (out->type & VIRTIO_BLK_T_OUT) { } else if (out->type & VIRTIO_BLK_T_OUT) {
/* Write */ /* Write */
...@@ -1453,7 +1453,7 @@ static bool service_io(struct device *dev) ...@@ -1453,7 +1453,7 @@ static bool service_io(struct device *dev)
errx(1, "Write past end %llu+%u", off, ret); errx(1, "Write past end %llu+%u", off, ret);
} }
wlen = sizeof(*in); wlen = sizeof(*in);
in->status = (ret >= 0 ? VIRTIO_BLK_S_OK : VIRTIO_BLK_S_IOERR); *in = (ret >= 0 ? VIRTIO_BLK_S_OK : VIRTIO_BLK_S_IOERR);
} else { } else {
/* Read */ /* Read */
...@@ -1466,10 +1466,10 @@ static bool service_io(struct device *dev) ...@@ -1466,10 +1466,10 @@ static bool service_io(struct device *dev)
verbose("READ from sector %llu: %i\n", out->sector, ret); verbose("READ from sector %llu: %i\n", out->sector, ret);
if (ret >= 0) { if (ret >= 0) {
wlen = sizeof(*in) + ret; wlen = sizeof(*in) + ret;
in->status = VIRTIO_BLK_S_OK; *in = VIRTIO_BLK_S_OK;
} else { } else {
wlen = sizeof(*in); wlen = sizeof(*in);
in->status = VIRTIO_BLK_S_IOERR; *in = VIRTIO_BLK_S_IOERR;
} }
} }
......
...@@ -35,7 +35,7 @@ struct virtblk_req ...@@ -35,7 +35,7 @@ struct virtblk_req
struct list_head list; struct list_head list;
struct request *req; struct request *req;
struct virtio_blk_outhdr out_hdr; struct virtio_blk_outhdr out_hdr;
struct virtio_blk_inhdr in_hdr; u8 status;
}; };
static void blk_done(struct virtqueue *vq) static void blk_done(struct virtqueue *vq)
...@@ -48,7 +48,7 @@ static void blk_done(struct virtqueue *vq) ...@@ -48,7 +48,7 @@ static void blk_done(struct virtqueue *vq)
spin_lock_irqsave(&vblk->lock, flags); spin_lock_irqsave(&vblk->lock, flags);
while ((vbr = vblk->vq->vq_ops->get_buf(vblk->vq, &len)) != NULL) { while ((vbr = vblk->vq->vq_ops->get_buf(vblk->vq, &len)) != NULL) {
int uptodate; int uptodate;
switch (vbr->in_hdr.status) { switch (vbr->status) {
case VIRTIO_BLK_S_OK: case VIRTIO_BLK_S_OK:
uptodate = 1; uptodate = 1;
break; break;
...@@ -101,7 +101,7 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk, ...@@ -101,7 +101,7 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
sg_init_table(vblk->sg, VIRTIO_MAX_SG); sg_init_table(vblk->sg, VIRTIO_MAX_SG);
sg_set_buf(&vblk->sg[0], &vbr->out_hdr, sizeof(vbr->out_hdr)); sg_set_buf(&vblk->sg[0], &vbr->out_hdr, sizeof(vbr->out_hdr));
num = blk_rq_map_sg(q, vbr->req, vblk->sg+1); num = blk_rq_map_sg(q, vbr->req, vblk->sg+1);
sg_set_buf(&vblk->sg[num+1], &vbr->in_hdr, sizeof(vbr->in_hdr)); sg_set_buf(&vblk->sg[num+1], &vbr->status, sizeof(vbr->status));
if (rq_data_dir(vbr->req) == WRITE) { if (rq_data_dir(vbr->req) == WRITE) {
vbr->out_hdr.type |= VIRTIO_BLK_T_OUT; vbr->out_hdr.type |= VIRTIO_BLK_T_OUT;
......
...@@ -41,13 +41,8 @@ struct virtio_blk_outhdr ...@@ -41,13 +41,8 @@ struct virtio_blk_outhdr
__u64 sector; __u64 sector;
}; };
/* And this is the final byte of the write scatter-gather list. */
#define VIRTIO_BLK_S_OK 0 #define VIRTIO_BLK_S_OK 0
#define VIRTIO_BLK_S_IOERR 1 #define VIRTIO_BLK_S_IOERR 1
#define VIRTIO_BLK_S_UNSUPP 2 #define VIRTIO_BLK_S_UNSUPP 2
/* This is the first element of the write scatter-gather list */
struct virtio_blk_inhdr
{
unsigned char status;
};
#endif /* _LINUX_VIRTIO_BLK_H */ #endif /* _LINUX_VIRTIO_BLK_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment