[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 19/52] vhost-vdpa: stick to -errno error return convention
|
From: |
Michael S. Tsirkin |
|
Subject: |
[PULL 19/52] vhost-vdpa: stick to -errno error return convention |
|
Date: |
Thu, 6 Jan 2022 08:17:06 -0500 |
From: Roman Kagan <rvkagan@yandex-team.ru>
Almost all VhostOps methods in vdpa_ops follow the convention of
returning negated errno on error.
Adjust the few that don't. To that end, rework vhost_vdpa_add_status to
check if setting of the requested status bits has succeeded and return
the respective error code it hasn't, and propagate the error codes
wherever it's appropriate.
Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
Message-Id: <20211111153354.18807-8-rvkagan@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/vhost-vdpa.c | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 0a4a83713c..ac0cb575fb 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -292,18 +292,34 @@ static int vhost_vdpa_call(struct vhost_dev *dev,
unsigned long int request,
return ret < 0 ? -errno : ret;
}
-static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)
+static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)
{
uint8_t s;
+ int ret;
trace_vhost_vdpa_add_status(dev, status);
- if (vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s)) {
- return;
+ ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s);
+ if (ret < 0) {
+ return ret;
}
s |= status;
- vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s);
+ ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s);
+ if (ret < 0) {
+ return ret;
+ }
+
+ ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s);
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (!(s & status)) {
+ return -EIO;
+ }
+
+ return 0;
}
static void vhost_vdpa_get_iova_range(struct vhost_vdpa *v)
@@ -484,7 +500,7 @@ static int vhost_vdpa_set_mem_table(struct vhost_dev *dev,
}
}
if (mem->padding) {
- return -1;
+ return -EINVAL;
}
return 0;
@@ -501,14 +517,11 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,
trace_vhost_vdpa_set_features(dev, features);
ret = vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features);
- uint8_t status = 0;
if (ret) {
return ret;
}
- vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
- vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
- return !(status & VIRTIO_CONFIG_S_FEATURES_OK);
+ return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
}
static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev)
@@ -650,12 +663,8 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev,
bool started)
}
if (started) {
- uint8_t status = 0;
memory_listener_register(&v->listener, &address_space_memory);
- vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
- vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
-
- return !(status & VIRTIO_CONFIG_S_DRIVER_OK);
+ return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
} else {
vhost_vdpa_reset_device(dev);
vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
--
MST
- [PULL 09/52] vhost: add support for configure interrupt, (continued)
- [PULL 09/52] vhost: add support for configure interrupt, Michael S. Tsirkin, 2022/01/06
- [PULL 12/52] virtio-pci: add support for configure interrupt, Michael S. Tsirkin, 2022/01/06
- [PULL 08/52] virtio: add support for configure interrupt, Michael S. Tsirkin, 2022/01/06
- [PULL 10/52] virtio-net: add support for configure interrupt, Michael S. Tsirkin, 2022/01/06
- [PULL 11/52] virtio-mmio: add support for configure interrupt, Michael S. Tsirkin, 2022/01/06
- [PULL 13/52] trace-events,pci: unify trace events format, Michael S. Tsirkin, 2022/01/06
- [PULL 14/52] vhost-user-blk: reconnect on any error during realize, Michael S. Tsirkin, 2022/01/06
- [PULL 16/52] chardev/char-socket: tcp_chr_sync_read: don't clobber errno, Michael S. Tsirkin, 2022/01/06
- [PULL 15/52] chardev/char-socket: tcp_chr_recv: don't clobber errno, Michael S. Tsirkin, 2022/01/06
- [PULL 17/52] vhost-backend: avoid overflow on memslots_limit, Michael S. Tsirkin, 2022/01/06
- [PULL 19/52] vhost-vdpa: stick to -errno error return convention,
Michael S. Tsirkin <=
- [PULL 20/52] vhost-user: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/06
- [PULL 22/52] vhost-user-blk: propagate error return from generic vhost, Michael S. Tsirkin, 2022/01/06
- [PULL 18/52] vhost-backend: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/06
- [PULL 23/52] pci: Export the pci_intx() function, Michael S. Tsirkin, 2022/01/06
- [PULL 25/52] smbios: Rename SMBIOS_ENTRY_POINT_* enums, Michael S. Tsirkin, 2022/01/06
- [PULL 21/52] vhost: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/06
- [PULL 26/52] hw/smbios: Use qapi for SmbiosEntryPointType, Michael S. Tsirkin, 2022/01/06
- [PULL 37/52] virtio: signal after wrapping packed used_idx, Michael S. Tsirkin, 2022/01/06
- [PULL 36/52] virtio-mem: Support "prealloc=on" option, Michael S. Tsirkin, 2022/01/06
- [PULL 28/52] hw/vhost-user-blk: turn on VIRTIO_BLK_F_SIZE_MAX feature for virtio blk device, Michael S. Tsirkin, 2022/01/06