Skip to contentSkip to conversation

net: synchronize net_host_device_remove with host_net_remove_completion

PATCH Applied Paolo Bonzini 4 participants 9 messages Dec 23, 2014 – Feb 6, 2015 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: synchronize net_host_device_remove with host_net_remove_completion

Using net_host_check_device is unnecessary. qemu_del_net_client asserts for the non-peer case that it can only process NIC type NetClientStates, and that assertion is valid for the peered case as well, so move it and use the same check in net_host_device_remove. host_net_remove_completion is already checking the type.

---
 net/net.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/net.c +3 -3
index 7acc162..1da612f 100644
@@ -324,6 +324,8 @@ void qemu_del_net_client(NetClientState *nc)
     NetClientState *ncs[MAX_QUEUE_NUM];
     int queues, i;
 
+    assert(nc->info->type != NET_CLIENT_OPTIONS_KIND_NIC);
+
     /* If the NetClientState belongs to a multiqueue backend, we will change all
      * other NetClientStates also.
      */
@@ -355,8 +357,6 @@ void qemu_del_net_client(NetClientState *nc)
         return;
     }
 
-    assert(nc->info->type != NET_CLIENT_OPTIONS_KIND_NIC);
-
     for (i = 0; i < queues; i++) {
         qemu_cleanup_net_client(ncs[i]);
         qemu_free_net_client(ncs[i]);
@@ -992,7 +992,7 @@ void net_host_device_remove(Monitor *mon, const QDict *qdict)
                      device, vlan_id);
         return;
     }
-    if (!net_host_check_device(nc->model)) {
+    if (nc->info->type == NET_CLIENT_OPTIONS_KIND_NIC) {
         error_report("invalid host network device '%s'", device);
         return;
     }
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 10 lines · Paolo Bonzini
net/net.c +2 -0
@@ -324,6 +324,8 @@ void qemu_del_net_client(NetClientState *nc)
     NetClientState *ncs[MAX_QUEUE_NUM];
     int queues, i;
 
+    assert(nc->info->type != NET_CLIENT_OPTIONS_KIND_NIC);
+
     /* If the NetClientState belongs to a multiqueue backend, we will change all
      * other NetClientStates also.
      */

net/net.c void qemu_del_net_client(NetClientState *nc) · line 362

Quoted 8 lines
net/net.c +0 -2
@@ -355,8 +357,6 @@ void qemu_del_net_client(NetClientState *nc)
         return;
     }
 
-    assert(nc->info->type != NET_CLIENT_OPTIONS_KIND_NIC);
-
     for (i = 0; i < queues; i++) {
         qemu_cleanup_net_client(ncs[i]);
         qemu_free_net_client(ncs[i]);

The assert can be dropped completely since the code already has an equivalent assert:

queues = qemu_find_net_clients_except(nc->name, ncs,

                                        NET_CLIENT_OPTIONS_KIND_NIC,
                                        MAX_QUEUE_NUM);

assert(queues != 0); <-- fail if type == NET_CLIENT_OPTIONS_KIND_NIC

#2 lore raw
Quoted 23 lines · Stefan Hajnoczi
Quoted 10 lines · Paolo Bonzini
net/net.c +2 -0
@@ -324,6 +324,8 @@ void qemu_del_net_client(NetClientState *nc)
     NetClientState *ncs[MAX_QUEUE_NUM];
     int queues, i;
 
+    assert(nc->info->type != NET_CLIENT_OPTIONS_KIND_NIC);
+
     /* If the NetClientState belongs to a multiqueue backend, we will change all
      * other NetClientStates also.
      */

net/net.c void qemu_del_net_client(NetClientState *nc) · line 362

Quoted 8 lines
net/net.c +0 -2
@@ -355,8 +357,6 @@ void qemu_del_net_client(NetClientState *nc)
         return;
     }
 
-    assert(nc->info->type != NET_CLIENT_OPTIONS_KIND_NIC);
-
     for (i = 0; i < queues; i++) {
         qemu_cleanup_net_client(ncs[i]);
         qemu_free_net_client(ncs[i]);

The assert can be dropped completely since the code already has an equivalent assert:

Quoted 4 lines

queues = qemu_find_net_clients_except(nc->name, ncs,

                                        NET_CLIENT_OPTIONS_KIND_NIC,
                                        MAX_QUEUE_NUM);

assert(queues != 0); <-- fail if type == NET_CLIENT_OPTIONS_KIND_NIC

I left it on purpose for documentation, but I'll send v2 next week that removes it.

Paolo

#3 lore raw
Quoted 10 lines · Paolo Bonzini
Quoted 8 lines
Quoted 8 lines

The assert can be dropped completely since the code already has an equivalent assert:

queues = qemu_find_net_clients_except(nc->name, ncs,

                                        NET_CLIENT_OPTIONS_KIND_NIC,
                                        MAX_QUEUE_NUM);

assert(queues != 0); <-- fail if type == NET_CLIENT_OPTIONS_KIND_NIC

I left it on purpose for documentation, but I'll send v2 next week that removes it.

Actually it's not the same. If you have "-netdev user,id=e1000 -device e1000,netdev=e1000" you will be able to call qemu_del_net_client on the NIC, and it will _not_ fail if the assertion is removed.

Paolo

#4 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 8 lines · Paolo Bonzini
Quoted 8 lines
Quoted 8 lines

The assert can be dropped completely since the code already has an equivalent assert:

queues = qemu_find_net_clients_except(nc->name, ncs,

                                        NET_CLIENT_OPTIONS_KIND_NIC,
                                        MAX_QUEUE_NUM);

assert(queues != 0); <-- fail if type == NET_CLIENT_OPTIONS_KIND_NIC

Quoted 6 lines
Quoted 2 lines

I left it on purpose for documentation, but I'll send v2 next week that removes it.

Actually it's not the same. If you have "-netdev user,id=e1000 -device e1000,netdev=e1000" you will be able to call qemu_del_net_client on the NIC, and it will _not_ fail if the assertion is removed.

Ping?

Paolo

#5 lore raw
In reply to Paolo Bonzini
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Paolo Bonzini
Quoted 8 lines
Quoted 8 lines

The assert can be dropped completely since the code already has an equivalent assert:

queues = qemu_find_net_clients_except(nc->name, ncs,

                                        NET_CLIENT_OPTIONS_KIND_NIC,
                                        MAX_QUEUE_NUM);

assert(queues != 0); <-- fail if type == NET_CLIENT_OPTIONS_KIND_NIC

Quoted 6 lines
Quoted 2 lines

I left it on purpose for documentation, but I'll send v2 next week that removes it.

Actually it's not the same. If you have "-netdev user,id=e1000 -device e1000,netdev=e1000" you will be able to call qemu_del_net_client on the NIC, and it will _not_ fail if the assertion is removed.

I don't follow.

If you call qemu_del_net_client(e1000_nic) then qemu_find_net_clients_except(nc->name, ncs, NET_CLIENT_OPTIONS_KIND_NIC, MAX_QUEUE_NUM) returns 0. This causes the assert(queues != 0) to fail.

Can you explain the scenario?

Stefan

#6 lore raw
Quoted 17 lines · Stefan Hajnoczi
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Paolo Bonzini
Quoted 8 lines
Quoted 8 lines

The assert can be dropped completely since the code already has an equivalent assert:

queues = qemu_find_net_clients_except(nc->name, ncs,

                                        NET_CLIENT_OPTIONS_KIND_NIC,
                                        MAX_QUEUE_NUM);

assert(queues != 0); <-- fail if type == NET_CLIENT_OPTIONS_KIND_NIC

Quoted 6 lines
Quoted 2 lines

I left it on purpose for documentation, but I'll send v2 next week that removes it.

Actually it's not the same. If you have "-netdev user,id=e1000 -device e1000,netdev=e1000" you will be able to call qemu_del_net_client on the NIC, and it will _not_ fail if the assertion is removed.

Quoted 5 lines

I don't follow.

If you call qemu_del_net_client(e1000_nic) then qemu_find_net_clients_except(nc->name, ncs, NET_CLIENT_OPTIONS_KIND_NIC, MAX_QUEUE_NUM) returns 0. This causes the assert(queues != 0) to fail.

NICs and other clients are in separate namespaces. So if you do

-netdev user,id=e1000
-device e1000,netdev=e1000,id=e1000

you have two NetClients named "e1000". If you call (by mistake) qemu_del_net_client(e1000_nic), qemu_find_net_clients_except will return the SLIRP client and the assertion will not fail.

So you need a separate assertion.

Paolo

#7 lore raw
Quoted 26 lines · Paolo Bonzini
Quoted 17 lines · Stefan Hajnoczi
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Paolo Bonzini
Quoted 8 lines
Quoted 8 lines

The assert can be dropped completely since the code already has an equivalent assert:

queues = qemu_find_net_clients_except(nc->name, ncs,

                                        NET_CLIENT_OPTIONS_KIND_NIC,
                                        MAX_QUEUE_NUM);

assert(queues != 0); <-- fail if type == NET_CLIENT_OPTIONS_KIND_NIC

Quoted 6 lines
Quoted 2 lines

I left it on purpose for documentation, but I'll send v2 next week that removes it.

Actually it's not the same. If you have "-netdev user,id=e1000 -device e1000,netdev=e1000" you will be able to call qemu_del_net_client on the NIC, and it will _not_ fail if the assertion is removed.

Quoted 5 lines

I don't follow.

If you call qemu_del_net_client(e1000_nic) then qemu_find_net_clients_except(nc->name, ncs, NET_CLIENT_OPTIONS_KIND_NIC, MAX_QUEUE_NUM) returns 0. This causes the assert(queues != 0) to fail.

Quoted 8 lines

NICs and other clients are in separate namespaces. So if you do

   -netdev user,id=e1000
   -device e1000,netdev=e1000,id=e1000

you have two NetClients named "e1000". If you call (by mistake) qemu_del_net_client(e1000_nic), qemu_find_net_clients_except will return the SLIRP client and the assertion will not fail.

Thanks for explaining.

Applied to my net tree:
https://github.com/stefanha/qemu/commits/net

Reviewed-by on v1 1/1
#8 lore raw
In reply to Paolo Bonzini
Quoted 34 lines · Paolo Bonzini

Using net_host_check_device is unnecessary. qemu_del_net_client asserts for the non-peer case that it can only process NIC type NetClientStates, and that assertion is valid for the peered case as well, so move it and use the same check in net_host_device_remove. host_net_remove_completion is already checking the type.

---
 net/net.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/net.c +2 -2
index 7acc162..1da612f 100644
@@ -324,6 +324,8 @@ void qemu_del_net_client(NetClientState *nc)
     NetClientState *ncs[MAX_QUEUE_NUM];
     int queues, i;
 
+    assert(nc->info->type != NET_CLIENT_OPTIONS_KIND_NIC);
+
     /* If the NetClientState belongs to a multiqueue backend, we will change all
      * other NetClientStates also.
      */
@@ -355,8 +357,6 @@ void qemu_del_net_client(NetClientState *nc)
         return;
     }
 
-    assert(nc->info->type != NET_CLIENT_OPTIONS_KIND_NIC);
-
     for (i = 0; i < queues; i++) {
         qemu_cleanup_net_client(ncs[i]);
         qemu_free_net_client(ncs[i]);

net/net.c void net_host_device_remove(Monitor *mon, const QDict *qdict) · line 998

Quoted 8 lines
net/net.c +1 -1
@@ -992,7 +992,7 @@ void net_host_device_remove(Monitor *mon, const QDict *qdict)
                      device, vlan_id);
         return;
     }
-    if (!net_host_check_device(nc->model)) {
+    if (nc->info->type == NET_CLIENT_OPTIONS_KIND_NIC) {
         error_report("invalid host network device '%s'", device);
         return;
     }