On 2023/7/21 19:57, Eugenio Perez Martin wrote:
> On Wed, Jul 19, 2023 at 9:48 AM Hawkins Jiawei <[email protected]> wrote:
>>
>> This patch introduces vhost_vdpa_net_load_single_vlan()
>> and vhost_vdpa_net_load_vlan() to restore the vlan
>> filtering state at device's startup.
>>
>> Co-developed-by: Eugenio Pérez <[email protected]>
>> Signed-off-by: Eugenio Pérez <[email protected]>
>> Signed-off-by: Hawkins Jiawei <[email protected]>
>> ---
>> net/vhost-vdpa.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 49 insertions(+)
>>
>> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
>> index 9795306742..0787dd933b 100644
>> --- a/net/vhost-vdpa.c
>> +++ b/net/vhost-vdpa.c
>> @@ -965,6 +965,51 @@ static int vhost_vdpa_net_load_rx(VhostVDPAState *s,
>> return 0;
>> }
>>
>> +static int vhost_vdpa_net_load_single_vlan(VhostVDPAState *s,
>> + const VirtIONet *n,
>> + uint16_t vid)
>> +{
>> + const struct iovec data = {
>> + .iov_base = &vid,
>> + .iov_len = sizeof(vid),
>> + };
>> + ssize_t dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_VLAN,
>> + VIRTIO_NET_CTRL_VLAN_ADD,
>> + &data, 1);
>> + if (unlikely(dev_written < 0)) {
>> + return dev_written;
>> + }
>> + if (unlikely(*s->status != VIRTIO_NET_OK)) {
>> + return -EIO;
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +static int vhost_vdpa_net_load_vlan(VhostVDPAState *s,
>> + const VirtIONet *n)
>> +{
>> + int r;
>> +
>> + if (!virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_CTRL_VLAN)) {
>> + return 0;
>> + }
>> +
>> + for (int i = 0; i < MAX_VLAN >> 5; i++) {
>> + for (int j = 0; n->vlans[i] && j <= 0x1f; j++) {
>> + if (n->vlans[i] & (1U << j)) {
>> + r = vhost_vdpa_net_load_single_vlan(s, n, (i << 5) + j);
>> + if (unlikely(r != 0)) {
>> + return r;
>> + }
>> + }
>> + }
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +
>
> Nit: I'm not sure if it was here originally, but there is an extra newline
> here.
Hi Eugenio,
It was not here originally, it was introduced mistakenly during the
refactoring process.
I will fix this in the v2 version.
Thanks!
>
>> static int vhost_vdpa_net_load(NetClientState *nc)
>> {
>> VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
>> @@ -995,6 +1040,10 @@ static int vhost_vdpa_net_load(NetClientState *nc)
>> if (unlikely(r)) {
>> return r;
>> }
>> + r = vhost_vdpa_net_load_vlan(s, n);
>> + if (unlikely(r)) {
>> + return r;
>> + }
>>
>> return 0;
>> }
>> --
>> 2.25.1
>>
>