vmd(8): clean up struct ioinfo.
authordv <dv@openbsd.org>
Wed, 6 Sep 2023 19:26:39 +0000 (19:26 +0000)
committerdv <dv@openbsd.org>
Wed, 6 Sep 2023 19:26:39 +0000 (19:26 +0000)
In prep for fixing some vioblk device issues, simplify the ioinfo
struct by dropping members that aren't needed.

ok mlarkin@

usr.sbin/vmd/vioblk.c
usr.sbin/vmd/vioscsi.c
usr.sbin/vmd/virtio.h

index ef38e9e..24d74b8 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vioblk.c,v 1.5 2023/09/01 19:42:26 dv Exp $   */
+/*     $OpenBSD: vioblk.c,v 1.6 2023/09/06 19:26:39 dv Exp $   */
 
 /*
  * Copyright (c) 2023 Dave Voutila <dv@openbsd.org>
@@ -305,7 +305,6 @@ vioblk_start_read(struct vioblk_dev *dev, off_t sector, size_t sz)
                goto nomem;
        info->len = sz;
        info->offset = sector * VIRTIO_BLK_SECTOR_SIZE;
-       info->file = &dev->file;
        return info;
 
 nomem:
@@ -316,17 +315,15 @@ nomem:
 
 
 static const uint8_t *
-vioblk_finish_read(struct ioinfo *info)
+vioblk_finish_read(struct vioblk_dev *dev, struct ioinfo *info)
 {
-       struct virtio_backing *file;
+       struct virtio_backing *file = &dev->file;
 
-       file = info->file;
        if (file == NULL || file->pread == NULL) {
                log_warnx("%s: XXX null?!", __func__);
                return NULL;
        }
        if (file->pread(file->p, info->buf, info->len, info->offset) != info->len) {
-               info->error = errno;
                log_warn("vioblk read error");
                return NULL;
        }
@@ -355,7 +352,6 @@ vioblk_start_write(struct vioblk_dev *dev, off_t sector,
                goto nomem;
        info->len = len;
        info->offset = sector * VIRTIO_BLK_SECTOR_SIZE;
-       info->file = &dev->file;
 
        if (read_mem(addr, info->buf, info->len)) {
                vioblk_free_info(info);
@@ -371,11 +367,10 @@ nomem:
 }
 
 static int
-vioblk_finish_write(struct ioinfo *info)
+vioblk_finish_write(struct vioblk_dev *dev, struct ioinfo *info)
 {
-       struct virtio_backing *file;
+       struct virtio_backing *file = &dev->file;
 
-       file = info->file;
        if (file->pwrite(file->p, info->buf, info->len, info->offset) != info->len) {
                log_warn("vioblk write error");
                return EIO;
@@ -479,7 +474,7 @@ vioblk_notifyq(struct vioblk_dev *dev)
                                }
 
                                /* read the data, use current data descriptor */
-                               secdata = vioblk_finish_read(info);
+                               secdata = vioblk_finish_read(dev, info);
                                if (secdata == NULL) {
                                        vioblk_free_info(info);
                                        log_warnx("vioblk: block read error, "
@@ -557,7 +552,7 @@ vioblk_notifyq(struct vioblk_dev *dev)
                                        goto out;
                                }
 
-                               if (vioblk_finish_write(info)) {
+                               if (vioblk_finish_write(dev, info)) {
                                        log_warnx("wr vioblk: disk write "
                                            "error");
                                        vioblk_free_info(info);
index 48d65fc..3fb3d4e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vioscsi.c,v 1.23 2023/04/01 06:39:03 jsg Exp $  */
+/*     $OpenBSD: vioscsi.c,v 1.24 2023/09/06 19:26:39 dv Exp $  */
 
 /*
  * Copyright (c) 2017 Carlos Cardenas <ccardenas@openbsd.org>
@@ -206,7 +206,6 @@ vioscsi_start_read(struct vioscsi_dev *dev, off_t block, size_t n_blocks)
                goto nomem;
        info->len = n_blocks * VIOSCSI_BLOCK_SIZE_CDROM;
        info->offset = block * VIOSCSI_BLOCK_SIZE_CDROM;
-       info->file = &dev->file;
 
        return info;
 
@@ -217,13 +216,11 @@ nomem:
 }
 
 static const uint8_t *
-vioscsi_finish_read(struct ioinfo *info)
+vioscsi_finish_read(struct vioscsi_dev *dev, struct ioinfo *info)
 {
-       struct virtio_backing *f;
+       struct virtio_backing *f = &dev->file;
 
-       f = info->file;
        if (f->pread(f->p, info->buf, info->len, info->offset) != info->len) {
-               info->error = errno;
                log_warn("vioscsi read error");
                return NULL;
        }
@@ -928,7 +925,7 @@ vioscsi_handle_read_6(struct vioscsi_dev *dev,
        }
 
        /* read block */
-       read_buf = vioscsi_finish_read(info);
+       read_buf = vioscsi_finish_read(dev, info);
 
        if (read_buf == NULL) {
                log_warnx("%s: error reading position %ud",
@@ -1057,7 +1054,7 @@ vioscsi_handle_read_10(struct vioscsi_dev *dev,
        }
 
        /* read block */
-       read_buf = vioscsi_finish_read(info);
+       read_buf = vioscsi_finish_read(dev, info);
 
        if (read_buf == NULL) {
                log_warnx("%s: error reading position %ud", __func__, read_lba);
index 24fd009..29fda47 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: virtio.h,v 1.46 2023/07/13 18:31:59 dv Exp $  */
+/*     $OpenBSD: virtio.h,v 1.47 2023/09/06 19:26:39 dv Exp $  */
 
 /*
  * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@@ -319,11 +319,9 @@ struct vmmci_dev {
 };
 
 struct ioinfo {
-       struct virtio_backing *file;
        uint8_t *buf;
        ssize_t len;
        off_t offset;
-       int error;
 };
 
 /* virtio.c */