Updated host/vhost/mic_blk.c to use iov_iter interface.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Sun, 2 May 2021 04:12:21 +0000 (21:12 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Sun, 2 May 2021 04:12:21 +0000 (21:12 -0700)
See also:

  - https://github.com/torvalds/linux/commit/9725d4cef62229b4ec4c912e0db0761e7d400650

  - https://lwn.net/Articles/625077/

  - https://stackoverflow.com/questions/42744637/what-is-iter-iovec-iter-kvec-and-iter-bvec

  - https://github.com/torvalds/linux/commit/a528d35

host/vhost/mic_blk.c

index 1a94a46..1d763d6 100644 (file)
@@ -116,6 +116,7 @@ static void handle_io_work(struct work_struct *work)
        struct vhost_blk *blk;
        struct list_head single, *head, *node, *tmp;
        struct iovec *iov;
        struct vhost_blk *blk;
        struct list_head single, *head, *node, *tmp;
        struct iovec *iov;
+       struct iov_iter iter;
        uint8_t *aper_va;
        struct vring *vring;
        unsigned int num;
        uint8_t *aper_va;
        struct vring *vring;
        unsigned int num;
@@ -150,15 +151,17 @@ static void handle_io_work(struct work_struct *work)
                ret = vfs_fsync(vbio->file, 1);
 #endif
        } else if (vbio->type & VIRTIO_BLK_T_OUT) {
                ret = vfs_fsync(vbio->file, 1);
 #endif
        } else if (vbio->type & VIRTIO_BLK_T_OUT) {
-         for (iov = vbio->iov; iov < &vbio->iov[vbio->nvecs]; iov++) {
-               iov->iov_base = mic_addr_in_host(aper_va, iov->iov_base);
-         }
-               ret = vfs_writev(vbio->file, vbio->iov, vbio->nvecs, &pos);
+               for (iov = vbio->iov; iov < &vbio->iov[vbio->nvecs]; iov++) {
+                       iov->iov_base = mic_addr_in_host(aper_va, iov->iov_base);
+               }
+               iov_iter_init(&iter, WRITE, vbio->iov, vbio->nvecs, iov_length(vbio->iov, vbio->nvecs));
+               ret = vfs_iter_write(vbio->file, &iter, &pos, 0);
        } else {
        } else {
-         for (iov = vbio->iov; iov < &vbio->iov[vbio->nvecs]; iov++) {
-               iov->iov_base = mic_addr_in_host(aper_va, iov->iov_base);
-         }
-               ret = vfs_readv(vbio->file, vbio->iov, vbio->nvecs, &pos);
+               for (iov = vbio->iov; iov < &vbio->iov[vbio->nvecs]; iov++) {
+                       iov->iov_base = mic_addr_in_host(aper_va, iov->iov_base);
+               }
+               iov_iter_init(&iter, READ, vbio->iov, vbio->nvecs, iov_length(vbio->iov, vbio->nvecs));
+               ret = vfs_iter_read(vbio->file, &iter, &pos, 0);
        }
        status = (ret < 0) ? VIRTIO_BLK_S_IOERR : VIRTIO_BLK_S_OK;
        if (vbio->head != -1) {
        }
        status = (ret < 0) ? VIRTIO_BLK_S_IOERR : VIRTIO_BLK_S_OK;
        if (vbio->head != -1) {
@@ -475,12 +478,7 @@ static long vhost_blk_set_backend(struct vhost_blk *vblk)
        writel(DISK_SEG_MAX, &vb_shared->blk_config.seg_max);
        writel(MIC_SECTOR_SIZE, &vb_shared->blk_config.blk_size);
 
        writel(DISK_SEG_MAX, &vb_shared->blk_config.seg_max);
        writel(MIC_SECTOR_SIZE, &vb_shared->blk_config.blk_size);
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
-       ret = vfs_getattr(&vblk->virtblk_file->f_path, &stat);
-#else
-       ret = vfs_getattr(vblk->virtblk_file->f_path.mnt,
-                                         vblk->virtblk_file->f_path.dentry, &stat);
-#endif
+       ret = vfs_getattr(&vblk->virtblk_file->f_path, &stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
        if (ret < 0)
                goto _exit_;
 
        if (ret < 0)
                goto _exit_;