Message ID | abecff1ddd3020adacb398e0f553600d0b088205.1689748694.git.yin31149@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v3,1/8] vhost: Add argument to vhost_svq_poll() | expand |
On Wed, Jul 19, 2023 at 9:54 AM Hawkins Jiawei <yin31149@gmail.com> wrote: > > Considering that vhost_vdpa_net_load_rx_mode() is only called > within vhost_vdpa_net_load_rx() now, this patch refactors > vhost_vdpa_net_load_rx_mode() to include a check for the > device's ack, simplifying the code and improving its maintainability. > > Signed-off-by: Hawkins Jiawei <yin31149@gmail.com> Acked-by: Eugenio Pérez <eperezma@redhat.com> > --- > net/vhost-vdpa.c | 76 ++++++++++++++++++++---------------------------- > 1 file changed, 31 insertions(+), 45 deletions(-) > > diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c > index ae8f59adaa..fe0ba19724 100644 > --- a/net/vhost-vdpa.c > +++ b/net/vhost-vdpa.c > @@ -814,14 +814,24 @@ static int vhost_vdpa_net_load_rx_mode(VhostVDPAState *s, > .iov_base = &on, > .iov_len = sizeof(on), > }; > - return vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_RX, > - cmd, &data, 1); > + ssize_t dev_written; > + > + dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_RX, > + cmd, &data, 1); > + if (unlikely(dev_written < 0)) { > + return dev_written; > + } > + if (*s->status != VIRTIO_NET_OK) { > + return -EIO; > + } > + > + return 0; > } > > static int vhost_vdpa_net_load_rx(VhostVDPAState *s, > const VirtIONet *n) > { > - ssize_t dev_written; > + ssize_t r; > > if (!virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_CTRL_RX)) { > return 0; > @@ -846,13 +856,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, > * configuration only at live migration. > */ > if (!n->mac_table.uni_overflow && !n->promisc) { > - dev_written = vhost_vdpa_net_load_rx_mode(s, > - VIRTIO_NET_CTRL_RX_PROMISC, 0); > - if (unlikely(dev_written < 0)) { > - return dev_written; > - } > - if (*s->status != VIRTIO_NET_OK) { > - return -EIO; > + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_PROMISC, 0); > + if (unlikely(r < 0)) { > + return r; > } > } > > @@ -874,13 +880,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, > * configuration only at live migration. > */ > if (n->mac_table.multi_overflow || n->allmulti) { > - dev_written = vhost_vdpa_net_load_rx_mode(s, > - VIRTIO_NET_CTRL_RX_ALLMULTI, 1); > - if (unlikely(dev_written < 0)) { > - return dev_written; > - } > - if (*s->status != VIRTIO_NET_OK) { > - return -EIO; > + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_ALLMULTI, 1); > + if (unlikely(r < 0)) { > + return r; > } > } > > @@ -899,13 +901,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, > * configuration only at live migration. > */ > if (n->alluni) { > - dev_written = vhost_vdpa_net_load_rx_mode(s, > - VIRTIO_NET_CTRL_RX_ALLUNI, 1); > - if (dev_written < 0) { > - return dev_written; > - } > - if (*s->status != VIRTIO_NET_OK) { > - return -EIO; > + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_ALLUNI, 1); > + if (r < 0) { > + return r; > } > } > > @@ -920,13 +918,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, > * configuration only at live migration. > */ > if (n->nomulti) { > - dev_written = vhost_vdpa_net_load_rx_mode(s, > - VIRTIO_NET_CTRL_RX_NOMULTI, 1); > - if (dev_written < 0) { > - return dev_written; > - } > - if (*s->status != VIRTIO_NET_OK) { > - return -EIO; > + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_NOMULTI, 1); > + if (r < 0) { > + return r; > } > } > > @@ -941,13 +935,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, > * configuration only at live migration. > */ > if (n->nouni) { > - dev_written = vhost_vdpa_net_load_rx_mode(s, > - VIRTIO_NET_CTRL_RX_NOUNI, 1); > - if (dev_written < 0) { > - return dev_written; > - } > - if (*s->status != VIRTIO_NET_OK) { > - return -EIO; > + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_NOUNI, 1); > + if (r < 0) { > + return r; > } > } > > @@ -962,13 +952,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, > * configuration only at live migration. > */ > if (n->nobcast) { > - dev_written = vhost_vdpa_net_load_rx_mode(s, > - VIRTIO_NET_CTRL_RX_NOBCAST, 1); > - if (dev_written < 0) { > - return dev_written; > - } > - if (*s->status != VIRTIO_NET_OK) { > - return -EIO; > + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_NOBCAST, 1); > + if (r < 0) { > + return r; > } > } > > -- > 2.25.1 >
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index ae8f59adaa..fe0ba19724 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -814,14 +814,24 @@ static int vhost_vdpa_net_load_rx_mode(VhostVDPAState *s, .iov_base = &on, .iov_len = sizeof(on), }; - return vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_RX, - cmd, &data, 1); + ssize_t dev_written; + + dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_RX, + cmd, &data, 1); + if (unlikely(dev_written < 0)) { + return dev_written; + } + if (*s->status != VIRTIO_NET_OK) { + return -EIO; + } + + return 0; } static int vhost_vdpa_net_load_rx(VhostVDPAState *s, const VirtIONet *n) { - ssize_t dev_written; + ssize_t r; if (!virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_CTRL_RX)) { return 0; @@ -846,13 +856,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, * configuration only at live migration. */ if (!n->mac_table.uni_overflow && !n->promisc) { - dev_written = vhost_vdpa_net_load_rx_mode(s, - VIRTIO_NET_CTRL_RX_PROMISC, 0); - if (unlikely(dev_written < 0)) { - return dev_written; - } - if (*s->status != VIRTIO_NET_OK) { - return -EIO; + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_PROMISC, 0); + if (unlikely(r < 0)) { + return r; } } @@ -874,13 +880,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, * configuration only at live migration. */ if (n->mac_table.multi_overflow || n->allmulti) { - dev_written = vhost_vdpa_net_load_rx_mode(s, - VIRTIO_NET_CTRL_RX_ALLMULTI, 1); - if (unlikely(dev_written < 0)) { - return dev_written; - } - if (*s->status != VIRTIO_NET_OK) { - return -EIO; + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_ALLMULTI, 1); + if (unlikely(r < 0)) { + return r; } } @@ -899,13 +901,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, * configuration only at live migration. */ if (n->alluni) { - dev_written = vhost_vdpa_net_load_rx_mode(s, - VIRTIO_NET_CTRL_RX_ALLUNI, 1); - if (dev_written < 0) { - return dev_written; - } - if (*s->status != VIRTIO_NET_OK) { - return -EIO; + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_ALLUNI, 1); + if (r < 0) { + return r; } } @@ -920,13 +918,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, * configuration only at live migration. */ if (n->nomulti) { - dev_written = vhost_vdpa_net_load_rx_mode(s, - VIRTIO_NET_CTRL_RX_NOMULTI, 1); - if (dev_written < 0) { - return dev_written; - } - if (*s->status != VIRTIO_NET_OK) { - return -EIO; + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_NOMULTI, 1); + if (r < 0) { + return r; } } @@ -941,13 +935,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, * configuration only at live migration. */ if (n->nouni) { - dev_written = vhost_vdpa_net_load_rx_mode(s, - VIRTIO_NET_CTRL_RX_NOUNI, 1); - if (dev_written < 0) { - return dev_written; - } - if (*s->status != VIRTIO_NET_OK) { - return -EIO; + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_NOUNI, 1); + if (r < 0) { + return r; } } @@ -962,13 +952,9 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s, * configuration only at live migration. */ if (n->nobcast) { - dev_written = vhost_vdpa_net_load_rx_mode(s, - VIRTIO_NET_CTRL_RX_NOBCAST, 1); - if (dev_written < 0) { - return dev_written; - } - if (*s->status != VIRTIO_NET_OK) { - return -EIO; + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_NOBCAST, 1); + if (r < 0) { + return r; } }
Considering that vhost_vdpa_net_load_rx_mode() is only called within vhost_vdpa_net_load_rx() now, this patch refactors vhost_vdpa_net_load_rx_mode() to include a check for the device's ack, simplifying the code and improving its maintainability. Signed-off-by: Hawkins Jiawei <yin31149@gmail.com> --- net/vhost-vdpa.c | 76 ++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 45 deletions(-)