@@ -180,6 +180,7 @@ static int virtio_net_cfgwrite(void *vdev, int offset, int size,
180
180
uint32_t value );
181
181
static void virtio_net_neg_features (void * vdev , uint64_t negotiated_features );
182
182
static void virtio_net_set_status (void * vdev , uint64_t status );
183
+ static void virtio_net_teardown (void * param );
183
184
static struct vhost_net * vhost_net_init (struct virtio_base * base , int vhostfd ,
184
185
int tapfd , int vq_idx );
185
186
static int vhost_net_deinit (struct vhost_net * vhost_net );
@@ -707,7 +708,8 @@ virtio_net_tap_setup(struct virtio_net *net, char *devname)
707
708
708
709
if (vhost_fd < 0 ) {
709
710
net -> mevp = mevent_add (net -> tapfd , EVF_READ ,
710
- virtio_net_rx_callback , net , NULL , NULL );
711
+ virtio_net_rx_callback , net ,
712
+ virtio_net_teardown , net );
711
713
if (net -> mevp == NULL ) {
712
714
WPRINTF (("Could not register event\n" ));
713
715
close (net -> tapfd );
@@ -934,10 +936,8 @@ virtio_net_set_status(void *vdev, uint64_t status)
934
936
935
937
if (!net -> vhost_net -> vhost_started &&
936
938
(status & VIRTIO_CR_STATUS_DRIVER_OK )) {
937
- if (net -> mevp ) {
938
- mevent_delete (net -> mevp );
939
- net -> mevp = NULL ;
940
- }
939
+ if (net -> mevp )
940
+ mevent_disable (net -> mevp );
941
941
942
942
rc = vhost_net_start (net -> vhost_net );
943
943
if (rc < 0 ) {
@@ -952,6 +952,24 @@ virtio_net_set_status(void *vdev, uint64_t status)
952
952
}
953
953
}
954
954
955
+ static void
956
+ virtio_net_teardown (void * param )
957
+ {
958
+ struct virtio_net * net ;
959
+
960
+ net = (struct virtio_net * )param ;
961
+ if (!net )
962
+ return ;
963
+
964
+ if (net -> tapfd >= 0 ) {
965
+ close (net -> tapfd );
966
+ net -> tapfd = -1 ;
967
+ } else
968
+ fprintf (stderr , "net->tapfd is -1!\n" );
969
+
970
+ free (net );
971
+ }
972
+
955
973
static void
956
974
virtio_net_deinit (struct vmctx * ctx , struct pci_vdev * dev , char * opts )
957
975
{
@@ -969,16 +987,10 @@ virtio_net_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
969
987
net -> vhost_net = NULL ;
970
988
}
971
989
972
- if (net -> tapfd >= 0 ) {
973
- close (net -> tapfd );
974
- net -> tapfd = -1 ;
975
- } else
976
- fprintf (stderr , "net->tapfd is -1!\n" );
977
-
978
990
if (net -> mevp != NULL )
979
991
mevent_delete (net -> mevp );
980
-
981
- free (net );
992
+ else
993
+ virtio_net_teardown (net );
982
994
983
995
DPRINTF (("%s: done\n" , __func__ ));
984
996
} else
0 commit comments