From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKlmR-0001Rq-Br for qemu-devel@nongnu.org; Fri, 22 Aug 2014 06:09:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XKlmL-00062L-6D for qemu-devel@nongnu.org; Fri, 22 Aug 2014 06:09:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11695) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKlmK-00062H-Ul for qemu-devel@nongnu.org; Fri, 22 Aug 2014 06:09:05 -0400 Date: Fri, 22 Aug 2014 11:08:41 +0100 From: Stefan Hajnoczi Message-ID: <20140822100841.GB11330@stefanha-thinkpad.redhat.com> References: <1408337205-10260-1-git-send-email-zhang.zhanghailiang@huawei.com> <53F1A363.8070009@redhat.com> <53F1BA2A.8020008@huawei.com> <20140819122953.GG25538@stefanha-thinkpad.redhat.com> <53F41364.3020302@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="i9LlY+UWpKt15+FH" Content-Disposition: inline In-Reply-To: <53F41364.3020302@redhat.com> Subject: Re: [Qemu-devel] [PATCH] net: Forbid dealing with packets when VM is not running List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Wang Cc: peter.maydell@linaro.org, zhanghailiang , mst@redhat.com, luonengjun@huawei.com, qemu-devel@nongnu.org, peter.huangpeng@huawei.com --i9LlY+UWpKt15+FH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Aug 20, 2014 at 11:17:56AM +0800, Jason Wang wrote: > On 08/19/2014 08:29 PM, Stefan Hajnoczi wrote: > > On Mon, Aug 18, 2014 at 04:32:42PM +0800, zhanghailiang wrote: > >> On 2014/8/18 14:55, Jason Wang wrote: > >>> On 08/18/2014 12:46 PM, zhanghailiang wrote: > >>>> diff --git a/net/net.c b/net/net.c > >>>> index 6d930ea..21f0d48 100644 > >>>> --- a/net/net.c > >>>> +++ b/net/net.c > >>>> @@ -242,6 +242,29 @@ NetClientState *qemu_new_net_client(NetClientIn= fo *info, > >>>> return nc; > >>>> } > >>>> > >>>> +static void nic_vmstate_change_handler(void *opaque, > >>>> + int running, > >>>> + RunState state) > >>>> +{ > >>>> + NICState *nic =3D opaque; > >>>> + NetClientState *nc; > >>>> + int i, queues; > >>>> + > >>>> + if (!running) { > >>>> + return; > >>>> + } > >>>> + > >>>> + queues =3D MAX(1, nic->conf->peers.queues); > >>>> + for (i =3D 0; i< queues; i++) { > >>>> + nc =3D&nic->ncs[i]; > >>>> + if (nc->receive_disabled > >>>> + || (nc->info->can_receive&& !nc->info->can_receive(nc)= )) { > >>>> + continue; > >>>> + } > >>>> + qemu_flush_queued_packets(nc); > >>> How about simply purge the receive queue during stop? If ok, there's = no > >>> need to introduce extra vmstate change handler. > >>> > >> I don't know whether it is OK to purge the receive packages, it was > >> suggested by Stefan Hajnoczi, and i am waiting for his opinion .:) > >> > >> I think we still need the extra vmstate change handler, Without the > >> change handler, we don't know if the VM will go to stop and the time > >> when to call qemu_purge_queued_packets. > > qemu_flush_queued_packets() sets nc->received_disabled =3D 0. This may= be > > needed to get packets flowing again if ->receive() previously returned = 0. > > > > Purging the queue does not clear nc->received_disabled so it is not > > enough. >=20 > Confused. >=20 > virtio_net_receive() only returns 0 when it does not have enough rx > buffers. In this case, it just wait for the guest to refill and kick > again. Its rx kick handler will call qemu_flush_queued_packets() to > clear nc->received_disabled. So does usbnet and others. >=20 > If nic_received_disabled is 1, it means the no available rx buffer. We > need wait guest to do the processing and refilling. Then why need clear > it after vm was started? I took a look at other emulated NICs, they don't use return 0 in ->receive(). I think you are right, we don't need to worry about flushing. Stefan --i9LlY+UWpKt15+FH Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJT9xapAAoJEJykq7OBq3PIRH0H/2cHs1SuOEizmV3ksxbNjGMn ojQyQO/EtOSIhcvOfYh4oZXAyVwbHRu2NopstJVqNkgAxhA8ckRAPOr8nCrlnMNE Nr8oU1kcAtpe27xAekgLv8FjGJu9aoxQdAw3wIdsH3e9Ep9P3wX3j09VI1UIkU+U QK/CBzCssISu9CaM41MJgYpxXcLM5HkyRnTcx/bibOt+RxBD5GmjW3rUOH30BL20 vKVyWfNJXag1tfi5YAxdFHFU2eFSaR75NmYt0IMyRWcjmVdykIRD5Ze6Hl/7ISk2 xYR+3VUt1a4QAMZnb1OVhbvomWeuPu+SmEZzE8TOohyZadgcib2G/jH5+MCvYQI= =pEvZ -----END PGP SIGNATURE----- --i9LlY+UWpKt15+FH--